Module:Sandbox/Aurelain
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:Sandbox/Aurelain/doc
local p = {}
local UnitModule = require('Module:Unit')
local LocGetString = require('Module:LocGetString')
-- Wrapper for Module:Unit.get()
local function get(unit, property, lang)
return UnitModule.get({ args = { name, property, lang or "en" } })
end
-- Wrapper for Module:LocGetString.getText()
local function describe(sid, lang)
local text = LocGetString.getText({ args = { sid = sid, lang = lang } })
return text or "—"
end
local statColumns = {
{
property = "initiative",
label = "unit_init",
icon = "Icon_Stats_Initiative",
},
{
property = "speed",
label = "unit_speed",
icon = "Icon_Stats_Speed",
},
{
property = "hp",
label = "unit_health",
icon = "Health Icon",
}
}
-- Define the list of units to include in the table.
-- (This could also be fetched dynamically from SMW/Cargo or frame arguments if needed).
local unitList = {
"Angel",
"Archangel",
"Apotheosis"
}
function p.renderStatsOverview(frame)
-- Allow passing language code from the template, defaulting to 'en'
local args = frame.args
local lang = mw.text.trim(args[1] or args.lang or "en")
-- We use an array to collect wikitext pieces for better performance
local output = {}
-- 1. Start the sortable wikitext table
table.insert(output, '{| class="wikitable sortable"')
-- 2. Construct the Header Row
local headerRow = "! Unit"
for _, col in ipairs(statColumns) do
headerRow = headerRow .. " !! [[File:" .. col.icon .. ".png|24px|"
headerRow = headerRow .. getLabel(col.label, lang)
end
table.insert(output, headerRow)
-- 3. Loop through each unit to construct the data rows
for _, unitName in ipairs(unitList) do
table.insert(output, '|-')
-- Add the unit name column (formatted as a wiki link)
table.insert(output, '| [[' .. unitName .. ']]')
-- Loop through each configured stat column and fetch the value
for _, col in ipairs(statColumns) do
local statValue = get(unitName, col.property, lang)
-- Fallback to a dash or '0' if the stat isn't found to prevent table breakage
if not statValue or statValue == "" then
statValue = "-"
end
table.insert(output, '| ' .. statValue)
end
end
-- 4. Close the table
table.insert(output, '|}')
-- Combine all pieces with newline characters and return the final wikitext
return table.concat(output, '\n')
end
return p


