The Opus package manager deletes the entire package directory on update (fs.delete(packageDir)) before re-downloading files. This wiped all config files (.manager_config, .client_config, etc.) that were stored inside packages/inventory-manager/. Fix: add _configPath() helper to every program that resolves config file paths to usr/config/inventory-manager/ when running under Opus, which lives outside the package directory and survives updates. Falls back to the local _path() for standalone (non-Opus) use. Updated files: - inventoryManager.lua, manager/config.lua, inventoryClient.lua, inventoryWebBridge.lua, dropperController.lua, craftingTurtle.lua - .package install script: saves configs to usr/config/inventory-manager/ - autorun/startup.lua: checks both persistent and package dirs - startup/client.lua: uses persistent dir for .client_setup/.dropper_config - web/server/Dockerfile: switch health check to wget (from prior fix)
87 lines
2.7 KiB
Lua
87 lines
2.7 KiB
Lua
-- Dropper Controller
|
|
-- Watches a dropper peripheral and pulses redstone until it's empty.
|
|
|
|
local DROPPER_SIDE = "back" -- side where the dropper peripheral is
|
|
local REDSTONE_SIDE = "back" -- side facing dropper (for redstone output)
|
|
local PULSE_TIME = 0.3 -- redstone pulse duration in seconds
|
|
local POLL_INTERVAL = 0.5 -- how often to check the dropper
|
|
|
|
-------------------------------------------------
|
|
-- Load config from file if present
|
|
-------------------------------------------------
|
|
|
|
local _baseDir = fs.getDir(shell.getRunningProgram())
|
|
|
|
-- Persistent config path: survives Opus package updates
|
|
local _PERSIST_DIR = "usr/config/inventory-manager"
|
|
local function _configPath(rel)
|
|
if fs.isDir(_PERSIST_DIR) or fs.isDir("packages/inventory-manager") then
|
|
if not fs.isDir(_PERSIST_DIR) then fs.makeDir(_PERSIST_DIR) end
|
|
return fs.combine(_PERSIST_DIR, rel)
|
|
end
|
|
return fs.combine(_baseDir, rel)
|
|
end
|
|
|
|
local CONFIG_FILE = _configPath(".dropper_config")
|
|
|
|
if fs.exists(CONFIG_FILE) then
|
|
local f = fs.open(CONFIG_FILE, "r")
|
|
local raw = f.readAll()
|
|
f.close()
|
|
local ok, cfg = pcall(textutils.unserialiseJSON, raw)
|
|
if ok and cfg then
|
|
if cfg.dropperSide then DROPPER_SIDE = cfg.dropperSide end
|
|
if cfg.redstoneSide then REDSTONE_SIDE = cfg.redstoneSide end
|
|
if cfg.pulseTime then PULSE_TIME = cfg.pulseTime end
|
|
if cfg.pollInterval then POLL_INTERVAL = cfg.pollInterval end
|
|
end
|
|
end
|
|
|
|
-------------------------------------------------
|
|
-- Helpers
|
|
-------------------------------------------------
|
|
|
|
-- Send a redstone pulse to trigger the dropper
|
|
local function pulseRedstone()
|
|
redstone.setOutput(REDSTONE_SIDE, true)
|
|
sleep(PULSE_TIME)
|
|
redstone.setOutput(REDSTONE_SIDE, false)
|
|
end
|
|
|
|
-- Check if the dropper has any items
|
|
local function dropperHasItems()
|
|
local dropper = peripheral.wrap(DROPPER_SIDE)
|
|
if not dropper then return false end
|
|
local contents = dropper.list()
|
|
if not contents then return false end
|
|
return next(contents) ~= nil
|
|
end
|
|
|
|
-------------------------------------------------
|
|
-- Main
|
|
-------------------------------------------------
|
|
|
|
print("=================================")
|
|
print(" Dropper Controller (ID " .. os.getComputerID() .. ")")
|
|
print("=================================")
|
|
print("")
|
|
print("Redstone side: " .. REDSTONE_SIDE)
|
|
print("Watching dropper for items...")
|
|
print("")
|
|
|
|
while true do
|
|
if dropperHasItems() then
|
|
print("[DISPENSE] Items detected, firing dropper...")
|
|
|
|
-- Keep pulsing until the dropper is empty
|
|
while dropperHasItems() do
|
|
pulseRedstone()
|
|
sleep(0.1)
|
|
end
|
|
|
|
print("[OK] Dropper empty.")
|
|
end
|
|
|
|
sleep(POLL_INTERVAL)
|
|
end
|