Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. local component = require("component")
  2. local computer  = require("computer")
  3. local term      = require("term")
  4. local event     = require("event")
  5. local thread    = require("thread")
  6. local os        = require("os")
  7.  
  8. local sg        = component.stargate
  9. local gpu       = component.gpu
  10.  
  11. local w,h       = gpu.getResolution()
  12.  
  13. local version   = "0.1"
  14.  
  15. local locAddr   = sg.localAddress()
  16.  
  17. local console   = {}
  18.  
  19. gpu.setDepth(gpu.maxDepth())
  20.  
  21. function strChk(string1,string2)
  22.   return string.find(string1,string2)
  23. end
  24.  
  25. function bgClr()
  26.   gpu.setBackground(0x0F0F0F)
  27. end
  28.  
  29. function bgCol()
  30.   gpu.setBackground(0x696969)
  31. end
  32.  
  33. function lineReset(y)
  34.   bgClr()
  35.   gpu.fill(0,0,w,y," ")
  36. end
  37.  
  38. function baseDraw()
  39. --Variables
  40.   local pcEn    = tostring(math.floor(computer.energy())).." RF"
  41.   local sgEn    = tostring(math.floor(sg.energyAvailable()*80)).." RF"
  42.   local sgState,sgEng,sgDir = sg.stargateState()
  43.   local remAddr = sg.remoteAddress()
  44.   local sgIris  = sg.irisState()
  45. --Draw Start
  46.   bgCol()
  47.  
  48. --Lines
  49.   gpu.fill(1,1,w,1," ")
  50.   gpu.fill(1,h,w,1," ")
  51.   gpu.fill(5,5,w-8,1," ")
  52.  
  53.   gpu.fill(1,14,w,1," ")
  54.   gpu.fill(1,16,w,1," ")
  55.  
  56. --OS info
  57.   gpu.set(1,1,"Stargate Control V."..version)
  58.   gpu.set(w-14,1,"Power: "..pcEn)
  59.   gpu.set(w-10,h,os.date("%X%p"))
  60.   gpu.set(3,14,"Command Line")
  61.   gpu.set(3,16,"Information Console")
  62.  
  63. --Console
  64.   if #console ~= 0 then
  65.     bgClr()
  66.     gpu.fill(1,17,w,8," ")
  67.     for i=1,#console do
  68.       gpu.set(1,(h)-i,console[i])
  69.     end
  70.     bgCol()
  71.   end
  72.  
  73. --SG info
  74.   gpu.setBackground(0x4B4B4B)
  75.   gpu.fill(5,6,w-8,5," ")
  76.   gpu.set(10,6,"Stargate Status: "..sgState)
  77.   gpu.set(10,10,"Iris Status: "..sgIris)
  78.  
  79.   if sgState ~= "Idle" then
  80.     gpu.set(12,7,"Direction: "..sgDir)
  81.     gpu.set(12,8,"Address:   "..remAddr)
  82.     gpu.set(12,9,"Chervon:   "..sgEng)
  83.   end
  84.   bgCol()
  85.   gpu.fill(5,5,w-8,1,"=")
  86.   gpu.set(6,5,"[Stargate Info]")
  87.   gpu.set(23,5,"[Local: "..locAddr.."]")
  88.   gpu.set(w-30,5,"[Energy: "..sgEn.."]")
  89.  
  90. --Draw End
  91.   bgClr()
  92.   os.sleep(1)
  93. end
  94.  
  95. t = thread.create(function()
  96.   term.clear()
  97.   term.setCursor(1,3)
  98.  
  99.   while true do
  100.     baseDraw()
  101.   end
  102. end)
  103. while true do
  104.   if #console >= 9 then
  105.     table.remove(console,9)
  106.   end
  107.   term.setCursor(1,15)
  108.   term.clearLine()
  109.   input = io.read()
  110.   term.setCursor(1,15)
  111.   if input == "dc" then
  112.      sg.disconnect()
  113.      table.insert(console,1,os.date("%X%p: ").."Stargate disconnected")
  114.   elseif input == "dial" then
  115.     term.write("Enter address: ")
  116.     local to = io.read()
  117.     sg.dial(to)
  118.     table.insert(console,1,os.date("%X%p: ").."Stargate Dialed to "..to)
  119.   elseif input == "iris" then
  120.     if sg.irisState() == "Open" then
  121.       sg.closeIris()
  122.       table.insert(console,1,os.date("%X%p: ").."Iris Closed")
  123.     else
  124.       sg.openIris()
  125.       table.insert(console,1,os.date("%X%p: ").."Iris Opened")
  126.     end
  127.   elseif input == "exit" then
  128.     term.write("Are you sure? Y/N ")
  129.     if io.read() == "y" then break end
  130.   end
  131. end
  132.  
  133.  
  134. t:kill()
  135. term.clear()
  136. print("Good night!")
  137. os.sleep(3)
  138. term.clear()
  139. os.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement