cc/orders.lua

96 lines
2.6 KiB
Lua
Raw Normal View History

2024-06-01 02:39:41 +00:00
local config = require "config"
local listframes = require "listframes"
local winhlp = require "winhlp"
2024-06-01 02:39:41 +00:00
local colony = peripheral.wrap(config.colony_interface_side)
local frame = term.current()
2024-06-01 02:39:41 +00:00
local function setTerm(termlike)
frame = termlike
listframes.setTerm(frame)
end
2024-06-01 02:39:41 +00:00
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
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
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
2024-06-01 02:39:41 +00:00
wait_for(config.step_sleep_time)
end
end
listframes.clearFrom(currentIdx)
2024-06-01 02:39:41 +00:00
end
local function drawEntry(win, obj)
2024-06-02 14:49:53 +00:00
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(" ")
2024-06-01 02:39:41 +00:00
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)
2024-06-01 02:39:41 +00:00
end
2024-06-01 14:20:00 +00:00
local function onTouch(self, touch_x, touch_y)
2024-06-01 02:39:41 +00:00
return false
end
2024-06-01 02:39:41 +00:00
return {
name="orders",
setTerm=setTerm,
2024-06-01 02:39:41 +00:00
fetch=fetch,
2024-06-01 14:20:00 +00:00
displayTab=displayTab,
onTouch=onTouch,
2024-06-01 02:39:41 +00:00
}