Advertisement
ben_mkiv

mekanism-hud.lua

Oct 29th, 2017
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.51 KB | None | 0 0
  1. component = require("component")
  2. event = require("event")
  3. serialization = require("serialization")
  4. sides = require("sides")
  5. tankDeuterium = false
  6. tankTritium = false
  7. laserAmplifier = false
  8. laIgnitionEnergy = 1250000
  9. redstone = false
  10. redstoneSide = false
  11. inductionMatrix = false
  12. glassesTerminal = false
  13. reactor = false
  14. offsetX = 0
  15. offsetY = 0
  16. buttons = {}
  17.  
  18. maxCaseHeat = 0
  19. maxPlasmaHeat = 0
  20. maxEnergyStored = 0
  21. maxEnergy = 0
  22. laMaxEnergyStored = 0
  23. imMaxStorage = 0
  24.  
  25. statusbox = {}
  26. statusbox.widgets = {}
  27.  
  28. injectionRateWidget = {}
  29.  
  30. function initComponents()
  31.     for address,type in pairs(component.list("reactor_logic_adapter")) do
  32.         if reactor == false then
  33.             print("found reactor "..address)
  34.             reactor = component.proxy(address)
  35.         else
  36.             print("found another reactor ("..address.."). first one will be used.")
  37.         end
  38.     end
  39.  
  40.     for address,type in pairs(component.list("glasses")) do
  41.         if glassesTerminal == false then
  42.             print("found glasses Terminal "..address)
  43.             glassesTerminal = component.proxy(address)
  44.         else
  45.             print("found another glasses Terminal ("..address.."). first one will be used.")
  46.         end
  47.     end
  48.  
  49.     for address,type in pairs(component.list("_gas_tank")) do checkTank(address); os.sleep(0); end
  50.  
  51.     for address,type in pairs(component.list("laser_amplifier")) do
  52.         if laserAmplifier == false then
  53.             print("found laser amplifier "..address)
  54.             laserAmplifier = component.proxy(address)
  55.         else
  56.             print("found another laser amplifier ("..address.."). first one will be used.")
  57.         end
  58.     end
  59.  
  60.     for address,type in pairs(component.list("redstone")) do
  61.         if redstone == false then
  62.             print("found redstone interface "..address)
  63.             redstone = component.proxy(address)
  64.         else
  65.             print("found another redstone interface ("..address.."). first one will be used.")
  66.         end
  67.     end
  68.  
  69.     for address,type in pairs(component.list("induction_matrix")) do
  70.         if inductionMatrix == false then
  71.             print("found induction matrix "..address)
  72.             inductionMatrix = component.proxy(address)
  73.         else
  74.             print("found another induction matrix ("..address.."). first one will be used.")
  75.         end
  76.     end
  77. end
  78.  
  79. function val2perc(val, maxVal)
  80.     if(maxVal == 0) then return 0; end
  81.     return (math.floor(0.5 + ((val/maxVal) * 100)*10)/10)
  82. end
  83.  
  84. function readTankFull(address)
  85.     local tank = component.proxy(address)
  86.     return { gas = tank.getGas(), amount = tank.getStoredGas(), maxAmount = tank.getMaxGas(), tankType = tank.type }
  87. end
  88.  
  89. function readTankStorage(tank)
  90.     return { amount = tank.getStoredGas(), maxAmount = tank.getMaxGas() }
  91. end
  92.  
  93. function checkTank(address)
  94.     local tankData = readTankFull(address)
  95.     if tankData.gas == nil then tankData.gas = "unknown"; end
  96.     print("# found ".. tankData.tankType .. " with " .. tankData.amount .. "/" .. tankData.maxAmount .. " of " .. tankData.gas)
  97.     if string.match(tankData.gas, "deuterium") then
  98.         print(" ... adding tank with address " .. address)
  99.         if tankDeuterium == false then
  100.             tankDeuterium = component.proxy(address)
  101.         else
  102.             print("found more than one Deuterium Gas Tank, using first one found")
  103.             print("set a address in the script to use a user defined tank")
  104.         end
  105.     elseif string.match(tankData.gas, "tritium") then
  106.         print(" ... adding tank")
  107.         if tankTritium == false then
  108.             tankTritium = component.proxy(address)
  109.         else
  110.             print("found more than one Tritium Gas Tank, using first one found")
  111.             print("set a address in the script to use a user defined tank")
  112.         end
  113.     end
  114. end
  115.  
  116. function addInfoHUD(x, y, w, h, label)
  117.     local boxPadding = 3
  118.     local element = {}
  119.     b = glassesTerminal.addBox2D()
  120.     b.addTranslation(x + offsetX, y + offsetY, 0)
  121.     b.setSize(w, h)
  122.     b.addColor(0, 0, 0, 0.5)
  123.     b.addColor(0.05, 0.05, 0.05, 0.5)
  124.     table.insert(element, b)
  125.     s = glassesTerminal.addBox2D()
  126.     s.addTranslation(x + offsetX + boxPadding, y + offsetY + boxPadding, 0)
  127.     s.setSize(w-(2*boxPadding), h-(2*boxPadding))
  128.     s.addColor(0, 0.5, 0, 0.5)
  129.     s.addColor(0.05, 1, 0.05, 0.5)
  130.     table.insert(element, s)
  131.     t = glassesTerminal.addText2D()
  132.     t.addTranslation(x + offsetX + 7, y + offsetY + 7, 0)
  133.     t.setText(label)
  134.     t.addColor(1, 1, 1, 0.7)   
  135.     table.insert(element, t)
  136.     return element
  137. end
  138.  
  139. function addReactorHUD(x, y, w, h, label)
  140.     local boxPadding = 3
  141.     local element = {} 
  142.     b = glassesTerminal.addBox2D()
  143.     b.addTranslation(x + offsetX, y + offsetY, 0)
  144.     b.setSize(w, h)
  145.     b.addColor(0, 0, 0, 0.5)
  146.     b.addColor(0.05, 0.05, 0.05, 0.5)  
  147.     table.insert(element, b)   
  148.     t = glassesTerminal.addText2D()
  149.     t.addTranslation(x + offsetX + 7, y + offsetY + 7, 0)
  150.     t.setText(label)
  151.     t.addColor(1, 1, 1, 0.7)   
  152.     table.insert(element, t)   
  153.     return element
  154. end
  155.  
  156. function MJ2RF(mj)
  157.     if type(mj) == "string" then
  158.         return mj
  159.     end
  160.     return math.ceil(mj * 0.4)
  161. end
  162.  
  163. function formatNumber(rf)
  164.     rf = (math.floor(0.5 + (rf*100)) / 100)
  165.     if rf >= 1000000000000 then
  166.         rf = (math.floor(0.5 + (rf*10/1000000000000)/10)) .. "T"
  167.     elseif rf >= 1000000000 then
  168.         rf = (math.floor(0.5 + (rf*10/1000000000)/10)) .. "G"
  169.     elseif rf >= 1000000 then
  170.         rf = (math.floor(0.5 + (rf*10/1000000)/10)) .. "M"
  171.     elseif rf >= 1000 then
  172.         rf = math.floor(0.5 + (rf/1000)).."k"
  173.     end
  174.     return rf
  175. end
  176.  
  177. function perc2color(p)
  178.     return { red = (1 * (1 - (p/100))), green = (1 * (p/100)), blue = 0 }
  179. end
  180.  
  181. function bool2color(bool)
  182.     if bool == true then
  183.         return { red = 0.2, green = 1, blue = 0.2 }
  184.     else
  185.         return { red = 1, green = 0.2, blue = 0.2 }
  186.     end        
  187. end
  188.  
  189. function addInfo(label, value, x, y)
  190.     info = {}
  191.     info.label = label
  192.     info.statusBar = false
  193.     info.r = 1
  194.     info.g = 1
  195.     info.b = 1
  196.     if type(value) == "boolean" then
  197.         color = bool2color(value)
  198.         info.r = color.red
  199.         info.g = color.green
  200.         info.b = color.blue
  201.         if value == true then
  202.             value = "true"
  203.         else
  204.             value = "false"
  205.         end        
  206.     elseif type(value) == "number" then
  207.         value = ""..value
  208.     end
  209.     info.widgets = {}
  210.     os.sleep(0)
  211.     info.widgets.key = glassesTerminal.addText2D()
  212.     info.widgets.key.setText(label)
  213.     info.widgets.key.addTranslation(x + 120 + 5, y + 10, 0)
  214.     info.widgets.key.addColor(1, 1, 1, 0.7)
  215.     os.sleep(0)
  216.     info.widgets.value = glassesTerminal.addText2D()
  217.     info.widgets.value.setText(""..value.."")
  218.     info.widgets.value.addTranslation(x + 100 + 120 + 5, y + 10, 0)
  219.     info.widgets.value.addColor(info.r, info.g, info.b, 0.7)
  220.     return info
  221. end
  222.  
  223. function setColor(el, p)
  224.     color = perc2color(p)
  225.     el.updateModifier(2, color.red, color.green, 0, 0.7)
  226.     el.updateModifier(3, color.red, color.green, 0, 0.8)   
  227. end
  228.  
  229. function updateInjectionRate()
  230.     injectionRate = reactor.getInjectionRate()
  231.     for i=1,#buttons do
  232.         if injectionRate == buttons[i].value then
  233.             buttons[i].widgets.box.updateModifier(2, 0, 0.7, 0, 0.5)
  234.             buttons[i].widgets.box.updateModifier(3, 0.05, 0.7, 0.05, 0.5)
  235.         else
  236.             buttons[i].widgets.box.updateModifier(2, 0, 0, 0, 0.5)
  237.             buttons[i].widgets.box.updateModifier(3, 0.05, 0.05, 0.05, 0.5)
  238.         end
  239.         os.sleep(0)
  240.     end
  241. end
  242.  
  243. function addInjectionButton(value, x, y)
  244.     return addButton(value, x, y, 25, 25, function(value)
  245.         if value == 0 then
  246.             print("canceling, injection rate of 0 would disable the reactor")
  247.             return
  248.         end
  249.         reactor.setInjectionRate(value)
  250.         updateInjectionRate()
  251.         print("set injection rate to " .. value)       
  252.     end)
  253. end
  254.  
  255. function addStatusBar(label, value, x, y)
  256.     b = glassesTerminal.addBox2D()
  257.     b.addTranslation(x + 123, y - 3, 0)
  258.     b.addColor(1, 1, 1, 0.3)
  259.     b.addColor(1, 1, 1, 0.2)   
  260.    
  261.     return updateStatusBar(b, value)
  262. end
  263.  
  264. function updateStatusBar(el, value)
  265.     w = ((value+5)/100) * 85 -- +5 to always display something
  266.     local color = perc2color(value)
  267.     el.setSize(w, 10)
  268.     el.updateModifier(2, color.red, color.green, color.blue, 0.3)
  269.     el.updateModifier(3, color.red, color.green, color.blue, 0.2)      
  270.     return el
  271. end
  272.  
  273. function addButton(value, x, y, w, h, cb)
  274.     el = {}
  275.     el.value = value
  276.     el.x = x
  277.     el.y = y
  278.     el.width = w
  279.     el.height = h
  280.     el.widgets = {}
  281.     el.widgets.box = glassesTerminal.addBox2D()
  282.     el.widgets.box.addTranslation(x, y, 0)
  283.     el.widgets.box.setSize(el.width, el.height)
  284.     el.widgets.box.addColor(0, 0, 0, 0.5)
  285.     el.widgets.box.addColor(0.05, 0.05, 0.05, 0.5)
  286.     el.widgets.text = glassesTerminal.addText2D()
  287.     el.widgets.text.addTranslation(x+5, y+5, 0)
  288.     el.widgets.text.setText(""..value.."") 
  289.     el.cb = cb
  290.     table.insert(buttons, el)  
  291.     return #buttons
  292. end
  293.  
  294. function rsIgnite(side)
  295.     if reactor.isIgnited() then
  296.         print("reactor is already ignited!")
  297.         return
  298.     end
  299.     io.write("ignating...")
  300.     redstone.setOutput(side, 15)
  301.     os.sleep(5 * 0.05) -- wait 5 ticks
  302.     redstone.setOutput(side, 0)
  303.     os.sleep(0.05)
  304.     if reactor.isIgnited() then
  305.         print(" succed!")
  306.         return true
  307.     else
  308.         print(" FAILED!")
  309.         return false; end
  310. end
  311.  
  312. function ignite(foo)
  313.     if redstone == false then
  314.         print("no redstone interface found!")
  315.         return false
  316.     end
  317.     if laserAmplifier ~= false and laserAmplifier.getEnergy() < laIgnitionEnergy then
  318.         print("not enough energy stored in the laser amplifier!")
  319.         return false
  320.     end
  321.     if redstoneSide == false then
  322.         print("no default side set, trying to figure out, good luck...")
  323.         for side=0,(#sides-1) do
  324.             print("trying "..sides[side])
  325.             if rsIgnite(side) then
  326.                 print("saving ".. sides[side] .." as default")
  327.                 redstoneSide = side            
  328.                 return true
  329.             end
  330.             os.sleep(0)
  331.         end
  332.     else
  333.         return rsIgnite(redstoneSide)
  334.     end
  335.     return false
  336. end
  337.  
  338. function getIndex(label)
  339.     for i=1,#statusbox.widgets do
  340.         if statusbox.widgets[i].label == label then
  341.             return i
  342.         end
  343.         os.sleep(0)
  344.     end
  345.     return false
  346. end
  347.  
  348. function updateStatusBoxKeyValue(label, value, perc)
  349.     index = getIndex(label)
  350.     if index == false then
  351.         print("unknown label: "..label)
  352.         return
  353.     end
  354.     statusbox.widgets[index].value = value
  355.     statusbox.widgets[index].widgets.value.setText(""..value.."")  
  356.     if statusbox.widgets[index].statusBar ~= false then    
  357.         updateStatusBar(statusbox.widgets[index].statusBar, perc)
  358.     end
  359. end
  360.  
  361. function setVisibility(label, bool)
  362.     index = getIndex(label)
  363.     if index == false then
  364.         print("unknown label: "..label)
  365.         return
  366.     end
  367.    
  368.     statusbox.widgets[index].widgets.value.setVisible(bool)
  369.     statusbox.widgets[index].widgets.key.setVisible(bool)
  370.     if statusbox.widgets[index].statusBar then
  371.         statusbox.widgets[index].statusBar.setVisible(bool)
  372.     end
  373. end
  374.  
  375. function initInjectionRateMenue(x, y)
  376.     injectionRateWidget.box = glassesTerminal.addBox2D()
  377.     injectionRateWidget.box.addTranslation(x, y, 0)
  378.     injectionRateWidget.box.setSize(200, 90)
  379.     injectionRateWidget.box.addColor(0, 0, 0, 0.5)
  380.     injectionRateWidget.box.addColor(0.05, 0.05, 0.05, 0.6)
  381.     --injectionRateWidget.box.setCondition(injectionRateWidget.box.addScale(0, 0, 0), "OVERLAY_INACTIVE", true)
  382.  
  383.     injectionRateWidget.text = glassesTerminal.addText2D()
  384.     injectionRateWidget.text.addTranslation(x + 5, y + 5, 0)
  385.     injectionRateWidget.text.setText("injection rate (ignition temp: "..formatNumber(reactor.getIgnitionTemp()).."°K)")   
  386.     --injectionRateWidget.text.setCondition(injectionRateWidget.text.addScale(0, 0, 0), "OVERLAY_INACTIVE", true)
  387.  
  388.     for i=0,9 do
  389.         if i < 5 then
  390.             addInjectionButton(2*i, x + 5 + (i*30),  y + 25)
  391.         else
  392.             addInjectionButton(2*i, x + 5 + ((i-5)*30), y + 55)
  393.         end
  394.         os.sleep(0)
  395.     end
  396.  
  397.     updateInjectionRate()
  398. end
  399.  
  400. function setIgniteButton(visible)
  401.     for i=1,#buttons do
  402.         if buttons[i].value == "ignite" then
  403.             buttons[i].widgets.box.setVisible(visible)
  404.             buttons[i].widgets.text.setVisible(visible)
  405.         end
  406.     end
  407. end
  408.  
  409. function initStatusBox()
  410.     statusbox.widgets = {}
  411.    
  412.     statusbox.box = glassesTerminal.addBox2D()
  413.     statusbox.box.addTranslation(offsetX + 120, offsetY, 0)
  414.     statusbox.box.addColor(0, 0, 0, 0.5)
  415.     statusbox.box.addColor(0.05, 0.05, 0.05, 0.6)
  416.    
  417.     table.insert(statusbox.widgets, addInfo("reactor status", "", offsetX , offsetY + (12*#statusbox.widgets)));
  418.        
  419.     info = addInfo("energy", 0, offsetX , offsetY + (12*#statusbox.widgets))
  420.     info.statusBar = addStatusBar("energy", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  421.     table.insert(statusbox.widgets, info)
  422.    
  423.     info = addInfo("energy stored", 0, offsetX , offsetY + (12*#statusbox.widgets))
  424.     info.statusBar = addStatusBar("energy stored", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  425.     table.insert(statusbox.widgets, info)
  426.        
  427.     info = addInfo("case heat", 0, offsetX , offsetY + (12*#statusbox.widgets))
  428.     info.statusBar = addStatusBar("case heat", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  429.     table.insert(statusbox.widgets, info)
  430.    
  431.     info = addInfo("plasma heat", 0, offsetX , offsetY + (12*#statusbox.widgets))
  432.     info.statusBar = addStatusBar("plasma heat", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  433.     table.insert(statusbox.widgets, info)  
  434.    
  435.     table.insert(statusbox.widgets, addInfo("water", 0, offsetX , offsetY + (12*#statusbox.widgets)))
  436.     table.insert(statusbox.widgets, addInfo("steam", 0, offsetX , offsetY + (12*#statusbox.widgets)))
  437.  
  438.     table.insert(statusbox.widgets, addInfo("can extract", false, offsetX , offsetY + (12*#statusbox.widgets)))
  439.     table.insert(statusbox.widgets, addInfo("can receive", false, offsetX , offsetY + (12*#statusbox.widgets)))
  440.    
  441.     info = addInfo("deuterium", 0, offsetX , offsetY + (12*#statusbox.widgets))
  442.     info.statusBar = addStatusBar("deuterium", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  443.     table.insert(statusbox.widgets, info)  
  444.    
  445.     info = addInfo("tritium", 0, offsetX , offsetY + (12*#statusbox.widgets))
  446.     info.statusBar = addStatusBar("tritium", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  447.     table.insert(statusbox.widgets, info)  
  448.    
  449.     info = addInfo("dt-Fuel", 0, offsetX , offsetY + (12*#statusbox.widgets))
  450.     info.statusBar = addStatusBar("dt-Fuel", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  451.     table.insert(statusbox.widgets, info)  
  452.  
  453.     info = addInfo("laser amplifier", 0, offsetX , offsetY + (12*#statusbox.widgets))
  454.     info.statusBar = addStatusBar("laser amplifier", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  455.     table.insert(statusbox.widgets, info)
  456.    
  457.    
  458.     info = addInfo("induction matrix", 0, offsetX , offsetY + (12*#statusbox.widgets))
  459.     info.statusBar = addStatusBar("induction matrix", 0, offsetX, offsetY + (12*(1+#statusbox.widgets)))
  460.     table.insert(statusbox.widgets, info)
  461.    
  462.     table.insert(statusbox.widgets, addInfo("matrix input", 0, offsetX , offsetY + (12*#statusbox.widgets)))
  463.     table.insert(statusbox.widgets, addInfo("matrix output", 0, offsetX , offsetY + (12*#statusbox.widgets)))
  464.    
  465.     statusbox.box.setSize(230, 15+(#statusbox.widgets*12))
  466.    
  467.     updateLazyValues()
  468.     updateStatusBox()
  469. end
  470.  
  471. function updateLazyValues()
  472.     maxCaseHeat = reactor.getMaxCaseHeat() 
  473.     maxPlasmaHeat = reactor.getMaxPlasmaHeat()
  474.        
  475.     maxEnergyStored = reactor.getMaxEnergyStored()
  476.     if maxEnergyStored > 0 then
  477.         setVisibility("energy stored", true)
  478.     else
  479.         setVisibility("energy stored", false)
  480.     end
  481.    
  482.     maxEnergy = reactor.getMaxEnergy()
  483.     if maxEnergy > 0 then
  484.         setVisibility("energy", true)
  485.     else
  486.         setVisibility("energy", false)
  487.     end
  488.  
  489.     if laserAmplifier then
  490.         laMaxEnergyStored = laserAmplifier.getMaxEnergy()
  491.         setVisibility("laser amplifier", true)
  492.     else
  493.         setVisibility("laser amplifier", false)    
  494.     end
  495.    
  496.     if inductionMatrix then
  497.         imMaxStorage = inductionMatrix.getMaxEnergy()      
  498.         setVisibility("induction matrix", true)
  499.         setVisibility("matrix input", true)
  500.         setVisibility("matrix output", true)
  501.     else
  502.         setVisibility("induction matrix", false)
  503.         setVisibility("matrix input", false)
  504.         setVisibility("matrix output", false)
  505.     end
  506. end
  507.  
  508. function updateStatusBox()
  509.     isIgnited = reactor.isIgnited()
  510.     if isIgnited then
  511.         setIgniteButton(false)
  512.         updateStatusBoxKeyValue("reactor status", "active")
  513.     else
  514.         if reactor.canIgnite() then
  515.             setIgniteButton(false)
  516.             updateStatusBoxKeyValue("reactor status", "inactive (can ignite)")
  517.         else
  518.             setIgniteButton(true)
  519.             updateStatusBoxKeyValue("reactor status", "inactive (can't ignite)")
  520.         end
  521.     end
  522.    
  523.     if laserAmplifier then
  524.         laEnergyStored = laserAmplifier.getEnergy()
  525.         value = val2perc(laEnergyStored, laMaxEnergyStored).."% ("..formatNumber(MJ2RF(laEnergyStored)).." / "..formatNumber(MJ2RF(laMaxEnergyStored)).."RF)"
  526.         updateStatusBoxKeyValue("laser amplifier", value, val2perc(laEnergyStored, laMaxEnergyStored))
  527.     end
  528.    
  529.     dtFuel = reactor.getFuel() 
  530.     deuterium = reactor.getDeuterium() 
  531.     tritium = reactor.getTritium()
  532.        
  533.     if dtFuel > 0 then
  534.         updateStatusBoxKeyValue("dt-Fuel", dtFuel.."mB", val2perc(dtFuel, 1000))   
  535.         setVisibility("dt-Fuel", true)
  536.         setVisibility("deuterium", false)
  537.         setVisibility("tritium", false)
  538.     elseif deuterium > 0 or tritium > 0 then
  539.         updateStatusBoxKeyValue("deuterium", deuterium.."mB", val2perc(deuterium, 1000))
  540.         updateStatusBoxKeyValue("tritium", tritium.."mB", val2perc(tritium, 1000)) 
  541.         setVisibility("dt-Fuel", false)
  542.         setVisibility("deuterium", true)
  543.         setVisibility("tritium", true)
  544.     end
  545.    
  546.     caseHeat = reactor.getCaseHeat()
  547.     value = val2perc(caseHeat, maxCaseHeat).."% ("..formatNumber(caseHeat).." / "..formatNumber(maxCaseHeat).."°K)"
  548.     updateStatusBoxKeyValue("case heat", value, val2perc(caseHeat, maxCaseHeat))
  549.    
  550.     plasmaHeat = reactor.getPlasmaHeat()
  551.     value = val2perc(plasmaHeat, maxPlasmaHeat).."% ("..formatNumber(plasmaHeat).." / "..formatNumber(maxPlasmaHeat).."°K)"
  552.     updateStatusBoxKeyValue("plasma heat", value, val2perc(plasmaHeat, maxPlasmaHeat))
  553.    
  554.     water = reactor.getWater()
  555.     steam = reactor.getSteam() 
  556.    
  557.     if water > 0 or steam > 0 then
  558.         updateStatusBoxKeyValue("water", water.."mB", val2perc(water, 1000))
  559.         updateStatusBoxKeyValue("steam", steam.."mB", val2perc(steam, 1000))
  560.         updateStatusBoxKeyValue("can extract", reactor.canExtract())
  561.         updateStatusBoxKeyValue("can receive", reactor.canReceive())
  562.         setVisibility("water", true)
  563.         setVisibility("steam", true)
  564.         setVisibility("can extract", true)
  565.         setVisibility("can receive", true)
  566.     else
  567.         setVisibility("water", false)
  568.         setVisibility("steam", false)
  569.         setVisibility("can extract", false)
  570.         setVisibility("can receive", false)
  571.     end
  572.    
  573.     if maxEnergy > 0 then
  574.         energy = reactor.getEnergy()
  575.         value = val2perc(energy, maxEnergy).."% ("..formatNumber(MJ2RF(energy)).." / "..formatNumber(MJ2RF(maxEnergy)).."RF)"
  576.         updateStatusBoxKeyValue("energy", value, val2perc(energy, maxEnergy))
  577.     end
  578.    
  579.     if maxEnergyStored > 0 then
  580.         energyStored = reactor.getEnergyStored()
  581.         value = val2perc(energyStored, maxEnergyStored).."% ("..formatNumber(MJ2RF(energyStored)).." / "..formatNumber(MJ2RF(maxEnergyStored)).."RF)"
  582.         updateStatusBoxKeyValue("energy stored", value, val2perc(energyStored, maxEnergyStored))
  583.     end
  584.    
  585.     if inductionMatrix then
  586.         imStorage = inductionMatrix.getEnergy()
  587.         value = val2perc(imStorage, imMaxStorage).."% ("..formatNumber(MJ2RF(imStorage)).." / "..formatNumber(MJ2RF(imMaxStorage)).."RF)"
  588.         updateStatusBoxKeyValue("induction matrix", value, val2perc(imStorage, imMaxStorage))
  589.        
  590.         imInput = inductionMatrix.getInput()
  591.         value = formatNumber(MJ2RF(imInput)).."RF/tick"
  592.         updateStatusBoxKeyValue("matrix input", value)
  593.        
  594.         imOutput = inductionMatrix.getOutput()
  595.         value = formatNumber(MJ2RF(imOutput)).."RF/tick"
  596.         updateStatusBoxKeyValue("matrix output", value)    
  597.     end
  598.    
  599.     os.sleep(0)
  600. end
  601.  
  602. function updateTankHUD(label, tankComponent, el)
  603.     if tankComponent == false then
  604.         return
  605.     end
  606.    
  607.     local tank = readTankStorage(tankComponent)
  608.     local w = (94 * (tank.amount / tank.maxAmount))
  609.     perc = val2perc(tank.amount, tank.maxAmount)
  610.     setColor(el[2], perc)
  611.     el[2].setSize(w, 14)
  612.     el[3].setText(label.." ".. perc .. "%")
  613.     os.sleep(0)
  614. end
  615.  
  616. function touchEvent(EVENT, ID, USER, X, Y, BUTTON)
  617.  for i=1,#buttons do
  618.     if X >= buttons[i].x and X <= (buttons[i].x+buttons[i].width) then
  619.         if Y >= buttons[i].y and Y <= (buttons[i].y+buttons[i].height) then
  620.             buttons[i].cb(buttons[i].value)
  621.  end; end; end
  622. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement