Module:ResourceTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary |
No edit summary |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
while recipe["ingredient"..i] do | while recipe["ingredient"..i] do | ||
local ingredient = recipe["ingredient"..i] | local ingredient = recipe["ingredient"..i] | ||
local icon = resourceData[ingredient] and resourceData[ingredient]. | local icon = resourceData[ingredient] and resourceData[ingredient].icon_file or "" | ||
table.insert(parts, | table.insert(parts, | ||
| Line 35: | Line 35: | ||
local sourceText = {} | local sourceText = {} | ||
local quantityText = {} | local quantityText = {} | ||
local recipeText = {} | |||
local prodSellText = {} | |||
for i = 1, 3 do | for i = 1, 3 do | ||
| Line 42: | Line 44: | ||
table.insert(sourceText, "[[" .. src .. "]]") | table.insert(sourceText, "[[" .. src .. "]]") | ||
local | 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) | table.insert(quantityText, qty_str) | ||
local recipe = recipeToText(resource.production["recipe"..i]) | |||
table.insert(recipeText, recipe) | |||
local prod_sell = string.format("%.1f", resource.stack_value * (qty / resource.stack_size)) | |||
table.insert(prodSellText, prod_sell) | |||
end | end | ||
end | end | ||
local | local recipes = table.concat(recipeText, "<hr/>") | ||
return table.concat({ | return table.concat({ | ||
"| [[File: " .. resource. | "| [[File: " .. resource.icon_file .. " |x96px]]", | ||
"[[" .. resource.name .. "]]", | "[[" .. resource.name .. "]]", | ||
table.concat(sourceText, "< | resource.category, | ||
table.concat(sourceText, "<hr/>"), | |||
table.concat(quantityText, "< | recipes, | ||
tostring(resource. | table.concat(quantityText, "<hr/>"), | ||
tostring(resource. | tostring(resource.stack_size), | ||
string.format("%.0f", resource.stack_value * 0.3), | |||
tostring(resource.stack_value), | |||
table.concat(prodSellText, " <hr/> ") | |||
}, " || ") | }, " || ") | ||
end | end | ||
| Line 70: | Line 82: | ||
return table.concat({ | return table.concat({ | ||
'{| class="wikitable sortable"', | '{| class="wikitable sortable"', | ||
'! class="unsortable" | Icon !! Name !! Production<br/>Building !! Ingredients<br/>per min. !! Production<br/>per min. !! Stack Size !! [[Trade Post|Stack Selling Value]]', | '! class="unsortable" | Icon !! Name !! Category !!Production<br/>Building !! Ingredients<br/>per min. !! Production<br/>per min. !! Stack Size !! [[Quartermaster|Cohesion Value]] !! [[Trade Post|Stack Selling Value]] !! [[Trade Post|Production Sale]]<br/>per min.', | ||
'|-', | '|-', | ||
table.concat(rows, '\n|-\n'), | table.concat(rows, '\n|-\n'), | ||
Latest revision as of 19:41, 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 = string.format("%.1f", 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),
string.format("%.0f", resource.stack_value * 0.3),
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 !! [[Quartermaster|Cohesion Value]] !! [[Trade Post|Stack Selling Value]] !! [[Trade Post|Production Sale]]<br/>per min.',
'|-',
table.concat(rows, '\n|-\n'),
'|}',
''
}, '\n')
end
return Export


