Module:Sandbox/Aurelain: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
local function getCurrentLang() | local function getCurrentLang() | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
if title.isSubpage | if title.isSubpage then | ||
if mw.language.isSupportedLanguage(title.subpageText) then | |||
return title.subpageText | |||
end | |||
end | end | ||
return 'en' | return 'en' | ||
Revision as of 17:03, 14 May 2026
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 = { unit, 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
-- Detects the "/lang" suffix of the page url
local function getCurrentLang()
local title = mw.title.getCurrentTitle()
if title.isSubpage then
if mw.language.isSupportedLanguage(title.subpageText) then
return title.subpageText
end
end
return 'en'
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",
}
}
-- Factions
local factionIcons = {
Temple = "Human icon.png",
Necropolis = "Undead icon.png",
Dungeon = "Dungeon icon.png",
Schism = "Unfrozen icon.png",
Sylvan = "Spring icon.png",
Hive = "Hive icon.png",
Neutral = "Primordial_Chaos.png"
}
-- 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()
local lang = getCurrentLang()
local langSuffix = lang == "en" and "" or "/" .. lang
-- 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 = "! [[File:Diplomacy_sub_larger_than_life.png|24px]]"
for _, col in ipairs(statColumns) do
headerRow = headerRow .. " !! [[File:" .. col.icon .. ".png|24px|"
headerRow = headerRow .. describe(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 .. '/' .. lang .. ']]')
-- 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


