Module:Sandbox/Aurelain/SpellInfobox: Difference between revisions

From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary
No edit summary
Line 27: Line 27:


------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
local function findMasterfulSpecializationText(spellNameEn)
local function findMasterfulSpecializationText(spellNameEn, lang)
     local table = UtilQuery.run([[
     local table = UtilQuery.run([[
         tables =
         tables =
             Translation = T
             Translation = E,
            Translation = F
        | join on =
            E.target_id = F.target_id
         | where =
         | where =
             T.description LIKE '%%starts with the “Masterful %s” spell%%'
             E.description LIKE '%%starts with the “Masterful %s” spell%%'
             AND T.language = 'en'
             AND E.language = 'en'
             AND T.type = 'hero_specialization'
             AND F.language = '%s'
         | fields =
         | fields =
             T.description = description
             F.description = description
         | limit =
         | limit =
             1
             1
     ]], spellNameEn)
     ]], spellNameEn, lang)
     return (table[1] or { description = '' }).description
     return (table[1] or { description = '' }).description
end
end
Line 46: Line 49:
function p.getMasterfulText(frame)
function p.getMasterfulText(frame)
     local spellId = frame.args.id
     local spellId = frame.args.id
    local lang = frame.args.lang
     local spellNameEn = getSpellEnglishName(spellId)
     local spellNameEn = getSpellEnglishName(spellId)
     local text = findMasterfulSpecializationText(spellNameEn)
     local text = findMasterfulSpecializationText(spellNameEn, lang)
     local secondSentence = mw.ustring.match(text, "[.,。]%s*([^.。]+[.。])") or ''
     local secondSentence = mw.ustring.match(text, "[.,。]%s*([^.。]+[.。])") or ''
     return secondSentence
     return secondSentence

Revision as of 07:23, 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, lang)
    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