Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- =================================================================
- -- CONFIGURATION - BITTE HIER DEINE UUIDS EINTRAGEN!
- -- =================================================================
- local REACTOR_UUID = "94b23646-6ef0-4a6c-8e3d-5319263d9175"
- local INPUT_GATE_UUID = "8fb02e6f-8e47-4677-88ed-16a8b55f9c43"
- local OUTPUT_GATE_UUID = "a656039b-a057-49e2-92b0-77f80fbf61d1"
- local FAILSAFE_PIN = "1234" -- Dein Wunsch-PIN zum Umschalten
- -- =================================================================
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local colors = require("colors")
- -- Komponenten binden
- local gpu = component.gpu
- local reactor = component.proxy(REACTOR_UUID)
- local input_gate = component.proxy(INPUT_GATE_UUID)
- local output_gate = component.proxy(OUTPUT_GATE_UUID)
- if not reactor or not input_gate or not output_gate then
- print("Fehler: Eine oder mehrere Komponenten wurden nicht gefunden!")
- print("Bitte überprüfe die UUIDs in der Konfiguration.")
- return
- end
- -- Override-Modus auf den Flux Gates aktivieren
- input_gate.setOverrideEnabled(true)
- output_gate.setOverrideEnabled(true)
- -- Bildschirm-Setup
- local screenW, screenH = 80, 25
- gpu.setResolution(screenW, screenH)
- -- Globale Zustände
- local running = true
- local controlMode = "AUTO"
- local opMode = "SAFE"
- local showWarning = false
- local failsafeEnabled = true
- local failsafeTriggered = false
- -- PIN-Pad Zustände
- local showPinPad = false
- local pinBuffer = ""
- -- Interne Fluss-Speicher
- local targetInput = input_gate.getFlow() or 100000
- local targetOutput = output_gate.getFlow() or 0
- -- Betriebsmodi Parameter
- local profiles = {
- SAFE = { targetTemp = 2500, targetShield = 70, maxOutput = 100000 },
- NORMAL = { targetTemp = 4500, targetShield = 60, maxOutput = 500000 },
- BOOST = { targetTemp = 6500, targetShield = 55, maxOutput = 2000000 },
- SUPERBOOST = { targetTemp = 7800, targetShield = 52, maxOutput = 8000000 }
- }
- -- Helfer: Text formatieren
- local function formatNum(num)
- if num >= 1000000 then return string.format("%.2fM", num / 1000000) end
- if num >= 1000 then return string.format("%.1fk", num / 1000) end
- return tostring(num)
- end
- -- Helfer: Textausgabe
- local function drawText(x, y, text, fg, bg, width)
- gpu.setForeground(fg or 0xFFFFFF)
- gpu.setBackground(bg or 0x151515)
- text = tostring(text)
- if width then
- if #text < width then
- text = text .. string.rep(" ", width - #text)
- elseif #text > width then
- text = string.sub(text, 1, width)
- end
- end
- gpu.set(x, y, text)
- end
- -- Button-Klassenspeicher
- local buttons = {}
- local function registerButton(x1, y1, x2, y2, id)
- table.insert(buttons, {x1=x1, y1=y1, x2=x2, y2=y2, id=id})
- end
- -- GUI statischen Hintergrund zeichnen
- local function drawStaticGUI()
- gpu.setBackground(0x151515)
- gpu.fill(1, 1, screenW, screenH, " ")
- gpu.setForeground(0x00FFD5)
- gpu.fill(1, 1, screenW, 1, "═")
- gpu.fill(1, screenH, screenW, 1, "═")
- gpu.set(4, 1, " DRACONIC REACTOR CONTROL SYSTEM [V2.2] ")
- for y = 3, 23 do gpu.set(42, y, "║") end
- drawText(4, 4, "REAKTOR STATUS:", 0xAAAAAA)
- drawText(4, 6, "Kerntemperatur:", 0xAAAAAA)
- drawText(4, 8, "Schildstärke :", 0xAAAAAA)
- drawText(4, 10, "Energie-Sätt. :", 0xAAAAAA)
- drawText(4, 12, "Generierung :", 0xAAAAAA)
- drawText(45, 4, "KONTROLLMODUS:", 0xAAAAAA)
- drawText(45, 7, "BETRIEBSMODUS:", 0xAAAAAA)
- drawText(45, 13, "FLUX GATE MANAGEMENT", 0x00FFD5)
- drawText(45, 15, "INPUT (Schild):", 0xAAAAAA)
- drawText(45, 17, "OUTPUT (Netz):", 0xAAAAAA)
- drawText(75, 1, "[ X ]", 0xFF0000, 0x333333)
- registerButton(75, 1, 79, 1, "EXIT")
- end
- -- Grafisches PIN-Pad Overlay zeichnen
- local function drawPinPadGUI()
- gpu.setBackground(0x222222)
- gpu.fill(25, 4, 32, 17, " ")
- drawText(29, 5, "PIN-CODE ERFORDERLICH", 0xFFFF00, 0x222222)
- -- Displayzeile für Sterne
- gpu.setBackground(0x111111)
- gpu.fill(28, 7, 26, 1, " ")
- local disp = string.rep("*", #pinBuffer)
- if pinBuffer == "FALSCH" then
- disp = "FALSCHER PIN!"
- gpu.setForeground(0xFF0000)
- else
- gpu.setForeground(0xFFFFFF)
- end
- gpu.set(29, 7, disp)
- -- Tasten-Layout (Zeile 1-3)
- drawText(29, 9, " [1] ", 0xFFFFFF, 0x333333) registerButton(29, 9, 33, 9, "PIN_1")
- drawText(36, 9, " [2] ", 0xFFFFFF, 0x333333) registerButton(36, 9, 40, 9, "PIN_2")
- drawText(43, 9, " [3] ", 0xFFFFFF, 0x333333) registerButton(43, 9, 47, 9, "PIN_3")
- drawText(29, 11, " [4] ", 0xFFFFFF, 0x333333) registerButton(29, 11, 33, 11, "PIN_4")
- drawText(36, 11, " [5] ", 0xFFFFFF, 0x333333) registerButton(36, 11, 40, 11, "PIN_5")
- drawText(43, 11, " [6] ", 0xFFFFFF, 0x333333) registerButton(43, 11, 47, 11, "PIN_6")
- drawText(29, 13, " [7] ", 0xFFFFFF, 0x333333) registerButton(29, 13, 33, 13, "PIN_7")
- drawText(36, 13, " [8] ", 0xFFFFFF, 0x333333) registerButton(36, 13, 40, 13, "PIN_8")
- drawText(43, 13, " [9] ", 0xFFFFFF, 0x333333) registerButton(43, 13, 47, 13, "PIN_9")
- -- Zeile 4 (Clear, 0, OK)
- drawText(29, 15, " [C] ", 0xFF5555, 0x333333) registerButton(29, 15, 33, 15, "PIN_C")
- drawText(36, 15, " [0] ", 0xFFFFFF, 0x333333) registerButton(36, 15, 40, 15, "PIN_0")
- drawText(43, 15, " [OK] ", 0x00FF00, 0x333333) registerButton(43, 15, 47, 15, "PIN_OK")
- -- Abbrechen Button unten drunter
- drawText(31, 18, " [ ABBRECHEN ] ", 0xFFFFFF, 0x444444) registerButton(31, 18, 45, 18, "PIN_CANCEL")
- end
- -- Dynamische UI Elemente aktualisieren
- local function drawDynamicGUI(info, shieldPct)
- if showPinPad then
- drawPinPadGUI()
- return
- end
- if showWarning then
- gpu.setBackground(0x330000)
- gpu.fill(20, 8, 42, 9, " ")
- drawText(22, 9, "!!! WARNUNG: UNSICHERER BETRIEB !!!", 0xFF0000, 0x330000)
- drawText(22, 11, "Superboost kann den Reaktor zerstören.", 0xFFFFFF, 0x330000)
- drawText(22, 12, "Failsafe wird zwingend vorausgesetzt.", 0xFFFFFF, 0x330000)
- drawText(26, 14, " [ BESTÄTIGEN ] ", 0x00FF00, 0x555555)
- registerButton(26, 14, 41, 14, "CONFIRM_SUPER")
- drawText(45, 14, " [ ABBRECHEN ] ", 0xFF0000, 0x555555)
- registerButton(45, 14, 59, 14, "CANCEL_SUPER")
- return
- end
- local statusColor = 0x00FF00
- if info.status == "offline" or info.status == "cold" then statusColor = 0x999999
- elseif info.status == "charging" then statusColor = 0xFFFF00
- elseif info.status == "stopping" then statusColor = 0xFF5500
- end
- drawText(21, 4, string.upper(info.status), statusColor, 0x151515, 15)
- local tempColor = 0x00FF00
- if info.temperature > 5000 then tempColor = 0xFFFF00 end
- if info.temperature > 7000 then tempColor = 0xFF0000 end
- drawText(21, 6, string.format("%.1f °C", info.temperature), tempColor, 0x151515, 15)
- local shieldColor = 0x00FF00
- if shieldPct < 60 then shieldColor = 0xFFFF00 end
- if shieldPct < 51 then shieldColor = 0xFF0000 end
- drawText(21, 8, string.format("%.2f %%", shieldPct), shieldColor, 0x151515, 15)
- local satPct = (info.energySaturation / info.maxEnergySaturation) * 100
- drawText(21, 10, string.format("%.2f %%", satPct), 0x00AAFF, 0x151515, 15)
- drawText(21, 12, formatNum(info.generationRate) .. " RF/t", 0x00FF00, 0x151515, 15)
- local btnAutoBG = (controlMode == "AUTO") and 0x0055FF or 0x333333
- local btnManBG = (controlMode == "MANUELL") and 0x0055FF or 0x333333
- drawText(61, 4, " AUTO ", 0xFFFFFF, btnAutoBG)
- registerButton(61, 4, 66, 4, "MODE_AUTO")
- drawText(69, 4, " MANUELL ", 0xFFFFFF, btnManBG)
- registerButton(69, 4, 77, 4, "MODE_MANUAL")
- local mSafe = (opMode == "SAFE") and 0x00FF00 or 0x333333
- local mNorm = (opMode == "NORMAL") and 0x0055FF or 0x333333
- local mBoost = (opMode == "BOOST") and 0xFFFF00 or 0x333333
- local mSBoost = (opMode == "SUPERBOOST") and 0xFF0000 or 0x333333
- drawText(45, 9, " SAFE ", 0xFFFFFF, mSafe)
- registerButton(45, 9, 52, 9, "OP_SAFE")
- drawText(54, 9, " NORMAL ", 0xFFFFFF, mNorm)
- registerButton(54, 9, 61, 9, "OP_NORMAL")
- drawText(63, 9, " BOOST ", 0xFFFF00, mBoost)
- registerButton(63, 9, 70, 9, "OP_BOOST")
- drawText(72, 9, " S-BST ", 0xFF0000, mSBoost)
- registerButton(72, 9, 79, 9, "OP_SUPERBOOST")
- drawText(61, 15, string.format("%9s RF/t", formatNum(targetInput)), 0xFFFF00, 0x151515)
- drawText(61, 17, string.format("%9s RF/t", formatNum(targetOutput)), 0x00FF00, 0x151515)
- if controlMode == "MANUELL" then
- drawText(45, 19, " [IN -10k] ", 0xFFFFFF, 0x333333) registerButton(45, 19, 54, 19, "IN_-10K")
- drawText(56, 19, " [IN +10k] ", 0xFFFFFF, 0x333333) registerButton(56, 19, 65, 19, "IN_+10K")
- drawText(45, 21, " [OUT-10k] ", 0xFFFFFF, 0x333333) registerButton(45, 21, 54, 21, "OUT_-10K")
- drawText(56, 21, " [OUT+10k] ", 0xFFFFFF, 0x333333) registerButton(56, 21, 65, 21, "OUT_+10K")
- else
- gpu.fill(45, 19, 25, 3, " ")
- end
- local actColor = (info.status == "online") and 0x00FF00 or 0x333333
- local chgColor = (info.status == "charging") and 0xFFFF00 or 0x333333
- drawText(4, 16, "┌────────────┐", 0xAAAAAA)
- drawText(4, 17, "│ CHARGE │", 0xFFFFFF, chgColor)
- drawText(4, 18, "└────────────┘", 0xAAAAAA)
- registerButton(4, 16, 17, 18, "ACT_CHARGE")
- drawText(20, 16, "┌────────────┐", 0xAAAAAA)
- drawText(20, 17, "│ ACTIVATE │", 0xFFFFFF, actColor)
- drawText(20, 18, "└────────────┘", 0xAAAAAA)
- registerButton(20, 16, 33, 18, "ACT_ACTIVATE")
- drawText(4, 20, "┌──────────────────────────────┐", 0xAAAAAA)
- drawText(4, 21, "│ STOP REACTOR │", 0xFFFFFF, 0x550000)
- drawText(4, 22, "└──────────────────────────────┘", 0xAAAAAA)
- registerButton(4, 20, 35, 22, "ACT_STOP")
- -- Interaktive Failsafe-Schaltfläche unten rechts
- if failsafeTriggered then
- drawText(45, 23, " FAILSAFE AUSGELÖST! SCHILD GEFALLEN ", 0xFFFFFF, 0xFF0000, 34)
- else
- if failsafeEnabled then
- drawText(45, 23, " [ FAILSAFE MODE: AKTIV (ON) ] ", 0x00FF00, 0x222222, 34)
- else
- drawText(45, 23, " [ FAILSAFE MODE: AUS (DEAKTIV) ] ", 0xFF5555, 0x222222, 34)
- end
- registerButton(45, 23, 79, 23, "TOGGLE_FAILSAFE")
- end
- end
- -- Klick-Logik verarbeiten
- local function handleTouch(x, y)
- for _, btn in ipairs(buttons) do
- if x >= btn.x1 and x <= btn.x2 and y >= btn.y1 and y <= btn.y2 then
- -- PIN-Pad Logik abfangen
- if showPinPad then
- if pinBuffer == "FALSCH" then pinBuffer = "" end
- if btn.id == "PIN_CANCEL" then
- showPinPad = false
- pinBuffer = ""
- elseif btn.id == "PIN_C" then
- pinBuffer = ""
- elseif btn.id == "PIN_OK" then
- if pinBuffer == FAILSAFE_PIN then
- failsafeEnabled = not failsafeEnabled
- showPinPad = false
- pinBuffer = ""
- else
- pinBuffer = "FALSCH"
- end
- else
- local num = btn.id:sub(5)
- if #pinBuffer < 6 then pinBuffer = pinBuffer .. num end
- end
- buttons = {}
- drawStaticGUI()
- return
- end
- if showWarning then
- if btn.id == "CONFIRM_SUPER" then opMode = "SUPERBOOST" showWarning = false
- elseif btn.id == "CANCEL_SUPER" then showWarning = false end
- buttons = {}
- drawStaticGUI()
- return
- end
- -- Normale GUI Buttons
- if btn.id == "EXIT" then running = false
- elseif btn.id == "TOGGLE_FAILSAFE" then
- showPinPad = true
- pinBuffer = ""
- buttons = {}
- drawStaticGUI()
- return
- elseif btn.id == "MODE_AUTO" then controlMode = "AUTO"
- elseif btn.id == "MODE_MANUAL" then controlMode = "MANUELL"
- elseif btn.id == "OP_SAFE" then opMode = "SAFE"
- elseif btn.id == "OP_NORMAL" then opMode = "NORMAL"
- elseif btn.id == "OP_BOOST" then opMode = "BOOST"
- elseif btn.id == "OP_SUPERBOOST" then showWarning = true
- elseif btn.id == "ACT_CHARGE" then reactor.chargeReactor()
- elseif btn.id == "ACT_ACTIVATE" then reactor.activateReactor()
- elseif btn.id == "ACT_STOP" then
- reactor.stopReactor()
- targetOutput = 0
- output_gate.setFlowOverride(0)
- elseif btn.id == "IN_-10K" then targetInput = math.max(0, targetInput - 10000) input_gate.setFlowOverride(targetInput)
- elseif btn.id == "IN_+10K" then targetInput = targetInput + 10000 input_gate.setFlowOverride(targetInput)
- elseif btn.id == "OUT_-10K" then targetOutput = math.max(0, targetOutput - 10000) output_gate.setFlowOverride(targetOutput)
- elseif btn.id == "OUT_+10K" then targetOutput = targetOutput + 10000 output_gate.setFlowOverride(targetOutput)
- end
- buttons = {}
- break
- end
- end
- end
- -- Auto-Regelungs-Logik
- local function performAutoRegulation(info, shieldPct)
- if controlMode ~= "AUTO" then return end
- local profile = profiles[opMode]
- -- 1. Schild-Regelung via Input Gate
- if shieldPct < profile.targetShield then
- targetInput = targetInput + 25000
- elseif shieldPct > profile.targetShield + 2 then
- targetInput = math.max(10000, targetInput - 10000)
- end
- -- 2. Temperatur-Regelung via Output Gate
- if info.status == "online" then
- if info.temperature < profile.targetTemp then
- targetOutput = targetOutput + 10000
- elseif info.temperature > profile.targetTemp + 50 then
- targetOutput = math.max(0, targetOutput - 20000)
- end
- targetOutput = math.min(targetOutput, profile.maxOutput)
- else
- targetOutput = 0
- end
- input_gate.setFlowOverride(targetInput)
- output_gate.setFlowOverride(targetOutput)
- end
- -- Hauptschleife
- drawStaticGUI()
- while running do
- local info = reactor.getReactorInfo()
- if info then
- local currentShield = info.fieldCharge or info.shieldCharge or 0
- local maxShield = info.maxFieldCharge or info.maxShieldCharge or 1
- local shieldPct = (currentShield / maxShield) * 100
- -- === CRITICAL FAILSAFE ===
- -- Greift jetzt NUR, wenn der Reaktor wirklich "online" (aktiv am Laufen) ist!
- if failsafeEnabled and info.status == "online" and shieldPct < 50.0 then
- reactor.stopReactor()
- targetOutput = 0
- output_gate.setFlowOverride(0)
- targetInput = 2000000
- input_gate.setFlowOverride(targetInput)
- failsafeTriggered = true
- controlMode = "MANUELL"
- elseif shieldPct >= 70.0 then
- failsafeTriggered = false
- end
- if not failsafeTriggered then
- performAutoRegulation(info, shieldPct)
- end
- buttons = {}
- registerButton(75, 1, 79, 1, "EXIT")
- drawDynamicGUI(info, shieldPct)
- end
- local id, _, x, y = event.pull(0.4, "touch")
- if id == "touch" then
- handleTouch(x, y)
- end
- end
- term.clear()
- print("Reaktor-Kontrollprogramm beendet.")
Advertisement
Add Comment
Please, Sign In to add comment