local ui = require("ui") do local success, dbg_module = pcall(require, "dbg") if success then dbg_module("logs.txt") end end local function is_inventory(peripheral_name) local types = {peripheral.getType(peripheral_name)} for _, t in ipairs(types) do if t == "inventory" then return true end end return false end local function has_in_array(value, array) for _, v in ipairs(array) do if v == value then return true end end end local function list_inventories() local inventories = {} for _, name in ipairs(peripheral.getNames()) do if is_inventory(name) and not has_in_array(name, { "top", "left", "right", "back", "bottom", "front" }) then table.insert(inventories, name) end end return inventories end local function main() local main_view = require("views.main") local save_file = "/storage-config.txt" if fs.exists(save_file) then main_view:load_from_file(save_file) else local inventories = list_inventories() main_view:prepare(inventories, {}, "minecraft:barrel_4") end main_view.save_file = save_file local update_interval = 0.1 local update_timer = os.startTimer(update_interval) while true do ---@diagnostic disable-next-line: missing-parameter local event = {os.pullEvent()} ui.event = event if event[1] == "timer" and event[2] == update_timer then update_timer = os.startTimer(update_interval) else local start = os.clock() main_view:on_event(table.unpack(event)) if os.clock() - start > update_interval then os.cancelTimer(update_timer) update_timer = os.startTimer(update_interval) end end main_view:run() end end main(...)