Module:ResourceTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary |
No edit summary |
||
| Line 67: | Line 67: | ||
tostring(resource.stack_size), | tostring(resource.stack_size), | ||
tostring(resource.stack_value), | tostring(resource.stack_value), | ||
table.concat(prodSellText, " <hr/>") | table.concat(prodSellText, " <hr/> ") | ||
}, " || ") | }, " || ") | ||
end | end | ||
Revision as of 13:17, 8 August 2026
This module arranges resource data into a table, providing detailed stats as well as useful cost calculations.
It uses data from Module:ResourceData.
local Export = {}
local resourceData = require("Module:ResourceData")
local function recipeToText(recipe)
if not recipe or next(recipe) == nil then
return "''None''"
end
local parts = {}
local i = 1
while recipe["ingredient"..i] do
local ingredient = recipe["ingredient"..i]
local icon = resourceData[ingredient] and resourceData[ingredient].icon_file or ""
table.insert(parts,
string.format(
"%d [[File:%s|16px]] [[%s]]",
recipe["ingredient"..i.."_qty"],
icon,
ingredient
)
)
i = i + 1
end
if #parts == 0 then
return "''None''"
end
return table.concat(parts, "<br/>")
end
function Export.resourceToWiki(resource)
local sourceText = {}
local quantityText = {}
local recipeText = {}
local prodSellText = {}
for i = 1, 3 do
local src = resource.production["source"..i]
if src and src ~= "" then
table.insert(sourceText, "[[" .. src .. "]]")
local qty = resource.production["quantity"..i] or 0
local qty_str = tostring(qty) .. " [[File:" .. resource.icon_file .. "|16px]] [[" .. resource.name .. "]]"
table.insert(quantityText, qty_str)
local recipe = recipeToText(resource.production["recipe"..i])
table.insert(recipeText, recipe)
local prod_sell = math.floor(resource.stack_value * (qty / resource.stack_size))
table.insert(prodSellText, prod_sell)
end
end
local recipes = table.concat(recipeText, "<hr/>")
return table.concat({
"| [[File: " .. resource.icon_file .. " |x96px]]",
"[[" .. resource.name .. "]]",
resource.category,
table.concat(sourceText, "<hr/>"),
recipes,
table.concat(quantityText, "<hr/>"),
tostring(resource.stack_size),
tostring(resource.stack_value),
table.concat(prodSellText, " <hr/> ")
}, " || ")
end
function Export.wikiResourceTable()
local rows = {}
for _, resource in pairs(resourceData) do
table.insert(rows, Export.resourceToWiki(resource))
end
return table.concat({
'{| class="wikitable sortable"',
'! class="unsortable" | Icon !! Name !! Category !!Production<br/>Building !! Ingredients<br/>per min. !! Production<br/>per min. !! Stack Size !! [[Trade Post|Stack Selling Value]] !! [[Trade Post|Production Sale]]<br/>per min.',
'|-',
table.concat(rows, '\n|-\n'),
'|}',
''
}, '\n')
end
return Export


