monster010

CC - DebiReactorDisplay

Apr 20th, 2016
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.20 KB | None | 0 0
  1. -- DebiReactorDisplay - (c) monster010
  2.  
  3.  
  4.  
  5. ----------------------------------
  6. ----- DONT CHANGE UNDER THIS -----
  7. ----------------------------------
  8. os.loadAPI("/debireactordisplay/api/config")
  9. os.loadAPI("/debireactordisplay/api/monster010")
  10. os.loadAPI("/debireactordisplay/api/bars")
  11. os.loadAPI("/debireactordisplay/api/lbl")
  12.  
  13.  
  14.  
  15. local software = "DebiReactorDisplay"
  16. local monitor
  17. local reactor
  18. local cfg = {}
  19. local labels = {
  20.     lbl1 = {text = "Rodstatus", x = 16, y = 3},
  21.     lbl2 = {text = "Casing", x = 2, y = 25},
  22.     lbl3 = {text = "Core", x = 10, y = 25},
  23. }
  24.  
  25. local rlabels = {
  26.     rod1 = {id = 0, text = "Rod 1: ", x = 27, y = 6, stxt = 0},
  27.     rod2 = {id = 1, text = "Rod 2: ", x = 27, y = 8, stxt = 0},
  28.     rod3 = {id = 2, text = "Rod 3: ", x = 27, y = 10, stxt = 0},
  29.     rod4 = {id = 3, text = "Rod 4: ", x = 27, y = 12, stxt = 0},
  30.     rod5 = {id = 4, text = "Rod 5: ", x = 27, y = 14, stxt = 0},
  31. }
  32. local barTemp = {
  33.     temp1 = {what = "temp", typ = "ver", maxVal = 3000, curVal = 3000, x = 4, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lightBlue},
  34.     temp2 = {what = "temp", typ = "ver", maxVal = 3000, curVal = 3000, x = 11, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lightBlue},
  35. }
  36.  
  37. local barRods = {
  38.     rod1 = {id = 0, what = "rod", typ = "ver", maxVal = 100, curVal = 100, x = 16, y = 5, w = 0, h = 10, clfill = colors.gray, clempty = colors.yellow},
  39.     rod2 = {id = 1, what = "rod", typ = "ver", maxVal = 100, curVal = 100, x = 18, y = 5, w = 0, h = 10, clfill = colors.gray, clempty = colors.yellow},
  40.     rod3 = {id = 2, what = "rod", typ = "ver", maxVal = 100, curVal = 100, x = 20, y = 5, w = 0, h = 10, clfill = colors.gray, clempty = colors.yellow},
  41.     rod4 = {id = 3, what = "rod", typ = "ver", maxVal = 100, curVal = 100, x = 22, y = 5, w = 0, h = 10, clfill = colors.gray, clempty = colors.yellow},
  42.     rod5 = {id = 4, what = "rod", typ = "ver", maxVal = 100, curVal = 100, x = 24, y = 5, w = 0, h = 10, clfill = colors.gray, clempty = colors.yellow},
  43. }
  44.  
  45.  
  46.  
  47. function connect_rc()
  48.     reactor = peripheral.wrap("BigReactors-Reactor_0")
  49. end
  50.  
  51. function addBars()
  52.     for name, data in pairs(barTemp) do
  53.         bars.add(name, data["typ"], data["maxVal"], data["curVal"], data["x"], data["y"], data["w"], data["h"], data["clfill"], data["clempty"])
  54.     end
  55.  
  56.     for name, data in pairs(barRods) do
  57.         bars.add(name, data["typ"], data["maxVal"], data["curVal"], data["x"], data["y"], data["w"], data["h"], data["clfill"], data["clempty"])
  58.     end
  59.  
  60.     bars.screen()
  61. end
  62.  
  63. function addLabels()
  64.     for name, data in pairs(labels) do
  65.         lbl.add(name, data["text"], data["x"], data["y"])
  66.     end
  67.  
  68.     for name, data in pairs(rlabels) do
  69.         lbl.add(name, data["text"], data["x"], data["y"], data["stxt"])
  70.     end
  71.  
  72.     lbl.screen()
  73. end
  74.  
  75. function updateRodLabels()
  76.     local mytimer = os.startTimer(1)
  77.  
  78.     while true do
  79.         local event, args = os.pullEvent()
  80.  
  81.         if event == "timer" and args == mytimer then
  82.             for name, data in pairs(rlabels) do
  83.                 local num = monster010.round(100 - reactor.getControlRodLevel(data["id"]))
  84.  
  85.                 if string.len(num) == 3 then
  86.                     num = num
  87.                 elseif string.len(num) == 2 then
  88.                     num = " "..num
  89.                 elseif string.len(num) == 1 then
  90.                     num = "  "..num
  91.                 end
  92.  
  93.                 lbl.set(name, "stxt", num.."%")
  94.             end
  95.         end
  96.  
  97.         lbl.screen()
  98.         break
  99.     end
  100. end
  101.  
  102. function updateReactorState()
  103.     local mytimer = os.startTimer(1)
  104.  
  105.     while true do
  106.         local event, args = os.pullEvent()
  107.  
  108.         if event == "timer" and args == mytimer then
  109.             for name, data in pairs(barTemp) do
  110.                 if reactor.getActive() then
  111.                     bars.set(name, "clfill", colors.gray)
  112.                     bars.set(name, "clempty", colors.lightBlue)
  113.                 else
  114.                     bars.set(name, "clfill", colors.red)
  115.                     bars.set(name, "clempty", colors.red)
  116.                 end
  117.             end
  118.  
  119.             for name, data in pairs(barRods) do
  120.                 if reactor.getActive() then
  121.                     bars.set(name, "clfill", colors.gray)
  122.                     bars.set(name, "clempty", colors.yellow)
  123.                 else
  124.                     bars.set(name, "clfill", colors.red)
  125.                     bars.set(name, "clempty", colors.red)
  126.                 end
  127.             end
  128.  
  129.             bars.screen()
  130.             break
  131.         end
  132.     end
  133. end
  134.  
  135. function updateTempBars()
  136.     local mytimer = os.startTimer(1)
  137.  
  138.     while true do
  139.         local event, args = os.pullEvent()
  140.  
  141.         if event == "timer" and args == mytimer then
  142.             bars.set("temp1", "cur", monster010.round(3000 - reactor.getCasingTemperature()))
  143.             bars.set("temp2", "cur", monster010.round(3000 - reactor.getFuelTemperature()))
  144.  
  145.             bars.screen()
  146.             break
  147.         end
  148.     end
  149. end
  150.  
  151. function updateRodBars()
  152.     local mytimer = os.startTimer(1)
  153.  
  154.     while true do
  155.         local event, args = os.pullEvent()
  156.  
  157.         if event == "timer" and args == mytimer then
  158.             for name, data in pairs(barRods) do
  159.                 if data["what"] == "rod" then
  160.                     bars.set(name, "cur", reactor.getControlRodLevel(data["id"]) + 1)
  161.                 end
  162.             end
  163.  
  164.             bars.screen()
  165.             break
  166.         end
  167.     end
  168. end
  169.  
  170.  
  171.  
  172. config.load("/debireactordisplay/cfg")
  173. cfg = config.getConfig()
  174.  
  175. monster010.construct(cfg["monSide"], software)
  176. monster010.startUp()
  177. monster010.heading(software)
  178. monitor = monster010.getMonitor()
  179. bars.construct(monitor)
  180. lbl.construct(monitor)
  181.  
  182. connect_rc()
  183. addBars()
  184. addLabels()
  185.  
  186. monster010.startUpDone()
  187.  
  188.  
  189.  
  190. while true do
  191.     updateReactorState()
  192.     updateTempBars()
  193.     updateRodBars()
  194.     updateRodLabels()
  195. end
Advertisement
Add Comment
Please, Sign In to add comment