diff --git a/inventoryManager.lua b/inventoryManager.lua index 1b9bcde..7c2cd61 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -1,6 +1,10 @@ -- Inventory Manager: Touch UI on monitor -- Main computer (networked). Computer 1 sits next to dropper_0 and auto-dispenses. +------------------------------------------------- +-- Default configuration (overridden by .manager_config) +------------------------------------------------- + local DROPPER_NAME = "minecraft:dropper_9" local BARREL_NAME = "minecraft:barrel_0" local POLL_INTERVAL = 2 -- seconds between barrel checks @@ -24,6 +28,49 @@ local BROADCAST_INTERVAL = 1 -- seconds between state broadcasts local CRAFT_CHANNEL = 4203 local CRAFT_REPLY_CHANNEL = 4204 +------------------------------------------------- +-- Load config from file if present +------------------------------------------------- + +local CONFIG_FILE = ".manager_config" +local _loadedConfig = nil -- stored for deferred overrides (compost settings declared later) + +local function loadConfig() + if not fs.exists(CONFIG_FILE) then return end + local f = fs.open(CONFIG_FILE, "r") + local data = f.readAll() + f.close() + local ok, cfg = pcall(textutils.unserialiseJSON, data) + if not ok or not cfg then + print("[WARN] Failed to parse " .. CONFIG_FILE) + return + end + _loadedConfig = cfg + -- Peripheral names + if cfg.dropperName then DROPPER_NAME = cfg.dropperName end + if cfg.barrelName then BARREL_NAME = cfg.barrelName end + if cfg.monitorSide then MONITOR_SIDE = cfg.monitorSide end + if cfg.smelterMonitorSide then SMELTER_MONITOR_SIDE = cfg.smelterMonitorSide end + -- Timing intervals + if cfg.pollInterval then POLL_INTERVAL = cfg.pollInterval end + if cfg.scanInterval then SCAN_INTERVAL = cfg.scanInterval end + if cfg.smeltInterval then SMELT_INTERVAL = cfg.smeltInterval end + if cfg.defragInterval then DEFRAG_INTERVAL = cfg.defragInterval end + if cfg.compostInterval then COMPOST_INTERVAL = cfg.compostInterval end + if cfg.alertInterval then ALERT_INTERVAL = cfg.alertInterval end + if cfg.broadcastInterval then BROADCAST_INTERVAL = cfg.broadcastInterval end + -- Reserves + if cfg.smeltReserve then SMELT_RESERVE = cfg.smeltReserve end + -- Modem channels + if cfg.broadcastChannel then BROADCAST_CHANNEL = cfg.broadcastChannel end + if cfg.orderChannel then ORDER_CHANNEL = cfg.orderChannel end + if cfg.craftChannel then CRAFT_CHANNEL = cfg.craftChannel end + if cfg.craftReplyChannel then CRAFT_REPLY_CHANNEL = cfg.craftReplyChannel end + print("[CONFIG] Loaded from " .. CONFIG_FILE) +end + +loadConfig() + ------------------------------------------------- -- Furnace types to manage ------------------------------------------------- @@ -371,6 +418,13 @@ local COMPOST_RESERVE = 128 -- 2 stacks local COMPOST_DROPPER = "minecraft:dropper_10" local COMPOST_HOPPER = "minecraft:hopper_0" +-- Apply config overrides for compost settings (loaded earlier) +if _loadedConfig then + if _loadedConfig.compostReserve then COMPOST_RESERVE = _loadedConfig.compostReserve end + if _loadedConfig.compostDropper then COMPOST_DROPPER = _loadedConfig.compostDropper end + if _loadedConfig.compostHopper then COMPOST_HOPPER = _loadedConfig.compostHopper end +end + -- Trash items: compostables with zero reserve (always fully composted) local COMPOST_TRASH = { ["minecraft:rotten_flesh"] = true,