Module:Sandbox/Aurelain/SpellInfobox: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary
No edit summary
Line 32: Line 32:
             Translation = T
             Translation = T
         | where =
         | where =
             T.description LIKE '%%starts with the %%"
             T.description LIKE '%%starts with the %%'
             AND T.language = 'en'
             AND T.language = 'en'
             AND T.type = 'hero_specialization'
             AND T.type = 'hero_specialization'

Revision as of 07:15, 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 %%'
            AND T.language = 'en'
            AND T.type = 'hero_specialization'
        | fields =
            T.description = description
        | limit =
            1
    ]], spellNameEn)
    return dump(table)
    --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