luanti_scripts/fabric_drawer_controller.lua

42 lines
1.3 KiB
Lua

if event.type == "program" then
mem.drawerChannel = "maindrawer"
mem.tubeChannel = "maindrawerout"
mem.filterChannel = "drawercontroller"
mem.count = 0
mem.queue = {}
mem.currentTask = nil
mem.state = "idle"
digiline_send("drawerindicator", "blue")
end
if event.type == "digiline" and event.channel == "drawercontroller" then
if event.msg.status then return end
table.insert(mem.queue, event.msg)
interrupt(1)
end
if event.type == "interrupt" then
if #mem.queue == 0 and mem.currentTask == nill then
mem.state = "idle"
digiline_send("drawerindicator", "green")
return
end
if mem.currentTask == nil then
mem.currentTask = table.remove(mem.queue, 1)
mem.count = mem.currentTask.count
mem.state = "working on " .. mem.currentTask.name
digiline_send("drawerindicator", "red")
digiline_send(mem.tubeChannel, mem.currentTask.destination)
end
if mem.count == 0 then
mem.state = "idle"
digiline_send(mem.filterChannel, {name=mem.currentTask.name, status="finished"})
digiline_send("drawerindicator", "green")
mem.currentTask = nil
else
digiline_send(mem.drawerChannel, mem.currentTask.item .. " " .. tostring(mem.currentTask.stacksize))
mem.count = mem.count - 1
end
interrupt(1)
end