oaky / draconic-test public computer
0
0
Web IDE
main
2 commits
oaky Update draconic-test
fa8c9640 2026-09-25
main
Update draconic-test2026-09-25
Update draconic-test2026-09-25
Update draconic-test2026-09-25
Update draconic-test2026-09-25
Update draconic-test2026-09-25
Overview
MIT

Draconic Test

Quick Install on your ComputerCraft device

Type this command in the terminal:

hub get draconic-test
📖
No README.md in this repository

Documenting your script or package helps other players learn how to install, configure and run it.

base.lua main
-- ============================================================
-- Draconic Reactor - Base Terminal
-- Laeuft bei den Monitoren in der Base
-- Benoetigt: Monitor (mind. 47x31 Zeichen) + Wireless Modem
-- ============================================================

local PROTOCOL = "draconic-reactor-v1"

local CONFIG = {
    steps = { 10000, 50000, 250000, 1000000, 5000000 },
    defaultStepIndex = 2,

    minPower = 0,
    maxPower = 200000000,

    staleAfter = 3000,

    minWidth  = 47,
    minHeight = 33
}


local function findWirelessModem()
    for _, name in ipairs(peripheral.getNames()) do
        if peripheral.hasType(name, "modem") then
            local modem = peripheral.wrap(name)

            if modem.isWireless and modem.isWireless() then
                return name
            end
        end
    end

    error("Kein Wireless Modem gefunden")
end


local monitor = peripheral.find("monitor")

if not monitor then
    error("Kein Monitor gefunden")
end

local modemName = findWirelessModem()
rednet.open(modemName)

monitor.setTextScale(0.5)


local telemetry      = nil
local telemetryTime  = 0
local requestedOutput = 3000000
local requestedInput  = 6000000
local stepIndex      = CONFIG.defaultStepIndex


local function currentStep()
    return CONFIG.steps[stepIndex]
end


-- ============================================================
-- Formatierung
-- ============================================================

local function formatEnergy(value)
    value = tonumber(value) or 0

    if value >= 1000000000 then
        return string.format("%.2f GOP/t", value / 1000000000)
    elseif value >= 1000000 then
        return string.format("%.2f MOP/t", value / 1000000)
    elseif value >= 1000 then
        return string.format("%.1f kOP/t", value / 1000)
    end

    return string.format("%.0f OP/t", value)
end


local function formatStep(value)
    if value >= 1000000 then
        return string.format("%gM", value / 1000000)
    end

    return string.format("%gk", value / 1000)
end


local function pct(value)
    return string.format("%.1f%%", (value or 0) * 100)
end


local function formatDuration(seconds)
    if seconds == nil or seconds <= 0 or seconds == math.huge then
        return "--"
    end

    local h = math.floor(seconds / 3600)
    local m = math.floor((seconds % 3600) / 60)

    if h > 999 then
        return "999h+"
    elseif h > 0 then
        return string.format("%dh %dm", h, m)
    else
        return string.format("%dm", m)
    end
end


-- ============================================================
-- Zeichenprimitive
-- ============================================================

local function center(y, text)
    local w = monitor.getSize()

    monitor.setCursorPos(
        math.max(1, math.floor((w - #text) / 2) + 1),
        y
    )

    monitor.write(text)
end


local function label(x, y, name, value)
    monitor.setTextColor(colors.lightGray)
    monitor.setCursorPos(x, y)
    monitor.write(name)

    monitor.setTextColor(colors.white)
    monitor.setCursorPos(x + 18, y)
    monitor.write(value)
end


local function bar(x, y, width, value, color)
    value = math.max(0, math.min(1, value or 0))

    local filled = math.floor(width * value)

    monitor.setCursorPos(x, y)
    monitor.setBackgroundColor(colors.gray)
    monitor.write(string.rep(" ", width))

    monitor.setCursorPos(x, y)
    monitor.setBackgroundColor(color)
    monitor.write(string.rep(" ", filled))

    monitor.setBackgroundColor(colors.black)
end


local buttons = {}

local function button(id, x, y, width, text, bg)
    buttons[id] = {
        x1 = x, y1 = y,
        x2 = x + width - 1, y2 = y
    }

    if #text > width then
        text = string.sub(text, 1, width)
    end

    monitor.setCursorPos(x, y)
    monitor.setBackgroundColor(bg)
    monitor.setTextColor(colors.white)

    local left  = math.floor((width - #text) / 2)
    local right = width - #text - left

    monitor.write(
        string.rep(" ", left) .. text .. string.rep(" ", right)
    )

    monitor.setBackgroundColor(colors.black)
end


-- Verteilt n Buttons gleichmaessig ueber die Breite
local function buttonRow(y, items)
    local w = monitor.getSize()

    local gap   = 1
    local total = w - 2 - (gap * (#items - 1))
    local bw    = math.floor(total / #items)

    local x = 2

    for _, item in ipairs(items) do
        button(item.id, x, y, bw, item.text, item.bg)
        x = x + bw + gap
    end
end


local function send(command, value)
    rednet.broadcast({
        target  = "reactor",
        command = command,
        value   = value
    }, PROTOCOL)
end


-- ============================================================
-- Hauptansicht
-- ============================================================

local function drawInner()
    monitor.setBackgroundColor(colors.black)
    monitor.setTextColor(colors.white)
    monitor.clear()

    buttons = {}

    local w, h = monitor.getSize()

    if w < CONFIG.minWidth or h < CONFIG.minHeight then
        monitor.setTextColor(colors.red)
        center(2, "MONITOR ZU KLEIN")
        monitor.setTextColor(colors.white)
        center(4, w .. "x" .. h .. " Zeichen")
        center(5, "benoetigt: " .. CONFIG.minWidth ..
                  "x" .. CONFIG.minHeight)
        center(7, "Mehr Bloecke oder")
        center(8, "setTextScale kleiner")
        return
    end

    center(1, "DRACONIC REACTOR CONTROL")

    local online =
        telemetry ~= nil
        and (os.epoch("utc") - telemetryTime) < CONFIG.staleAfter

    if not online then
        monitor.setTextColor(colors.red)
        center(4, "REACTOR OFFLINE")
        monitor.setTextColor(colors.lightGray)
        center(6, "Keine Telemetrie vom Controller")
        return
    end

    local r = telemetry.reactor
    local c = telemetry.controller

    -- ---- Status ----
    monitor.setTextColor(
        c.emergency and colors.red or colors.lime
    )

    monitor.setCursorPos(2, 3)
    monitor.write("MODE: " .. string.upper(tostring(c.mode)))

    if c.emergency then
        monitor.setCursorPos(2, 4)
        monitor.write(
            "EMERGENCY: " .. tostring(c.emergencyReason)
        )
    end

    -- ---- Messwerte ----
    label(2, 6, "Temperature",
        string.format("%.0f C", r.temperature or 0))

    label(2, 7, "Containment", pct(r.fieldPercent))
    bar(2, 8, w - 4, r.fieldPercent, colors.cyan)

    label(2, 10, "Saturation", pct(r.saturationPercent))
    bar(2, 11, w - 4, r.saturationPercent, colors.blue)

    label(2, 13, "Fuel Converted", pct(r.fuelPercent))
    bar(2, 14, w - 4, r.fuelPercent, colors.orange)

    local remainingFuel   = (r.maxFuelConversion or 0) - (r.fuelConversion or 0)
    local fuelRatePerTick = (r.fuelConversionRate or 0) / 1000000

    local remainingSeconds = nil
    if fuelRatePerTick > 0 then
        remainingSeconds = (remainingFuel / fuelRatePerTick) / 20
    end

    label(2, 15, "Laufzeit noch", formatDuration(remainingSeconds))

    label(2, 16, "Generation", formatEnergy(r.generationRate))
    label(2, 17, "Field Drain", formatEnergy(r.fieldDrainRate))
    label(2, 18, "Aktiver Output", formatEnergy(c.commandedOutput))
    label(2, 19, "Aktiver Input", formatEnergy(c.commandedInput))

    -- ---- Output-Regler ----
    monitor.setTextColor(colors.yellow)
    center(21, "OUTPUT TARGET: " .. formatEnergy(requestedOutput))

    local stepText = formatStep(currentStep())

    buttonRow(22, {
        { id = "out_minus", text = "-" .. stepText, bg = colors.orange },
        { id = "out_apply", text = "APPLY OUT",     bg = colors.green  },
        { id = "out_plus",  text = "+" .. stepText, bg = colors.orange }
    })

    -- ---- Input-Regler ----
    monitor.setTextColor(colors.yellow)
    center(24, "INPUT TARGET: " .. formatEnergy(requestedInput))

    buttonRow(25, {
        { id = "in_minus", text = "-" .. stepText, bg = colors.orange },
        { id = "in_apply", text = "APPLY IN",      bg = colors.green  },
        { id = "in_plus",  text = "+" .. stepText, bg = colors.orange }
    })

    -- ---- Schrittweite (fuer beide Regler) ----
    monitor.setTextColor(colors.lightGray)
    monitor.setCursorPos(2, 27)
    monitor.write("STEP")

    local stepButtons = {}

    for i, s in ipairs(CONFIG.steps) do
        stepButtons[i] = {
            id   = "step" .. i,
            text = formatStep(s),
            bg   = (i == stepIndex)
                   and colors.cyan
                   or colors.gray
        }
    end

    buttonRow(28, stepButtons)

    -- ---- Auto-Optimize ----
    buttonRow(29, {
        {
            id   = "auto_optimize",
            text = c.autoOptimize and "AUTO-OPTIMIZE: AN" or "AUTO-OPTIMIZE: AUS",
            bg   = c.autoOptimize and colors.lime or colors.gray
        }
    })

    -- ---- Aktionen ----
    buttonRow(30, {
        { id = "charge",   text = "CHARGE",   bg = colors.blue   },
        { id = "activate", text = "ACTIVATE", bg = colors.green  },
        { id = "shutdown", text = "STOP",     bg = colors.orange },
        { id = "reset",    text = "RESET",    bg = colors.red    }
    })

    -- ---- Node-Status ----
    if h >= 33 then
        monitor.setTextColor(
            c.inputNodeOnline and colors.lime or colors.red
        )
        monitor.setCursorPos(2, 32)
        monitor.write("INPUT: " ..
            (c.inputNodeOnline and "ONLINE" or "OFFLINE"))

        monitor.setTextColor(
            c.outputNodeOnline and colors.lime or colors.red
        )
        monitor.setCursorPos(math.floor(w / 2) + 1, 32)
        monitor.write("OUTPUT: " ..
            (c.outputNodeOnline and "ONLINE" or "OFFLINE"))
    end

    monitor.setTextColor(colors.white)
end


-- Drei Coroutinen rufen draw() auf. Ohne Sperre ueberlagern
-- sich die Zeichenvorgaenge und das Bild flackert.
local drawing = false

local function draw()
    if drawing then
        return
    end

    drawing = true
    local ok, err = pcall(drawInner)
    drawing = false

    if not ok then
        monitor.setBackgroundColor(colors.black)
        monitor.setTextColor(colors.red)
        monitor.setCursorPos(1, 1)
        monitor.write("DRAW ERROR: " .. tostring(err))
    end
end


-- ============================================================
-- Eingaben
-- ============================================================

local function hit(x, y)
    for id, b in pairs(buttons) do
        if x >= b.x1 and x <= b.x2
            and y >= b.y1 and y <= b.y2 then
            return id
        end
    end

    return nil
end


local function handleButton(id)
    if id == nil then
        return
    end

    local stepPick = string.match(id, "^step(%d+)$")

    if stepPick then
        stepIndex = tonumber(stepPick)
        return
    end

    if id == "out_minus" then
        requestedOutput = math.max(
            CONFIG.minPower,
            requestedOutput - currentStep()
        )

    elseif id == "out_plus" then
        requestedOutput = math.min(
            CONFIG.maxPower,
            requestedOutput + currentStep()
        )

    elseif id == "out_apply" then
        send("set_output", requestedOutput)

    elseif id == "in_minus" then
        requestedInput = math.max(
            CONFIG.minPower,
            requestedInput - currentStep()
        )

    elseif id == "in_plus" then
        requestedInput = math.min(
            CONFIG.maxPower,
            requestedInput + currentStep()
        )

    elseif id == "in_apply" then
        send("set_input", requestedInput)

    elseif id == "auto_optimize" then
        local currentlyOn = telemetry ~= nil
            and telemetry.controller ~= nil
            and telemetry.controller.autoOptimize
        send("set_auto_optimize", not currentlyOn)

    elseif id == "charge"   then send("charge")
    elseif id == "activate" then send("activate")
    elseif id == "shutdown" then send("shutdown")
    elseif id == "reset"    then send("reset")
    end
end


-- ============================================================
-- Schleifen
-- ============================================================

local function networkLoop()
    while true do
        local sender, msg = rednet.receive(PROTOCOL)

        if type(msg) == "table" and msg.type == "telemetry" then
            telemetry     = msg
            telemetryTime = os.epoch("utc")
        end
    end
end


local function touchLoop()
    while true do
        local event, side, x, y =
            os.pullEvent("monitor_touch")

        handleButton(hit(x, y))
        draw()
    end
end


local function redrawLoop()
    while true do
        draw()
        sleep(0.5)
    end
end


draw()

parallel.waitForAll(networkLoop, touchLoop, redrawLoop)

Usage

Once installed with hub get draconic-test, run:

draconic-test
Careful what you run: This script was written by oaky, not by us. It runs with full access to the computer you install it on — it can read and delete files there. Read it before you run it.

About

No description provided.

MIT License
★ 0 stars
0 in-game downloads

Hardware Targets

computer

Owner