Module:Item class: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
(Added item class list function from Module:Miscellaneous. Translation strings moved to Module:Item class/config for easier porting. No globals.)
(Remade item class list: Added column showing internal name of item class (used for item filters). Removed column containing item class categories.)
Line 30: Line 30:


local function _list(args)
local function _list(args)
     args.no_id = args.no_id or false
     local tbl = mw.html.create('table')
     args.no_category = args.no_category or false
        :attr('class', 'wikitable sortable')
     args.no_empty_class_names = args.no_empty_class_names or false
     local tr = mw.html.create('tr')
    args.show_removed = args.show_removed or false
     local headers = {
   
        i18n.list.item_class,
     local out = {}
        i18n.list.internal_name,
 
        i18n.list.internal_id,
     for id, data in pairs(m_game.constants.item.classes) do
     }
         local rowhtml = ''
     for _, h in ipairs(headers) do
        if (data['is_removed'] ~= true) or args.show_removed then
         tr
             local datafullpresent = (data['full'] ~= nil) and (data['full'] ~= '')
             :tag('th')
            if datafullpresent or (not args.no_empty_class_names) then
                :wikitext(h)
                local datafull = "''none''"
    end
                if (data['full'] ~= nil) and (data['full'] ~= '') then
    tbl:node(tr)
                    datafull = string.format('[[%s]]', data['full'])
    for id, class_data in pairs(m_game.constants.item.classes) do
                end
        tr = mw.html.create('tr')
                local datacategory = "''none''"
        if not cfg.list.skip_ids[id] and not class_data.disabled and class_data.long_lower then
                if (data['category'] ~= nil) and (data['category'] ~= '') then
            local fields = {
                    datacategory = data['category']
                 m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),
                end
                 class_data.name,
                 local tdfull = mw.html.create('td')
                 id,
                    :wikitext(datafull)
            }
                 local tdid
            for _, f in ipairs(fields) do
                 if not args.no_id then
                 tr
                    tdid = mw.html.create('td')
                     :tag('td')
                        :wikitext(id)
                         :wikitext(f)
                 end
                local tdcategory
                if not args.no_category then
                     tdcategory = mw.html.create('td')
                         :wikitext(datacategory)
                end
                local tr = mw.html.create('tr')
                    :node(tdfull)
                    :node(tdid)
                    :node(tdcategory)
                rowhtml = tostring(tr)
             end
             end
            tbl:node(tr)
         end
         end
        out[data['id']] = rowhtml
     end
     end
   
    local thfull = mw.html.create('th')
        :wikitext(i18n.list.item_class)
    local thid
    if not args.no_id then
        thid = mw.html.create('th')
            :wikitext(i18n.list.item_class_id)
    end
    local thcategory
    if not args.no_category then
        thcategory = mw.html.create('th')
            :wikitext(i18n.list.item_class_category)
    end
    local tbl = mw.html.create('table')
        :attr('class', 'wikitable sortable')
        :tag('tr')
            :node(thfull)
            :node(thid)
            :node(thcategory)
            :done()
        :wikitext(table.concat(out))
   
     return tostring(tbl)
     return tostring(tbl)
end
end

Revision as of 23:56, 27 May 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 infocard')

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