Module:BuildingTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 67: | Line 67: | ||
table.insert(out, "|}") | table.insert(out, "|}") | ||
return | return table.concat(out, "\n") | ||
end | end | ||
return p | return p | ||
Revision as of 10:57, 1 August 2026
This module can display buildings from the 4 separate major categories.
- Housing
- Production
- Community
- Principle
Each category table displays relevant stats for that respective category.
local p = {}
local data = require("Module:BuildingData")
local function stackFormat(inputs)
if not inputs then
return "{{Resource stack}}"
end
local parts = {}
for _, item in ipairs(inputs) do
if item.resource ~= "" and (item.qty or 0) > 0 then
table.insert(parts, item.resource .. "=" .. item.qty)
end
end
if #parts == 0 then
return "{{Resource stack}}"
end
return "{{Resource stack|" .. table.concat(parts, "|") .. "}}"
end
function p.producers(frame)
local out = {}
table.insert(out, '{| class="wikitable sortable"')
table.insert(out, '! Icon !! Name !! Category !! Dedicated Workers !! Product !! Input !! Building Cost')
for _, building in pairs(data) do
local icon = building.building_icon_filename
if icon == nil or icon == "" then
icon = "T ICO resource Hardwood.png"
end
local workers = (building.hands_greenhands or 0) + (building.hands_masterhands or 0)
if workers > 0 then
local cost = "''None''"
-- Build construction cost string
local parts = {}
for _, item in ipairs(building.construction or {}) do
if item.qty > 0 and item.resource ~= "" then
table.insert(parts,
string.format("%d [[%s]]", item.qty, item.resource))
end
end
table.insert(out, "|-\\n")
table.insert(out,
string.format(
"| {{Producer icon|%s|size=lg}} || [[%s]] || %s || %d [[Pirates|Greenhands]] || [[%s]] || %s || %s",
icon,
building.name,
building.category,
workers,
building.production_output or "",
stackFormat(building.production_input) or "''None''",
stackFormat(building.construction) or "''None''"
)
)
end
end
table.insert(out, "|}")
return table.concat(out, "\n")
end
return p


