Module:Patch: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 26: Line 26:
         .. '| type=hero'
         .. '| type=hero'
         .. '| filename=1'
         .. '| filename=1'
        .. '| lang=' .. lang
        .. '}}'
    return frame:preprocess(template)
end
--
------------------------------------------------------------------------------------------------------------------------
local function renderArtifactLink(id, lang, frame)
    local template = '{{LinkIcon'
        .. '| id=' .. id
        .. '| type=artifact'
        .. '| lang=' .. lang
        .. '}} (Artifact)'
    return frame:preprocess(template)
end
--
------------------------------------------------------------------------------------------------------------------------
local function renderSpellLink(id, lang, frame)
    local template = '{{Spell'
        .. '| id=' .. id
        .. '| lang=' .. lang
        .. '}}'
    return frame:preprocess(template)
end
--
------------------------------------------------------------------------------------------------------------------------
local function renderGeneric(id, lang, frame)
    local template = '{{LinkIcon'
        .. '| id=' .. id
         .. '| lang=' .. lang
         .. '| lang=' .. lang
         .. '}}'
         .. '}}'
Line 40: Line 71:


     if id:match('skill_') then
     if id:match('skill_') then
        if id:match('_sub_') then
            id = id:gsub('_sub_', '')
            id = id:gsub('_%d', '')
        end
         return renderSkillLink(id, lang, field, frame)
         return renderSkillLink(id, lang, field, frame)
     end
     end


     if id:match('_hero_') then
     if id:match('_hero_') then
        if id:match('_specialization') then
            id = id:gsub('_specialization', '')
        end
         return renderHeroLink(id, lang, frame)
         return renderHeroLink(id, lang, frame)
     end
     end


    if id:match('_artifact') then
        return renderArtifactLink(id, lang, frame)
    end
    if id:match('_magic_') then
        return renderSpellLink(id, lang, frame)
    end
    --return renderGeneric(id, lang, frame)
     return id
     return id
end
end
Line 53: Line 100:
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local function replaceMarkers(text)
local function replaceMarkers(text)
     return text:gsub("❮([^▸]*)▸([^❯]*)❯", "<del>%1</del><ins>%2</ins>")
     return text:gsub("❮(.-)▸(.-)❯", "<del>%1</del><ins>%2</ins>")
end
end


Line 59: Line 106:
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local function getOld(text)
local function getOld(text)
     return text:gsub("❮([^▸]*)▸([^❯]*)❯", "%1")
     return text:gsub("❮(.-)▸(.-)❯", "%1")
end
end


Line 65: Line 112:
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local function getNew(text)
local function getNew(text)
     return text:gsub("❮([^▸]*)▸([^❯]*)❯", "%2")
     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
end


Line 94: Line 125:
     local replaced = replaceMarkers(summary)
     local replaced = replaceMarkers(summary)


     local collapse = '<span class="mw-customtoggle-myBox">🔽</span>'
     local collapse = '<div class="mw-collapsible mw-collapsed">'
     collapse = collapse .. '<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myBox">'
    collapse = collapse .. '<span class="mw-collapsible-toggle">🔽</span>'
     collapse = collapse .. '❌ ' .. getOld(summary)
     collapse = collapse .. '<div class="mw-collapsible-content">'
    collapse = collapse .. '<br/>'
     collapse = collapse .. '<div>❌ ' .. getOld(summary) .. '</div>'
     collapse = collapse .. '✅ ' .. getNew(summary)
     collapse = collapse .. '<div>✅ ' .. getNew(summary) .. '</div>'
     collapse = collapse .. '</div>'
     collapse = collapse .. '</div>'


     return prefix .. replaced .. tostring(generateCollapse(old, new))
     return prefix .. replaced .. collapse
end
end


return p
return p

Latest revision as of 08:13, 14 October 2026

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


2. renderText():

Input: Output:
{{#invoke:Patch|renderLink
            | field = skill_description
            | summary = +❮10▸20❯% Magic Damage dealt.
        }}
+1020% 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

--
------------------------------------------------------------------------------------------------------------------------
local function renderArtifactLink(id, lang, frame)
    local template = '{{LinkIcon'
        .. '| id=' .. id
        .. '| type=artifact'
        .. '| lang=' .. lang
        .. '}} (Artifact)'
    return frame:preprocess(template)
end

--
------------------------------------------------------------------------------------------------------------------------
local function renderSpellLink(id, lang, frame)
    local template = '{{Spell'
        .. '| id=' .. id
        .. '| lang=' .. lang
        .. '}}'
    return frame:preprocess(template)
end

--
------------------------------------------------------------------------------------------------------------------------
local function renderGeneric(id, lang, frame)
    local template = '{{LinkIcon'
        .. '| id=' .. id
        .. '| 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
        if id:match('_sub_') then
            id = id:gsub('_sub_', '')
            id = id:gsub('_%d', '')
        end
        return renderSkillLink(id, lang, field, frame)
    end

    if id:match('_hero_') then
        if id:match('_specialization') then
            id = id:gsub('_specialization', '')
        end
        return renderHeroLink(id, lang, frame)
    end

    if id:match('_artifact') then
        return renderArtifactLink(id, lang, frame)
    end

    if id:match('_magic_') then
        return renderSpellLink(id, lang, frame)
    end

    --return renderGeneric(id, lang, frame)
    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

--
------------------------------------------------------------------------------------------------------------------------
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 .. '<div>❌ ' .. getOld(summary) .. '</div>'
    collapse = collapse .. '<div>✅ ' .. getNew(summary) .. '</div>'
    collapse = collapse .. '</div>'

    return prefix .. replaced .. collapse
end

return p