svdragster

PSAV

Mar 16th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. function fileTableGet(path)
  2.     if fs.exists(path) then
  3.         local file = io.open(path, "r")
  4.         local lines = {}
  5.         local i = 1
  6.         local line = file:read("*l")
  7.         while line ~= nil do
  8.             lines[i] = line
  9.             line = file:read("*l")
  10.             i = i + 1
  11.         end
  12.         file:close()
  13.         return lines
  14.     end
  15.     return {}
  16. end
  17.  
  18. function fileLineGet(path, line)
  19.     if fs.exists(path) then
  20.         local lines = fileTableGet(path)
  21.         return lines[line]
  22.     end
  23.     return ""
  24. end
  25.  
  26. local split = function(str, pat) local t = {} local fpat = "(.-)"..pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
  27.  
  28. local lines = fileTableGet("/PSAV/reports/logs.txt", "r")
  29. logfilename = lines[#lines]
  30.  
  31. --Für den Hintergrund
  32.  
  33. scantext = [[
  34.   --- ---  --  -    -
  35.   |   |   |  | |\   |
  36.   --- |   |--| | \  |
  37.     | |   |  | |  \ |
  38.   --- --- -  - -   --
  39. ]]
  40.  
  41. function bg(pcount)
  42.     term.setBackgroundColour( colors.green )
  43.     term.clear()
  44.     term.setTextColour(colors.cyan)
  45.     term.setCursorPos(2,2)
  46.     print("PSAV - BETA")
  47.     term.setCursorPos(51,1)
  48.     term.setBackgroundColour( colors.red )
  49.     print("x")
  50.     term.setBackgroundColour( colors.green )
  51.     term.setCursorPos(2,5)
  52.     term.setTextColour(colors.yellow)
  53.     print(scantext)
  54.     term.setCursorPos(37,2)
  55.     if pcount == 0 then
  56.       term.setTextColour(colors.lime)
  57.       print("Safe!")
  58.       term.setTextColour(colors.white)
  59.     else
  60.     term.setTextColour(colors.orange)
  61.     write("Problems!\(")
  62.     write(problemcount)
  63.     write("\)")
  64.      
  65.     end
  66.     term.setTextColour(colors.cyan)
  67.     term.setCursorPos(1,19)
  68.     write("Settings")
  69.    
  70. end
  71.  
  72. os.loadAPI("PSAV/api/border")
  73. term.setCursorPos(49,1)
  74. print("x")
  75.  
  76. -- problem/infektion
  77.  
  78. problemcount = fileLineGet("/PSAV/data/problem", 4)
  79.  
  80. term.setCursorPos(3,2)
  81.  
  82. problemcount = 0
  83. linecount = 0
  84. okay = false
  85. line = "blah"
  86. while line ~= nil do
  87.   line = fileLineGet(logfilename, linecount + 1)
  88.   if line ~= nil then
  89.     linecount = linecount + 1
  90.     res = split(line, "\t")
  91.     if res[3] == "problem" then
  92.       problemcount = problemcount + 1
  93.     end
  94.   end
  95. end
  96.  
  97. --klicken
  98.  
  99. geklickt = false
  100. fileMenu = {"open", "save as", "exit"}
  101.  
  102. --local Menu = {fileMenu, EditMenu}
  103.  
  104. bg(problemcount)
  105.  
  106. while geklickt == false do
  107.   event, knopf, x, y = os.pullEvent("mouse_click")
  108. --Klicken auf >Probleme<
  109.   if (x >= 37) and (x < 51) and (y == 2) then
  110.     geklickt = true
  111.       shell.run("/PSAV/details")
  112.   end
  113.  
  114. --Klicken auf PSAV
  115.   if (x >= 2) and (x < 5) and (y == 2) then
  116.  
  117.   end
  118.  
  119. --Klicken auf X / Beenden
  120.   if (x  == 51) and (y == 1) then
  121.     geklickt = true
  122.     term.setBackgroundColour( colors.black )
  123.     term.clear()
  124.     term.setCursorPos(1,1)
  125.     shell.run()
  126.   end
  127.  
  128. --Klicken auf SCAN
  129.   if (x >= 3) and (x <= 21) and (y >= 6) and (y <= 10) then
  130.     shell.run("/PSAV/scan")
  131.     geklickt = true
  132.   end
  133.  
  134. --Klicken auf Settings
  135.   if (x >= 1) and (x <= 8) and (y == 19) then
  136.     shell.run("/PSAV/settings")
  137.     geklickt = true
  138.   end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment