cc/orders.lua

104 lines
2.9 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)
2024-06-02 15:01:39 +00:00
local resStatus = "?/?/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
2024-06-02 15:01:39 +00:00
resStatus = unavailable_count .. "/" .. deliver_count .. "/" .. #resources
2024-06-01 02:39:41 +00:00
end
2024-06-02 15:01:39 +00:00
listframes.updateItemAt(currentIdx, {id=wo.id, type=wo.workOrderType, target=wo.type, pos=wo.builder, status=resStatus, 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
local padding
2024-06-02 15:01:39 +00:00
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)
2024-06-02 15:01:39 +00:00
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)
2024-06-01 02:39:41 +00:00
end
2024-06-02 15:51:21 +00:00
local function estimatedHeight()
return listframes.estimatedHeight()
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,
2024-06-02 15:51:21 +00:00
estimatedHeight=estimatedHeight,
2024-06-01 14:20:00 +00:00
onTouch=onTouch,
2024-06-01 02:39:41 +00:00
}