ALpha_R

tbScreen.lua

Dec 7th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6. -------------------------------------------------//Initilisation
  7.  
  8. local monitor = peripheral.wrap("right")
  9. monitor.setTextScale(1)
  10. term.redirect(monitor)
  11.  
  12. local ptc = "reactorNetwork"
  13. local hostname = "tbScreen"
  14.  
  15. rednet.open("top")
  16. rednet.host(ptc, hostname)
  17.  
  18. local info = {}
  19. local color = {}
  20.  
  21. local res
  22.  
  23. print("Connection ...")
  24.  
  25. -------------------------------------------------//getInfo()
  26.  
  27. function getInfo()
  28.     res, info = rednet.receive(ptc, 10)
  29. end
  30.  
  31. -------------------------------------------------//serialize()
  32.  
  33. function serialize()
  34.     tb1EnergyPerc = ((info.tb1rotorSpeed/1000000)*47)
  35.     tb1RpmPerc  = ((info.tb1rotorSpeed/2000)*47)
  36.  
  37.     tb2EnergyPerc = ((info.tb2rotorSpeed/1000000)*47)
  38.     tb2RpmPerc  = ((info.tb2rotorSpeed/2000)*47)
  39.  
  40.     tb3EnergyPerc = ((info.tb3rotorSpeed/1000000)*47)
  41.     tb3RpmPerc  = ((info.tb3rotorSpeed/2000)*47)
  42. end
  43.  
  44. -------------------------------------------------//affichage()
  45.  
  46. function affichage()
  47.     term.setBackgroundColor(colors.black)
  48.     term.clear()
  49.  
  50.     term.setCursorPos(21, 2)
  51.     term.write("TURBINES")
  52.  
  53.     --titre ecran
  54.  
  55.     color[1] = (info.tb1Active and colors.green or colors.red)
  56.     color[2] = (info.tb2Active and colors.green or colors.red)
  57.     color[3] = (info.tb3Active and colors.green or colors.red)
  58.  
  59.     paintutils.drawFilledBox(1, 6, 50, 13, color[1])
  60.     paintutils.drawFilledBox(1, 16, 50, 23, color[2])
  61.     paintutils.drawFilledBox(1, 26, 50, 33, color[3])
  62.  
  63.     term.setBackgroundColor(colors.black)
  64.     term.setCursorPos(2, 5)
  65.     term.write("Turbine 1  "..(info.tb1Active and "[ON]" or "[OFF]"))
  66.     term.setCursorPos(30, 5)
  67.     term.write("RF/t  :  "..math.floor(info.tb1energyLastTick))
  68.     term.setBackgroundColor(color[1])
  69.     term.setCursorPos(2, 7)
  70.     term.write("RPM                 "..math.floor(info.tb1rotorSpeed))
  71.     term.setCursorPos(2, 10)
  72.     term.write("Energy Stored       "..math.floor(info.tb1energyStored))
  73.     paintutils.drawFilledBox(2, 8, 2 + tb1RpmPerc, 9, colors.yellow)
  74.     paintutils.drawFilledBox(2, 11, 2 + tb1EnergyPerc, 12, colors.yellow)
  75.  
  76.     term.setBackgroundColor(colors.black)
  77.     term.setCursorPos(2, 15)
  78.     term.write("Turbine 2  "..(info.tb2Active and "[ON]" or "[OFF]"))
  79.     term.setCursorPos(30, 15)
  80.     term.write("RF/t  :  "..math.floor(info.tb2energyLastTick))
  81.     term.setBackgroundColor(color[2])
  82.     term.setCursorPos(2, 17)
  83.     term.write("RPM                 "..math.floor(info.tb2rotorSpeed))
  84.     term.setCursorPos(2, 20)
  85.     term.write("Energy Stored       "..math.floor(info.tb2energyStored))
  86.     paintutils.drawFilledBox(2, 18, 2 + tb2RpmPerc, 19, colors.yellow)
  87.     paintutils.drawFilledBox(2, 21, 2 + tb2EnergyPerc, 22, colors.yellow)
  88.  
  89.     term.setBackgroundColor(colors.black)
  90.     term.setCursorPos(2, 25)
  91.     term.write("Turbine 3  "..(info.tb3Active and "[ON]" or "[OFF]"))
  92.     term.setCursorPos(30, 25)
  93.     term.write("RF/t  :  "..math.floor(info.tb3energyLastTick))
  94.     term.setBackgroundColor(color[3])
  95.     term.setCursorPos(2, 27)
  96.     term.write("RPM                 "..math.floor(info.tb3rotorSpeed))
  97.     term.setCursorPos(2, 30)
  98.     term.write("Energy Stored       "..math.floor(info.tb3energyStored))
  99.     paintutils.drawFilledBox(2, 28, 2 + tb3RpmPerc, 29, colors.yellow)
  100.     paintutils.drawFilledBox(2, 31, 2 + tb3EnergyPerc, 32, colors.yellow)
  101. end
  102.  
  103. -------------------------------------------------//Main Script
  104.  
  105. while(true)do
  106.     getInfo()
  107.     serialize()
  108.     affichage()
  109. end
Advertisement
Add Comment
Please, Sign In to add comment