Module:Sandbox/Aurelain/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:Sandbox/Aurelain/Patch|renderLink
    | id = skill_sorcery
    | lang = en
    | field = foo
}}
Sorcery
{{#invoke:Sandbox/Aurelain/Patch|renderLink
    | id = skill_sorcery
    | lang = en
    | field = skill_level_2_description
}}
Advanced Sorcery
{{#invoke:Sandbox/Aurelain/Patch|renderLink
    | id = dungeon_hero_11
    | lang = en
}}
Zakron the Great


2. renderText():

Input: Output:
{{#invoke:Sandbox/Aurelain/Patch|renderLink
            | field = skill_description
            | summary = +❮10▸20❯% Magic Damage dealt.
        }}
+❮10▸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 renderSummary(summary)
    return summary
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 summaryText = renderSummary(summary, frame)

    return prefix .. summaryText
end

return p