2024-06-01 02:39:41 +00:00
|
|
|
local config = require "config"
|
|
|
|
local permset = require "permset"
|
2024-06-01 22:52:58 +00:00
|
|
|
local listview = require "listview"
|
|
|
|
local winhlp = require "winhlp"
|
2024-06-01 02:39:41 +00:00
|
|
|
|
|
|
|
-- list of allowed item names, will be requested
|
|
|
|
local allowed_items = permset.new(".allowed_items")
|
|
|
|
|
|
|
|
local main_me = {}
|
|
|
|
if config.has_me then
|
|
|
|
main_me = peripheral.wrap(config.main_system_ae_bridge_side)
|
|
|
|
end
|
|
|
|
|
|
|
|
local colony = peripheral.wrap(config.colony_interface_side)
|
2024-06-01 22:52:58 +00:00
|
|
|
|
|
|
|
local frame = term.current()
|
|
|
|
|
|
|
|
local function setTerm(termlike)
|
|
|
|
frame = termlike
|
|
|
|
listview.setTerm(frame)
|
|
|
|
end
|
2024-06-01 02:39:41 +00:00
|
|
|
|
|
|
|
local function fetch(wait_for)
|
|
|
|
local me_items = nil
|
|
|
|
if config.has_me then
|
|
|
|
me_items = main_me.listItems()
|
|
|
|
end
|
2024-06-01 22:52:58 +00:00
|
|
|
local currentIdx = 1
|
2024-06-02 14:41:54 +00:00
|
|
|
if colony.isInColony() then
|
|
|
|
for i, req in pairs(colony.getRequests()) do
|
|
|
|
local found = false
|
|
|
|
if me_items then
|
|
|
|
local left_amount = req.count
|
|
|
|
for j, it in pairs(req.items) do
|
|
|
|
for k, have_it in pairs(me_items) do
|
|
|
|
-- TODO: check NBT
|
|
|
|
if have_it.name == it.name then
|
|
|
|
found = true
|
|
|
|
listview.updateItemAt(currentIdx, {req=req, answer=have_it})
|
|
|
|
currentIdx = currentIdx + 1
|
|
|
|
if left_amount > 0 and permset.has(allowed_items, it.name) then
|
|
|
|
local export_amount = math.min(have_it.amount, left_amount)
|
|
|
|
left_amount = left_amount - export_amount
|
|
|
|
main_me.exportItem({name=it.name, count=export_amount}, config.main_me_inventory_side)
|
|
|
|
end
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-06-02 14:41:54 +00:00
|
|
|
if found == false then
|
|
|
|
listview.updateItemAt(currentIdx, {req=req, answer=nil})
|
|
|
|
currentIdx = currentIdx + 1
|
|
|
|
end
|
|
|
|
wait_for(config.step_sleep_time)
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
end
|
2024-06-02 01:25:04 +00:00
|
|
|
listview.clearFrom(currentIdx)
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
local function drawLine(termlike, obj)
|
2024-06-02 00:35:00 +00:00
|
|
|
termlike.setBackgroundColor(colors.black)
|
2024-06-01 22:52:58 +00:00
|
|
|
termlike.setTextColor(colors.white)
|
|
|
|
termlike.write(obj.req.name)
|
|
|
|
termlike.write(" ")
|
|
|
|
if obj.answer == nil then
|
|
|
|
termlike.setTextColor(colors.orange)
|
2024-06-02 14:58:30 +00:00
|
|
|
local padding = winhlp.alignRightPadding(termlike, 5)
|
2024-06-01 22:52:58 +00:00
|
|
|
termlike.write(string.format("%" .. padding+5 .. "s", " N/A "))
|
|
|
|
else
|
|
|
|
if permset.has(allowed_items, obj.answer.name) then
|
|
|
|
termlike.setTextColor(colors.green)
|
|
|
|
else
|
|
|
|
termlike.setTextColor(colors.yellow)
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
2024-06-01 22:52:58 +00:00
|
|
|
termlike.write(obj.answer.name)
|
|
|
|
termlike.setTextColor(colors.white)
|
2024-06-02 14:58:30 +00:00
|
|
|
local padding = winhlp.alignRightPadding(termlike, 5)
|
2024-06-01 22:52:58 +00:00
|
|
|
termlike.write(string.format("%" .. padding+2 .. "s", " ["))
|
|
|
|
if permset.has(allowed_items, obj.answer.name) then
|
|
|
|
termlike.setTextColor(colors.green)
|
|
|
|
termlike.write("X")
|
|
|
|
termlike.setTextColor(colors.white)
|
|
|
|
else
|
|
|
|
termlike.write(" ")
|
|
|
|
end
|
|
|
|
termlike.write("] ")
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
end
|
2024-06-02 14:41:54 +00:00
|
|
|
listview.setDrawEntryFunc(drawLine)
|
2024-06-01 22:52:58 +00:00
|
|
|
|
|
|
|
local function displayTab(self)
|
|
|
|
listview.updatePage(self.scrollPos)
|
|
|
|
end
|
2024-06-01 02:39:41 +00:00
|
|
|
|
2024-06-01 14:20:00 +00:00
|
|
|
local function onTouch(self, touch_x, touch_y)
|
|
|
|
local tw, th = self.window.getSize()
|
2024-06-01 22:52:58 +00:00
|
|
|
if touch_x > tw-5 then
|
2024-06-02 12:46:28 +00:00
|
|
|
local obj = listview.itemAt(touch_y+self.scrollPos-1)
|
2024-06-01 22:52:58 +00:00
|
|
|
if obj ~= nil and obj.answer ~= nil then
|
|
|
|
if permset.has(allowed_items, obj.answer.name) then
|
|
|
|
permset.remove(allowed_items, obj.answer.name)
|
|
|
|
else
|
|
|
|
permset.add(allowed_items, obj.answer.name)
|
|
|
|
end
|
2024-06-02 02:22:07 +00:00
|
|
|
listview.updatePartial(function (item) return item.answer ~= nil and item.answer.name == obj.answer.name end)
|
2024-06-01 22:52:58 +00:00
|
|
|
return true
|
2024-06-01 02:39:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
|
2024-06-01 02:39:41 +00:00
|
|
|
return {
|
|
|
|
name="requests",
|
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
|
|
|
}
|