diff --git a/craftingTurtle.lua b/craftingTurtle.lua index 4c7eef8..cf8a8e1 100644 --- a/craftingTurtle.lua +++ b/craftingTurtle.lua @@ -5,7 +5,7 @@ -- Requires a wired modem attached to the turtle. ------------------------------------------------- --- Configuration +-- Default configuration (overridden by .turtle_config) ------------------------------------------------- -- Modem channels (must match inventoryManager.lua) @@ -15,6 +15,29 @@ local CRAFT_REPLY_CHANNEL = 4204 -- turtle -> master (craft results) -- Crafting grid slots in a turtle's 4x4 inventory local CRAFT_SLOTS = {1, 2, 3, 5, 6, 7, 9, 10, 11} +------------------------------------------------- +-- Load config from file if present +------------------------------------------------- + +local TURTLE_CONFIG_FILE = ".turtle_config" + +local function loadConfig() + if not fs.exists(TURTLE_CONFIG_FILE) then return end + local f = fs.open(TURTLE_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 " .. TURTLE_CONFIG_FILE) + return + end + if cfg.craftChannel then CRAFT_CHANNEL = cfg.craftChannel end + if cfg.craftReplyChannel then CRAFT_REPLY_CHANNEL = cfg.craftReplyChannel end + print("[CONFIG] Loaded from " .. TURTLE_CONFIG_FILE) +end + +loadConfig() + ------------------------------------------------- -- Setup -------------------------------------------------