Module:Item class: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
(From sandbox: Backed out some changes)
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--  
--  
--                        Module:Item class infocard
--                        Module:Item class
--  
--  
-- This module implements Template:Item class infocard
-- This module implements Template:Item class list and
-- Template:Item class infocard
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------


Line 10: Line 11:
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------


local getArgs = require('Module:Arguments').getArgs
require('Module:No globals')
local m_util = require('Module:Util')
local m_util = require('Module:Util')


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


local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or mw.loadData('Module:Game')
local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or mw.loadData('Module:Game')


local i18n = {
-- The cfg table contains all localisable strings and configuration, to make it
    page = '[[Item class]]',
-- easier to port this module to another wiki.
    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'),
local cfg = use_sandbox and mw.loadData('Module:Item class/config/sandbox') or mw.loadData('Module:Item class/config')
    also_referred_to_as = 'Also referred to as: %s',
    filterid = 'Item filter ID: %s',
    is_removed = "''Removed from the game.''",
    long_upper = 'Long uppercase name: %s',
    long_lower = 'Long lowercase name: %s',


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


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


function p.main(frame)
local function _list(args)
     -- Get args
    local tbl = mw.html.create('table')
     local tpl_args = getArgs(frame, {
        :attr('class', 'wikitable sortable')
         parentFirst = true
     local tr = mw.html.create('tr')
     })
     local headers = {
 
        i18n.list.item_class,
     frame = m_util.misc.get_frame(frame)
        i18n.list.internal_name,
   
         i18n.list.internal_id,
    if not doInfoCard then
     }
        doInfoCard = require('Module:Infocard')._main
    for _, h in ipairs(headers) do
        tr
            :tag('th')
                :wikitext(h)
    end
     tbl:node(tr)
    for id, class_data in pairs(m_game.constants.item.classes) do
        tr = mw.html.create('tr')
        if not cfg.list.skip_ids[id] and not class_data.disabled and class_data.long_lower then
            local fields = {
                m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),
                class_data.name,
                id,
            }
            for _, f in ipairs(fields) do
                tr
                    :tag('td')
                        :wikitext(f)
            end
            tbl:node(tr)
        end
     end
     end
    return tostring(tbl)
end


local function _infocard(args)
    local doInfoCard = require('Module:Infocard').main
     local constinfo = nil
     local constinfo = nil
     local filterid = nil
     local filterid = nil
     for id, row in pairs(m_game.constants.item.classes) do
     for id, row in pairs(m_game.constants.item.classes) do
         if row['full'] == tpl_args.name then
         if row['full'] == args.name then
             constinfo = row
             constinfo = row
             filterid = id
             filterid = id
Line 60: Line 76:
      
      
     if constinfo == nil then
     if constinfo == nil then
         error(string.format(i18n.errors.invalid_class, tostring(tpl_args.name)))
         error(string.format(i18n.infocard.errors.invalid_class, tostring(args.name)))
     end
     end


Line 67: Line 83:
     local infocard_args = {}
     local infocard_args = {}


     if tpl_args.name_list ~= nil then
     if args.name_list ~= nil then
         local names = m_util.string.split(tpl_args.name_list, ',%s*')
         local names = m_util.string.split(args.name_list, ',%s*')
         local ul = mw.html.create('ul')
         local ul = mw.html.create('ul')
         for _, item in ipairs(names) do
         for _, item in ipairs(names) do
Line 76: Line 92:
                     :done()
                     :done()
         end
         end
         table.insert(infocard_args, string.format(i18n.also_referred_to_as, tostring(ul)))     
         table.insert(infocard_args, string.format(i18n.infocard.also_referred_to_as, tostring(ul)))     
     end
     end
      
      
     if (tpl_args.verbose) then
     if (args.verbose) then
         table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper'])))
         table.insert(infocard_args, string.format(i18n.infocard.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.infocard.long_lower, tostring(constinfo['long_lower'])))
     end
     end
     table.insert(infocard_args, string.format(i18n.filterid, tostring(filterid)))
     table.insert(infocard_args, string.format(i18n.infocard.filterid, tostring(filterid)))


     if (constinfo['is_removed'] == true) then
     if (constinfo['is_removed'] == true) then
         table.insert(infocard_args, i18n.is_removed)
         table.insert(infocard_args, i18n.infocard.is_removed)
     end
     end
      
      
     -- Output Infocard
     -- Output Infocard


     infocard_args['header'] = tpl_args.name
     infocard_args['header'] = args.name
     infocard_args['subheader'] = i18n.page .. i18n.info
     infocard_args['subheader'] = i18n.infocard.page .. i18n.infocard.info
      
      
     -- cats
     -- cats
Line 98: Line 114:
     local cats = {
     local cats = {
         'Item classes',
         'Item classes',
         tpl_args.name,
         args.name,
     }
     }
      
      
     -- Done
     -- Done
      
      
     return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist=tpl_args.debug})
     return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist=args.debug})
end
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
--
-- Template:Item class list
--
p.list = m_util.misc.invoker_factory(_list, {
    wrappers = cfg.wrappers.item_class_list,
})
--
-- Template:Item class infocard
--
p.infocard = m_util.misc.invoker_factory(_infocard, {
    wrappers = cfg.wrappers.item_class_infocard,
})


return p
return p

Latest revision as of 15:21, 4 June 2022

Module documentation[view] [edit] [history] [purge]


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

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

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

require('Module:No globals')
local m_util = require('Module:Util')

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

local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or mw.loadData('Module:Game')

-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Item class/config/sandbox') or mw.loadData('Module:Item class/config')

local i18n = cfg.i18n

-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------

local function _list(args)
    local tbl = mw.html.create('table')
        :attr('class', 'wikitable sortable')
    local tr = mw.html.create('tr')
    local headers = {
        i18n.list.item_class,
        i18n.list.internal_name,
        i18n.list.internal_id,
    }
    for _, h in ipairs(headers) do
        tr
            :tag('th')
                :wikitext(h)
    end
    tbl:node(tr)
    for id, class_data in pairs(m_game.constants.item.classes) do
        tr = mw.html.create('tr')
        if not cfg.list.skip_ids[id] and not class_data.disabled and class_data.long_lower then
            local fields = {
                m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),
                class_data.name,
                id,
            }
            for _, f in ipairs(fields) do
                tr
                    :tag('td')
                        :wikitext(f)
            end
            tbl:node(tr)
        end
    end
    return tostring(tbl)
end

local function _infocard(args)
    local doInfoCard = require('Module:Infocard').main
    local constinfo = nil
    local filterid = nil
    for id, row in pairs(m_game.constants.item.classes) do
        if row['full'] == args.name then
            constinfo = row
            filterid = id
            break
        end
    end
    
    if constinfo == nil then
        error(string.format(i18n.infocard.errors.invalid_class, tostring(args.name)))
    end

    --
    
    local infocard_args = {}

    if args.name_list ~= nil then
        local names = m_util.string.split(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.infocard.also_referred_to_as, tostring(ul)))    
    end
    
    if (args.verbose) then
        table.insert(infocard_args, string.format(i18n.infocard.long_upper, tostring(constinfo['long_upper'])))
        table.insert(infocard_args, string.format(i18n.infocard.long_lower, tostring(constinfo['long_lower'])))
    end
    table.insert(infocard_args, string.format(i18n.infocard.filterid, tostring(filterid)))

    if (constinfo['is_removed'] == true) then
        table.insert(infocard_args, i18n.infocard.is_removed)
    end
    
    -- Output Infocard

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

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

--
-- Template:Item class list
-- 
p.list = m_util.misc.invoker_factory(_list, {
    wrappers = cfg.wrappers.item_class_list,
})

--
-- Template:Item class infocard
-- 
p.infocard = m_util.misc.invoker_factory(_infocard, {
    wrappers = cfg.wrappers.item_class_infocard,
})

return p