abc123mewot

Power distribution

Dec 18th, 2023 (edited)
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.90 KB | None | 0 0
  1. mainMonitorSide = "monitor_2"
  2. local mon = peripheral.wrap(mainMonitorSide)
  3. local dataTbl = {
  4.     { side = "flux_gate_2", name = "Powerplant functions" },
  5.     { side = "flux_gate_0", name = "Main base distribution" },
  6.     { side = "flux_gate_1", name = "ME base distribution" }
  7. }
  8. local ind = peripheral.find('Induction Matrix')
  9. local rla = peripheral.find('Reactor Logic Adapter')
  10. local trb = peripheral.find('Industrial Turbine')
  11.  
  12. mon.setTextScale(1.25)
  13. mon.setBackgroundColor(colors.black)
  14. local monW, monH = mon.getSize()
  15. if not fs.exists("ui.lua") then
  16.     print("Downloadind UI API")
  17.     shell.run("pastebin get W13Fx2tv ui.lua")
  18. end
  19. os.loadAPI("ui.lua")
  20. local ui = ui.initUI(mon)
  21.  
  22. for k,v in pairs(dataTbl) do
  23.     if v and v.side then
  24.         v.p = peripheral.wrap(v.side)
  25.         if not v.p then
  26.             print("Failed to get peripheral, skipping!")
  27.             dataTbl[k] = nil
  28.         end
  29.     end
  30. end
  31.  
  32. info = {}
  33. info.lastIndEgy = ind.getEnergy()
  34. info.lastIndTime = os.time()
  35. local function collectInfo()
  36.     info.trbKRFt = math.floor((trb.getSteamInput() * 568.33) / 33150)
  37.     info.rcrKRFt = math.floor((rla.getProducing() * 0.4) / 1000)
  38.     info.indEgy = ind.getEnergy() local ctime = os.time()
  39.     info.indKRFt = math.floor(((info.indEgy - info.lastIndEgy) * 0.0004) / ((ctime - info.lastIndTime) * 1000))
  40.     info.lastIndTime = ctime
  41.     info.lastIndEgy = info.indEgy
  42.     info.indPct = math.ceil(100.0 * (info.indEgy / ind.getMaxEnergy()))
  43. end
  44. local function drawGeneration(wasTouched)
  45.     local cx, cy = mon.getCursorPos()
  46.     mon.setTextColor(colors.yellow)
  47.     mon.setBackgroundColor(colors.black)
  48.    
  49.     cy = cy + 1
  50.     mon.setCursorPos(cx, cy) cy = cy + 1
  51.     mon.write("Turbine (KRF/t)")
  52.     mon.setTextColor(colors.green)
  53.     mon.setBackgroundColor(colors.black)
  54.     mon.setCursorPos(cx, cy) cy = cy + 6
  55.     ui.writeNumber(info.trbKRFt, 5)
  56.    
  57.     mon.setTextColor(colors.yellow)
  58.     mon.setCursorPos(cx, cy) cy = cy + 1
  59.     mon.write("Reactor (KRF/t)")
  60.     mon.setTextColor(colors.green)
  61.     mon.setBackgroundColor(colors.black)
  62.     mon.setCursorPos(cx, cy) cy = cy + 5
  63.     ui.writeNumber(info.rcrKRFt, 5)
  64. end
  65.  
  66. local function drawBuffering(wasTouched)
  67.     local cx, cy = mon.getCursorPos()
  68.     mon.setTextColor(colors.yellow)
  69.     mon.setBackgroundColor(colors.black)
  70.    
  71.     cy = cy + 1
  72.     mon.setCursorPos(cx, cy) cy = cy + 1
  73.     mon.write("Induction storage")
  74.     if info.indPct < 30 then mon.setTextColor(colors.red) elseif info.indPct < 50 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.green) end
  75.     mon.setCursorPos(cx, cy) cy = cy + 6 ui.writeNumber(info.indPct, 3, true) ui.writeDigit(12) ui.writeDigit(13) -- Percent sign
  76.    
  77.     mon.setTextColor(colors.yellow)
  78.     mon.setCursorPos(cx, cy) cy = cy + 1
  79.     mon.write("Net energy (KRF/t)")
  80.     if info.indKRFt > 0 then mon.setTextColor(colors.green) elseif info.indKRFt < 0 then mon.setTextColor(colors.red) else mon.setTextColor(colors.yellow) end
  81.     mon.setBackgroundColor(colors.black)
  82.     mon.setCursorPos(cx, cy) cy = cy + 5
  83.     ui.writeNumber(math.abs(info.indKRFt), 5)
  84. end
  85. local function drawMonitoring(wasTouched)
  86.     local cx, cy = mon.getCursorPos()
  87.     mon.setTextColor(colors.yellow)
  88.     mon.setBackgroundColor(colors.black)
  89.    
  90.     cy = cy + 1
  91.     for k,v in pairs(dataTbl) do
  92.         if v then
  93.             mon.setCursorPos(cx, cy)
  94.             mon.write(v.name)
  95.             cy = cy + 1
  96.         end
  97.     end
  98. end
  99.  
  100. local loopTimer = os.startTimer(0.3)
  101. local blinky = false
  102. while true do
  103.     local event, param1, param2, param3, param4 = os.pullEvent()
  104.     local wasTouched = event == "monitor_touch" and param1 == mainMonitorSide
  105.     local wasTimer = event == "timer" and param1 == loopTimer
  106.     if wasTouched or wasTimer then -- Touchscreen or timer event!
  107.         loopTimer = os.startTimer(0.3)
  108.         collectInfo()
  109.         mon.clear()
  110.         mon.setBackgroundColor(colors.gray)
  111.         mon.setTextColor(colors.white)
  112.         ui.spacer(1, "Power distribution")
  113.         ui.spacer(2, "")
  114.         ui.spacer(3, "")
  115.         ui.spacer(4, "")
  116.        
  117.         mon.setCursorPos(monW, 1)
  118.         mon.setTextColor(colors.black)
  119.         if blinky then mon.write("\\") blinky = false else mon.write("/") blinky = true end
  120.         mon.setCursorPos(1, 1)
  121.         mon.setTextColor(colors.white)
  122.        
  123.         local mainW = 23 local midX = mainW * 2
  124.         mon.setTextColor(colors.yellow)
  125.         mon.setCursorPos(1, 3)
  126.         ui.writeMid("Production", mainW)
  127.         mon.setCursorPos(2, 5)
  128.         drawGeneration(wasTouched and param2 > 0 and param2 < mainW)
  129.        
  130.         mon.setBackgroundColor(colors.gray)
  131.         mon.setCursorPos(mainW - 1, 3)
  132.         ui.drawVbar(4, monH)
  133.         ui.drawVbar(4, monH)
  134.         mon.setTextColor(colors.yellow)
  135.         mon.setCursorPos(mainW - 2, 3)
  136.         mon.write("---->")
  137.         mon.setCursorPos(mainW, 3)
  138.         ui.writeMid("Buffering", mainW)
  139.         mon.setCursorPos(mainW + 2, 5)
  140.         drawBuffering(wasTouched and param2 > mainW and param2 < midX)
  141.        
  142.         mon.setBackgroundColor(colors.gray)
  143.         mon.setCursorPos(midX - 1, 3)
  144.         ui.drawVbar(4, monH)
  145.         ui.drawVbar(4, monH)
  146.         mon.setTextColor(colors.yellow)
  147.         mon.setCursorPos(midX - 2, 3)
  148.         mon.write("---->   Distribution")
  149.         mon.setCursorPos(midX + 2, 5)
  150.         drawMonitoring(wasTouched and param2 > midX)
  151.     end
  152. end
  153.  
Advertisement
Add Comment
Please, Sign In to add comment