Scope Andesite display to local production data

This commit is contained in:
2026-07-17 01:52:27 +02:00
parent 03a88fb2c5
commit 661becfb45
2 changed files with 21 additions and 76 deletions
+14 -70
View File
@@ -2,7 +2,6 @@
-- Two Create Item Vaults are discovered by their contents and remembered.
local REFRESH_SECONDS = 1
local SENSOR_SETTLE_SECONDS = 0.15
local MIN_WIDTH = 28
local MIN_HEIGHT = 13
local CLUTCH_OUTPUT_SIDE = "left"
@@ -41,14 +40,10 @@ end
local requestedRunning = loadText(STATE_FILE) == "RUNNING"
local devices = textutils.unserialize(loadText(DEVICE_FILE) or "") or {}
local capacityCache = {}
local lastAppliedRunning = nil
local function setMachineRunning(running)
local level = running and OUTPUT_LEVEL_WHEN_RUNNING or not OUTPUT_LEVEL_WHEN_RUNNING
redstone.setOutput(CLUTCH_OUTPUT_SIDE, level)
local changed = lastAppliedRunning ~= running
lastAppliedRunning = running
return changed
end
-- Fail safe while peripherals are being discovered.
@@ -102,17 +97,6 @@ local function formatInteger(value)
return table.concat(parts, ".")
end
local function getValueIgnoringCase(data, wantedKeys)
if type(data) ~= "table" then return nil end
for key, value in pairs(data) do
local lowered = tostring(key):lower()
for _, wanted in ipairs(wantedKeys) do
if lowered == wanted:lower() then return value end
end
end
return nil
end
local function isVault(name)
return peripheral.isPresent(name)
and peripheral.hasType(name, "inventory")
@@ -220,61 +204,24 @@ local function discoverVaults()
return savedZinc or getInventory(devices.zinc), savedAlloy or getInventory(devices.alloy)
end
local function discoverStressometer()
for _, name in ipairs(peripheral.getNames()) do
if peripheral.hasType(name, "block_reader") then
local ok, data = pcall(peripheral.call, name, "getBlockData")
if ok and type(data) == "table" and tonumber(getValueIgnoringCase(data, { "Speed" })) then
local network = getValueIgnoringCase(data, { "Network" })
local speed = math.abs(tonumber(getValueIgnoringCase(data, { "Speed" })) or 0)
if type(network) == "table" then
local capacity = tonumber(getValueIgnoringCase(network, { "Capacity" })) or 0
local usage = tonumber(getValueIgnoringCase(network, { "Stress" })) or 0
local load = capacity > 0 and usage / capacity * 100 or 0
return speed, capacity, usage, load
end
return speed, nil, nil, nil
end
end
end
return nil, nil, nil, nil
end
local function evaluate()
local zincVault, alloyVault = discoverVaults()
local zinc = countItems(zincVault, ZINC_ITEMS)
local alloy = countItems(alloyVault, ALLOY_ITEMS)
local speed, capacity, usage, load = discoverStressometer()
local missing = not zincVault or not alloyVault
local noMaterial = zincVault and zinc <= 0
local outputFull = alloyVault and alloyVault.capacity > 0 and alloyVault.total >= alloyVault.capacity
local overstressed = capacity and usage and usage > capacity
local allowed = not missing and not noMaterial and not outputFull and not overstressed
local allowed = not missing and not noMaterial and not outputFull
local effectiveRunning = requestedRunning and allowed
local outputChanged = setMachineRunning(effectiveRunning)
-- Create updates the kinetic network after the redstone event. Without a
-- short settling period, the first frame after a touch shows the previous
-- state and therefore looks inverted.
if outputChanged then
sleep(SENSOR_SETTLE_SECONDS)
speed, capacity, usage, load = discoverStressometer()
overstressed = capacity and usage and usage > capacity
if overstressed and effectiveRunning then
effectiveRunning = false
setMachineRunning(false)
end
end
setMachineRunning(effectiveRunning)
local status, color = "STOPPED", colors.red
if requestedRunning then
if missing then status, color = "NO VAULT DATA", colors.red
elseif noMaterial then status, color = "WAITING: NO ZINC", colors.orange
elseif outputFull then status, color = "STANDBY: OUTPUT FULL", colors.orange
elseif overstressed then status, color = "STOPPED: OVERSTRESSED", colors.red
elseif not speed or speed == 0 then status, color = "STARTING / NO ROTATION", colors.orange
else status, color = "RUNNING", colors.lime end
end
@@ -283,10 +230,8 @@ local function evaluate()
alloyVault = alloyVault,
zinc = zinc,
alloy = alloy,
speed = speed,
capacity = capacity,
usage = usage,
load = load,
noMaterial = noMaterial,
outputFull = outputFull,
status = status,
statusColor = color,
effectiveRunning = effectiveRunning,
@@ -339,21 +284,20 @@ local function render()
drawInventory(4, "ALLOY", data.alloy, data.alloyVault,
data.alloyVault and data.alloyVault.total >= data.alloyVault.capacity and colors.orange or colors.lime)
center(6, "MACHINE SHAFT", colors.cyan)
if data.speed ~= nil then
center(7, ("Speed: %.1f RPM"):format(data.speed), data.speed > 0 and colors.lime or colors.orange)
center(6, "LOCAL CONTROL", colors.cyan)
if not data.zincVault then
center(7, "INPUT: NO DATA", colors.red)
else
center(7, "Speed: NO DATA", colors.red)
center(7, data.noMaterial and "INPUT: EMPTY" or "INPUT: READY",
data.noMaterial and colors.orange or colors.lime)
end
if data.capacity then
center(8, "SU: " .. formatInteger(data.usage) .. " / " .. formatInteger(data.capacity), colors.white)
local loadText = ("Load: %.1f %%"):format(data.load):gsub("%.", ",")
center(9, loadText, data.load >= 90 and colors.red or data.load >= 70 and colors.orange or colors.lime)
if not data.alloyVault then
center(8, "OUTPUT: NO DATA", colors.red)
else
center(8, "Shaft network offline", colors.gray)
center(8, data.outputFull and "OUTPUT: FULL" or "OUTPUT: SPACE",
data.outputFull and colors.orange or colors.lime)
end
center(11, data.status, data.statusColor)
center(10, data.status, data.statusColor)
drawButton(height, data)
center(height, "Touch = Anlage freigeben/stoppen", colors.gray)
end