Module:BuildingTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary Tag: Reverted |
No edit summary |
||
| (47 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local buildingData = require("Module:BuildingData") | ||
local resourceData = require("Module:ResourceData") | |||
local function getResourceIcon(resourceName) | |||
local data = resourceData[resourceName] | |||
if not data then | |||
return "T Button SelectionBorder Default.png" -- or some other safe fallback | |||
end | |||
if not data.icon_file then | |||
return "T Button SelectionBorder Default.png" | |||
end | |||
return data.icon_file | |||
end | |||
local function stackFormat(inputs) | local function stackFormat(inputs) | ||
if not inputs then | if not inputs then | ||
return " | return "''None''" | ||
end | end | ||
| Line 12: | Line 24: | ||
for _, item in ipairs(inputs) do | for _, item in ipairs(inputs) do | ||
if item.resource ~= "" and (item.qty or 0) > 0 then | if item.resource ~= "" and (item.qty or 0) > 0 then | ||
table.insert(parts, item.resource .. " | table.insert(parts, item.qty .. " [[File:" .. getResourceIcon(item.resource) .. "|16px]] " .. "[[" .. item.resource .. "]]") | ||
end | end | ||
end | end | ||
if #parts == 0 then | if #parts == 0 then | ||
return " | return "''None''" | ||
end | end | ||
return | return table.concat(parts, "<br/>") | ||
end | end | ||
| Line 27: | Line 39: | ||
table.insert(out, '{| class="wikitable sortable"') | table.insert(out, '{| class="wikitable sortable"') | ||
table.insert(out, '! Icon !! Name !! Category !! Dedicated Workers !! Product !! Input !! Building Cost') | table.insert(out, '!class="unsortable"| Icon !! Name !! Category !! Dedicated Workers !! Product !! Input !! Building Cost') | ||
for _, building in pairs( | for _, building in pairs(buildingData) do | ||
local icon = building.building_icon_filename | local icon = building.building_icon_filename or "T Button SelectionBorder Default.png" | ||
if icon == nil or icon == "" then | if icon == nil or icon == "" then | ||
icon = "T | icon = "T Button SelectionBorder Default.png" | ||
end | end | ||
local workers = (building.hands_greenhands or 0) + (building.hands_masterhands or 0) | local workers = (building.hands_greenhands or 0) + (building.hands_masterhands or 0) | ||
if workers > 0 then | if workers > 0 and building.production_output ~= "" and building.production_output ~= nil then | ||
local cost = "''None''" | local cost = "''None''" | ||
| Line 49: | Line 61: | ||
end | end | ||
table.insert(out, "|- | table.insert(out, "|-") | ||
local icon2 = getResourceIcon(building.production_output) | |||
if icon2 == nil then | |||
error(string.format( | |||
"DEBUG: getResourceIcon returned nil for production_output=%q (building=%s)", | |||
tostring(building.production_output), tostring(building.name) | |||
)) | |||
end | |||
table.insert(out, | |||
string.format( | |||
"| <div class='cc-producer-icon'>[[File:%s|64px]] || [[%s]] || %s || %d [[Pirates|Greenhands]] || %d [[File:%s|16px]] [[%s]] || %s || %s", | |||
icon or "T Button SelectionBorder Default.png", | |||
building.name or "", | |||
building.category or "", | |||
workers or 0, | |||
building.production_output_qty or 0, | |||
icon2 or "T Button SelectionBorder Default.png", | |||
building.production_output or "", | |||
stackFormat(building.production_input) or "''None''", | |||
stackFormat(building.construction) or "''None''" | |||
) | |||
) | |||
end | end | ||
end | |||
table.insert(out, "|}") | |||
return table.concat(out, "\n") | |||
end | |||
function p.housing(frame) | |||
local out = {} | |||
table.insert(out, '{| class="wikitable sortable"') | |||
table.insert(out, '!class="unsortable"| Icon !! Name !! Capacity !! Unlock Requirement !! Building Cost') | |||
for _, building in pairs(buildingData) do | |||
local icon = building.building_icon_filename | |||
if icon == nil or icon == "" then | |||
icon = "T Button SelectionBorder Default.png" | |||
end | |||
if building.housing > 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( | |||
"| [[File:%s|64px]] || [[%s]] || %d || %s || %s", | |||
icon or "T Button SelectionBorder Default.png", | |||
building.name or "", | |||
building.housing or 0, | |||
building.unlock_requirement or "", | |||
stackFormat(building.construction) or "''None''" | |||
) | |||
) | |||
end | |||
end | |||
table.insert(out, "|}") | |||
return table.concat(out, "\n") | |||
end | |||
function p.principle(frame) | |||
local out = {} | |||
table.insert(out, '{| class="wikitable sortable"') | |||
table.insert(out, '!class="unsortable"| Icon !! Name !! Effect !! Unlock Requirement !! Building Cost') | |||
for _, building in pairs(buildingData) do | |||
local icon = building.building_icon_filename | |||
if icon == nil or icon == "" then | |||
icon = "T Button SelectionBorder Default.png" | |||
end | |||
if building.category == "Principle" 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( | |||
"| [[File:%s|64px]] || [[%s]] || %s || %s || %s", | |||
icon or "T Button SelectionBorder Default.png", | |||
building.name or "", | |||
building.description or "", | |||
building.unlock_requirement or "", | |||
stackFormat(building.construction) or "''None''" | |||
) | |||
) | |||
end | |||
end | |||
table.insert(out, "|}") | |||
return table.concat(out, "\n") | |||
end | |||
function p.community(frame) | |||
local out = {} | |||
table.insert(out, '{| class="wikitable sortable"') | |||
table.insert(out, "!class='unsortable'| Icon !! Name !! Dedicated Workers<br/>''Without [[Pirates|Drifters]]'' !! Function !! Resource Input !! Building Cost") | |||
for _, building in pairs(buildingData) do | |||
local icon = building.building_icon_filename | |||
if icon == nil or icon == "" then | |||
icon = "T Button SelectionBorder Default.png" | |||
end | |||
if building.category == "Community" 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( | |||
"|[[File:%s|64px]] || [[%s]] || %d [[Pirates|Builders]] || %s || %s || %s", | |||
icon or "T Button SelectionBorder Default.png", | |||
building.name or "", | |||
building.hands_builders or 0, | |||
building.description or "", | |||
stackFormat(building.community_upkeep) or "''None''", | |||
stackFormat(building.construction) or "''None''" | |||
) | |||
) | |||
end | |||
end | end | ||
Latest revision as of 10:19, 7 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 buildingData = require("Module:BuildingData")
local resourceData = require("Module:ResourceData")
local function getResourceIcon(resourceName)
local data = resourceData[resourceName]
if not data then
return "T Button SelectionBorder Default.png" -- or some other safe fallback
end
if not data.icon_file then
return "T Button SelectionBorder Default.png"
end
return data.icon_file
end
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
table.insert(parts, item.qty .. " [[File:" .. getResourceIcon(item.resource) .. "|16px]] " .. "[[" .. 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, '!class="unsortable"| Icon !! Name !! Category !! Dedicated Workers !! Product !! Input !! Building Cost')
for _, building in pairs(buildingData) do
local icon = building.building_icon_filename or "T Button SelectionBorder Default.png"
if icon == nil or icon == "" then
icon = "T Button SelectionBorder Default.png"
end
local workers = (building.hands_greenhands or 0) + (building.hands_masterhands or 0)
if workers > 0 and building.production_output ~= "" and building.production_output ~= nil 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, "|-")
local icon2 = getResourceIcon(building.production_output)
if icon2 == nil then
error(string.format(
"DEBUG: getResourceIcon returned nil for production_output=%q (building=%s)",
tostring(building.production_output), tostring(building.name)
))
end
table.insert(out,
string.format(
"| <div class='cc-producer-icon'>[[File:%s|64px]] || [[%s]] || %s || %d [[Pirates|Greenhands]] || %d [[File:%s|16px]] [[%s]] || %s || %s",
icon or "T Button SelectionBorder Default.png",
building.name or "",
building.category or "",
workers or 0,
building.production_output_qty or 0,
icon2 or "T Button SelectionBorder Default.png",
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
function p.housing(frame)
local out = {}
table.insert(out, '{| class="wikitable sortable"')
table.insert(out, '!class="unsortable"| Icon !! Name !! Capacity !! Unlock Requirement !! Building Cost')
for _, building in pairs(buildingData) do
local icon = building.building_icon_filename
if icon == nil or icon == "" then
icon = "T Button SelectionBorder Default.png"
end
if building.housing > 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(
"| [[File:%s|64px]] || [[%s]] || %d || %s || %s",
icon or "T Button SelectionBorder Default.png",
building.name or "",
building.housing or 0,
building.unlock_requirement or "",
stackFormat(building.construction) or "''None''"
)
)
end
end
table.insert(out, "|}")
return table.concat(out, "\n")
end
function p.principle(frame)
local out = {}
table.insert(out, '{| class="wikitable sortable"')
table.insert(out, '!class="unsortable"| Icon !! Name !! Effect !! Unlock Requirement !! Building Cost')
for _, building in pairs(buildingData) do
local icon = building.building_icon_filename
if icon == nil or icon == "" then
icon = "T Button SelectionBorder Default.png"
end
if building.category == "Principle" 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(
"| [[File:%s|64px]] || [[%s]] || %s || %s || %s",
icon or "T Button SelectionBorder Default.png",
building.name or "",
building.description or "",
building.unlock_requirement or "",
stackFormat(building.construction) or "''None''"
)
)
end
end
table.insert(out, "|}")
return table.concat(out, "\n")
end
function p.community(frame)
local out = {}
table.insert(out, '{| class="wikitable sortable"')
table.insert(out, "!class='unsortable'| Icon !! Name !! Dedicated Workers<br/>''Without [[Pirates|Drifters]]'' !! Function !! Resource Input !! Building Cost")
for _, building in pairs(buildingData) do
local icon = building.building_icon_filename
if icon == nil or icon == "" then
icon = "T Button SelectionBorder Default.png"
end
if building.category == "Community" 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(
"|[[File:%s|64px]] || [[%s]] || %d [[Pirates|Builders]] || %s || %s || %s",
icon or "T Button SelectionBorder Default.png",
building.name or "",
building.hands_builders or 0,
building.description or "",
stackFormat(building.community_upkeep) or "''None''",
stackFormat(building.construction) or "''None''"
)
)
end
end
table.insert(out, "|}")
return table.concat(out, "\n")
end
return p


