diff --git a/inventoryClient.lua b/inventoryClient.lua index 5a42ad4..8b6074b 100644 --- a/inventoryClient.lua +++ b/inventoryClient.lua @@ -4,7 +4,7 @@ -- Orders and smelter controls are sent to the master. ------------------------------------------------- --- Configuration +-- Default configuration (overridden by .client_config) ------------------------------------------------- local BROADCAST_CHANNEL = 4200 -- master sends state on this channel @@ -20,6 +20,38 @@ local CLIENT_BARREL_NAME = "" -- e.g. "minecraft:barrel_3" local DROPPER_ANNOUNCE_INTERVAL = 30 -- seconds between dropper announcements +------------------------------------------------- +-- Load config from file if present +------------------------------------------------- + +local CLIENT_CONFIG_FILE = ".client_config" + +local function loadConfig() + if not fs.exists(CLIENT_CONFIG_FILE) then return end + local f = fs.open(CLIENT_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 " .. CLIENT_CONFIG_FILE) + return + end + -- Channels + if cfg.broadcastChannel then BROADCAST_CHANNEL = cfg.broadcastChannel end + if cfg.orderChannel then ORDER_CHANNEL = cfg.orderChannel end + if cfg.clientChannel then CLIENT_CHANNEL = cfg.clientChannel end + -- Peripherals + if cfg.monitorSide then MONITOR_SIDE = cfg.monitorSide end + if cfg.smelterMonitorSide then SMELTER_MONITOR_SIDE = cfg.smelterMonitorSide end + if cfg.dropperName then CLIENT_DROPPER_NAME = cfg.dropperName end + if cfg.barrelName then CLIENT_BARREL_NAME = cfg.barrelName end + -- Timing + if cfg.dropperAnnounceInterval then DROPPER_ANNOUNCE_INTERVAL = cfg.dropperAnnounceInterval end + print("[CONFIG] Loaded from " .. CLIENT_CONFIG_FILE) +end + +loadConfig() + ------------------------------------------------- -- State (received from master) -------------------------------------------------