Module:SpellInfobox

From Heroes of Might and Magic: Olden Era Official Wiki
Revision as of 07:31, 3 August 2026 by Aurelain (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:SpellInfobox/doc

-- This module is intended as a supporting muscle for the SpellInfobox template.
local p = {}
local UtilQuery = require('Module:UtilQuery')

-- Displays a variable
------------------------------------------------------------------------------------------------------------------------
local function dump(target)
    return '<pre>' .. mw.dumpObject(target) .. '</pre>'
end

------------------------------------------------------------------------------------------------------------------------
local function getSpellEnglishName(spellId)
    local table = UtilQuery.run([[
        tables =
            Translation = T
        | where =
            T.target_id = "%s"
            AND T.language = 'en'
            AND T.type = 'spell'
        | fields =
            T.name = name
        | limit =
            1
    ]], spellId)
    return (table[1] or { name = '' }).name
end

------------------------------------------------------------------------------------------------------------------------
local function findMasterfulSpecializationText(spellNameEn, lang)
    spellNameEn = mw.ustring.gsub(spellNameEn, "[’']", "%")
    local table = UtilQuery.run([[
        tables =
            Translation = E,
            Translation = F
        | join on =
            E.target_id = F.target_id
        | where =
            E.description LIKE '%%starts with the “Masterful %s” spell%%'
            AND E.language = 'en'
            AND F.language = '%s'
        | fields =
            F.description = description
        | limit =
            1
    ]], spellNameEn, lang)
    return (table[1] or { description = '' }).description
end

------------------------------------------------------------------------------------------------------------------------
function p.getMasterfulText(frame)
    local spellId = frame.args.id
    local lang = frame.args.lang
    local spellNameEn = getSpellEnglishName(spellId)
    local text = findMasterfulSpecializationText(spellNameEn, lang)
    local secondSentence = mw.ustring.match(text, "[.,。]%s*([^.。]+[.。])") or ''
    return secondSentence
end

return p