73 lines
1.6 KiB
Lua
73 lines
1.6 KiB
Lua
local ui = require("ui")
|
|
|
|
require("dbg")("logs.txt")
|
|
|
|
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 bundles = {
|
|
green = {
|
|
["minecraft:kelp"] = 64,
|
|
["minecraft:grass_block"] = 64
|
|
},
|
|
terraform = {
|
|
["minecraft:grass_block"] = 64,
|
|
["minecraft:stone"] = 64,
|
|
["#green"] = 1
|
|
}
|
|
}
|
|
local inventories = list_inventories()
|
|
main_view:prepare(inventories, bundles, "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:run()
|
|
end
|
|
end
|
|
|
|
main(...)
|