Module:Sandbox/Aurelain/SpellInfobox: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary
No edit summary
Line 22: Line 22:
         | limit =
         | limit =
             1
             1
     ]], spellId);
     ]], spellId)
     return (table[1] or { name = '' }).name
     return (table[1] or { name = '' }).name
end
------------------------------------------------------------------------------------------------------------------------
local function findMasterfulSpecializationText(spellNameEn)
    local table = UtilQuery.run([[
        tables =
            Translation = T
        | where =
            T.description LIKE '%%starts with the “Masterful %s” spell%%"
            AND T.language = 'en'
            AND T.type = 'hero_specialization'
        | fields =
            T.description = description
        | limit =
            1
    ]], spellNameEn)
    return (table[1] or { description = '' }).description
end
end


Line 30: Line 47:
     local spellId = frame.args.id
     local spellId = frame.args.id
     local spellNameEn = getSpellEnglishName(spellId)
     local spellNameEn = getSpellEnglishName(spellId)
     return spellNameEn
    local text = findMasterfulSpecializationText(spellNameEn)
     return text
end
end


return p
return p

Revision as of 07:10, 3 August 2026

Documentation for this module may be created at Module:Sandbox/Aurelain/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)
    local table = UtilQuery.run([[
        tables =
            Translation = T
        | where =
            T.description LIKE '%%starts with the “Masterful %s” spell%%"
            AND T.language = 'en'
            AND T.type = 'hero_specialization'
        | fields =
            T.description = description
        | limit =
            1
    ]], spellNameEn)
    return (table[1] or { description = '' }).description
end

------------------------------------------------------------------------------------------------------------------------
function p.getMasterfulText(frame)
    local spellId = frame.args.id
    local spellNameEn = getSpellEnglishName(spellId)
    local text = findMasterfulSpecializationText(spellNameEn)
    return text
end

return p