2024-06-01 02:39:41 +00:00
|
|
|
local config = require "config"
|
2024-06-02 14:41:54 +00:00
|
|
|
local listframes = require "listframes"
|
|
|
|
local winhlp = require "winhlp"
|
2024-06-01 02:39:41 +00:00
|
|
|
|
|
|
|
local colony = peripheral.wrap(config.colony_interface_side)
|
2024-06-02 14:41:54 +00:00
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
local frame = term.current()
|
2024-06-01 02:39:41 +00:00
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
local function setTerm(termlike)
|
|
|
|
frame = termlike
|
2024-06-02 14:41:54 +00:00
|
|
|
listframes.setTerm(frame)
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
2024-06-01 02:39:41 +00:00
|
|
|
|
|
|
|
local function fetch(wait_for)
|
2024-06-02 14:41:54 +00:00
|
|
|
local currentIdx = 1
|
|
|
|
if colony.isInColony() then
|
|
|
|
for i, wo in pairs(colony.getWorkOrders()) do
|
2024-06-01 02:48:39 +00:00
|
|
|
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
|
2024-06-01 02:48:39 +00:00
|
|
|
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
|
2024-06-02 14:41:54 +00:00
|
|
|
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
|
2024-06-02 14:41:54 +00:00
|
|
|
listframes.clearFrom(currentIdx)
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
|
2024-06-02 14:41:54 +00:00
|
|
|
local function drawEntry(win, obj)
|
|
|
|
local winX, winY = win.getPosition()
|
|
|
|
local sizeX, sizeY = win.getSize()
|
|
|
|
win.reposition(winX, winY, sizeX, 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
|
2024-06-02 14:41:54 +00:00
|
|
|
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 22:52:58 +00:00
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
return {
|
|
|
|
name="orders",
|
2024-06-01 22:52:58 +00:00
|
|
|
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
|
|
|
}
|