cc/orders.lua

104 lines
2.9 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 resStatus = "?/?/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
resStatus = unavailable_count .. "/" .. deliver_count .. "/" .. #resources
end
listframes.updateItemAt(currentIdx, {id=wo.id, type=wo.workOrderType, target=wo.type, pos=wo.builder, status=resStatus, 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
local padding
if obj.status then
padding = winhlp.alignRightPadding(win, #obj.status + 4)
win.write(string.format("%" .. padding+1 .. "s", " "))
win.write(obj.status .. " ")
else
padding = winhlp.alignRightPadding(win, 3)
win.write(string.format("%" .. padding+1 .. "s", " "))
end
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
padding = winhlp.alignRightPadding(win, #obj.target + 1)
win.write(string.format("%" .. padding+1 .. "s", " "))
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 estimatedHeight()
return listframes.estimatedHeight()
end
local function onTouch(self, touch_x, touch_y)
return false
end
return {
name="orders",
setTerm=setTerm,
fetch=fetch,
displayTab=displayTab,
estimatedHeight=estimatedHeight,
onTouch=onTouch,
}