Module:Item class: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
m (Fixed typo)
(From sandbox: Display more information; support for new 'is suppressed' and 'is uncertain' flags)
Line 12: Line 12:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local m_util = require('Module:Util')
local m_game = mw.loadData('Module:Game')
 
-- Should we use the sandbox version of the game data?
local use_sandbox = m_util.misc.maybe_sandbox('Item class infocard')
 
local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or mw.loadData('Module:Game')


local i18n = {
local i18n = {
     page = '[[Item class]]',
     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'),
     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:',
     also_referred_to_as = 'Also referred to as: %s',
    filterid = 'Item filter ID: %s',
    is_suppressed = "''Suppressed from most item class lists.''",
    is_uncertain = "''Data may be incorrect.'' " .. m_util.html.abbr('(?)', 'Some of this information is questionable. If you can confirm or correct it, please let us know on the talk page.'),
    long_upper = 'Long uppercase name: %s',
    long_lower = 'Long lowercase name: %s',


     errors = {
     errors = {
Line 34: Line 43:
         parentFirst = true
         parentFirst = true
     })
     })
     frame = m_util.misc.get_frame(frame)
     frame = m_util.misc.get_frame(frame)
      
      
Line 39: Line 49:
         doInfoCard = require('Module:Infocard')._main
         doInfoCard = require('Module:Infocard')._main
     end
     end
      
 
     local err = true
     local constinfo = nil
     for _, row in pairs(m_game.constants.item.classes) do
     local filterid = nil
     for id, row in pairs(m_game.constants.item.classes) do
         if row['full'] == tpl_args.name then
         if row['full'] == tpl_args.name then
             err = false
             constinfo = row
            filterid = id
             break
             break
         end
         end
     end
     end
      
      
     if err then
     if constinfo == nil then
         error(string.format(i18n.errors.invalid_class, tostring(tpl_args.name)))
         error(string.format(i18n.errors.invalid_class, tostring(tpl_args.name)))
     end
     end
    --
      
      
    local infocard_args = {}
     if tpl_args.name_list ~= nil then
     if tpl_args.name_list ~= nil then
         tpl_args.name_list = m_util.string.split(tpl_args.name_list, ',%s*')
         local names = m_util.string.split(tpl_args.name_list, ',%s*')
    else
        local ul = mw.html.create('ul')
         tpl_args.name_list = {}
        for _, item in ipairs(names) do
            ul
                :tag('li')
                    :wikitext(item)
                    :done()
         end
        table.insert(infocard_args, string.format(i18n.also_referred_to_as, tostring(ul)))   
     end
     end
      
      
     --
     table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper'])))
    table.insert(infocard_args, string.format(i18n.long_lower, tostring(constinfo['long_lower'])))
    table.insert(infocard_args, string.format(i18n.filterid, tostring(filterid)))
 
    if (constinfo['is_suppressed'] == true) then
        table.insert(infocard_args, i18n.is_suppressed)
        if (constinfo['is_suppressed_details'] ~= nil) and (constinfo['is_suppressed_details'] ~= "") then
            table.insert(infocard_args, tostring(constinfo['is_suppressed_details']))
        end
    end
      
      
     local ul = mw.html.create('ul')
     if (constinfo['is_uncertain'] == true) then
    for _, item in ipairs(tpl_args.name_list) do
        table.insert(infocard_args, i18n.is_uncertain)
         ul
         if (constinfo['is_uncertain_details'] ~= nil) and (constinfo['is_uncertain_details'] ~= "") then
            :tag('li')
            table.insert(infocard_args, tostring(constinfo['is_uncertain_details']))
                :wikitext(item)
        end
                :done()
     end
     end
      
      
    -- Output Infocard


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


return p
return p

Revision as of 04:04, 19 December 2021

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')

-- Should we use the sandbox version of the game data?
local use_sandbox = m_util.misc.maybe_sandbox('Item class infocard')

local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or 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: %s',
    filterid = 'Item filter ID: %s',
    is_suppressed = "''Suppressed from most item class lists.''",
    is_uncertain = "''Data may be incorrect.'' " .. m_util.html.abbr('(?)', 'Some of this information is questionable. If you can confirm or correct it, please let us know on the talk page.'),
    long_upper = 'Long uppercase name: %s',
    long_lower = 'Long lowercase name: %s',

    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 constinfo = nil
    local filterid = nil
    for id, row in pairs(m_game.constants.item.classes) do
        if row['full'] == tpl_args.name then
            constinfo = row
            filterid = id
            break
        end
    end
    
    if constinfo == nil then
        error(string.format(i18n.errors.invalid_class, tostring(tpl_args.name)))
    end

    --
    
    local infocard_args = {}

    if tpl_args.name_list ~= nil then
        local names = m_util.string.split(tpl_args.name_list, ',%s*')
        local ul = mw.html.create('ul')
        for _, item in ipairs(names) do
            ul
                :tag('li')
                    :wikitext(item)
                    :done()
        end
        table.insert(infocard_args, string.format(i18n.also_referred_to_as, tostring(ul)))    
    end
    
    table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper'])))
    table.insert(infocard_args, string.format(i18n.long_lower, tostring(constinfo['long_lower'])))
    table.insert(infocard_args, string.format(i18n.filterid, tostring(filterid)))

    if (constinfo['is_suppressed'] == true) then
        table.insert(infocard_args, i18n.is_suppressed)
        if (constinfo['is_suppressed_details'] ~= nil) and (constinfo['is_suppressed_details'] ~= "") then
            table.insert(infocard_args, tostring(constinfo['is_suppressed_details']))
        end
    end
    
    if (constinfo['is_uncertain'] == true) then
        table.insert(infocard_args, i18n.is_uncertain)
        if (constinfo['is_uncertain_details'] ~= nil) and (constinfo['is_uncertain_details'] ~= "") then
            table.insert(infocard_args, tostring(constinfo['is_uncertain_details']))
        end
    end
    
    -- Output Infocard

    infocard_args['header'] = tpl_args.name
    infocard_args['subheader'] = i18n.page .. i18n.info
    
    -- cats
    
    local cats = {
        'Item classes',
        tpl_args.name,
    }
    
    -- Done
    
    return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist=tpl_args.debug})
end

return p