Module:Item class

From Path of Exile Wiki
Revision as of 03:46, 10 July 2021 by >Vinifera7 (Fixed typo)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]


Implements {{item class list}} and {{item class infocard}}.

-------------------------------------------------------------------------------
-- 
--                        Module:Item class infocard
-- 
-- This module implements Template:Item class infocard
-------------------------------------------------------------------------------

-- ----------------------------------------------------------------------------
-- Includes
-- ----------------------------------------------------------------------------

local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local m_game = mw.loadData('Module:Game')

local i18n = {
    page = '[[Item class]]',
    info = m_util.html.abbr('(?)', 'Item classes categorize items. Classes are often used to restrict items or skill gems to a specific class or by item filters'),
    also_referred_to_as = 'Also referred to as:',

    errors = {
        invalid_class = 'The item class name "%s" is invalid.',
    },
}

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}

function p.main(frame)
    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    if not doInfoCard then
        doInfoCard = require('Module:Infocard')._main
    end
    
    local err = true
    for _, row in pairs(m_game.constants.item.classes) do
        if row['full'] == tpl_args.name then
            err = false
            break
        end
    end
    
    if err then
        error(string.format(i18n.errors.invalid_class, tostring(tpl_args.name)))
    end
    
    if tpl_args.name_list ~= nil then
        tpl_args.name_list = m_util.string.split(tpl_args.name_list, ',%s*')
    else
        tpl_args.name_list = {}
    end
    
    --
    
    local ul = mw.html.create('ul')
    for _, item in ipairs(tpl_args.name_list) do
        ul
            :tag('li')
                :wikitext(item)
                :done()
    end
    

    -- Output Infocard
    
    local tplargs = {
        ['header'] = tpl_args.name,
        ['subheader'] = i18n.page .. i18n.info,
        [1] = i18n.also_referred_to_as .. tostring(ul),
    }
    
    -- cats
    
    local cats = {
        'Item classes',
        tpl_args.name,
    }
    
    -- Done
    
    return doInfoCard(tplargs) .. m_util.misc.add_category(cats, {ignore_blacklist=tpl_args.debug})
end

return p