Module:Item class/sandbox: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 15: Line 15:


-- Should we use the sandbox version of our submodules?
-- 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')
Line 46: Line 46:
     for id, class_data in pairs(m_game.constants.item.classes) do
     for id, class_data in pairs(m_game.constants.item.classes) do
         tr = mw.html.create('tr')
         tr = mw.html.create('tr')
         if not cfg.list.skip_ids[id] and class_data.disabled ~= false and class_data.long_lower then
         if not cfg.list.skip_ids[id] and not class_data.disabled and class_data.long_lower then
             local fields = {
             local fields = {
                 m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),
                 m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),

Latest revision as of 15:21, 4 June 2022

This is the module sandbox page for Module:Item class (diff).

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