cc/orders.lua

86 lines
2.6 KiB
Lua
Raw Normal View History

2024-06-01 02:39:41 +00:00
local config = require "config"
local colony = peripheral.wrap(config.colony_interface_side)
local orders = {}
local function fetch(wait_for)
orders = {}
local colony_orders = colony.getWorkOrders()
if colony_orders ~= nil then
for i, wo in pairs(colony_orders) do
local resources = colony.getWorkOrderResources(wo.id)
local res_status = "?/?/0"
if resources ~= nil then
local unavailable_count = 0
local deliver_count = 0
2024-06-01 02:50:08 +00:00
for j, res in pairs(resources) do
if not res.available then
unavailable_count = unavailable_count + 1
end
if res.delivering then
deliver_count = deliver_count + 1
end
end
res_status = unavailable_count .. "/" .. deliver_count .. "/" .. #resources
2024-06-01 02:39:41 +00:00
end
table.insert(orders, {id=wo.id, type=wo.workOrderType, target=wo.type, pos=wo.builder, res_status=res_status, claimed=wo.isClaimed})
2024-06-01 02:39:41 +00:00
wait_for(config.step_sleep_time)
end
end
end
local function display(page_start_idx)
local tw,th = term.getSize()
for i, val in pairs(orders) do
local line_num = (i-page_start_idx)*2+3
if line_num > 2 and line_num < th-1 then
term.setTextColor(colors.lightGray)
term.setCursorPos(1,line_num)
term.write(val.id)
term.write(" ")
if val.pos then
term.write(val.pos.x .. "," .. val.pos.y .. "," .. val.pos.z)
term.write(" ")
end
term.setCursorPos(2,line_num+1)
term.setTextColor(colors.white)
if val.type then
term.write(val.type)
term.write(" ")
end
if val.target then
term.write(val.target)
term.write(" ")
end
if val.res_status then
term.setCursorPos(tw-2-#val.res_status, line_num)
term.write(val.res_status)
2024-06-01 02:39:41 +00:00
else
term.setCursorPos(tw-2, line_num)
end
term.write(" ")
if val.claimed then
term.setTextColor(colors.yellow)
term.write("C")
term.setTextColor(colors.white)
else
term.write(" ")
end
term.write(" ")
end
end
end
local function on_touch(touch_x, touch_y)
return false
end
return {
name="orders",
fetch=fetch,
display=display,
on_touch=on_touch,
}