Module:Sandbox/Aurelain/SkillInfobox: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| Line 24: | Line 24: | ||
function p.listEpicClasses(frame) | function p.listEpicClasses(frame) | ||
local csv = frame.args[1] or '' | local csv = frame.args[1] or '' | ||
local | local genericTemplateString = buildTemplate(frame.args) | ||
local epicClasses = mw.text.split(csv, ',') | local epicClasses = mw.text.split(csv, ',') | ||
local results = {} | local results = {} | ||
| Line 31: | Line 31: | ||
local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$') | local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$') | ||
local heroClass = type .. '_' .. faction | local heroClass = type .. '_' .. faction | ||
local templateString = genericTemplateString:gsub('#epic_class_id', epicId) | |||
templateString = templateString:gsub('#hero_class_id', heroClass) | |||
table.insert(results, frame:preprocess(templateString)) | |||
end | end | ||
return dump(results) | return dump(results) | ||
Revision as of 11:21, 26 August 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 = {}
-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end
-- 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 = frame.args[1] or ''
local genericTemplateString = buildTemplate(frame.args)
local epicClasses = mw.text.split(csv, ',')
local results = {}
for _, epicId in ipairs(epicClasses) do
local faction, type = epicId:match('([^_]+)_([^_]+)_[0-9]$')
local heroClass = type .. '_' .. faction
local templateString = genericTemplateString:gsub('#epic_class_id', epicId)
templateString = templateString:gsub('#hero_class_id', heroClass)
table.insert(results, frame:preprocess(templateString))
end
return dump(results)
--return table.concat(results, '\n')
end
return p


