Advertisement
Fabrimat

TDS Train

Jul 9th, 2021 (edited)
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --VARIABILI DA POPOLARE
  2.  
  3. apiVersion = "1.0"
  4. progVersion = "v1.0"
  5. defconLvl = "Defcon 5"
  6. isEndorOn = false
  7. lockTrain = false
  8. sleep = 60
  9.  
  10. shell.run("pastebin get ADaQ4War json")
  11. os.loadAPI("json")
  12.  
  13. function updateVars()
  14.     rest = http.get("http://rgbvm.fabrimat.me/~fabrimat/tds.php")
  15.     s = rest.readAll()
  16.     t = json.decode(s)
  17.    
  18.     defconLvl = t.defcon
  19.     isEndorOn = t.endor
  20.     lockTrain = t.lock_train
  21.     sleep = t.next_sleep
  22. end
  23.  
  24. maxw, maxh = term.getSize()
  25. halfw = math.floor(maxw/2)
  26. halfh = math.floor(maxh/2)
  27.  
  28. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  29. local function drawPixelInternal(xPos, yPos)
  30.     term.setCursorPos(xPos, yPos)
  31.     term.write(" ")
  32. end
  33.  
  34. local tColourLookup = {}
  35. for n = 1, 16 do
  36.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  37. end
  38.  
  39. function drawFilledBox(startX, startY, endX, endY, nColour)
  40.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  41.         "number" or type(endY) ~= "number" or
  42.         (nColour ~= nil and type(nColour) ~= "number") then
  43.         error("Expected startX, startY, endX, endY, colour", 2)
  44.     end
  45.  
  46.     startX = math.floor(startX)
  47.     startY = math.floor(startY)
  48.     endX = math.floor(endX)
  49.     endY = math.floor(endY)
  50.  
  51.     if nColour then term.setBackgroundColor(nColour) end
  52.     if startX == endX and startY == endY then
  53.         drawPixelInternal(startX, startY)
  54.         return
  55.     end
  56.  
  57.     local minX = math.min(startX, endX)
  58.     if minX == startX then
  59.         minY = startY
  60.         maxw = endX
  61.         maxh = endY
  62.     else
  63.         minY = endY
  64.         maxw = startX
  65.         maxh = startY
  66.     end
  67.  
  68.     for x = minX, maxw do for y = minY, maxh do drawPixelInternal(x, y) end end
  69. end
  70.  
  71. function colore(sfumatura) term.setTextColour(sfumatura) end
  72.  
  73. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  74.  
  75. function fineColore() term.setTextColour(colours.white) end
  76.  
  77. function fineSfondo() term.setBackgroundColour(colours.black) end
  78.  
  79. function titolo(testo)
  80.     maxw, maxh = term.getSize()
  81.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  82.     term.setCursorPos((maxw - #testo) / 2, 1)
  83.     colore(colors.black)
  84.     term.write(testo)
  85. end
  86.  
  87. function clear()
  88.     term.clear()
  89.     term.setCursorPos(1,1)
  90. end
  91.  
  92. function printCentered(text)
  93.     local curx, cury = term.getCursorPos()
  94.     local maxw, maxh = term.getSize()
  95.     term.setCursorPos((maxw - #text) / 2, cury)
  96.     term.write(text)
  97.     term.setCursorPos(curx, cury + 1)    
  98. end
  99.  
  100.  
  101. function drawMain()
  102.     titolo("Tyrian Defense System")
  103.     if(lockTrain) then
  104.         drawFilledBox(halfw - 9, halfh, halfw + 9, halfh + 2, colors.lime)
  105.         term.setCursorPos(1, halfh+1)
  106.         printCentered("Richiesta accesso")
  107.     end
  108.     term.setBackgroundColor(colors.black)
  109.     term.setTextColor(colors.white)
  110.  
  111.     term.setCursorPos(1, halfh/2)
  112.  
  113.     local defconLvls = {}
  114.     defconLvls["Defcon 1"] = colors.red
  115.     defconLvls["Defcon 2"] = colors.yellow
  116.     defconLvls["Defcon 3"] = colors.lime
  117.     defconLvls["Defcon 4"] = colors.cyan
  118.     defconLvls["Defcon 5"] = colors.purple
  119.     colore(defconLvls[defconLvl])
  120.     printCentered(defconLvl)
  121.  
  122.     term.setCursorPos(1, halfh/2 + 2)
  123.     colore(colors.white)
  124.     if isEndorOn == false then
  125.         printCentered("ENDOR non attivo")
  126.     else
  127.         printCentered("ENDOR attivo")
  128.     end
  129.  
  130.     maxw, maxh = term.getSize()
  131.     local versionString = "(C) Proclus & Albannach 2021 - " .. progVersion .. " - API " .. apiVersion .. " "
  132.     term.setCursorPos(1, maxh)
  133.     printCentered(versionString)
  134. end
  135.  
  136. function drawMessage(message, background, text)
  137.     clear()
  138.     titolo("Tyrian Defense System")
  139.     term.setBackgroundColor(background)
  140.     term.setTextColor(text)
  141.    
  142.     term.setCursorPos(1, halfh)
  143.    
  144.     printCentered(message)
  145.  
  146.     maxw, maxh = term.getSize()
  147.     term.setBackgroundColor(colors.black)
  148.     term.setTextColor(colors.white)
  149.     local versionString = "(C) Proclus & Albannach 2021 - " .. progVersion .. " - API " .. apiVersion .. " "
  150.     term.setCursorPos(1, maxh)
  151.     printCentered(versionString)
  152. end
  153.  
  154.  
  155. function requestAuthorization()
  156.     drawMessage("Richiesta accesso in corso", colors.black, colors.white)
  157.     os.sleep(0.5)
  158.     drawMessage("Richiesta accesso in corso.", colors.black, colors.white)
  159.     os.sleep(0.5)
  160.     drawMessage("Richiesta accesso in corso..", colors.black, colors.white)
  161.     os.sleep(0.5)
  162.     drawMessage("Richiesta accesso in corso...", colors.black, colors.white)
  163.     os.sleep(0.5)
  164.     if(isEndorOn) then
  165.         denyAuth()
  166.     else
  167.         allowAuth()
  168.     end
  169. end
  170.  
  171. function denyAuth()
  172.     drawMessage("Accesso negato", colors.black, colors.red)
  173.     os.sleep(10)
  174. end
  175.  
  176. function allowAuth()
  177.     drawMessage("Accesso consentito", colors.black, colors.lime)
  178.     rs.setOutput("back", false)
  179.     os.sleep(30)
  180. end
  181.  
  182. clear()
  183. updateVars()
  184.  
  185. while true do
  186.     if(lockTrain) then
  187.         rs.setOutput("top", true)
  188.         rs.setOutput("back", true)
  189.     else
  190.         rs.setOutput("top", false)
  191.         rs.setOutput("back", false)
  192.     end
  193.    
  194.     os.startTimer(sleep)
  195.    
  196.     clear()
  197.     drawMain()
  198.     event, button, x, y = os.pullEvent()
  199.     term.setCursorPos(1, 17)
  200.     if(event == 'mouse_click' and lockTrain) then
  201.         if x >= (halfw - 9) and x <= (halfw + 9) and y <= (halfh + 2) and y >= (halfh) then
  202.             requestAuthorization()
  203.         end
  204.     elseif(event == 'timer') then
  205.         updateVars()
  206.     end
  207. end
  208.  
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement