77 lines
2.1 KiB
Lua
77 lines
2.1 KiB
Lua
|
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 res = colony.getWorkOrderResources(wo.id)
|
||
|
if res == nil then
|
||
|
res = "0"
|
||
|
else
|
||
|
res = "" .. #res
|
||
|
end
|
||
|
table.insert(orders, {id=wo.id, type=wo.workOrderType, target=wo.type, pos=wo.builder, res_count=res, claimed=wo.isClaimed})
|
||
|
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_count then
|
||
|
term.setCursorPos(tw-2-#val.res_count, line_num)
|
||
|
term.write(val.res_count)
|
||
|
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,
|
||
|
}
|