Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mainMonitorSide = "monitor_2"
- local mon = peripheral.wrap(mainMonitorSide)
- local dataTbl = {
- { side = "flux_gate_2", name = "Powerplant functions" },
- { side = "flux_gate_0", name = "Main base distribution" },
- { side = "flux_gate_1", name = "ME base distribution" }
- }
- local ind = peripheral.find('Induction Matrix')
- local rla = peripheral.find('Reactor Logic Adapter')
- local trb = peripheral.find('Industrial Turbine')
- mon.setTextScale(1.25)
- mon.setBackgroundColor(colors.black)
- local monW, monH = mon.getSize()
- if not fs.exists("ui.lua") then
- print("Downloadind UI API")
- shell.run("pastebin get W13Fx2tv ui.lua")
- end
- os.loadAPI("ui.lua")
- local ui = ui.initUI(mon)
- for k,v in pairs(dataTbl) do
- if v and v.side then
- v.p = peripheral.wrap(v.side)
- if not v.p then
- print("Failed to get peripheral, skipping!")
- dataTbl[k] = nil
- end
- end
- end
- info = {}
- info.lastIndEgy = ind.getEnergy()
- info.lastIndTime = os.time()
- local function collectInfo()
- info.trbKRFt = math.floor((trb.getSteamInput() * 568.33) / 33150)
- info.rcrKRFt = math.floor((rla.getProducing() * 0.4) / 1000)
- info.indEgy = ind.getEnergy() local ctime = os.time()
- info.indKRFt = math.floor(((info.indEgy - info.lastIndEgy) * 0.0004) / ((ctime - info.lastIndTime) * 1000))
- info.lastIndTime = ctime
- info.lastIndEgy = info.indEgy
- info.indPct = math.ceil(100.0 * (info.indEgy / ind.getMaxEnergy()))
- end
- local function drawGeneration(wasTouched)
- local cx, cy = mon.getCursorPos()
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- cy = cy + 1
- mon.setCursorPos(cx, cy) cy = cy + 1
- mon.write("Turbine (KRF/t)")
- mon.setTextColor(colors.green)
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(cx, cy) cy = cy + 6
- ui.writeNumber(info.trbKRFt, 5)
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(cx, cy) cy = cy + 1
- mon.write("Reactor (KRF/t)")
- mon.setTextColor(colors.green)
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(cx, cy) cy = cy + 5
- ui.writeNumber(info.rcrKRFt, 5)
- end
- local function drawBuffering(wasTouched)
- local cx, cy = mon.getCursorPos()
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- cy = cy + 1
- mon.setCursorPos(cx, cy) cy = cy + 1
- mon.write("Induction storage")
- if info.indPct < 30 then mon.setTextColor(colors.red) elseif info.indPct < 50 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.green) end
- mon.setCursorPos(cx, cy) cy = cy + 6 ui.writeNumber(info.indPct, 3, true) ui.writeDigit(12) ui.writeDigit(13) -- Percent sign
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(cx, cy) cy = cy + 1
- mon.write("Net energy (KRF/t)")
- if info.indKRFt > 0 then mon.setTextColor(colors.green) elseif info.indKRFt < 0 then mon.setTextColor(colors.red) else mon.setTextColor(colors.yellow) end
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(cx, cy) cy = cy + 5
- ui.writeNumber(math.abs(info.indKRFt), 5)
- end
- local function drawMonitoring(wasTouched)
- local cx, cy = mon.getCursorPos()
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- cy = cy + 1
- for k,v in pairs(dataTbl) do
- if v then
- mon.setCursorPos(cx, cy)
- mon.write(v.name)
- cy = cy + 1
- end
- end
- end
- local loopTimer = os.startTimer(0.3)
- local blinky = false
- while true do
- local event, param1, param2, param3, param4 = os.pullEvent()
- local wasTouched = event == "monitor_touch" and param1 == mainMonitorSide
- local wasTimer = event == "timer" and param1 == loopTimer
- if wasTouched or wasTimer then -- Touchscreen or timer event!
- loopTimer = os.startTimer(0.3)
- collectInfo()
- mon.clear()
- mon.setBackgroundColor(colors.gray)
- mon.setTextColor(colors.white)
- ui.spacer(1, "Power distribution")
- ui.spacer(2, "")
- ui.spacer(3, "")
- ui.spacer(4, "")
- mon.setCursorPos(monW, 1)
- mon.setTextColor(colors.black)
- if blinky then mon.write("\\") blinky = false else mon.write("/") blinky = true end
- mon.setCursorPos(1, 1)
- mon.setTextColor(colors.white)
- local mainW = 23 local midX = mainW * 2
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(1, 3)
- ui.writeMid("Production", mainW)
- mon.setCursorPos(2, 5)
- drawGeneration(wasTouched and param2 > 0 and param2 < mainW)
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(mainW - 1, 3)
- ui.drawVbar(4, monH)
- ui.drawVbar(4, monH)
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(mainW - 2, 3)
- mon.write("---->")
- mon.setCursorPos(mainW, 3)
- ui.writeMid("Buffering", mainW)
- mon.setCursorPos(mainW + 2, 5)
- drawBuffering(wasTouched and param2 > mainW and param2 < midX)
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(midX - 1, 3)
- ui.drawVbar(4, monH)
- ui.drawVbar(4, monH)
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(midX - 2, 3)
- mon.write("----> Distribution")
- mon.setCursorPos(midX + 2, 5)
- drawMonitoring(wasTouched and param2 > midX)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment