Module:Item acquisition: Difference between revisions
Jump to navigation
Jump to search
>OmegaK2 (make item links as long there aren't too many) |
>OmegaK2 (Added drop_text to output, added more header sections, added item links for ingredients) |
||
Line 19: | Line 19: | ||
acquisition = { | acquisition = { | ||
header = 'Item acquisition', | header = 'Item acquisition', | ||
area_header = 'Area restrictions', | |||
area = 'This item can be acquired in the following areas:', | area = 'This item can be acquired in the following areas:', | ||
upgraded_from_header = 'Upgrade paths', | |||
upgraded_from = 'This item can be acquired through the following upgrade paths or vendor recipes:', | upgraded_from = 'This item can be acquired through the following upgrade paths or vendor recipes:', | ||
Line 33: | Line 36: | ||
local c = {} | local c = {} | ||
c.max_links = 3 | c.max_links = 3 | ||
-- ---------------------------------------------------------------------------- | |||
-- Helper functions | |||
-- ---------------------------------------------------------------------------- | |||
local h = {} | |||
function h.head(str) | |||
local head = mw.html.create('h3') | |||
head:wikitext(str) | |||
return tostring(head) | |||
end | |||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
Line 59: | Line 73: | ||
local query | local query | ||
-- ------------------------- | |||
-- Drop restrictions by area | out[#out+1] = tpl_args.acquisition_insert | ||
-- ------------------------- | |||
-- ------------------------------ | |||
-- Drop restrictions by text/area | |||
-- ------------------------------ | |||
results = m_util.cargo.query( | results = m_util.cargo.query( | ||
{'items'}, | {'items'}, | ||
{ | { | ||
where=string.format('items._pageName="%s"', tpl_args.page) | 'items.drop_areas_html', | ||
'items.drop_text', | |||
}, | |||
{ | |||
where=string.format('items._pageName="%s" AND (items.drop_areas_html IS NOT NULL OR items.drop_text IS NOT NULL)', tpl_args.page), | |||
limit=1, | limit=1, | ||
} | } | ||
Line 76: | Line 93: | ||
if #results > 0 then | if #results > 0 then | ||
results = results[1] | results = results[1] | ||
if results['items.drop_text'] then | |||
out[#out+1] = results['items.drop_text'] | |||
end | |||
if results['items.drop_areas_html'] then | if results['items.drop_areas_html'] then | ||
local ul = mw.html.create('ul') | local ul = mw.html.create('ul') | ||
Line 82: | Line 102: | ||
:wikitext(area) | :wikitext(area) | ||
end | end | ||
out[#out+1] = h.head(i18n.acquisition.area_header) | |||
out[#out+1] = i18n.acquisition.area | out[#out+1] = i18n.acquisition.area | ||
out[#out+1]= '<br>' | out[#out+1]= '<br>' | ||
Line 161: | Line 182: | ||
end | end | ||
out[#out+1] = h.head(i18n.acquisition.upgraded_from_header) | |||
out[#out+1] = i18n.acquisition.upgraded_from | out[#out+1] = i18n.acquisition.upgraded_from | ||
out[#out+1]= '<br>' | out[#out+1]= '<br>' | ||
out[#out+1] = tostring(ul) | out[#out+1] = tostring(ul) | ||
end | end | ||
-- ------------------------------------- | -- ------------------------------------- | ||
-- Ingredient of vendor recipes/upgrades | -- Ingredient of vendor recipes/upgrades | ||
Line 174: | Line 194: | ||
-- Query | -- Query | ||
-- | -- | ||
results = m_util.cargo.query( | results = m_util.cargo.query( | ||
{'upgraded_from_groups'}, | {'upgraded_from_groups', 'items',}, | ||
{'upgraded_from_groups._pageName', }, | { | ||
'upgraded_from_groups._pageName', | |||
'items.name', | |||
'items.inventory_icon', | |||
'items.html', | |||
}, | |||
{ | { | ||
where=string.format('upgraded_from_groups.item_page="%s"', tpl_args.page), | where=string.format('upgraded_from_groups.item_page="%s"', tpl_args.page), | ||
join='upgraded_from_groups._pageID=items._pageID', | |||
} | } | ||
) | ) | ||
if #results > 0 then | if #results > 0 then | ||
out[#out+1] = h.head(i18n.acquisition.ingredient_header) | |||
out[#out+1] = i18n.acquisition.ingredient | out[#out+1] = i18n.acquisition.ingredient | ||
out[#out+1]= '<br>' | out[#out+1]= '<br>' | ||
Line 196: | Line 216: | ||
for _, row in ipairs(results) do | for _, row in ipairs(results) do | ||
ul:tag('li') | ul:tag('li') | ||
:wikitext( | :wikitext(f_item_link{page=row['upgraded_from_groups._pageName'], name=row['items.name'], inventory_icon=row['items.inventory_icon'] or '', html=row['items.html'] or '', skip_query=true}) | ||
end | end | ||
Revision as of 12:22, 18 March 2018
The above documentation is transcluded from Module:Item acquisition/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-- ----------------------------------------------------------------------------
-- Imports
-- ----------------------------------------------------------------------------
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local f_item_link = require('Module:Item link').item_link
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
-- This section contains strings used by this module.
-- Add new strings here instead of in-code directly, this will help other
-- people to correct spelling mistakes easier and help with translation to
-- other PoE wikis.
--
-- TODO: Maybe move this out to a separate sub-page module
local i18n = {
acquisition = {
header = 'Item acquisition',
area_header = 'Area restrictions',
area = 'This item can be acquired in the following areas:',
upgraded_from_header = 'Upgrade paths',
upgraded_from = 'This item can be acquired through the following upgrade paths or vendor recipes:',
ingredient_header = 'Usage in recipes',
ingredient = 'This item is used by upgrade paths or vendor recipes to create the following items:',
},
}
-- ----------------------------------------------------------------------------
-- Globals
-- ----------------------------------------------------------------------------
local c = {}
c.max_links = 3
-- ----------------------------------------------------------------------------
-- Helper functions
-- ----------------------------------------------------------------------------
local h = {}
function h.head(str)
local head = mw.html.create('h3')
head:wikitext(str)
return tostring(head)
end
-- ----------------------------------------------------------------------------
-- Templates
-- ----------------------------------------------------------------------------
local p = {}
--
-- Template: Item acquisition
--
-- Used to duplicate the information from the infobox in a more readable manner on the page.
function p.item_acquisition (frame)
-- Get args
local tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
tpl_args.page = tpl_args.page or tostring(mw.title.getCurrentTitle())
local out = {}
local results
local query
out[#out+1] = tpl_args.acquisition_insert
-- ------------------------------
-- Drop restrictions by text/area
-- ------------------------------
results = m_util.cargo.query(
{'items'},
{
'items.drop_areas_html',
'items.drop_text',
},
{
where=string.format('items._pageName="%s" AND (items.drop_areas_html IS NOT NULL OR items.drop_text IS NOT NULL)', tpl_args.page),
limit=1,
}
)
if #results > 0 then
results = results[1]
if results['items.drop_text'] then
out[#out+1] = results['items.drop_text']
end
if results['items.drop_areas_html'] then
local ul = mw.html.create('ul')
for _, area in ipairs(m_util.string.split(results['items.drop_areas_html'], '%s*•%s*')) do
ul:tag('li')
:wikitext(area)
end
out[#out+1] = h.head(i18n.acquisition.area_header)
out[#out+1] = i18n.acquisition.area
out[#out+1]= '<br>'
out[#out+1] = tostring(ul)
end
end
-- ------------------------------------
-- Obtained via vendor recipes/upgrades
-- ------------------------------------
--
-- Query data
--
local sets = {}
results = m_util.cargo.query(
{'upgraded_from_sets'},
{
'upgraded_from_sets.set_id',
'upgraded_from_sets.text',
},
{
where=string.format('upgraded_from_sets._pageName="%s"', tpl_args.page),
-- Workaround: Fix cargo duplicates
groupBy='upgraded_from_sets._pageID,upgraded_from_sets.set_id',
}
)
for _, row in ipairs(results) do
row.groups = {}
sets[tonumber(row['upgraded_from_sets.set_id'])] = row
end
results = m_util.cargo.query(
{'upgraded_from_groups'},
{
'upgraded_from_groups.set_id',
'upgraded_from_groups.group_id',
'upgraded_from_groups.notes',
'upgraded_from_groups.amount',
'upgraded_from_groups.item_name',
'upgraded_from_groups.item_page',
},
{
where=string.format('upgraded_from_groups._pageName="%s"', tpl_args.page),
-- Workaround: Fix cargo duplicates
groupBy='upgraded_from_groups._pageID,upgraded_from_groups.set_id,upgraded_from_groups.group_id',
}
)
for _, row in ipairs(results) do
sets[tonumber(row['upgraded_from_groups.set_id'])].groups[tonumber(row['upgraded_from_groups.group_id'])] = row
end
--
-- Build output
--
if #sets > 0 then
local ul = mw.html.create('ul')
for _, set in ipairs(sets) do
local li = ul:tag('li')
if set['upgraded_from_sets.text'] then
li:wikitext(set['upgraded_from_sets.text'] .. '<br>')
end
local str = {}
for _, group in ipairs(set.groups) do
if #sets > c.max_links then
str[#str+1] = string.format('%sx [[%s|%s]]', group['upgraded_from_groups.amount'], group['upgraded_from_groups.item_page'], group['upgraded_from_groups.item_name'] or group['upgraded_from_groups.item_page'])
else
str[#str+1] = string.format('%sx %s', group['upgraded_from_groups.amount'], f_item_link{page=group['upgraded_from_groups.item_page']})
end
if group['upgraded_from_groups.notes'] then
str[#str] = string.format('%s (%s)', str[#str], group['upgraded_from_groups.notes'])
end
end
li:wikitext(table.concat(str, ', '))
end
out[#out+1] = h.head(i18n.acquisition.upgraded_from_header)
out[#out+1] = i18n.acquisition.upgraded_from
out[#out+1]= '<br>'
out[#out+1] = tostring(ul)
end
-- -------------------------------------
-- Ingredient of vendor recipes/upgrades
-- -------------------------------------
--
-- Query
--
results = m_util.cargo.query(
{'upgraded_from_groups', 'items',},
{
'upgraded_from_groups._pageName',
'items.name',
'items.inventory_icon',
'items.html',
},
{
where=string.format('upgraded_from_groups.item_page="%s"', tpl_args.page),
join='upgraded_from_groups._pageID=items._pageID',
}
)
if #results > 0 then
out[#out+1] = h.head(i18n.acquisition.ingredient_header)
out[#out+1] = i18n.acquisition.ingredient
out[#out+1]= '<br>'
local ul = mw.html.create('ul')
for _, row in ipairs(results) do
ul:tag('li')
:wikitext(f_item_link{page=row['upgraded_from_groups._pageName'], name=row['items.name'], inventory_icon=row['items.inventory_icon'] or '', html=row['items.html'] or '', skip_query=true})
end
out[#out+1] = tostring(ul)
end
out[#out+1] = tpl_args.ingredient_append
-- ------------------------------------
-- output
-- ------------------------------------
local head = mw.html.create('h2')
head:wikitext(i18n.acquisition.header .. '[[File:Questionmark.png|right|24px|link=Path_of_Exile_Wiki:How_to_edit_item_acquisition]]')
return tostring(head) .. table.concat(out)
end
-- ----------------------------------------------------------------------------
-- Return
-- ----------------------------------------------------------------------------
return p