cc/orders.lua

96 lines
2.6 KiB
Lua

local config = require "config"
local listframes = require "listframes"
local winhlp = require "winhlp"
local colony = peripheral.wrap(config.colony_interface_side)
local frame = term.current()
local function setTerm(termlike)
frame = termlike
listframes.setTerm(frame)
end
local function fetch(wait_for)
local currentIdx = 1
if colony.isInColony() then
for i, wo in pairs(colony.getWorkOrders()) do
local resources = colony.getWorkOrderResources(wo.id)
local res_status = "?/?/0"
if resources ~= nil then
local unavailable_count = 0
local deliver_count = 0
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
end
listframes.updateItemAt(currentIdx, {id=wo.id, type=wo.workOrderType, target=wo.type, pos=wo.builder, res_status=res_status, claimed=wo.isClaimed})
currentIdx = currentIdx + 1
wait_for(config.step_sleep_time)
end
end
listframes.clearFrom(currentIdx)
end
local function drawEntry(win, obj)
winhlp.setHeight(win, 2)
win.setBackgroundColor(colors.black)
win.setTextColor(colors.lightGray)
win.write(obj.id)
win.write(" ")
win.setTextColor(colors.yellow)
if obj.pos then
win.write(obj.pos.x .. "," .. obj.pos.y .. "," .. obj.pos.z)
win.write(" ")
end
if obj.res_status then
winhlp.alignRight(win, #obj.res_status + 4)
win.write(" " .. obj.res_status)
else
winhlp.alignRight(win, 3)
end
win.write(" ")
if obj.claimed then
win.setTextColor(colors.green)
win.write("C")
else
win.write(" ")
end
win.write(" ")
win.setTextColor(colors.gray)
win.setCursorPos(1, 2)
if obj.target then
winhlp.alignRight(win, #obj.target + 1)
win.write(" " .. obj.target)
end
win.setTextColor(colors.white)
win.setCursorPos(1, 2)
if obj.type then
win.write(obj.type)
end
end
listframes.setDrawEntryFunc(drawEntry)
local function displayTab(self)
listframes.updatePage(self.scrollPos)
end
local function onTouch(self, touch_x, touch_y)
return false
end
return {
name="orders",
setTerm=setTerm,
fetch=fetch,
displayTab=displayTab,
onTouch=onTouch,
}