local ui = require("ui") local term_stack = require("term-stack") local dbg_file = fs.combine(shell.dir(), "logs.txt") if dbg_file then fs.delete(dbg_file) end function dbg(...) if dbg_file then local out = io.open(dbg_file, "a") if not out then return end for i = 1, select("#", ...) do local value = select(i, ...) if type(value) == "table" then out:write(textutils.serialise(value)) else out:write(tostring(value)) out:write(" ") end end out:write("\n") out:close() else local pretty = require("cc.pretty") for i = 1, select("#", ...) do local value = select(i, ...) pretty.pretty_print(value) end 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 inventories = list_inventories() main_view:prepare(inventories, "minecraft:barrel_4") 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:draw() end end main(...)