Path of Exile Wiki

Wiki поддерживается сообществом, поэтому подумайте над тем, чтобы внести свой вклад.

ПОДРОБНЕЕ

Path of Exile Wiki
Нет описания правки
Нет описания правки
 
(не показаны 4 промежуточные версии 2 участников)
Строка 13: Строка 13:
   
 
local i18n = {
 
local i18n = {
icon_name = 'File:%s passive skill icon.png',
+
icon_name = 'File:%s passive skill icon.png',
 
errors = {
 
errors = {
invalid_args = 'id, int_id, page or name must be specified',
+
invalid_args = 'id, passive_name, page or q_where must be specified',
 
too_many_passives_found = 'Too many passives found with q_where = %s',
 
too_many_passives_found = 'Too many passives found with q_where = %s',
 
no_passives_found = 'No passives found with q_where = %s',
 
no_passives_found = 'No passives found with q_where = %s',
Строка 36: Строка 36:
 
is_keystone = 'passive_skills.is_keystone',
 
is_keystone = 'passive_skills.is_keystone',
 
is_notable = 'passive_skills.is_notable',
 
is_notable = 'passive_skills.is_notable',
ascendancy_class = 'passive_skills.ascendancy_class',
+
ascendancy_class = 'passive_skills.ascendancy_class',
 
html = 'passive_skills.html',
 
html = 'passive_skills.html',
 
page = 'passive_skills.main_page',
 
}
 
}
   
c.selectors = {'id', 'int_id', 'page', 'name'}
+
c.selectors = {'id', 'page', 'passive_name', 'q_where'}
   
   
Строка 50: Строка 51:
   
 
h.type_order = {
 
h.type_order = {
'basic',
+
'basic',
'notable',
+
'notable',
'keystone',
+
'keystone',
'ascendancy_basic',
+
'ascendancy_basic',
 
'ascendancy_notable'
 
'ascendancy_notable'
 
}
 
}
 
function h.get_type(passive)
 
function h.get_type(passive)
 
--[[
  +
Determine what type of passive skill this passive is.
 
]]
 
local key
 
local key
 
if tonumber(passive['passive_skills.is_keystone']) == 1 then
 
if tonumber(passive['passive_skills.is_keystone']) == 1 then
Строка 65: Строка 69:
 
key = 'basic'
 
key = 'basic'
 
end
 
end
  +
 
 
if passive['passive_skills.ascendancy_class'] ~= nil then
 
if passive['passive_skills.ascendancy_class'] ~= nil then
 
key = 'ascendancy_' .. key
 
key = 'ascendancy_' .. key
 
end
 
end
  +
 
 
return key
 
return key
 
end
 
end
Строка 75: Строка 79:
 
function h.format_passive_icon(passive, tpl_args)
 
function h.format_passive_icon(passive, tpl_args)
 
--[[
 
--[[
Add a frame to passive image.
+
Add a frame to the passive image.
  +
 
 
TODO: Add a inline size.
 
TODO: Add a inline size.
 
]]
 
]]
  +
 
 
if passive['passive_skills.icon'] == nil then
 
if passive['passive_skills.icon'] == nil then
 
return ''
 
return ''
 
end
 
end
  +
local cls = string.format('passive-icon-type__%s', h.get_type(passive))
 
local main_page = passive['passive_skills.main_page']
+
local div = mw.html.create('div')
  +
if tpl_args.large then
or passive['main_pages._pageName']
 
  +
-- Only use frames for large pictures, hard to see anything with it:
or passive['passive_skills.name']
 
or passive['passive_skills.icon']
+
local _type = h.get_type(passive)
 
if _type ~= nil then
 
 
local cls = string.format('passive-icon-type__%s', _type)
div = mw.html.create('div')
 
div:addClass('passive-icon-container')
+
div:addClass('passive-icon-container')
div:addClass(cls)
+
div:addClass(cls)
if tpl_args.large then
+
end
  +
 
div:tag('div')
 
div:tag('div')
 
:addClass('passive-icon-frame')
 
:addClass('passive-icon-frame')
Строка 98: Строка 103:
 
div:wikitext(
 
div:wikitext(
 
string.format(
 
string.format(
'[[%s|link=%s]]',
+
'[[%s|link=%s]]',
passive['passive_skills.icon'],
+
passive['passive_skills.icon'],
main_page
+
passive['passive_skills.main_page']
 
)
 
)
 
)
 
)
else
+
else
 
-- Inline size
 
-- Inline size
div:tag('div')
+
-- div:tag('div')
:addClass('passive-icon-frame')
+
-- :addClass('passive-icon-frame')
 
-- :attr('style', 'height:16px;width:16px')
 
-- :attr('style', 'height:16px;width:16px')
:done()
+
-- :done()
div:wikitext(
+
div = (
 
string.format(
 
string.format(
'[[%s|link=%s]]',
+
'[[%s|14px|link=%s]]',
passive['passive_skills.icon'],
+
passive['passive_skills.icon'],
main_page
+
passive['passive_skills.main_page']
 
)
 
)
 
)
 
)
end
+
end
 
return tostring(div)
 
return tostring(div)
 
end
 
end
Строка 129: Строка 134:
 
--[[
 
--[[
 
Links a passive skill.
 
Links a passive skill.
  +
 
 
TODO:
 
TODO:
 
* Use own CSS.
 
* Use own CSS.
  +
 
 
Examples
 
Examples
 
--------
 
--------
  +
= p.passive_skill_link{'Ghost Reaver', "Ghost Reaver's"}
 
= p.passive_skill_link{id='AscendancyAscendant45'}
 
= p.passive_skill_link{id='AscendancyAscendant45'}
 
= p.passive_skill_link{
 
= p.passive_skill_link{
 
skip_query=true,
 
skip_query=true,
page='Passive Skill:AscendancyAscendant45',
+
page='Passive Skill:AscendancyAscendant45',
name='test',
+
name='test',
 
icon='File:GLADSpeedAoE (Gladiator) passive skill icon.png',
 
icon='File:GLADSpeedAoE (Gladiator) passive skill icon.png',
 
large=1,
 
large=1,
 
}
 
}
 
= p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'}
 
= p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'}
  +
 
 
]]
 
]]
  +
 
 
-- Get args
 
-- Get args
tpl_args = getArgs(frame, {
+
local tpl_args = getArgs(frame, {
 
parentFirst = true
 
parentFirst = true
 
})
 
})
 
frame = m_util.misc.get_frame(frame)
 
frame = m_util.misc.get_frame(frame)
  +
 
  +
-- Hande first and second arguments:
 
tpl_args.passive_name = tpl_args.passive_name or tpl_args[1]
  +
tpl_args.name = tpl_args.name or tpl_args[2]
  +
  +
-- Check if the correct parameters have been set:
 
if m_util.table.has_all_value(tpl_args, c.selectors) and tpl_args.skip_query == nil then
 
if m_util.table.has_all_value(tpl_args, c.selectors) and tpl_args.skip_query == nil then
 
return m_util.html.error{msg=i18n.errors.invalid_args .. m_util.misc.add_category(i18n.errors.cats)}
 
return m_util.html.error{msg=i18n.errors.invalid_args .. m_util.misc.add_category(i18n.errors.cats)}
end
+
end
  +
 
local passive
+
--
 
local passive = {}
 
if m_util.table.has_one_value(tpl_args, c.selectors, nil) and tpl_args.skip_query == nil then
 
if m_util.table.has_one_value(tpl_args, c.selectors, nil) and tpl_args.skip_query == nil then
  +
-- Create q_where depending on the input:
tpl_args.name = tpl_args.name or tpl_args[1]
 
if tpl_args.name then
+
if tpl_args.passive_name then
tpl_args.q_where = string.format('passive_skills.name="%s"', tpl_args.name)
+
tpl_args.q_where = string.format(
 
'passive_skills.name="%s"',
  +
tpl_args.passive_name
 
)
 
elseif tpl_args.id then
 
elseif tpl_args.id then
tpl_args.q_where = string.format('passive_skills.id="%s"', tpl_args.id)
+
tpl_args.q_where = string.format(
  +
'passive_skills.id="%s"',
 
tpl_args.id
 
)
 
elseif tpl_args.q_where then
 
elseif tpl_args.q_where then
  +
-- Use tpl_args.q_where.
 
else
 
else
 
return m_util.html.error{
 
return m_util.html.error{
Строка 170: Строка 189:
 
}
 
}
 
end
 
end
  +
 
  +
-- Query cargo:
 
local results = m_cargo.query(
 
local results = m_cargo.query(
 
{'passive_skills', 'main_pages'},
 
{'passive_skills', 'main_pages'},
 
{
 
{
'passive_skills._pageName',
+
'passive_skills._pageName',
 
'passive_skills.stat_text',
 
'passive_skills.stat_text',
 
'passive_skills.main_page',
 
'passive_skills.main_page',
Строка 182: Строка 202:
 
'passive_skills.is_notable',
 
'passive_skills.is_notable',
 
'passive_skills.ascendancy_class',
 
'passive_skills.ascendancy_class',
 
-- 'passive_skills.html',
 
'main_pages._pageName',
 
'main_pages._pageName',
},
+
},
{
+
{
 
join='passive_skills.id=main_pages.id',
 
join='passive_skills.id=main_pages.id',
 
where=string.format(
 
where=string.format(
'(%s)',
+
'(%s)',
 
tpl_args.q_where
 
tpl_args.q_where
 
),
 
),
Строка 194: Строка 215:
 
}
 
}
 
)
 
)
  +
 
  +
-- Check number of results, there should only be one result:
 
if #results > 1 then
 
if #results > 1 then
  +
local q_where = tostring(tpl_args.q_where)
 
return m_util.html.error{
 
return m_util.html.error{
 
msg=string.format(
 
msg=string.format(
i18n.errors.too_many_passives_found,
+
i18n.errors.too_many_passives_found,
tostring(tpl_args.q_where) .. m_util.misc.add_category(i18n.errors.cats)
+
q_where .. m_util.misc.add_category(i18n.errors.cats)
 
)
 
)
 
}
 
}
 
elseif #results < 1 then
 
elseif #results < 1 then
  +
local q_where = tostring(tpl_args.q_where)
 
return m_util.html.error{
 
return m_util.html.error{
 
msg=string.format(
 
msg=string.format(
i18n.errors.no_passives_found,
+
i18n.errors.no_passives_found,
tostring(tpl_args.q_where) .. m_util.misc.add_category(i18n.errors.cats)
+
q_where .. m_util.misc.add_category(i18n.errors.cats)
 
)
 
)
 
}
 
}
 
end
 
end
  +
 
 
passive = results[1]
 
passive = results[1]
else
 
passive = {
 
['passive_skills.main_page']=tpl_args.page or tpl_args.name
 
}
 
 
end
 
end
  +
 
  +
-- Set the link to the main page:
  +
passive['passive_skills.main_page'] = passive['passive_skills.main_page']
 
or passive['main_pages._pageName']
 
-- or passive['passive_skills.name']
 
or passive['passive_skills._pageName']
  +
  +
-- Add allowed override parameters:
 
for k, prop in pairs(c.parameters) do
 
for k, prop in pairs(c.parameters) do
 
if tpl_args[k] ~= nil then
 
if tpl_args[k] ~= nil then
Строка 223: Строка 250:
 
end
 
end
 
end
 
end
  +
 
if tpl_args.image ~= nil then
+
-- Format the passive icon:
passive['passive_skills.icon'] = 'File:' .. tpl_args.image
 
end
 
 
local img = h.format_passive_icon(passive, tpl_args)
 
local img = h.format_passive_icon(passive, tpl_args)
 
local main_page = passive['passive_skills.main_page']
 
or passive['main_pages._pageName']
 
-- or passive['passive_skills.name']
 
or passive['passive_skills._pageName']
 
 
   
 
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
 
-- Output
 
-- Output
 
---------------------------------------------------------------------------
 
---------------------------------------------------------------------------
  +
 
 
-- Display in a table:
 
-- Display in a table:
 
if tpl_args.format == 'tablerow' then
 
if tpl_args.format == 'tablerow' then
  +
tpl_args.skip_query = true
  +
tpl_args.page = passive['passive_skills.main_page']
 
tpl_args.name = passive['passive_skills.name'] or tpl_args.page
 
tpl_args.icon = passive['passive_skills.icon']
  +
tpl_args.format = nil
 
return string.format(
 
return string.format(
'| [[%s|%s]]%s\n| %s',
+
'| %s\n| %s',
main_page,
+
p.passive_skill_link(tpl_args),
passive['passive_skills.name'],
 
h.format_passive_icon(passive, tpl_args),
 
 
passive['passive_skills.stat_text']
 
passive['passive_skills.stat_text']
 
)
 
)
  +
 
-- Normal inline link:
+
-- Normal inline link:
elseif tpl_args.format == nil then
+
elseif tpl_args.format == nil then
 
local container = mw.html.create('span')
 
local container = mw.html.create('span')
 
container:addClass('c-item-hoverbox')
 
container:addClass('c-item-hoverbox')
Строка 257: Строка 279:
 
container:addClass('c-item-hoverbox--large')
 
container:addClass('c-item-hoverbox--large')
 
end
 
end
  +
 
 
local activator = mw.html.create('span')
 
local activator = mw.html.create('span')
 
activator:addClass('c-item-hoverbox__activator')
 
activator:addClass('c-item-hoverbox__activator')
Строка 264: Строка 286:
 
activator:wikitext(img)
 
activator:wikitext(img)
 
end
 
end
  +
 
 
activator:wikitext(string.format(
 
activator:wikitext(string.format(
'[[%s|%s]]',
+
'[[%s|%s]]',
main_page,
+
passive['passive_skills.main_page'],
passive['passive_skills.name'] or main_page
+
passive['passive_skills.name'] or passive['passive_skills.main_page']
 
)
 
)
 
)
 
)
  +
 
 
local display = mw.html.create('span')
 
local display = mw.html.create('span')
 
display:attr('class', 'c-item-hoverbox__display')
 
display:attr('class', 'c-item-hoverbox__display')
  +
 
if passive['passive_skills.html'] ~= nil then
+
if passive['passive_skills.html'] ~= nil then
 
display:wikitext(passive['passive_skills.html'])
 
display:wikitext(passive['passive_skills.html'])
  +
 
 
if img then
 
if img then
 
display:wikitext(img)
 
display:wikitext(img)
Строка 291: Строка 313:
 
:node(display)
 
:node(display)
 
:done()
 
:done()
  +
 
 
return tostring(container)
 
return tostring(container)
 
else
 
else
Строка 299: Строка 321:
 
end
 
end
 
end
 
end
 
 
 
 
   
 
-- ----------------------------------------------------------------------------
 
-- ----------------------------------------------------------------------------

Текущая версия от 11:13, 5 апреля 2020

Template info icon Документация модуля[просмотр] [править] [история] [очистить]

--
-- Module for passive skill links
--

local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')
local getArgs = require('Module:Arguments').getArgs


-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------

local i18n = {
    icon_name = 'File:%s passive skill icon.png',
    errors = {
        invalid_args = 'id, passive_name, page or q_where must be specified',
        too_many_passives_found = 'Too many passives found with q_where = %s',
        no_passives_found = 'No passives found with q_where = %s',
        invalid_format = 'Invalid return format specified: %s',
        cats = 'Pages with passive skill link errors'
    },
}


-- ----------------------------------------------------------------------------
-- Constants & Data
-- ----------------------------------------------------------------------------

local c = {}
c.image_size = 39
c.image_size_full = c.image_size * 2
c.parameters = {
    name = 'passive_skills.name',
    icon = 'passive_skills.icon',
    is_keystone = 'passive_skills.is_keystone',
    is_notable = 'passive_skills.is_notable',
    ascendancy_class = 'passive_skills.ascendancy_class',
    html = 'passive_skills.html',
    page = 'passive_skills.main_page',
}

c.selectors = {'id', 'page', 'passive_name', 'q_where'}


-- ----------------------------------------------------------------------------
-- Helper functions
-- ----------------------------------------------------------------------------

local h = {}

h.type_order = {
    'basic',
    'notable',
    'keystone',
    'ascendancy_basic',
    'ascendancy_notable'
}
function h.get_type(passive)
    --[[
    Determine what type of passive skill this passive is.
    ]]
    local key
    if tonumber(passive['passive_skills.is_keystone']) == 1 then
        key = 'keystone'
    elseif tonumber(passive['passive_skills.is_notable']) == 1 then
        key = 'notable'
    else
        key = 'basic'
    end

    if passive['passive_skills.ascendancy_class'] ~= nil then
        key = 'ascendancy_' .. key
    end

    return key
end

function h.format_passive_icon(passive, tpl_args)
    --[[
    Add a frame to the passive image.

    TODO: Add a inline size.
    ]]

    if passive['passive_skills.icon'] == nil then
        return ''
    end

    local div = mw.html.create('div')
    if tpl_args.large then
        -- Only use frames for large pictures, hard to see anything with it:
        local _type = h.get_type(passive)
        if _type ~= nil then
            local cls = string.format('passive-icon-type__%s', _type)
            div:addClass('passive-icon-container')
            div:addClass(cls)
        end

        div:tag('div')
            :addClass('passive-icon-frame')
            :done()
        div:wikitext(
            string.format(
                '[[%s|link=%s]]',
                passive['passive_skills.icon'],
                passive['passive_skills.main_page']
            )
        )
    else
        -- Inline size
        -- div:tag('div')
            -- :addClass('passive-icon-frame')
            -- :attr('style', 'height:16px;width:16px')
            -- :done()
        div = (
            string.format(
                '[[%s|14px|link=%s]]',
                passive['passive_skills.icon'],
                passive['passive_skills.main_page']
            )
        )
    end
    return tostring(div)
end

-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------

local p = {}

function p.passive_skill_link(frame)
    --[[
    Links a passive skill.

    TODO:
    * Use own CSS.

    Examples
    --------
    = p.passive_skill_link{'Ghost Reaver', "Ghost Reaver's"}
    = p.passive_skill_link{id='AscendancyAscendant45'}
    = p.passive_skill_link{
        skip_query=true,
        page='Passive Skill:AscendancyAscendant45',
        name='test',
        icon='File:GLADSpeedAoE (Gladiator) passive skill icon.png',
        large=1,
    }
    = p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'}

    ]]

    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)

    -- Hande first and second arguments:
    tpl_args.passive_name = tpl_args.passive_name or tpl_args[1]
    tpl_args.name = tpl_args.name or tpl_args[2]

    -- Check if the correct parameters have been set:
    if m_util.table.has_all_value(tpl_args, c.selectors) and tpl_args.skip_query == nil then
        return m_util.html.error{msg=i18n.errors.invalid_args .. m_util.misc.add_category(i18n.errors.cats)}
    end

    --
    local passive = {}
    if m_util.table.has_one_value(tpl_args, c.selectors, nil) and tpl_args.skip_query == nil then
        -- Create q_where depending on the input:
        if tpl_args.passive_name then
            tpl_args.q_where = string.format(
                'passive_skills.name="%s"',
                tpl_args.passive_name
            )
        elseif tpl_args.id then
            tpl_args.q_where = string.format(
                'passive_skills.id="%s"',
                tpl_args.id
            )
        elseif tpl_args.q_where then
            -- Use tpl_args.q_where.
        else
            return m_util.html.error{
                msg=i18n.errors.invalid_args .. m_util.misc.add_category(i18n.errors.cats)
            }
        end

        -- Query cargo:
        local results = m_cargo.query(
            {'passive_skills', 'main_pages'},
            {
                'passive_skills._pageName',
                'passive_skills.stat_text',
                'passive_skills.main_page',
                'passive_skills.name',
                'passive_skills.icon',
                'passive_skills.is_keystone',
                'passive_skills.is_notable',
                'passive_skills.ascendancy_class',
                -- 'passive_skills.html',
                'main_pages._pageName',
            },
            {
                join='passive_skills.id=main_pages.id',
                where=string.format(
                    '(%s)',
                    tpl_args.q_where
                ),
                orderBy='passive_skills.stat_text',
                limit=2,
            }
        )

        -- Check number of results, there should only be one result:
        if #results > 1 then
            local q_where = tostring(tpl_args.q_where)
            return m_util.html.error{
                msg=string.format(
                    i18n.errors.too_many_passives_found,
                    q_where .. m_util.misc.add_category(i18n.errors.cats)
                    )
                }
        elseif #results < 1 then
            local q_where = tostring(tpl_args.q_where)
            return m_util.html.error{
                msg=string.format(
                    i18n.errors.no_passives_found,
                    q_where .. m_util.misc.add_category(i18n.errors.cats)
                )
            }
        end

        passive = results[1]
    end

    -- Set the link to the main page:
    passive['passive_skills.main_page'] = passive['passive_skills.main_page']
        or passive['main_pages._pageName']
        -- or passive['passive_skills.name']
        or passive['passive_skills._pageName']

    -- Add allowed override parameters:
    for k, prop in pairs(c.parameters) do
        if tpl_args[k] ~= nil then
            passive[prop] = tpl_args[k]
        end
    end

    -- Format the passive icon:
    local img = h.format_passive_icon(passive, tpl_args)

    ---------------------------------------------------------------------------
    -- Output
    ---------------------------------------------------------------------------

    -- Display in a table:
    if tpl_args.format == 'tablerow' then
        tpl_args.skip_query = true
        tpl_args.page = passive['passive_skills.main_page']
        tpl_args.name = passive['passive_skills.name'] or tpl_args.page
        tpl_args.icon = passive['passive_skills.icon']
        tpl_args.format = nil
        return string.format(
            '| %s\n| %s',
            p.passive_skill_link(tpl_args),
            passive['passive_skills.stat_text']
        )

    -- Normal inline link:
    elseif tpl_args.format == nil then
        local container = mw.html.create('span')
        container:addClass('c-item-hoverbox')

        if tpl_args.large then
            container:addClass('c-item-hoverbox--large')
        end

        local activator = mw.html.create('span')
        activator:addClass('c-item-hoverbox__activator')

        if img and not tpl_args.large then
            activator:wikitext(img)
        end

        activator:wikitext(string.format(
            '[[%s|%s]]',
            passive['passive_skills.main_page'],
            passive['passive_skills.name'] or passive['passive_skills.main_page']
            )
        )

        local display = mw.html.create('span')
        display:attr('class', 'c-item-hoverbox__display')

        if passive['passive_skills.html'] ~= nil then
            display:wikitext(passive['passive_skills.html'])

            if img then
                display:wikitext(img)
            end
        end

        if img and tpl_args.large then
            activator:wikitext(img)
        end

        container
            :node(activator)
            :node(display)
            :done()

        return tostring(container)
    else
        return m_util.html.error{
            msg=string.format(i18n.error.invalid_format, tpl_args.format .. m_util.misc.add_category(i18n.errors.cats))
        }
    end
end

-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------

return p