Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Draconic Reactor GUI Controller
- Clean rewrite: Unicode box UI, drag sliders, stable ETA display
- Usage:
- dc1
- dc1 -d
- dc1 --in=<input flux gate address> --out=<output flux gate address>
- dc1 --mult=10
- Normal mode: Temp 2500-8000 C, Field 1.0-50.0%
- Danger mode: Temp 2500-20000 C, Field 0.5-100.0% (-d / --danger)
- ]]
- local component = require("component")
- local event = require("event")
- local term = require("term")
- --------------------------------------------------------------------------------
- -- CONFIG / ARGS
- --------------------------------------------------------------------------------
- local OUTPUT_FLUX_ADDRESS = nil
- local INPUT_FLUX_ADDRESS = nil
- local reactorOutputMultiplier = 1
- local dangerMode = false
- local MAX_GATE_FLOW = 2147000000
- local WARMUP_INPUT_RF_T = 5000000
- local PROBE_INPUT_RF_T = 1
- local PROBE_TICK_S = 0.05
- local MC_TICKS_PER_S = 20
- local FUEL_CUTOFF = 0.875 -- stop at 87.5% conversion
- -- ETA smoothing
- local ETA_ALPHA_STEADY = 0.04 -- slow drift when stable
- local ETA_ALPHA_MOVING = 0.18 -- faster when targets changing
- local ETA_STEADY_TEMP_ERR = 200 -- C
- local ETA_STEADY_FIELD_ERR = 0.02
- for _, arg in ipairs({...}) do
- if arg == "-d" or arg == "--danger" or arg == "--chaos" then
- dangerMode = true
- elseif arg:sub(1,6) == "--out=" then OUTPUT_FLUX_ADDRESS = arg:sub(7)
- elseif arg:sub(1,5) == "--in=" then INPUT_FLUX_ADDRESS = arg:sub(6)
- elseif arg:sub(1,7) == "--mult=" then
- reactorOutputMultiplier = tonumber(arg:sub(8)) or reactorOutputMultiplier
- end
- end
- --------------------------------------------------------------------------------
- -- COMPONENT SETUP
- --------------------------------------------------------------------------------
- if not component.isAvailable("gpu") then error("No GPU found.") end
- if not component.isAvailable("screen") then error("No screen found.") end
- if not component.isAvailable("draconic_reactor") then error("No draconic_reactor found.") end
- local gpu = component.gpu
- local reactor = component.draconic_reactor
- local savedFg = gpu.getForeground()
- local savedBg = gpu.getBackground()
- --------------------------------------------------------------------------------
- -- PALETTE
- --------------------------------------------------------------------------------
- local C = {
- bg = 0x0A0E1A,
- panel = 0x0F1629,
- panel2 = 0x141E35,
- border = 0x2A3A5C,
- text = 0xD0D8F0,
- muted = 0x5A6A8A,
- white = 0xFFFFFF,
- black = 0x000000,
- blue = 0x4FC3F7,
- purple = 0xB39DDB,
- green = 0x66BB6A,
- yellow = 0xFFD54F,
- orange = 0xFF8A65,
- red = 0xEF5350,
- slider_t = 0xFF6B35, -- temp slider track/handle
- slider_f = 0x42A5F5, -- field slider track/handle
- bar_bg = 0x1A2540,
- }
- --------------------------------------------------------------------------------
- -- UTILS
- --------------------------------------------------------------------------------
- local function clamp(v, lo, hi)
- v = tonumber(v) or lo
- if v ~= v then return lo end
- return math.max(lo, math.min(hi, v))
- end
- local function safeDiv(a, b, fb)
- a, b = tonumber(a) or 0, tonumber(b) or 0
- if b == 0 then return fb or 0 end
- return a / b
- end
- local function formatRF(n)
- n = tonumber(n) or 0
- if math.abs(n) >= 1e9 then return string.format("%.2f GRF/t", n/1e9) end
- if math.abs(n) >= 1e6 then return string.format("%.2f MRF/t", n/1e6) end
- if math.abs(n) >= 1e3 then return string.format("%.2f kRF/t", n/1e3) end
- return string.format("%d RF/t", math.floor(n+0.5))
- end
- local function formatPct(p)
- return string.format("%.1f%%", clamp(tonumber(p) or 0, 0, 1)*100)
- end
- local function formatTargetPct(p)
- return string.format("%.2f%%", clamp(tonumber(p) or 0, 0, 1)*100)
- end
- local function shortAddr(a)
- a = tostring(a or "none")
- if #a <= 13 then return a end
- return a:sub(1,8) .. "…" .. a:sub(-4)
- end
- local function fit(s, w)
- s = tostring(s or "")
- if w <= 0 then return "" end
- if #s > w then return s:sub(1,w-1) .. "…" end
- return s .. string.rep(" ", w - #s)
- end
- local function formatETA(sec)
- sec = tonumber(sec)
- if not sec or sec ~= sec or sec == math.huge or sec < 0 then return "--:--:--" end
- if sec > 359999 then return ">99h" end
- sec = math.floor(sec + 0.5)
- local h = math.floor(sec / 3600)
- local m = math.floor((sec % 3600) / 60)
- local s = sec % 60
- return string.format("%d:%02d:%02d", h, m, s)
- end
- --------------------------------------------------------------------------------
- -- GPU HELPERS
- --------------------------------------------------------------------------------
- local function setColor(fg, bg)
- if fg then gpu.setForeground(fg) end
- if bg then gpu.setBackground(bg) end
- end
- local function writeAt(x, y, s, fg, bg)
- setColor(fg or C.text, bg or C.bg)
- gpu.set(x, y, tostring(s))
- end
- local function fillAt(x, y, w, h, fg, bg, ch)
- if w <= 0 or h <= 0 then return end
- setColor(fg or C.text, bg or C.bg)
- gpu.fill(x, y, w, h, ch or " ")
- end
- --------------------------------------------------------------------------------
- -- BOX DRAWING (real UTF-8 literals — no byte-escape gymnastics needed)
- --------------------------------------------------------------------------------
- local BOX = {
- tl="┌", tr="┐", bl="└", br="┘",
- h="─", v="│",
- lt="├", rt="┤", tt="┬", bt="┴", cross="┼",
- }
- local function drawBox(x, y, w, h, title, fg, bg)
- fg = fg or C.border
- bg = bg or C.panel
- if w < 3 or h < 2 then return end
- fillAt(x, y, w, h, C.text, bg)
- -- top
- gpu.setForeground(fg); gpu.setBackground(bg)
- gpu.set(x, y, BOX.tl .. string.rep(BOX.h, w-2) .. BOX.tr)
- -- sides
- for yy = y+1, y+h-2 do
- gpu.set(x, yy, BOX.v)
- gpu.set(x+w-1, yy, BOX.v)
- end
- -- bottom
- gpu.set(x, y+h-1, BOX.bl .. string.rep(BOX.h, w-2) .. BOX.br)
- -- title
- if title and title ~= "" then
- writeAt(x+2, y, " " .. fit(title, w-6) .. " ", C.text, bg)
- end
- end
- local function hline(x, y, w, fg, bg)
- setColor(fg or C.border, bg or C.panel)
- gpu.set(x, y, BOX.lt .. string.rep(BOX.h, w-2) .. BOX.rt)
- end
- --------------------------------------------------------------------------------
- -- BAR RENDERER
- -- Draws a horizontal bar from x,y of width w filled to fraction t (0-1)
- -- filled cells use fillChar (defaults to "█"), empty use "░"
- --------------------------------------------------------------------------------
- local function drawBar(x, y, w, t, fillClr, emptyClr, bg)
- t = clamp(t, 0, 1)
- local filled = math.floor(t * w + 0.5)
- bg = bg or C.panel
- setColor(fillClr, bg)
- if filled > 0 then gpu.fill(x, y, filled, 1, "█") end
- setColor(emptyClr or C.bar_bg, bg)
- if filled < w then gpu.fill(x+filled, y, w-filled, 1, "░") end
- end
- --------------------------------------------------------------------------------
- -- FLUX GATE PROBE / BINDING
- --------------------------------------------------------------------------------
- local gateMsg = ""
- local input_flux = nil
- local output_flux = nil
- local input_flux_addr = nil
- local output_flux_addr= nil
- local function rawSetGate(g, v)
- if not g then return false end
- v = math.floor(clamp(v or 0, 0, MAX_GATE_FLOW) + 0.5)
- pcall(function() g.setOverrideEnabled(true) end)
- return pcall(function() g.setFlowOverride(v) end)
- end
- local function rawGetGate(g)
- if not g then return 0 end
- local ok, v = pcall(function() return g.getFlowOverride() end)
- if ok then return tonumber(v) or 0 end
- ok, v = pcall(function() return g.getFlow() end)
- if ok then return tonumber(v) or 0 end
- return 0
- end
- local function collectGates()
- local t = {}
- for addr in pairs(component.list("flux_gate")) do
- local ok, p = pcall(component.proxy, addr)
- if ok and p then
- pcall(function() p.setOverrideEnabled(true) end)
- t[#t+1] = {address=addr, proxy=p}
- end
- end
- return t
- end
- local function zeroAll(gates)
- for _, g in ipairs(gates or {}) do rawSetGate(g.proxy, 0) end
- end
- local function reactorSnap()
- local ok, s = pcall(function() return reactor.getReactorInfo() end)
- if not ok or not s then return nil end
- return {
- status = tostring(s.status or "unknown"),
- temperature = tonumber(s.temperature) or 0,
- fieldStrength = tonumber(s.fieldStrength) or 0,
- maxFieldStrength = tonumber(s.maxFieldStrength) or 0,
- energySaturation = tonumber(s.energySaturation) or 0,
- maxEnergySaturation = tonumber(s.maxEnergySaturation) or 0,
- }
- end
- local function probeInputGate(gates)
- term.clear(); term.setCursor(1,1)
- print("Draconic Reactor: flux gate probe")
- print("Found " .. #gates .. " gate(s). Sending 1 RF/t pulse per gate…")
- zeroAll(gates)
- local snap0 = reactorSnap()
- local status0 = snap0 and snap0.status or "unknown"
- local temp0 = snap0 and snap0.temperature or 0
- local canCharge = (status0=="cold" or status0=="cooling" or status0=="offline" or status0=="stopped") and temp0 < 1000
- if canCharge then
- print("Cold state — requesting brief charge for probe.")
- pcall(function() reactor.chargeReactor() end)
- os.sleep(PROBE_TICK_S)
- end
- local bestIdx, bestScore, bestFG, bestSG = nil, -1, 0, 0
- for i, g in ipairs(gates) do
- zeroAll(gates); os.sleep(PROBE_TICK_S)
- local before = reactorSnap()
- rawSetGate(g.proxy, PROBE_INPUT_RF_T)
- os.sleep(PROBE_TICK_S)
- local after = reactorSnap()
- rawSetGate(g.proxy, 0)
- local fg = (after and after.fieldStrength or 0) - (before and before.fieldStrength or 0)
- local sg = (after and after.energySaturation or 0) - (before and before.energySaturation or 0)
- local score = math.max(0,fg)*1000 + math.max(0,sg)
- print(string.format(" Gate #%d %s score=%d field+=%d sat+=%d", i, shortAddr(g.address), math.floor(score+0.5), math.floor(fg+0.5), math.floor(sg+0.5)))
- if score > bestScore then bestIdx, bestScore, bestFG, bestSG = i, score, fg, sg end
- end
- zeroAll(gates)
- if canCharge then pcall(function() reactor.stopReactor() end) end
- if not bestIdx or bestScore < 1 then
- gateMsg = "Probe inconclusive; defaulting gate #1=input, #2=output."
- return 1, 2
- end
- local outIdx
- for i in ipairs(gates) do if i ~= bestIdx then outIdx = i; break end end
- gateMsg = string.format("Probe: input=#%d output=#%d score=%d", bestIdx, outIdx or 0, math.floor(bestScore+0.5))
- return bestIdx, outIdx
- end
- local function findByAddr(gates, addr)
- if not addr or addr == "" then return nil end
- for i, g in ipairs(gates) do if g.address == addr then return i end end
- return nil
- end
- local function otherIdx(gates, idx)
- for i in ipairs(gates) do if i ~= idx then return i end end
- return nil
- end
- local function bindGates()
- local gates = collectGates()
- if #gates < 2 then
- error("Need at least 2 flux_gate components; found " .. #gates)
- end
- local iIdx = findByAddr(gates, INPUT_FLUX_ADDRESS)
- local oIdx = findByAddr(gates, OUTPUT_FLUX_ADDRESS)
- if not iIdx and not oIdx then
- iIdx, oIdx = probeInputGate(gates)
- os.sleep(0.5)
- elseif iIdx and not oIdx then
- oIdx = otherIdx(gates, iIdx)
- gateMsg = "Manual input; output = first other gate."
- elseif oIdx and not iIdx then
- iIdx = otherIdx(gates, oIdx)
- gateMsg = "Manual output; input = first other gate."
- else
- gateMsg = "Manual input/output bound."
- end
- if not iIdx or not oIdx or iIdx == oIdx then
- error("Could not allocate distinct input/output gates.")
- end
- -- Hot-restart inversion: if the reactor is already hot, gate roles are flipped
- local snap = reactorSnap()
- local hotTemp = snap and snap.temperature or 0
- if hotTemp > 2000 then
- iIdx, oIdx = oIdx, iIdx
- gateMsg = gateMsg .. string.format(" Hot-start %.0fC: roles inverted.", hotTemp)
- end
- input_flux = gates[iIdx].proxy
- output_flux = gates[oIdx].proxy
- input_flux_addr = gates[iIdx].address
- output_flux_addr = gates[oIdx].address
- rawSetGate(input_flux, 0)
- rawSetGate(output_flux, 0)
- end
- local function setGate(g, v)
- if not g then return end
- rawSetGate(g, math.floor(clamp(v or 0, 0, MAX_GATE_FLOW) + 0.5))
- end
- --------------------------------------------------------------------------------
- -- CONTROL MATH (verbatim from dc0.lua / pastebin v15.1)
- --------------------------------------------------------------------------------
- local function computeControl(info, targetTemp, targetShield, multiplier)
- if not info then return {} end
- local targetTemp50 = math.min((targetTemp / 10000) * 50, 99)
- local coreSat = safeDiv(info.energySaturation, info.maxEnergySaturation, 0)
- local convLVL = (safeDiv(info.fuelConversion, info.maxFuelConversion, 0) * 1.3) - 0.3
- local targetTempResist = (targetTemp50^4) / (100 - targetTemp50)
- local targetTempExpo = -(targetTempResist * convLVL) - 1000*convLVL + targetTempResist
- local term1 = 1334.1 - (3 * targetTempExpo)
- local term2 = (1200690 - (2700 * targetTempExpo))^2
- local inner = (-4*term1^3 + term2)
- local sqrtInner = inner >= 0 and inner^0.5 or 0
- local term3 = ((-1350*targetTempExpo) + sqrtInner/2 + 600345)^(1/3)
- local targetNegCSat = -(term1/(3*term3)) - (term3/3)
- local targetCoreSat = 1 - (targetNegCSat / 99)
- local targetSat = targetCoreSat * info.maxEnergySaturation
- local satError = info.energySaturation - targetSat
- local tempDrainFactor = 0
- local t = info.temperature
- if t > 8000 then tempDrainFactor = 1 + (t-8000)^2 * 0.0000025
- elseif t > 2000 then tempDrainFactor = 1
- elseif t > 1000 then tempDrainFactor = (t-1000)/1000
- end
- local baseMaxRFt = (info.maxEnergySaturation / 1000) * multiplier * 1.5
- local fieldDrain = math.min(tempDrainFactor * math.max(0.01, 1-coreSat) * (baseMaxRFt/10.923556), MAX_GATE_FLOW)
- -- Minimum field strength above 9000C: 10% + temp/500 percent
- -- Prevents cascade collapse where drain acceleration outpaces a single tick's input
- local minField = 0.0
- if info.temperature > 9000 then
- minField = (0.10 + (info.temperature / 500)) / 100
- end
- local effectiveShield = math.max(targetShield, minField)
- local fsError = (info.maxFieldStrength * effectiveShield) - info.fieldStrength
- local reqInput = math.min(
- safeDiv(info.maxFieldStrength * info.fieldDrainRate, info.maxFieldStrength - info.fieldStrength, 0),
- info.maxFieldStrength - info.fieldStrength
- )
- local outputNeeded = math.min(satError, info.maxEnergySaturation / 40) + (info.generationRate or 0)
- local inputCmd = math.min(fsError + reqInput, info.maxFieldStrength)
- return {
- satError = satError,
- fieldStrengthError = fsError,
- requiredInput = reqInput,
- outputNeeded = outputNeeded,
- inputCommand = inputCmd,
- targetCoreSat = targetCoreSat,
- tempDrainFactor = tempDrainFactor,
- convLVL = convLVL,
- targetTempResist= targetTempResist,
- }
- end
- --------------------------------------------------------------------------------
- -- ETA MODEL (fuel remaining / burn rate at current temperature)
- --------------------------------------------------------------------------------
- -- Fuel burn rate model (nb/tick) as a function of temperature.
- -- Derived from the pastebin v15 reference table at known operating points.
- -- convLVL is (fuelConversion/maxFuelConversion * 1.3) - 0.3
- local function modeledFuelNbPerTick(temp, convLVL)
- -- At temp T the saturation target drives a specific burn rate.
- -- We approximate via the observed relationship: rate ∝ temp^1.8 / 1e9
- -- This is a rough model; the actual figure from getReactorInfo is used
- -- for smoothing, not raw ETA.
- temp = clamp(tonumber(temp) or 4000, 1000, 25000)
- convLVL = clamp(tonumber(convLVL) or 0, 0, 1)
- return math.max(0.001, (temp^1.8) / 3e10 * (0.5 + convLVL))
- end
- local function etaSecondsToConversion(info, targetConv, temp)
- if not info then return nil end
- local fuelRemaining = (info.maxFuelConversion or 0) - (info.fuelConversion or 0)
- local toConsume = math.max(0, targetConv * (info.maxFuelConversion or 0) - (info.fuelConversion or 0))
- -- Prefer live rate, fall back to model
- local liveRate = tonumber(info.fuelConversionRate) or 0 -- nb/tick
- if liveRate < 0.001 then
- local cLVL = safeDiv(info.fuelConversion, info.maxFuelConversion, 0) * 1.3 - 0.3
- liveRate = modeledFuelNbPerTick(temp or 4000, cLVL) / 1e6 -- convert nb to internal units
- end
- -- fuelConversionRate is in nb/tick; maxFuelConversion is in "units" where 1 unit = 1e6 nb
- -- ETA in seconds = toConsume_units / (liveRate_nb_per_tick / 1e6) / MC_TICKS_PER_S
- local rateUnitsPerTick = liveRate / 1e6
- if rateUnitsPerTick < 1e-12 then return nil end
- return toConsume / (rateUnitsPerTick * MC_TICKS_PER_S)
- end
- -- Smoothed ETA state
- local etaStopSec, etaEmptySec = nil, nil
- local function smoothEta(which, raw, isStable)
- if not raw then return nil end
- local alpha = isStable and ETA_ALPHA_STEADY or ETA_ALPHA_MOVING
- if which == "stop" then
- if not etaStopSec then etaStopSec = raw end
- etaStopSec = etaStopSec + (raw - etaStopSec) * alpha
- return etaStopSec
- else
- if not etaEmptySec then etaEmptySec = raw end
- etaEmptySec = etaEmptySec + (raw - etaEmptySec) * alpha
- return etaEmptySec
- end
- end
- --------------------------------------------------------------------------------
- -- LAYOUT
- -- Screen assumed 80×25 minimum; adapts to actual resolution
- --------------------------------------------------------------------------------
- local W, H -- screen dimensions, set in buildLayout
- local layout = {}
- local function buildLayout()
- W, H = gpu.getResolution()
- W, H = tonumber(W) or 80, tonumber(H) or 25
- -- Three columns:
- -- Left (stats) : x=1, width = floor(W*0.45)
- -- Right (calc) : x=lw+1, width = W - lw - 1
- -- Rows:
- -- Title bar : y=1
- -- Status box : y=2, height=10 (stats + bars)
- -- Slider section : y=13, height=6
- -- Button row : y=20
- -- Gate / ETA row : y=22
- -- Status line : y=H
- local lw = math.floor(W * 0.55)
- local rw = W - lw
- layout.W, layout.H = W, H
- layout.lw, layout.rw = lw, rw
- -- Main stats box
- layout.statsBox = { x=1, y=2, w=lw, h=11 }
- -- Calc/debug box
- layout.calcBox = { x=lw+1, y=2, w=rw, h=11 }
- -- Slider section (inside a box) — expanded to fit offset slider
- layout.sliderBox = { x=1, y=13, w=W, h=11 }
- -- Sliders (inside sliderBox, 2 rows)
- local sw = math.floor((W - 6) / 2)
- layout.sliders = {
- temp = { x=3, y=17, w=sw, min=dangerMode and 2500 or 2500, max=dangerMode and 20000 or 8000, step=25, isTemp=true },
- field = { x=3+sw+2, y=17, w=W-5-sw, min=dangerMode and 0.005 or 0.01, max=dangerMode and 1.0 or 0.50, step=0.0025, isTemp=false },
- -- Bipolar output offset slider: ±1,000,000 RF/t, zero at center
- offset = { x=3, y=21, w=W-4, min=-1000000, max=1000000, step=1000, isOffset=true },
- }
- -- Button row
- layout.btnY = 24
- layout.btnStart = { x=2, y=layout.btnY, w=12, h=1 }
- layout.btnStop = { x=15, y=layout.btnY, w=12, h=1 }
- layout.btnQuit = { x=W-7, y=layout.btnY, w=7, h=1 }
- -- Status line
- layout.statusY = H
- end
- --------------------------------------------------------------------------------
- -- STATE
- --------------------------------------------------------------------------------
- local lastInfo = nil
- local lastCalc = {}
- local lastSentOutput = nil
- local emaOutput = nil
- local EMA_ALPHA = 0.15
- local outputOffset = 0 -- bipolar RF/t offset applied to output gate
- local targetTemp = 8000
- local targetShield = 0.15 -- 15%
- local controlEnabled = true
- local armed = false
- local running = true
- local statusMsg = ""
- local lastError = nil
- local timers = {}
- -- Dirty flags
- local staticDirty = true
- local dynDirty = true
- local sliderDirty = true
- local btnDirty = true
- -- Drag state
- local dragging = nil -- "temp" | "field"
- --------------------------------------------------------------------------------
- -- STATIC UI
- --------------------------------------------------------------------------------
- local function drawStaticUI()
- gpu.setResolution(W, H)
- fillAt(1, 1, W, H, C.text, C.bg)
- -- Title bar
- setColor(C.bg, C.blue)
- gpu.fill(1, 1, W, 1, " ")
- local title = " ◈ DRACONIC REACTOR CONTROLLER"
- if dangerMode then title = title .. " ⚠ DANGER MODE" end
- writeAt(2, 1, title, C.bg, C.blue)
- writeAt(W-12, 1, fit("mult×"..reactorOutputMultiplier, 12), C.bg, C.blue)
- -- Stats box
- drawBox(layout.statsBox.x, layout.statsBox.y, layout.statsBox.w, layout.statsBox.h, "Reactor Status", C.border, C.panel)
- -- Calc box
- drawBox(layout.calcBox.x, layout.calcBox.y, layout.calcBox.w, layout.calcBox.h, "Control Math", C.border, C.panel)
- -- Slider box
- drawBox(layout.sliderBox.x, layout.sliderBox.y, layout.sliderBox.w, layout.sliderBox.h, "Setpoints", C.border, C.panel)
- -- Slider labels (static portion — values drawn in dynamic)
- local sl = layout.sliders
- writeAt(sl.temp.x, layout.sliderBox.y+1, "Temperature Target", C.muted, C.panel)
- writeAt(sl.field.x, layout.sliderBox.y+1, "Shield Field Target", C.muted, C.panel)
- writeAt(sl.offset.x, layout.sliderBox.y+6, "RF Input Offset", C.muted, C.panel)
- -- slider rail labels
- writeAt(sl.temp.x, sl.temp.y+1, tostring(sl.temp.min) .. "C", C.muted, C.panel)
- writeAt(sl.temp.x + sl.temp.w - #tostring(sl.temp.max) - 1, sl.temp.y+1, tostring(sl.temp.max) .. "C", C.muted, C.panel)
- writeAt(sl.field.x, sl.field.y+1, string.format("%.0f%%", sl.field.min*100), C.muted, C.panel)
- local fmaxStr = string.format("%.0f%%", sl.field.max*100)
- writeAt(sl.field.x + sl.field.w - #fmaxStr - 1, sl.field.y+1, fmaxStr, C.muted, C.panel)
- -- offset rail labels
- writeAt(sl.offset.x, sl.offset.y+1, "-1,000,000 RF/t", C.muted, C.panel)
- local omaxStr = "+1,000,000 RF/t"
- writeAt(sl.offset.x + sl.offset.w - #omaxStr, sl.offset.y+1, omaxStr, C.muted, C.panel)
- staticDirty = false
- end
- --------------------------------------------------------------------------------
- -- SLIDER DRAWING
- --------------------------------------------------------------------------------
- local function sliderPos(sl, val)
- -- returns pixel x of the handle for value val
- local t = safeDiv(val - sl.min, sl.max - sl.min, 0)
- return sl.x + math.floor(t * (sl.w - 1) + 0.5)
- end
- local function sliderVal(sl, px)
- -- Map pixel x linearly into the value range, then snap to nearest step.
- -- We do NOT add 0.5 bias before flooring — that shifts the snap boundary
- -- and causes some pixel positions to jump 2 steps while others jump 0.
- -- Plain round() (floor + 0.5 applied to the step-divided value) is correct.
- local t = clamp(safeDiv(px - sl.x, sl.w - 1, 0), 0, 1)
- local raw = sl.min + t * (sl.max - sl.min)
- -- Round to nearest step symmetrically
- local snapped = math.floor(raw / sl.step + 0.5) * sl.step
- return clamp(snapped, sl.min, sl.max)
- end
- local function drawSlider(sl, val, color, label)
- -- Rail
- local ry = sl.y
- local t = safeDiv(val - sl.min, sl.max - sl.min, 0)
- -- filled portion
- local filled = math.floor(t * sl.w + 0.5)
- setColor(color, C.panel)
- if filled > 0 then gpu.fill(sl.x, ry, filled, 1, "▬") end
- setColor(C.muted, C.panel)
- if filled < sl.w then gpu.fill(sl.x+filled, ry, sl.w-filled, 1, "─") end
- -- Handle
- local hx = sliderPos(sl, val)
- setColor(C.bg, color)
- gpu.set(hx, ry, "◆")
- -- Value label above handle
- local lbl = label or (sl.isTemp and (tostring(math.floor(val+0.5)) .. "C") or string.format("%.2f%%", val*100))
- local lx = clamp(hx - math.floor(#lbl/2), sl.x, sl.x + sl.w - #lbl)
- writeAt(lx, ry-1, lbl, color, C.panel)
- -- Clear rest of label row
- if lx > sl.x then
- writeAt(sl.x, ry-1, string.rep(" ", lx - sl.x), C.panel, C.panel)
- end
- local rEnd = lx + #lbl
- if rEnd < sl.x + sl.w then
- writeAt(rEnd, ry-1, string.rep(" ", sl.x + sl.w - rEnd), C.panel, C.panel)
- end
- end
- local function drawOffsetSlider()
- local sl = layout.sliders.offset
- local ry = sl.y
- local mid = sl.x + math.floor(sl.w / 2)
- local t = (outputOffset - sl.min) / (sl.max - sl.min) -- 0..1
- local hx = sl.x + math.floor(t * (sl.w - 1) + 0.5)
- -- Draw full rail as empty first
- setColor(C.muted, C.panel)
- gpu.fill(sl.x, ry, sl.w, 1, "─")
- -- Fill from center to handle
- local fillColor = outputOffset >= 0 and C.green or C.red
- if hx >= mid then
- setColor(fillColor, C.panel)
- gpu.fill(mid, ry, hx - mid + 1, 1, "▬")
- elseif hx < mid then
- setColor(fillColor, C.panel)
- gpu.fill(hx, ry, mid - hx + 1, 1, "▬")
- end
- -- Center mark
- setColor(C.muted, C.panel)
- gpu.set(mid, ry, "┼")
- -- Handle
- setColor(C.bg, fillColor)
- gpu.set(hx, ry, "◆")
- -- Value label
- local lbl
- if outputOffset == 0 then lbl = "0 RF/t"
- elseif outputOffset > 0 then lbl = "+" .. formatRF(outputOffset)
- else lbl = "-" .. formatRF(math.abs(outputOffset))
- end
- local lx = clamp(hx - math.floor(#lbl/2), sl.x, sl.x + sl.w - #lbl)
- writeAt(lx, ry-1, lbl, fillColor, C.panel)
- if lx > sl.x then fillAt(sl.x, ry-1, lx - sl.x, 1, C.panel, C.panel) end
- local rEnd = lx + #lbl
- if rEnd < sl.x + sl.w then fillAt(rEnd, ry-1, sl.x + sl.w - rEnd, 1, C.panel, C.panel) end
- end
- local function drawSliders()
- local sl = layout.sliders
- drawSlider(sl.temp, targetTemp, C.slider_t)
- drawSlider(sl.field, targetShield, C.slider_f)
- drawOffsetSlider()
- sliderDirty = false
- end
- --------------------------------------------------------------------------------
- -- DYNAMIC INFO
- --------------------------------------------------------------------------------
- -- Cache to avoid redundant gpu.set calls
- local dynCache = {}
- local function putDyn(id, x, y, w, text, fg, bg)
- local s = fit(tostring(text or ""), w)
- local k = id .. "\0" .. tostring(fg)
- if dynCache[k] == s then return end
- dynCache[k] = s
- writeAt(x, y, s, fg, bg)
- end
- local function drawBarCached(id, x, y, w, t, fillClr, emptyClr, bg)
- t = clamp(t, 0, 1)
- local filled = math.floor(t * w + 0.5)
- local key = id .. "_bar"
- if dynCache[key] == filled then return end
- dynCache[key] = filled
- drawBar(x, y, w, t, fillClr, emptyClr, bg)
- end
- local function drawStat(id, x, y, label, value, vcolor, w)
- local lb = fit(label .. ":", 14)
- putDyn(id .. "_l", x, y, 14, lb, C.muted, C.panel)
- putDyn(id .. "_v", x+14, y, (w or 20)-14, value, vcolor or C.text, C.panel)
- end
- local function statusColor(s)
- s = tostring(s or "")
- if s == "running" then return C.green end
- if s == "warming_up" or s == "charged" then return C.yellow end
- if s == "stopping" then return C.orange end
- if s == "cold" or s == "offline" or s == "stopped" or s == "cooling" then return C.muted end
- return C.red
- end
- local function tempColor(t)
- t = clamp(tonumber(t) or 2500, 2000, 20000)
- if t < 6000 then return C.blue end
- if t < 8500 then return C.yellow end
- if t < 12000 then return C.orange end
- return C.red
- end
- local function drawDynamicInfo()
- local sb = layout.statsBox
- local info = lastInfo
- -- Layout constants for the stats box
- -- Each row: [label 11] [value 12] [bar BW] with 2 char left margin
- -- Right block starts at midpoint: [label 11] [value 14]
- local LX = sb.x + 2 -- left block start
- local LBLW = 11 -- label column width
- local VALW = 12 -- value column width (right-aligned in here)
- local MID = sb.x + math.floor(sb.w * 0.52) -- right block start
- local RVALW = 16 -- right value column width
- local BW = MID - LX - LBLW - VALW - 3 -- bar width, gap of 1 each side
- -- Helper: write a right-aligned value in a fixed-width field
- local function rval(id, x, y, w, s, fg)
- local padded = string.rep(" ", math.max(0, w - #s)) .. s
- putDyn(id, x, y, w, padded, fg, C.panel)
- end
- -- Helper: label + right-aligned value + optional bar, all on one row
- local function statRow(id, row, label, value, vcolor, barFrac, barColor)
- local lbl = fit(label, LBLW)
- putDyn(id.."_l", LX, row, LBLW, lbl, C.muted, C.panel)
- rval(id.."_v", LX+LBLW, row, VALW, value, vcolor)
- if barFrac and BW > 3 then
- drawBarCached(id, LX+LBLW+VALW+1, row, BW, barFrac, barColor, C.bar_bg, C.panel)
- elseif BW > 3 then
- -- clear bar area for rows without a bar (ETA rows) — cached
- putDyn(id.."_bar_clr", LX+LBLW+VALW+1, row, BW, string.rep(" ", BW), C.panel, C.panel)
- end
- end
- -- Helper: right-side label + value (no bar)
- local function statRowR(id, row, label, value, vcolor)
- local lbl = fit(label, LBLW)
- putDyn(id.."_l", MID, row, LBLW, lbl, C.muted, C.panel)
- rval(id.."_v", MID+LBLW, row, RVALW, value, vcolor)
- end
- if info then
- local status = tostring(info.status or "unknown")
- local fieldPct = safeDiv(info.fieldStrength + (info.fieldDrainRate or 0), info.maxFieldStrength, 0)
- local satPct = safeDiv(info.energySaturation, info.maxEnergySaturation, 0)
- local fuelConvPct = safeDiv(info.fuelConversion, info.maxFuelConversion, 0)
- local fuelLeftPct = clamp(1 - fuelConvPct, 0, 1)
- local temp = tonumber(info.temperature) or 0
- local isSteady = status == "running"
- and math.abs(temp - targetTemp) <= ETA_STEADY_TEMP_ERR
- and math.abs(fieldPct - targetShield) <= ETA_STEADY_FIELD_ERR
- local rawStop = etaSecondsToConversion(info, FUEL_CUTOFF, temp)
- local rawEmpty = etaSecondsToConversion(info, 1.0, temp)
- local etaStop = formatETA(smoothEta("stop", rawStop, isSteady))
- local etaEmpty = formatETA(smoothEta("empty", rawEmpty, isSteady))
- local row = sb.y + 1
- -- Status (no bar — text value, variable width)
- local statusVal = fit(status, VALW)
- putDyn("status_l", LX, row, LBLW, fit("Status", LBLW), C.muted, C.panel)
- putDyn("status_v", LX+LBLW, row, VALW + BW + 1, fit(status, VALW + BW + 1), statusColor(status), C.panel)
- -- Temperature: "8000.0 C" right-aligned in value column
- local tempStr = string.format("%.1fC", temp)
- local tempFrac = clamp((temp - 2000) / (dangerMode and 18000 or 6000), 0, 1)
- statRow("temp", row+1, "Temp", tempStr, tempColor(temp), tempFrac, tempColor(temp))
- -- Field: "15.000%" right-aligned
- local fieldStr = string.format("%.3f%%", fieldPct * 100)
- local fieldOk = fieldPct >= targetShield * 0.97
- statRow("field", row+2, "Field", fieldStr, fieldOk and C.green or C.red, fieldPct, C.slider_f)
- -- Saturation: "11.4%"
- local satStr = string.format("%.1f%%", satPct * 100)
- statRow("sat", row+3, "Saturation",satStr, C.blue, satPct, C.blue)
- -- Fuel left: "99.7%"
- local fuelStr = string.format("%.1f%%", fuelLeftPct * 100)
- local fuelClr = fuelLeftPct < 0.15 and C.red or C.text
- statRow("fuel", row+4, "Fuel Left", fuelStr, fuelClr, fuelLeftPct, fuelLeftPct < 0.15 and C.red or C.green)
- -- ETA rows (no bar)
- statRow("etastop", row+5, "ETA cutoff", etaStop, C.yellow, nil, nil)
- statRow("etaemp", row+6, "ETA empty", etaEmpty, C.orange, nil, nil)
- -- Right column
- statRowR("gen", row, "Generation", formatRF(info.generationRate or 0), C.green)
- statRowR("fdrain", row+1, "Field Drain", formatRF(info.fieldDrainRate or 0), C.orange)
- statRowR("frate", row+2, "Fuel Rate", formatRF((tonumber(info.fuelConversionRate) or 0) * MC_TICKS_PER_S), C.purple)
- statRowR("igate", row+3, "In Gate", formatRF(rawGetGate(input_flux)), C.purple)
- statRowR("ogate", row+4, "Out Gate", formatRF(rawGetGate(output_flux)), C.purple)
- -- Calc box
- local c = lastCalc
- local cb = layout.calcBox
- local cx = cb.x + 2
- local cw = cb.w - 4
- local crow = cb.y + 1
- local function cc(id, lbl, val, vc)
- putDyn(id, cx, crow, cw, fit(lbl .. ": " .. tostring(val), cw), vc or C.text, C.panel)
- crow = crow + 1
- end
- cc("cm1", "Target Sat", string.format("%.1f%%", (c.targetCoreSat or 0)*100), C.yellow)
- cc("cm2", "Sat Error", formatRF(c.satError or 0), C.text)
- cc("cm3", "Req Input", formatRF(c.requiredInput or 0), C.purple)
- cc("cm4", "Out Needed", formatRF(c.outputNeeded or 0), C.green)
- cc("cm5", "In Cmd", formatRF(c.inputCommand or 0), C.blue)
- cc("cm6", "Drain Factor", string.format("%.3f", c.tempDrainFactor or 0), C.text)
- cc("cm7", "ConvLVL", string.format("%.3f", c.convLVL or 0), C.muted)
- cc("cm8", "In Gate", shortAddr(input_flux_addr), C.muted)
- cc("cm9", "Out Gate", shortAddr(output_flux_addr), C.muted)
- else
- local cb = layout.calcBox
- putDyn("noinfo", cb.x+2, cb.y+1, cb.w-4, "Waiting for reactor data…", C.yellow, C.panel)
- end
- end
- --------------------------------------------------------------------------------
- -- BUTTONS
- --------------------------------------------------------------------------------
- local function drawBtn(btn, label, fg, bg)
- setColor(fg, bg)
- gpu.fill(btn.x, btn.y, btn.w, btn.h, " ")
- local tx = btn.x + math.floor((btn.w - #label)/2)
- gpu.set(tx, btn.y, label)
- end
- local function drawButtons()
- local info = lastInfo
- local status = info and tostring(info.status or "unknown") or "unknown"
- local canStart = status == "cold" or status == "cooling" or status == "offline" or status == "stopped" or status == "stopping"
- local canStop = status == "running" or status == "warming_up"
- if canStart then
- drawBtn(layout.btnStart, " ▶ START ", C.bg, C.green)
- else
- drawBtn(layout.btnStart, " ▶ START ", C.muted, C.panel2)
- end
- if canStop then
- drawBtn(layout.btnStop, " ■ STOP ", C.bg, C.red)
- else
- drawBtn(layout.btnStop, " ■ STOP ", C.muted, C.panel2)
- end
- drawBtn(layout.btnQuit, " QUIT ", C.bg, 0x444444)
- btnDirty = false
- end
- --------------------------------------------------------------------------------
- -- STATUS LINE
- --------------------------------------------------------------------------------
- local function drawStatusLine()
- local msg = lastError or statusMsg or ""
- local color = lastError and C.red or C.muted
- putDyn("statusline", 2, layout.statusY, W-2, msg, color, C.bg)
- end
- --------------------------------------------------------------------------------
- -- CONTROL TICK
- --------------------------------------------------------------------------------
- local function readInfo()
- local ok, s = pcall(function() return reactor.getReactorInfo() end)
- if not ok or not s then lastError = "reactor.getReactorInfo() failed"; return end
- lastError = nil
- lastInfo = {
- status = tostring(s.status or "unknown"),
- temperature = tonumber(s.temperature) or 0,
- fieldStrength = tonumber(s.fieldStrength) or 0,
- maxFieldStrength = tonumber(s.maxFieldStrength) or 0,
- energySaturation = tonumber(s.energySaturation) or 0,
- maxEnergySaturation = tonumber(s.maxEnergySaturation) or 0,
- fuelConversion = tonumber(s.fuelConversion) or 0,
- maxFuelConversion = tonumber(s.maxFuelConversion) or 0,
- fuelConversionRate = tonumber(s.fuelConversionRate) or 0,
- generationRate = tonumber(s.generationRate) or 0,
- fieldDrainRate = tonumber(s.fieldDrainRate) or 0,
- }
- end
- local function controlTick()
- readInfo()
- if not lastInfo then return end
- local info = lastInfo
- local status = info.status
- lastCalc = computeControl(info, targetTemp, targetShield, reactorOutputMultiplier)
- -- Safety: emergency stop if fuel nearly gone
- if info.maxFuelConversion > 0 then
- local conv = safeDiv(info.fuelConversion, info.maxFuelConversion, 0)
- if conv >= FUEL_CUTOFF and (status == "running" or status == "warming_up") then
- pcall(function() reactor.stopReactor() end)
- setGate(output_flux, 0)
- setGate(input_flux, 0)
- statusMsg = "Fuel cutoff reached — reactor stopped."
- return
- end
- end
- -- Activate whenever the reactor is ready: charged state, or warm enough,
- -- or still warming up (activateReactor during warming_up is what kicks it
- -- over to running once the field fills — same as the original script).
- if status == "charged" or status == "warming_up" then
- pcall(function() reactor.activateReactor() end)
- elseif info.temperature >= 2000 and status ~= "stopping" then
- pcall(function() reactor.activateReactor() end)
- end
- if not controlEnabled then return end
- if status == "running" then
- local smoothOut = math.max(0, lastCalc.outputNeeded or 0)
- lastSentOutput = smoothOut
- setGate(output_flux, smoothOut)
- setGate(input_flux, math.max(0, (lastCalc.inputCommand or 0) + outputOffset))
- elseif status == "warming_up" then
- lastSentOutput = 0
- setGate(output_flux, 0)
- setGate(input_flux, WARMUP_INPUT_RF_T)
- elseif status == "stopping" or status == "cooling" then
- lastSentOutput = 0
- emaOutput = nil
- setGate(output_flux, 0)
- setGate(input_flux, math.max(0, lastCalc.requiredInput or 0))
- else
- lastSentOutput = 0
- emaOutput = nil
- setGate(output_flux, 0)
- setGate(input_flux, 0)
- end
- dynDirty = true
- btnDirty = true
- end
- --------------------------------------------------------------------------------
- -- ARM / STOP
- --------------------------------------------------------------------------------
- local function armStart()
- if not lastInfo then return end
- local s = lastInfo.status
- if s == "cold" or s == "cooling" or s == "offline" or s == "stopped" then
- pcall(function() reactor.chargeReactor() end)
- statusMsg = "Reactor charging…"
- elseif s == "stopping" then
- pcall(function() reactor.activateReactor() end)
- statusMsg = "Reactor reactivating…"
- elseif s == "charged" then
- -- Charging complete — kick it over to running
- pcall(function() reactor.activateReactor() end)
- statusMsg = "Reactor activating…"
- end
- btnDirty, dynDirty = true, true
- end
- local function stopReactor()
- pcall(function() reactor.stopReactor() end)
- setGate(output_flux, 0)
- statusMsg = "Reactor stop commanded."
- btnDirty, dynDirty = true, true
- end
- --------------------------------------------------------------------------------
- -- INPUT HANDLING
- --------------------------------------------------------------------------------
- local function ptInBtn(x, y, btn)
- return x >= btn.x and x < btn.x+btn.w and y >= btn.y and y < btn.y+btn.h
- end
- local function ptInSlider(x, y, sl)
- return y >= sl.y-2 and y <= sl.y+1 and x >= sl.x and x < sl.x+sl.w
- end
- -- Relative drag state: anchor pixel and value at touch-down.
- -- Each pixel of movement adds exactly one step to the anchor value.
- -- The handle visually decouples from the finger position, which is the
- -- only way to get fine-grained steps on a rail that's too narrow to
- -- represent them spatially (e.g. 77px covering 5500C = 71C/px >> 25C/step).
- local dragAnchorX = 0
- local dragAnchorVal = 0
- local function commitSlider(which, val)
- local sl = layout.sliders
- if which == "temp" then
- local snapped = math.floor(val / sl.temp.step + 0.5) * sl.temp.step
- targetTemp = clamp(snapped, sl.temp.min, sl.temp.max)
- elseif which == "field" then
- local snapped = math.floor(val / sl.field.step + 0.5) * sl.field.step
- targetShield = clamp(snapped, sl.field.min, sl.field.max)
- elseif which == "offset" then
- local snapped = math.floor(val / sl.offset.step + 0.5) * sl.offset.step
- outputOffset = clamp(snapped, sl.offset.min, sl.offset.max)
- end
- sliderDirty = true
- end
- local function handleTouch(ex, ey)
- -- Buttons
- if ptInBtn(ex, ey, layout.btnStart) then armStart(); return end
- if ptInBtn(ex, ey, layout.btnStop) then stopReactor(); return end
- if ptInBtn(ex, ey, layout.btnQuit) then running = false; return end
- -- Sliders: snap to click position, then anchor for relative drag from there
- local sl = layout.sliders
- if ptInSlider(ex, ey, sl.temp) then
- dragging = "temp"
- -- Snap to absolute position at click, then anchor for relative drag
- local clickVal = sl.temp.min + (ex - sl.temp.x) / (sl.temp.w - 1) * (sl.temp.max - sl.temp.min)
- local snapped = math.floor(clickVal / sl.temp.step + 0.5) * sl.temp.step
- targetTemp = clamp(snapped, sl.temp.min, sl.temp.max)
- dragAnchorX = ex
- dragAnchorVal = targetTemp
- sliderDirty = true
- return
- end
- if ptInSlider(ex, ey, sl.field) then
- dragging = "field"
- local clickVal = sl.field.min + (ex - sl.field.x) / (sl.field.w - 1) * (sl.field.max - sl.field.min)
- local snapped = math.floor(clickVal / sl.field.step + 0.5) * sl.field.step
- targetShield = clamp(snapped, sl.field.min, sl.field.max)
- dragAnchorX = ex
- dragAnchorVal = targetShield
- sliderDirty = true
- return
- end
- if ptInSlider(ex, ey, sl.offset) then
- dragging = "offset"
- local clickVal = sl.offset.min + (ex - sl.offset.x) / (sl.offset.w - 1) * (sl.offset.max - sl.offset.min)
- local snapped = math.floor(clickVal / sl.offset.step + 0.5) * sl.offset.step
- outputOffset = clamp(snapped, sl.offset.min, sl.offset.max)
- dragAnchorX = ex
- dragAnchorVal = outputOffset
- sliderDirty = true
- return
- end
- end
- local function handleDrag(ex, ey)
- if not dragging then return end
- local sl = layout.sliders
- local delta = ex - dragAnchorX
- if dragging == "temp" then
- commitSlider("temp", dragAnchorVal + delta * sl.temp.step)
- elseif dragging == "field" then
- commitSlider("field", dragAnchorVal + delta * sl.field.step)
- elseif dragging == "offset" then
- commitSlider("offset", dragAnchorVal + delta * sl.offset.step)
- end
- end
- local function handleKey(char)
- if not char or char <= 0 then return end
- local c = string.lower(string.char(char))
- local sl = layout.sliders
- if c == "q" then running = false
- elseif c == "s" then armStart()
- elseif c == "x" then stopReactor()
- elseif c == "c" then
- statusMsg = "Use START/STOP buttons to control the reactor."
- btnDirty, dynDirty = true, true
- -- Keyboard temp nudges
- elseif c == "," then targetTemp = clamp(targetTemp - sl.temp.step, sl.temp.min, sl.temp.max); sliderDirty=true
- elseif c == "." then targetTemp = clamp(targetTemp + sl.temp.step, sl.temp.min, sl.temp.max); sliderDirty=true
- elseif c == "[" then targetShield = clamp(targetShield - sl.field.step, sl.field.min, sl.field.max); sliderDirty=true
- elseif c == "]" then targetShield = clamp(targetShield + sl.field.step, sl.field.min, sl.field.max); sliderDirty=true
- elseif c == "-" then outputOffset = clamp(outputOffset - sl.offset.step, sl.offset.min, sl.offset.max); sliderDirty=true
- elseif c == "=" then outputOffset = clamp(outputOffset + sl.offset.step, sl.offset.min, sl.offset.max); sliderDirty=true
- elseif c == "0" then outputOffset = 0; sliderDirty=true
- end
- end
- local function handleEvent(ev)
- local name = ev[1]
- if name == "touch" then handleTouch(ev[3], ev[4])
- elseif name == "drag" then handleDrag(ev[3], ev[4])
- elseif name == "drop" then dragging = nil
- elseif name == "key_down" then handleKey(ev[3])
- elseif name == "screen_resized" then
- buildLayout(); dynCache={}
- drawStaticUI(); sliderDirty=true; btnDirty=true; dynDirty=true
- elseif name == "interrupted" then running = false
- end
- end
- --------------------------------------------------------------------------------
- -- DRAW LOOP
- --------------------------------------------------------------------------------
- local function drawDynamic()
- if sliderDirty then drawSliders() end
- if btnDirty then drawButtons() end
- if dynDirty then drawDynamicInfo() end
- drawStatusLine()
- dynDirty = false
- sliderDirty = false
- end
- --------------------------------------------------------------------------------
- -- MAIN
- --------------------------------------------------------------------------------
- local function restoreScreen()
- for _, tid in ipairs(timers) do pcall(event.cancel, tid) end
- pcall(function() setGate(output_flux, 0) end)
- gpu.setForeground(savedFg or C.white)
- gpu.setBackground(savedBg or C.black)
- term.clear()
- end
- local function main()
- running = true
- timers = {}
- bindGates()
- buildLayout()
- drawStaticUI()
- readInfo()
- drawDynamic()
- statusMsg = gateMsg
- timers[#timers+1] = event.timer(0.05, function() controlTick() end, math.huge)
- timers[#timers+1] = event.timer(0.25, function() dynDirty = true end, math.huge)
- while running do
- local ev = {event.pull(0.05)}
- if ev and ev[1] then handleEvent(ev) end
- drawDynamic()
- end
- end
- local ok, err = xpcall(main, debug.traceback)
- restoreScreen()
- if not ok then
- print("Draconic Reactor GUI crashed:")
- print(tostring(err))
- else
- print("Draconic Reactor GUI closed.")
- end
- print("Keys: S=start X=stop C=toggle control Q=quit ,./[]=nudge targets")
Advertisement