Module:Sandbox/Aurelain/SkillInfobox: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| (16 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- This module is intended as a supporting muscle for the SkillInfobox template. | -- This module is intended as a supporting muscle for the SkillInfobox template. | ||
local p = {} | local p = {} | ||
-- Creates a template instruction as string (ready for preprocessing) from arguments | -- Creates a template instruction as string (ready for preprocessing) from arguments | ||
| Line 12: | Line 6: | ||
local function buildTemplate(args) | local function buildTemplate(args) | ||
local template = args.template or '' | local template = args.template or '' | ||
local lines = {'{{' .. template} | local lines = { '{{' .. template } | ||
for key, value in pairs(args) do | for key, value in pairs(args) do | ||
if key ~= 'template' and type(key) ~= "number" then | if key ~= 'template' and type(key) ~= "number" then | ||
| Line 18: | Line 12: | ||
end | end | ||
end | end | ||
return table.concat(lines, '\n') | return table.concat(lines, '\n') .. '}}' | ||
end | end | ||
------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ||
function p.listEpicClasses(frame) | function p.listEpicClasses(frame) | ||
local csv = frame.args[1] or '' | local csv = mw.text.trim(frame.args[1] or '') | ||
if csv == '' then return '—' end | |||
local genericTemplateString = buildTemplate(frame.args) | local genericTemplateString = buildTemplate(frame.args) | ||
| Line 29: | Line 25: | ||
local results = {} | local results = {} | ||
for _, epicId in ipairs(epicClasses) do | for _, epicId in ipairs(epicClasses) do | ||
-- Infer hero class id: | |||
local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$') | local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$') | ||
faction = faction or '' | faction = faction or '' | ||
| Line 34: | Line 31: | ||
type = type or '' | type = type or '' | ||
local heroClass = type .. '_' .. faction | local heroClass = type .. '_' .. faction | ||
-- Replace dynamic parameters: | |||
local templateString = genericTemplateString:gsub('#epic_class_id', epicId) | local templateString = genericTemplateString:gsub('#epic_class_id', epicId) | ||
templateString = templateString:gsub('#hero_class_id', heroClass) | templateString = templateString:gsub('#hero_class_id', heroClass) | ||
-- Preprocess | |||
table.insert(results, frame:preprocess(templateString)) | table.insert(results, frame:preprocess(templateString)) | ||
end | end | ||
return | |||
return table.concat(results, '') | |||
end | |||
------------------------------------------------------------------------------------------------------------------------ | |||
function p.getFaction(frame) | |||
local id = frame.args[1] or '' | |||
local faction = id:match('skill_faction_([a-z]+)') or '' | |||
faction = faction:gsub('s$', '') | |||
return faction | |||
end | end | ||
return p | return p | ||
Latest revision as of 06:27, 2 September 2026
Documentation for this module may be created at Module:Sandbox/Aurelain/SkillInfobox/doc
-- This module is intended as a supporting muscle for the SkillInfobox template.
local p = {}
-- Creates a template instruction as string (ready for preprocessing) from arguments
------------------------------------------------------------------------------------------------------------------------
local function buildTemplate(args)
local template = args.template or ''
local lines = { '{{' .. template }
for key, value in pairs(args) do
if key ~= 'template' and type(key) ~= "number" then
table.insert(lines, '|' .. key .. '=' .. value)
end
end
return table.concat(lines, '\n') .. '}}'
end
------------------------------------------------------------------------------------------------------------------------
function p.listEpicClasses(frame)
local csv = mw.text.trim(frame.args[1] or '')
if csv == '' then return '—' end
local genericTemplateString = buildTemplate(frame.args)
local epicClasses = mw.text.split(csv, ',')
local results = {}
for _, epicId in ipairs(epicClasses) do
-- Infer hero class id:
local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$')
faction = faction or ''
faction = faction:gsub('s$', '')
type = type or ''
local heroClass = type .. '_' .. faction
-- Replace dynamic parameters:
local templateString = genericTemplateString:gsub('#epic_class_id', epicId)
templateString = templateString:gsub('#hero_class_id', heroClass)
-- Preprocess
table.insert(results, frame:preprocess(templateString))
end
return table.concat(results, '')
end
------------------------------------------------------------------------------------------------------------------------
function p.getFaction(frame)
local id = frame.args[1] or ''
local faction = id:match('skill_faction_([a-z]+)') or ''
faction = faction:gsub('s$', '')
return faction
end
return p


