Module:BuildingTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary |
No edit summary |
||
| Line 19: | Line 19: | ||
end | end | ||
table.insert(parts, prefix .. "[[" .. item.resource .. "]]") | table.insert(parts, prefix .. " {{Resource icon|" .. item.resource .. "}} [[" .. item.resource .. "]]") | ||
end | end | ||
end | end | ||
Revision as of 10:42, 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 "''None''"
end
local parts = {}
for _, item in ipairs(inputs) do
if item.resource ~= "" and (item.qty or 0) > 0 then
local prefix = ""
-- Only show quantity if greater than 1
if item.qty > 1 then
prefix = item.qty .. " "
end
table.insert(parts, prefix .. " {{Resource icon|" .. item.resource .. "}} [[" .. item.resource .. "]]")
end
end
if #parts == 0 then
return "''None''"
end
return table.concat(parts, "<br/>")
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, "|-")
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


