Module:Patch
From Heroes of Might and Magic: Olden Era Official Wiki
This module provides helpful functions for the rendering of a Template:Patch/row.
1. renderLink():
| Input: | Output: |
|---|---|
{{#invoke:Patch|renderLink
| id = skill_sorcery
| lang = en
| field = foo
}} |
|
{{#invoke:Patch|renderLink
| id = skill_sorcery
| lang = en
| field = skill_level_2_description
}} |
|
{{#invoke:Patch|renderLink
| id = dungeon_hero_11
| lang = en
}} |
2. renderText():
| Input: | Output: |
|---|---|
{{#invoke:Patch|renderLink
| field = skill_description
| summary = +❮10▸20❯% Magic Damage dealt.
}} |
+ 🔽 ❌ +10% Magic Damage dealt. ✅ +20% Magic Damage dealt. |
-- Usage: see Module:Patch/doc
local p = {}
-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end
--
------------------------------------------------------------------------------------------------------------------------
local function renderSkillLink(id, lang, field, frame)
local template = '{{Skill'
.. '| id=' .. id
.. '| level=' .. (field:match("level_(%d+)") or '')
.. '| lang=' .. lang
.. '}}'
return frame:preprocess(template)
end
--
------------------------------------------------------------------------------------------------------------------------
local function renderHeroLink(id, lang, frame)
local template = '{{LinkIcon'
.. '| id=' .. id
.. '| type=hero'
.. '| filename=1'
.. '| lang=' .. lang
.. '}}'
return frame:preprocess(template)
end
--
------------------------------------------------------------------------------------------------------------------------
function p.renderLink(frame)
local args = frame.args
local id = args.id or ''
local lang = args.lang or ''
local field = args.field or ''
if id:match('skill_') then
return renderSkillLink(id, lang, field, frame)
end
if id:match('_hero_') then
return renderHeroLink(id, lang, frame)
end
return id
end
--
------------------------------------------------------------------------------------------------------------------------
local function replaceMarkers(text)
return text:gsub("❮(.-)▸(.-)❯", "<del>%1</del><ins>%2</ins>")
end
--
------------------------------------------------------------------------------------------------------------------------
local function getOld(text)
return text:gsub("❮([^▸]*)▸([^❯]*)❯", "%1")
end
--
------------------------------------------------------------------------------------------------------------------------
local function getNew(text)
return text:gsub("❮([^▸]*)▸([^❯]*)❯", "%2")
end
--
------------------------------------------------------------------------------------------------------------------------
local function generateCollapse(old, new)
local container = mw.html.create('div')
:addClass('mw-collapsible mw-collapsed')
container:tag('span')
:addClass('mw-collapsible-toggle')
:wikitext('🔽')
container:tag('div')
:addClass('mw-collapsible-content')
:wikitext('Your dynamic Lua content here')
return container;
end
--
------------------------------------------------------------------------------------------------------------------------
function p.renderText(frame)
local args = frame.args
local field = args.field or ''
local summary = args.summary or ''
local prefix = field:match('description') and '' or (field .. ': ')
local replaced = replaceMarkers(summary)
local collapse = '<div class="mw-collapsible mw-collapsed">'
collapse = collapse .. '<span class="mw-collapsible-toggle">🔽</span>'
collapse = collapse .. '<div class="mw-collapsible-content">'
collapse = collapse .. '❌ ' .. getOld(summary)
collapse = collapse .. '<br/>'
collapse = collapse .. '✅ ' .. getNew(summary)
collapse = collapse .. '</div>'
collapse = collapse .. '</div>'
return prefix .. replaced .. collapse
end
return p


