Persist and resume Create production state
This commit is contained in:
@@ -5,6 +5,7 @@ local REFRESH_SECONDS = 1
|
||||
local MIN_WIDTH = 38
|
||||
local MIN_HEIGHT = 14
|
||||
local CLUTCH_OUTPUT_SIDE = "left"
|
||||
local STATE_FILE = "create_boiler_state.txt"
|
||||
|
||||
local BOILERS = {
|
||||
{ label = "BOILER 1", position = { 11266, 64, 10810 } },
|
||||
@@ -14,6 +15,26 @@ local BOILERS = {
|
||||
|
||||
local clutchButton = { x1 = 0, x2 = 0, y = 0 }
|
||||
|
||||
local function loadProductionState()
|
||||
if not fs.exists(STATE_FILE) then return false end
|
||||
local handle = fs.open(STATE_FILE, "r")
|
||||
if not handle then return false end
|
||||
local saved = handle.readAll()
|
||||
handle.close()
|
||||
return saved == "RUNNING"
|
||||
end
|
||||
|
||||
local function saveProductionState(running)
|
||||
local handle = fs.open(STATE_FILE, "w")
|
||||
if not handle then return false end
|
||||
handle.write(running and "RUNNING" or "STOPPED")
|
||||
handle.close()
|
||||
return true
|
||||
end
|
||||
|
||||
local productionRunning = loadProductionState()
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, productionRunning)
|
||||
|
||||
local monitor = peripheral.find("monitor")
|
||||
if not monitor then
|
||||
error("Kein Monitor gefunden. Monitor direkt oder per Wired Modem verbinden.", 0)
|
||||
@@ -152,8 +173,7 @@ local function drawClutchButton(height)
|
||||
local width = monitor.getSize()
|
||||
-- With the external redstone-torch inverter, output ON means the clutch is
|
||||
-- unpowered and production runs. Output OFF is the fail-safe stopped state.
|
||||
local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
|
||||
local label = running and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED "
|
||||
local label = productionRunning and " PRODUCTION: RUNNING " or " PRODUCTION: STOPPED "
|
||||
local x = math.max(1, math.floor((width - #label) / 2) + 1)
|
||||
local y = math.max(13, height - 1)
|
||||
|
||||
@@ -165,15 +185,16 @@ local function drawClutchButton(height)
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
monitor.write((" "):rep(width))
|
||||
monitor.setCursorPos(x, y)
|
||||
monitor.setBackgroundColor(running and colors.lime or colors.red)
|
||||
monitor.setBackgroundColor(productionRunning and colors.lime or colors.red)
|
||||
monitor.setTextColor(colors.black)
|
||||
monitor.write(label)
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
end
|
||||
|
||||
local function toggleProduction()
|
||||
local running = redstone.getOutput(CLUTCH_OUTPUT_SIDE)
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, not running)
|
||||
productionRunning = not productionRunning
|
||||
redstone.setOutput(CLUTCH_OUTPUT_SIDE, productionRunning)
|
||||
saveProductionState(productionRunning)
|
||||
end
|
||||
|
||||
local function render()
|
||||
|
||||
Reference in New Issue
Block a user