Module:Sandbox/Aurelain/Patch: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ||
local function renderSkillLink(id, lang, field, frame) | local function renderSkillLink(id, lang, field, frame) | ||
return frame:preprocess('{{ | 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 | end | ||
| Line 24: | Line 41: | ||
if id:match('skill_') then | if id:match('skill_') then | ||
return renderSkillLink(id, lang, field, frame) | return renderSkillLink(id, lang, field, frame) | ||
end | |||
if id:match('_hero_') then | |||
return renderHeroLink(id, lang, frame) | |||
end | end | ||
return id | return id | ||
end | |||
-- | |||
------------------------------------------------------------------------------------------------------------------------ | |||
local function replaceMarkers(text) | |||
return text:gsub("❮([^▸]+)▸([^❯]+)❯", "{{Hint|%2|%1}}") | |||
end | end | ||
| Line 35: | Line 62: | ||
local field = args.field or '' | local field = args.field or '' | ||
local summary = args.summary or '' | local summary = args.summary or '' | ||
return | |||
local prefix = field:match('description') and '' or (field .. ': ') | |||
local replaced = replaceMarkers(summary) | |||
return prefix .. frame:preprocess(replaced) | |||
end | end | ||
return p | return p | ||
Latest revision as of 07:22, 7 October 2026
This module provides helpful functions for the rendering of a Template:Patch/row.
1. renderLink():
| Input: | Output: |
|---|---|
{{#invoke:Sandbox/Aurelain/Patch|renderLink
| id = skill_sorcery
| lang = en
| field = foo
}} |
|
{{#invoke:Sandbox/Aurelain/Patch|renderLink
| id = skill_sorcery
| lang = en
| field = skill_level_2_description
}} |
|
{{#invoke:Sandbox/Aurelain/Patch|renderLink
| id = dungeon_hero_11
| lang = en
}} |
2. renderText():
| Input: | Output: |
|---|---|
{{#invoke:Sandbox/Aurelain/Patch|renderLink
| field = skill_description
| summary = +❮10▸20❯% Magic Damage dealt.
}} |
+2010% 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("❮([^▸]+)▸([^❯]+)❯", "{{Hint|%2|%1}}")
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)
return prefix .. frame:preprocess(replaced)
end
return p


