ComputerCraft/bures-monitor.lua
2022-07-03 12:54:26 +02:00

56 lines
1.4 KiB
Lua

-- script for monitoring Build Resources
require("printTable")
if not colony.isValid() then
print("Colony is not valid.")
return
end
local monitor = peripheral.find("monitor")
term.redirect(monitor)
local buildings = colony.getBuildings()
local buRes = {}
local function clearMonitor()
monitor.setTextScale(0.5)
monitor.clear()
monitor.setCursorPos(1, 1)
end
local function tFilter(t, func)
local result = {}
for key, value in pairs(t) do
if func(value) then
table.insert(result, value)
end
end
return result
end
local function printBuRes()
for name, list in pairs(buRes) do
print(name, "asd")
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
print(name)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
for key, value in pairs(list) do
print(value.item.displayName, value.available .. "+" .. value.delivering .. "/" .. value.item.count)
end
end
end
local function bures()
for key, value in pairs(buildings) do
local name = value.name
if name == "" then
name = "Builder " .. tostring(value.level)
end
buRes[name] = colony.getBuilderResources(value.location)
end
end
clearMonitor()
buildings = tFilter(buildings, function(value) return value.type == "builder" end)
bures()
printBuRes()