Last active
July 29, 2019 01:29
-
-
Save copygirl/610db9d3b4a1217033e2c2b8a3583c3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local component = require("component"); | |
local sides = require("sides"); | |
package.loaded["./resources"] = nil | |
local resources = require("./resources"); | |
function pretty_amount(n) | |
if n < 1000 then return string.format("%.0f", n) | |
elseif n < 1000000 then return string.format("%.1fK", n / 1000) | |
else return string.format("%.1fM", n / 1000000) end | |
end | |
local transposer = component.transposer | |
local stacks = transposer.getAllStacks(sides.bottom) | |
local count = stacks.count() | |
local compacted = {} | |
for i=1, stacks.count() do | |
local stack = stacks() | |
if stack.size and stack.size > 0 then | |
local lookup = resources.lookup[stack.label] | |
if lookup then | |
local c = compacted[lookup.name] | |
if not c then | |
c = {} | |
compacted[lookup.name] = c | |
end | |
c[lookup.type] = (c[lookup.type] or 0) + stack.size | |
else | |
print(string.format("%4s %s", | |
pretty_amount(stack.size), stack.label)) | |
end | |
end | |
end | |
function add_part(str, label, amount, width) | |
if not width then width = #label end | |
if #str > 1 then str = str .. " | " end | |
if amount == nil then return str .. string.rep(" ", width + 5) end | |
return str .. string.format("%4s %-" .. width .. "s", | |
pretty_amount(amount), label) | |
end | |
for name,d in pairs(compacted) do | |
local data = resources.data[name] | |
local line = "" | |
line = add_part(line, data.default_label, (d._default_ or 0), 14) | |
line = add_part(line, d.Block == 1 and "Block" or "Blocks", d.Block, 6) | |
line = add_part(line, "Ore", d.Ore) | |
line = add_part(line, "Dust", d.Dust) | |
print(line) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment