Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - -- AE2 Stockpile Manager - Configuration Module
 - -- v1
 - local config = {}
 - -- Configuration constants
 - config.CONFIG_FILE = "ae2_stockpile.txt"
 - config.CHECK_INTERVAL = 30 -- seconds between checks
 - -- Private variables
 - local settings = {}
 - local testMode = false
 - -- Load settings from file
 - function config.load()
 - if fs.exists(config.CONFIG_FILE) then
 - local file = fs.open(config.CONFIG_FILE, "r")
 - if file then
 - local data = file.readAll()
 - file.close()
 - settings = textutils.unserialize(data) or {}
 - print("Loaded " .. #settings .. " configured items")
 - end
 - else
 - settings = {}
 - print("No existing configuration found")
 - end
 - end
 - -- Save settings to file
 - function config.save()
 - local file = fs.open(config.CONFIG_FILE, "w")
 - if file then
 - file.write(textutils.serialize(settings))
 - file.close()
 - print("Settings saved")
 - return true
 - else
 - print("ERROR: Could not save settings")
 - return false
 - end
 - end
 - -- Get current settings
 - function config.getSettings()
 - return settings
 - end
 - -- Add or update item configuration
 - function config.addItem(itemName, target, threshold)
 - -- Find existing config or create new one
 - local found = false
 - for i, itemConfig in pairs(settings) do
 - if itemConfig.item == itemName then
 - itemConfig.target = target
 - itemConfig.threshold = threshold
 - found = true
 - break
 - end
 - end
 - if not found then
 - table.insert(settings, {
 - item = itemName,
 - target = target,
 - threshold = threshold
 - })
 - end
 - return config.save()
 - end
 - -- Remove item configuration
 - function config.removeItem(index)
 - if index > 0 and index <= #settings then
 - local removed = table.remove(settings, index)
 - config.save()
 - return removed
 - end
 - return nil
 - end
 - -- Test mode functions
 - function config.isTestMode()
 - return testMode
 - end
 - function config.setTestMode(enabled)
 - testMode = enabled
 - end
 - function config.toggleTestMode()
 - testMode = not testMode
 - end
 - return config
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment