Module:Passive skill: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Trying to add some visuals and support for icons) |
||
Line 1: | Line 1: | ||
-- | -- | ||
-- Module for | -- Module for Mastery Groups | ||
-- | -- | ||
Line 15: | Line 15: | ||
local i18n = { | local i18n = { | ||
icon_name = 'File:%s | icon_name = 'File:%s mastery icon.png', | ||
cats = { | cats = { | ||
effect = 'Mastery Group', | |||
data = 'Passive skill data', | data = 'Passive skill data', | ||
Line 40: | Line 40: | ||
}, | }, | ||
mastery_group_box_table = { | |||
id = 'Id', | id = 'Id', | ||
mastery_effects = 'Mastery Effects', | |||
}, | }, | ||
Line 57: | Line 52: | ||
errors = { | errors = { | ||
no_passives_found = 'No | no_passives_found = 'No mastery groups with the given name were found', | ||
}, | }, | ||
} | } | ||
Line 67: | Line 62: | ||
local tables = {} | local tables = {} | ||
tables. | tables.mastery_groups = { | ||
table = ' | table = 'mastery_groups', | ||
order = {'id | order = {'id', 'main_page', 'mastery_effects',}, | ||
fields = { | fields = { | ||
id = { | id = { | ||
Line 75: | Line 70: | ||
type = 'String', | type = 'String', | ||
required = true, | required = true, | ||
}, | }, | ||
main_page = { | main_page = { | ||
field = 'main_page', | field = 'main_page', | ||
type = 'Page', | type = 'Page', | ||
}, | }, | ||
icon = { | icon = { | ||
Line 116: | Line 84: | ||
end | end | ||
}, | }, | ||
mastery_effects = { | |||
field = ' | field = 'mastery_effects', | ||
type = 'List (,) of String', | type = 'List (,) of String', | ||
}, | }, | ||
Line 184: | Line 91: | ||
} | } | ||
local display = {} | local display = {} | ||
Line 203: | Line 97: | ||
{ | { | ||
key = 'id', | key = 'id', | ||
header = i18n. | header = i18n.mastery_group_box_table.id, | ||
display = nil, | display = nil, | ||
}, | }, | ||
{ | { | ||
key = ' | key = 'mastery_effects', | ||
header = i18n. | header = i18n.mastery_group_box_table.mastery_effects, | ||
display = function (tpl_args, frame, value) | display = function (tpl_args, frame, value) | ||
local results = m_cargo.map_results_to_id{ | local results = m_cargo.map_results_to_id{ | ||
field=' | field='mastery_effects.id', | ||
results=m_cargo.array_query{ | results=m_cargo.array_query{ | ||
tables={' | tables={'mastery_effects'}, | ||
fields={' | fields={'mastery_effects.id', 'mastery_effects._pageName', 'mastery_effects.stat_text'}, | ||
id_array=value, | id_array=value, | ||
id_field=' | id_field='mastery_effects.id', | ||
ignore_missing=true, | ignore_missing=true, | ||
} | } | ||
Line 257: | Line 123: | ||
local text | local text | ||
if row then | if row then | ||
text = string.format('[[%s|%s]]', row[' | text = string.format('[[%s|%s]]', row['mastery_effects._pageName'], row['mastery_effects.id'] or row['mastery_effects._pageName']) | ||
else | else | ||
text = key | text = key | ||
Line 278: | Line 144: | ||
local h = {} | local h = {} | ||
function h. | function h.format_mastery_icon(mastery_group) | ||
if | if mastery_group['mastery_groups.icon'] == nil then | ||
return '' | return '' | ||
end | end | ||
local cls = | local cls = 'passive-icon-type__mastery' | ||
local main_page = | local main_page = mastery_group['mastery_groups.main_page'] or mastery_group['main_pages._pageName'] or mastery_group['mastery_groups.name'] or mastery_group['mastery_groups.icon'] | ||
div = mw.html.create('div') | div = mw.html.create('div') | ||
div:addClass('passive-icon-container') | div:addClass('passive-icon-container') | ||
Line 294: | Line 160: | ||
string.format( | string.format( | ||
'[[%s|link=%s]]', | '[[%s|link=%s]]', | ||
passive[' | passive['mastery_groups.icon'], | ||
main_page | main_page | ||
) | ) | ||
Line 302: | Line 168: | ||
end | end | ||
function h.make_stat_order(results) | -- function h.make_stat_order(results) | ||
local stats = {} | -- local stats = {} | ||
local stat_order = {} | -- local stat_order = {} | ||
-- for _, row in ipairs(results) do | |||
-- local stat = row['passive_skills.stat_text'] | |||
-- -- Can't show results here that don't have a stat line | |||
-- if stat then | |||
-- if stats[stat] == nil then | |||
-- stats[stat] = {row} | |||
-- table.insert(stat_order, stat) | |||
-- else | |||
-- table.insert(stats[stat], row) | |||
-- end | |||
-- end | |||
-- end | |||
-- return stats, stat_order | |||
-- end | |||
------------------------------------- | |||
-- Parameters: | |||
-- results: the set of mastery_groups matching the query | |||
------------------------------------- | |||
function h.make_effects_order(results) | |||
local mastery_effects_list = {} | |||
local me_order = {} | |||
for _, row in ipairs(results) do | for _, row in ipairs(results) do | ||
local | local mastery_effects = row['mastery_groups.mastery_effects'] | ||
-- Can't show results here that don't have a stat line | -- Can't show results here that don't have a stat line | ||
if | if mastery_effects then | ||
if | if mastery_effects_list[mastery_effects] == nil then | ||
mastery_effects_list[mastery_effects] = {row} | |||
table.insert( | table.insert(me_order, mastery_effects) | ||
else | else | ||
table.insert( | table.insert(mastery_effects_list[mastery_effects], row) | ||
end | end | ||
end | end | ||
end | end | ||
return | return mastery_effects_list, me_order | ||
end | end | ||
function h.stat_page_links(stat_order, stats) | -- function h.stat_page_links(stat_order, stats) | ||
-- local out = {} | |||
-- for i, key in ipairs(stat_order) do | |||
-- local links = {} | |||
-- for j, row in ipairs(stats[key]) do | |||
-- links[#links+1] = string.format('[[%s|[%s]]]', row['passive_skills._pageName'], j) | |||
-- end | |||
-- out[i] = string.format('<span class="passive-line">%s <span class="passive-hover">%s</span></span>', key, table.concat(links, ' ')) | |||
-- end | |||
-- return table.concat(out, '<hr>') | |||
-- end | |||
function h.effect_page_links(effects_order, effects_list) | |||
local out = {} | local out = {} | ||
for i, key in ipairs( | for i, key in ipairs(effects_order) do | ||
local links = {} | local links = {} | ||
for j, row in ipairs( | for j, row in ipairs(effects_list[key]) do | ||
links[#links+1] = string.format('[[%s|[%s]]]', row[' | links[#links+1] = string.format('[[%s|[%s]]]', row['mastery_groups._pageName'], j) | ||
end | end | ||
out[i] = string.format('<span class="passive-line">%s <span class="passive-hover">%s</span></span>', key, table.concat(links, ' ')) | out[i] = string.format('<span class="passive-line">%s <span class="passive-hover">%s</span></span>', key, table.concat(links, ' ')) | ||
Line 334: | Line 236: | ||
end | end | ||
-- function h.intro_text(tpl_args, frame) | |||
-- --[[ | |||
-- Display an introductory text about the passive skill. | |||
-- ]] | |||
-- local out = {} | |||
-- if mw.ustring.find(tpl_args['id'], '_') then | |||
-- out[#out+1] = frame:expandTemplate{ | |||
-- title='Incorrect title', | |||
-- args = {title=tpl_args['id']} | |||
-- } | |||
-- end | |||
function h.intro_text(tpl_args, frame) | |||
--[[ | |||
Display an introductory text about the passive skill. | |||
]] | |||
local out = {} | |||
if mw.ustring.find(tpl_args['id'], '_') then | |||
out[#out+1] = frame:expandTemplate{ | |||
title='Incorrect title', | |||
args = {title=tpl_args['id']} | |||
} | |||
end | |||
if tpl_args['name'] then | -- if tpl_args['name'] then | ||
out[#out+1] = string.format( | -- out[#out+1] = string.format( | ||
i18n.intro.text_with_name, | -- i18n.intro.text_with_name, | ||
tpl_args['id'], | -- tpl_args['id'], | ||
tpl_args['main_page'] or tostring(mw.title.getCurrentTitle()), | -- tpl_args['main_page'] or tostring(mw.title.getCurrentTitle()), | ||
tpl_args['name'] | -- tpl_args['name'] | ||
) | -- ) | ||
else | -- else | ||
out[#out+1] = string.format( | -- out[#out+1] = string.format( | ||
i18n.intro.text_without_name, | -- i18n.intro.text_without_name, | ||
tpl_args['id'] | -- tpl_args['id'] | ||
) | -- ) | ||
end | -- end | ||
return table.concat(out) | -- return table.concat(out) | ||
end | -- end | ||
function h.stat_box(tpl_args, frame) | -- function h.stat_box(tpl_args, frame) | ||
--[[ | -- --[[ | ||
Display the stat box. | -- Display the stat box. | ||
]] | -- ]] | ||
local container = mw.html.create('div') | -- local container = mw.html.create('div') | ||
container | -- container | ||
:attr('class', 'modbox floatright') | -- :attr('class', 'modbox floatright') | ||
-- stat table | -- -- stat table | ||
tbl = container:tag('table') | -- tbl = container:tag('table') | ||
tbl | -- tbl | ||
:attr('class', 'wikitable sortable') | -- :attr('class', 'wikitable sortable') | ||
-- :attr('style', 'style="width: 100%;"') | -- -- :attr('style', 'style="width: 100%;"') | ||
:tag('tr') | -- :tag('tr') | ||
:tag('th') | -- :tag('th') | ||
:attr('colspan', 3) | -- :attr('colspan', 3) | ||
:wikitext('Stats') | -- :wikitext('Stats') | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
:tag('tr') | -- :tag('tr') | ||
:tag('th') | -- :tag('th') | ||
:wikitext('#') | -- :wikitext('#') | ||
:done() | -- :done() | ||
:tag('th') | -- :tag('th') | ||
:wikitext('Stat Id') | -- :wikitext('Stat Id') | ||
:done() | -- :done() | ||
:tag('th') | -- :tag('th') | ||
:wikitext('Value') | -- :wikitext('Value') | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
local i = 0 | -- local i = 0 | ||
local value = nil | -- local value = nil | ||
repeat | -- repeat | ||
i = i + 1 | -- i = i + 1 | ||
value = { | -- value = { | ||
id = tpl_args[string.format('stat%s_id', i)], | -- id = tpl_args[string.format('stat%s_id', i)], | ||
value = tpl_args[string.format('stat%s_value', i)], | -- value = tpl_args[string.format('stat%s_value', i)], | ||
} | -- } | ||
if value.id then | -- if value.id then | ||
tbl | -- tbl | ||
:tag('tr') | -- :tag('tr') | ||
:tag('td') | -- :tag('td') | ||
:wikitext(i) | -- :wikitext(i) | ||
:done() | -- :done() | ||
:tag('td') | -- :tag('td') | ||
:wikitext(value.id) | -- :wikitext(value.id) | ||
:done() | -- :done() | ||
:tag('td') | -- :tag('td') | ||
:wikitext(value.value) | -- :wikitext(value.value) | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
:done() | -- :done() | ||
end | -- end | ||
until value.id == nil | -- until value.id == nil | ||
return tostring(container) | -- return tostring(container) | ||
end | -- end | ||
Line 467: | Line 338: | ||
-- Declare cargo tables: | -- Declare cargo tables: | ||
p. | p.table_mastery_groups = m_cargo.declare_factory{data=tables.mastery_groups} | ||
function p. | function p.mastery_group(frame) | ||
--[[ | --[[ | ||
Stores data and displays a infobox about the passive skill. | Stores data and displays a infobox about the passive skill. | ||
Line 476: | Line 346: | ||
Examples | Examples | ||
-------- | -------- | ||
= p. | = p.mastery_group{ | ||
id = ' | id = 'Armour', | ||
mastery_effects = 'Armour1,Armour2,Armour3,Armour4,Armour5,Armour6', | |||
} | } | ||
Line 497: | Line 358: | ||
}) | }) | ||
frame = m_util.misc.get_frame(frame) | frame = m_util.misc.get_frame(frame) | ||
-- parse | |||
-- parse and store mastery group into cargo table | |||
m_util.args.from_cargo_map{ | m_util.args.from_cargo_map{ | ||
tpl_args=tpl_args, | tpl_args=tpl_args, | ||
frame=frame, | frame=frame, | ||
table_map=tables. | table_map=tables.mastery_groups, | ||
} | } | ||
-- | -- | ||
-- Infobox | -- Infobox | ||
-- | -- | ||
local passive = {} | -- local passive = {} | ||
for _, key in ipairs(display.map_to_property) do | -- for _, key in ipairs(display.map_to_property) do | ||
-- local v = tpl_args[key] | |||
-- if type(v) == 'boolean' then | |||
-- if v then | |||
-- v = 1 | |||
-- else | |||
-- v = 0 | |||
-- end | |||
-- end | |||
-- passive[string.format('%s.%s', tables.passive_skills.table, tables.passive_skills.fields[key].field)] = v | |||
end | -- end | ||
local type_key = h.get_type(passive) | -- local type_key = h.get_type(passive) | ||
local infocard_args = {} | -- local infocard_args = {} | ||
infocard_args.header = tpl_args.name | -- infocard_args.header = tpl_args.name | ||
infocard_args.subheader = i18n.passive_box[type_key] | -- infocard_args.subheader = i18n.passive_box[type_key] | ||
local tbl = mw.html.create('table') | -- local tbl = mw.html.create('table') | ||
for _, data in ipairs(display.tbl) do | -- for _, data in ipairs(display.tbl) do | ||
-- local value = tpl_args[data.key] | |||
-- -- if default is nil, this will be compared against nil which is what we want, so value ~= nil isn't needed | |||
-- if value ~= tables.passive_skills.fields[data.key].default then | |||
-- local dsp | |||
-- if data.display then | |||
-- dsp = data.display(tpl_args, frame, value) | |||
-- else | |||
-- dsp = value | |||
-- end | |||
-- tbl | |||
-- :tag('tr') | |||
-- :tag('th') | |||
-- :wikitext(data.header) | |||
-- :done() | |||
-- :tag('td') | |||
-- :attr('class', data.css) | |||
-- :wikitext(dsp) | |||
-- :done() | |||
-- :done() | |||
-- end | |||
end | -- end | ||
infocard_args[1] = tostring(tbl) | -- infocard_args[1] = tostring(tbl) | ||
infocard_args[2] = tpl_args.stat_text | -- infocard_args[2] = tpl_args.stat_text | ||
infocard_args[3] = h. | -- infocard_args[3] = h.format_mastery_icon(mastery_group) | ||
local out = { | -- local out = { | ||
-- f_infocard(infocard_args), | |||
-- h.intro_text(tpl_args, frame), | |||
-- h.stat_box(tpl_args, frame), | |||
} | -- } | ||
local cats = { | -- local cats = { | ||
-- i18n.cats.data, | |||
} | -- } | ||
return table.concat(out) .. m_util.misc.add_category(cats) | -- return table.concat(out) .. m_util.misc.add_category(cats) | ||
end | end | ||
function p. | function p.mastery_group_box(frame) | ||
--[[ | --[[ | ||
Queries a | Queries a mastery group and displays it. | ||
Examples | Examples | ||
-------- | -------- | ||
= p. | = p.mastery_group_box{name='Accuracy'} | ||
]] | ]] | ||
Line 592: | Line 447: | ||
if not tpl_args.q_where and tpl_args.name then | if not tpl_args.q_where and tpl_args.name then | ||
tpl_args.q_where = string.format(' | tpl_args.q_where = string.format('mastery_groups.id="%s" AND mastery_groups.mastery_effects > ""', tpl_args.name) | ||
elseif not (tpl_args.q_where and not tpl_args.name) then | elseif not (tpl_args.q_where and not tpl_args.name) then | ||
error('q_where or name must be specified') | error('q_where or name must be specified') | ||
Line 598: | Line 453: | ||
local results = m_cargo.query( | local results = m_cargo.query( | ||
{' | {'mastery_groups'}, | ||
{ | { | ||
' | 'mastery_groups.icon', | ||
'mastery_groups.mastery_effects', | |||
'mastery_groups.id' | |||
' | |||
' | |||
}, | }, | ||
{ | { | ||
where=tpl_args.q_where, | where=tpl_args.q_where, | ||
orderBy=' | orderBy='mastery_groups.id', | ||
limit=5000, | limit=5000, | ||
} | } | ||
Line 622: | Line 469: | ||
end | end | ||
local out = {} | local out = {} | ||
local cats = {} | local cats = {} | ||
if #results > 0 then | |||
cats[#cats+1] = i18n.cats[type_key] | |||
local effects_list, effects_order = h.make_effects_order(results) | |||
local mastery_group = results[1] | |||
local infocard_args = {} | |||
infocard_args.header = mastery_group['mastery_groups.id'] | |||
infocard_args[1] = h.format_mastery_icon(passive) | |||
infocard_args[2] = h.effect_page_links(effects_order, effects_list) | |||
infocard_args[3] = m_util.html.poe_color('flavour', passive['passive_skills.flavour_text']) | |||
out[#out+1] = f_infocard(infocard_args) | |||
-- Store as main page: | |||
for _, v in ipairs(results) do | |||
m_cargo.store( | |||
frame, | |||
{ | |||
_table='main_pages', | |||
id=v['mastery_groups.id'], | |||
} | |||
) | |||
end | end | ||
end | end | ||
Line 663: | Line 505: | ||
end | end | ||
function p.passive_skill_link(frame) | -- function p.passive_skill_link(frame) | ||
--[[ | -- --[[ | ||
Links a passive skill | -- Links a passive skill | ||
Examples | -- Examples | ||
-------- | -- -------- | ||
= p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'} | -- = p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'} | ||
]] | -- ]] | ||
-- Get args | -- -- Get args | ||
tpl_args = getArgs(frame, { | -- tpl_args = getArgs(frame, { | ||
parentFirst = true | -- parentFirst = true | ||
}) | -- }) | ||
frame = m_util.misc.get_frame(frame) | -- frame = m_util.misc.get_frame(frame) | ||
tpl_args.name = tpl_args.name or tpl_args[1] | -- tpl_args.name = tpl_args.name or tpl_args[1] | ||
if tpl_args.name then | -- if tpl_args.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.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 | ||
else | -- else | ||
error('Either name, id or q_where must be specified') | -- error('Either name, id or q_where must be specified') | ||
end | -- end | ||
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', | ||
'passive_skills.name', | -- 'passive_skills.name', | ||
'passive_skills.icon', | -- 'passive_skills.icon', | ||
'passive_skills.is_keystone', | -- 'passive_skills.is_keystone', | ||
'passive_skills.is_notable', | -- 'passive_skills.is_notable', | ||
'passive_skills.ascendancy_class', | -- 'passive_skills.ascendancy_class', | ||
'main_pages._pageName', | -- 'main_pages._pageName', | ||
}, | -- }, | ||
{ | -- { | ||
join='passive_skills.id=main_pages.id', | -- join='passive_skills.id=main_pages.id', | ||
where=string.format('(%s) AND passive_skills.stat_text IS NOT NULL', tpl_args.q_where), | -- where=string.format('(%s) AND passive_skills.stat_text IS NOT NULL', tpl_args.q_where), | ||
orderBy='passive_skills.stat_text', | -- orderBy='passive_skills.stat_text', | ||
limit=2, | -- limit=2, | ||
} | -- } | ||
) | -- ) | ||
if #results > 1 then | -- if #results > 1 then | ||
error('Too many passives found!') | -- error('Too many passives found!') | ||
elseif #results < 1 then | -- elseif #results < 1 then | ||
error('No passives found') | -- error('No passives found') | ||
end | -- end | ||
local passive = results[1] | -- local passive = results[1] | ||
if tpl_args.format == 'tablerow' then | -- if tpl_args.format == 'tablerow' then | ||
local main_page = passive['passive_skills.main_page'] or passive['main_pages._pageName'] or passive['passive_skills.name'] | -- local main_page = passive['passive_skills.main_page'] or passive['main_pages._pageName'] or passive['passive_skills.name'] | ||
return string.format( | -- return string.format( | ||
'| [[%s|%s]]%s\n| %s', | -- '| [[%s|%s]]%s\n| %s', | ||
main_page, | -- main_page, | ||
passive['passive_skills.name'], | -- passive['passive_skills.name'], | ||
h. | -- h.format_mastery_icon(passive), | ||
passive['passive_skills.stat_text'] | -- passive['passive_skills.stat_text'] | ||
) | -- ) | ||
elseif tpl_args.format == nil then | -- elseif tpl_args.format == nil then | ||
return | -- return | ||
else | -- else | ||
error(string.format('Invalid return format specified: %s', tpl_args.format)) | -- error(string.format('Invalid return format specified: %s', tpl_args.format)) | ||
end | -- end | ||
end | -- end | ||
-- Not sure whether we need a more sophisticated variant like item or mod tables here yet | -- -- Not sure whether we need a more sophisticated variant like item or mod tables here yet | ||
function p.passive_skill_table2(frame) | -- function p.passive_skill_table2(frame) | ||
-- Get args | -- -- Get args | ||
tpl_args = getArgs(frame, { | -- tpl_args = getArgs(frame, { | ||
parentFirst = true | -- parentFirst = true | ||
}) | -- }) | ||
frame = m_util.misc.get_frame(frame) | -- frame = m_util.misc.get_frame(frame) | ||
if tpl_args.q_tables then | -- if tpl_args.q_tables then | ||
tpl_args.q_tables = tpl_args.q_tables .. ',' .. 'passive_skill_stats' | -- tpl_args.q_tables = tpl_args.q_tables .. ',' .. 'passive_skill_stats' | ||
else | -- else | ||
tpl_args.q_tables = 'passive_skill_stats' | -- tpl_args.q_tables = 'passive_skill_stats' | ||
end | -- end | ||
if tpl_args.q_join then | -- if tpl_args.q_join then | ||
tpl_args.q_join = tpl_args.q_join .. ',' .. 'passive_skills._pageID=passive_skill_stats._pageID' | -- tpl_args.q_join = tpl_args.q_join .. ',' .. 'passive_skills._pageID=passive_skill_stats._pageID' | ||
else | -- else | ||
tpl_args.q_join = 'passive_skills._pageID=passive_skill_stats._pageID' | -- tpl_args.q_join = 'passive_skills._pageID=passive_skill_stats._pageID' | ||
end | -- end | ||
tpl_args.q_orderBy = 'passive_skills.ascendancy_class IS NULL DESC, passive_skills.is_keystone, passive_skills.is_notable, passive_skills.name' | -- tpl_args.q_orderBy = 'passive_skills.ascendancy_class IS NULL DESC, passive_skills.is_keystone, passive_skills.is_notable, passive_skills.name' | ||
return m_cargo.table_query{ | -- return m_cargo.table_query{ | ||
tpl_args=tpl_args, | -- tpl_args=tpl_args, | ||
frame=frame, | -- frame=frame, | ||
main_table='passive_skills', | -- main_table='passive_skills', | ||
row_unique_fields = {'passive_skills.name'}, | -- row_unique_fields = {'passive_skills.name'}, | ||
data={ | -- data={ | ||
tables = { | -- tables = { | ||
passive_skill_stats = { | -- passive_skill_stats = { | ||
join='passive_skills._pageID=passive_skill_stats._pageID', | -- join='passive_skills._pageID=passive_skill_stats._pageID', | ||
}, | -- }, | ||
}, | -- }, | ||
-- display data | -- -- display data | ||
{ | -- { | ||
args = {'ascendancy'}, | -- args = {'ascendancy'}, | ||
header = i18n.passive_table.ascendancy_class, | -- header = i18n.passive_table.ascendancy_class, | ||
fields = { | -- fields = { | ||
'passive_skills.ascendancy_class', | -- 'passive_skills.ascendancy_class', | ||
}, | -- }, | ||
display = function (tpl_args, frame, tr, data) | -- display = function (tpl_args, frame, tr, data) | ||
local passive = data[1] | -- local passive = data[1] | ||
if passive['passive_skills.ascendancy_class'] then | -- if passive['passive_skills.ascendancy_class'] then | ||
tr:tag('td') | -- tr:tag('td') | ||
:wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class'])) | -- :wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class'])) | ||
else | -- else | ||
tr:wikitext(m_util.html.td.na{}) | -- tr:wikitext(m_util.html.td.na{}) | ||
end | -- end | ||
end, | -- end, | ||
order = 0, | -- order = 0, | ||
sort_type = 'text', | -- sort_type = 'text', | ||
}, | -- }, | ||
{ | -- { | ||
args = nil, | -- args = nil, | ||
header = i18n.passive_table.name, | -- header = i18n.passive_table.name, | ||
fields = { | -- fields = { | ||
'passive_skills._pageName', | -- 'passive_skills._pageName', | ||
'passive_skills.main_page', | -- 'passive_skills.main_page', | ||
'passive_skills.name', | -- 'passive_skills.name', | ||
'passive_skills.icon', | -- 'passive_skills.icon', | ||
'passive_skills.is_keystone', | -- 'passive_skills.is_keystone', | ||
'passive_skills.is_notable', | -- 'passive_skills.is_notable', | ||
'passive_skills.ascendancy_class', | -- 'passive_skills.ascendancy_class', | ||
}, | -- }, | ||
display = function (tpl_args, frame, tr, data) | -- display = function (tpl_args, frame, tr, data) | ||
local passive = data[1] | -- local passive = data[1] | ||
local type_key = h.get_type(passive) | -- local type_key = h.get_type(passive) | ||
tr | -- tr | ||
:tag('td') | -- :tag('td') | ||
:attr('data-sort-value', passive['passive_skills.name'] .. type_key) | -- :attr('data-sort-value', passive['passive_skills.name'] .. type_key) | ||
:wikitext(string.format('[[%s|%s]]<br>%s', passive['passive_skills.main_page'] or passive['passive_skills.name'], passive['passive_skills.name'], h. | -- :wikitext(string.format('[[%s|%s]]<br>%s', passive['passive_skills.main_page'] or passive['passive_skills.name'], passive['passive_skills.name'], h.format_mastery_icon(passive)) | ||
:done() | -- :done() | ||
end, | -- end, | ||
order = 1000, | -- order = 1000, | ||
sort_type = 'text', | -- sort_type = 'text', | ||
options = { | -- options = { | ||
[7] = { | -- [7] = { | ||
optional=true, | -- optional=true, | ||
}, | -- }, | ||
}, | -- }, | ||
}, | -- }, | ||
{ | -- { | ||
arg = {'default', 'stat', 'stats', 'stat_text'}, | -- arg = {'default', 'stat', 'stats', 'stat_text'}, | ||
header = i18n.passive_table.stats, | -- header = i18n.passive_table.stats, | ||
fields = { | -- fields = { | ||
'passive_skills.stat_text', | -- 'passive_skills.stat_text', | ||
}, | -- }, | ||
display = function (tpl_args, frame, tr, data) | -- display = function (tpl_args, frame, tr, data) | ||
local passive = data[1] | -- local passive = data[1] | ||
local stats, stat_order = h.make_stat_order(data) | -- local stats, stat_order = h.make_stat_order(data) | ||
tr | -- tr | ||
:tag('td') | -- :tag('td') | ||
:wikitext(h.stat_page_links(stat_order, stats)) | -- :wikitext(h.stat_page_links(stat_order, stats)) | ||
:done() | -- :done() | ||
end, | -- end, | ||
order = 1001, | -- order = 1001, | ||
sort_type = 'text', | -- sort_type = 'text', | ||
} | -- } | ||
}, | -- }, | ||
} | -- } | ||
end | -- end | ||
function p.passive_skill_table(frame) | -- function p.passive_skill_table(frame) | ||
-- Get args | -- -- Get args | ||
tpl_args = getArgs(frame, { | -- tpl_args = getArgs(frame, { | ||
parentFirst = true | -- parentFirst = true | ||
}) | -- }) | ||
frame = m_util.misc.get_frame(frame) | -- frame = m_util.misc.get_frame(frame) | ||
tpl_args.ascendancy = m_util.cast.boolean(tpl_args.ascendancy) | -- tpl_args.ascendancy = m_util.cast.boolean(tpl_args.ascendancy) | ||
local prepend = { | -- local prepend = { | ||
q_join=true, | -- q_join=true, | ||
} | -- } | ||
local query = { | -- local query = { | ||
join='passive_skills._pageID=passive_skill_stats._pageID', | -- join='passive_skills._pageID=passive_skill_stats._pageID', | ||
limit=5000, | -- limit=5000, | ||
groupBy='passive_skills._pageID', | -- groupBy='passive_skills._pageID', | ||
} | -- } | ||
for key, value in pairs(tpl_args) do | -- for key, value in pairs(tpl_args) do | ||
if string.sub(key, 0, 2) == 'q_' then | -- if string.sub(key, 0, 2) == 'q_' then | ||
if prepend[key] then | -- if prepend[key] then | ||
value = ',' .. value | -- value = ',' .. value | ||
end | -- end | ||
query[string.sub(key, 3)] = value | -- query[string.sub(key, 3)] = value | ||
end | -- end | ||
end | -- end | ||
local results = m_cargo.query( | -- local results = m_cargo.query( | ||
{'passive_skills', 'passive_skill_stats'}, | -- {'passive_skills', 'passive_skill_stats'}, | ||
{ | -- { | ||
'passive_skills._pageName', | -- 'passive_skills._pageName', | ||
'passive_skills.main_page', | -- 'passive_skills.main_page', | ||
'passive_skills.name', | -- 'passive_skills.name', | ||
'passive_skills.stat_text', | -- 'passive_skills.stat_text', | ||
'passive_skills.icon', | -- 'passive_skills.icon', | ||
'passive_skills.is_keystone', | -- 'passive_skills.is_keystone', | ||
'passive_skills.is_notable', | -- 'passive_skills.is_notable', | ||
'passive_skills.ascendancy_class', | -- 'passive_skills.ascendancy_class', | ||
}, | -- }, | ||
query | -- query | ||
) | -- ) | ||
result_map = m_cargo.map_results_to_id{ | -- result_map = m_cargo.map_results_to_id{ | ||
results=results, | -- results=results, | ||
field='passive_skills.name', | -- field='passive_skills.name', | ||
keep_id_field=true, | -- keep_id_field=true, | ||
} | -- } | ||
for key, rows in pairs(result_map) do | -- for key, rows in pairs(result_map) do | ||
result_map[key] = h.sort_by_type(rows) | -- result_map[key] = h.sort_by_type(rows) | ||
end | -- end | ||
-- header | -- -- header | ||
local tbl = mw.html.create('table') | -- local tbl = mw.html.create('table') | ||
tbl:addClass('wikitable') | -- tbl:addClass('wikitable') | ||
tbl:addClass('sortable') | -- tbl:addClass('sortable') | ||
local tr = tbl:tag('tr') | -- local tr = tbl:tag('tr') | ||
if tpl_args.ascendancy then | -- if tpl_args.ascendancy then | ||
tr:tag('th') | -- tr:tag('th') | ||
:wikitext(i18n.passive_table.ascendancy_class) | -- :wikitext(i18n.passive_table.ascendancy_class) | ||
end | -- end | ||
tr | -- tr | ||
:tag('th') | -- :tag('th') | ||
:wikitext(i18n.passive_table.name) | -- :wikitext(i18n.passive_table.name) | ||
:done() | -- :done() | ||
:tag('th') | -- :tag('th') | ||
:wikitext(i18n.passive_table.stats) | -- :wikitext(i18n.passive_table.stats) | ||
:done() | -- :done() | ||
-- rows | -- -- rows | ||
local used_names = {} | -- local used_names = {} | ||
for _, passive_row in ipairs(results) do | -- for _, passive_row in ipairs(results) do | ||
local pn = passive_row['passive_skills.name'] | -- local pn = passive_row['passive_skills.name'] | ||
if used_names[pn] == nil then | -- if used_names[pn] == nil then | ||
local type_results_map = result_map[passive_row['passive_skills.name']] | -- local type_results_map = result_map[passive_row['passive_skills.name']] | ||
used_names[pn] = true | -- used_names[pn] = true | ||
for _, type_key in ipairs(h.type_order) do | -- for _, type_key in ipairs(h.type_order) do | ||
local type_results = type_results_map[type_key] | -- local type_results = type_results_map[type_key] | ||
if #type_results > 0 then | -- if #type_results > 0 then | ||
local row = type_results[1] | -- local row = type_results[1] | ||
tr = tbl:tag('tr') | -- tr = tbl:tag('tr') | ||
if tpl_args.ascendancy then | -- if tpl_args.ascendancy then | ||
if row['passive_skills.ascendancy_class'] then | -- if row['passive_skills.ascendancy_class'] then | ||
tr:tag('td') | -- tr:tag('td') | ||
:wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class'])) | -- :wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class'])) | ||
else | -- else | ||
tr:wikitext(m_util.html.td.na{}) | -- tr:wikitext(m_util.html.td.na{}) | ||
end | -- end | ||
end | -- end | ||
local stats, stat_order = h.make_stat_order(type_results) | -- local stats, stat_order = h.make_stat_order(type_results) | ||
tr | -- tr | ||
:tag('td') | -- :tag('td') | ||
:attr('data-sort-value', row['passive_skills.name'] .. type_key) | -- :attr('data-sort-value', row['passive_skills.name'] .. type_key) | ||
:wikitext(string.format('[[%s|%s]]<br>%s', row['passive_skills.main_page'] or row['passive_skills.name'], row['passive_skills.name'], h. | -- :wikitext(string.format('[[%s|%s]]<br>%s', row['passive_skills.main_page'] or row['passive_skills.name'], row['passive_skills.name'], h.format_mastery_icon(row))) | ||
:done() | -- :done() | ||
:tag('td') | -- :tag('td') | ||
:wikitext(h.stat_page_links(stat_order, stats)) | -- :wikitext(h.stat_page_links(stat_order, stats)) | ||
:done() | -- :done() | ||
end | -- end | ||
end | -- end | ||
end | -- end | ||
end | -- end | ||
return tostring(tbl) | -- return tostring(tbl) | ||
end | -- end | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- |
Revision as of 07:47, 12 November 2021
You might want to create a documentation page for this module.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
--
-- Module for Mastery Groups
--
local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')
local getArgs = require('Module:Arguments').getArgs
local f_infocard = require('Module:Infocard')._main
local p = {}
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
local i18n = {
icon_name = 'File:%s mastery icon.png',
cats = {
effect = 'Mastery Group',
data = 'Passive skill data',
keystone = 'Keystone passive skills',
notable = 'Notable passive skills',
basic = 'Basic passive skills',
ascendancy_notable = 'Ascendancy notable passive skills',
ascendancy_basic = 'Ascendancy basic passive skills',
},
passive_box = {
keystone = 'Keystone',
notable = 'Notable Passive Skill',
basic = 'Passive Skill',
ascendancy_notable = 'Ascendancy Notable Passive Skill',
ascendancy_basic = 'Ascendancy Passive Skill',
},
intro = {
text_with_name = "'''%s''' is the internal id for the [[%s|%s]] [[passive skill]]. ",
text_without_name = "'''%s''' is the internal id of an unnamed [[passive skill]]. ",
},
mastery_group_box_table = {
id = 'Id',
mastery_effects = 'Mastery Effects',
},
passive_table = {
ascendancy_class = 'Ascendancy<br>Class',
name = 'Name',
stats = 'Stats',
},
errors = {
no_passives_found = 'No mastery groups with the given name were found',
},
}
-- ----------------------------------------------------------------------------
-- Cargo
-- ----------------------------------------------------------------------------
local tables = {}
tables.mastery_groups = {
table = 'mastery_groups',
order = {'id', 'main_page', 'mastery_effects',},
fields = {
id = {
field = 'id',
type = 'String',
required = true,
},
main_page = {
field = 'main_page',
type = 'Page',
},
icon = {
field = 'icon',
type = 'Page',
func = function(tpl_args, frame, value)
if value then
return string.format(i18n.icon_name, value)
end
end
},
mastery_effects = {
field = 'mastery_effects',
type = 'List (,) of String',
},
}
}
local display = {}
display.map_to_property = {'icon', 'is_keystone', 'is_notable', 'ascendancy_class'}
display.tbl = {
{
key = 'id',
header = i18n.mastery_group_box_table.id,
display = nil,
},
{
key = 'mastery_effects',
header = i18n.mastery_group_box_table.mastery_effects,
display = function (tpl_args, frame, value)
local results = m_cargo.map_results_to_id{
field='mastery_effects.id',
results=m_cargo.array_query{
tables={'mastery_effects'},
fields={'mastery_effects.id', 'mastery_effects._pageName', 'mastery_effects.stat_text'},
id_array=value,
id_field='mastery_effects.id',
ignore_missing=true,
}
}
local ul = mw.html.create('ul')
for _, key in ipairs(value) do
local row = results[key]
if row then
row = row[1]
end
local text
if row then
text = string.format('[[%s|%s]]', row['mastery_effects._pageName'], row['mastery_effects.id'] or row['mastery_effects._pageName'])
else
text = key
end
ul
:tag('li')
:wikitext(text)
:done()
end
return tostring(ul)
end,
},
}
-- ----------------------------------------------------------------------------
-- Helper functions
-- ----------------------------------------------------------------------------
local h = {}
function h.format_mastery_icon(mastery_group)
if mastery_group['mastery_groups.icon'] == nil then
return ''
end
local cls = 'passive-icon-type__mastery'
local main_page = mastery_group['mastery_groups.main_page'] or mastery_group['main_pages._pageName'] or mastery_group['mastery_groups.name'] or mastery_group['mastery_groups.icon']
div = mw.html.create('div')
div:addClass('passive-icon-container')
div:addClass(cls)
div:tag('div')
:addClass('passive-icon-frame')
:done()
div:wikitext(
string.format(
'[[%s|link=%s]]',
passive['mastery_groups.icon'],
main_page
)
)
return tostring(div)
end
-- function h.make_stat_order(results)
-- local stats = {}
-- local stat_order = {}
-- for _, row in ipairs(results) do
-- local stat = row['passive_skills.stat_text']
-- -- Can't show results here that don't have a stat line
-- if stat then
-- if stats[stat] == nil then
-- stats[stat] = {row}
-- table.insert(stat_order, stat)
-- else
-- table.insert(stats[stat], row)
-- end
-- end
-- end
-- return stats, stat_order
-- end
-------------------------------------
-- Parameters:
-- results: the set of mastery_groups matching the query
-------------------------------------
function h.make_effects_order(results)
local mastery_effects_list = {}
local me_order = {}
for _, row in ipairs(results) do
local mastery_effects = row['mastery_groups.mastery_effects']
-- Can't show results here that don't have a stat line
if mastery_effects then
if mastery_effects_list[mastery_effects] == nil then
mastery_effects_list[mastery_effects] = {row}
table.insert(me_order, mastery_effects)
else
table.insert(mastery_effects_list[mastery_effects], row)
end
end
end
return mastery_effects_list, me_order
end
-- function h.stat_page_links(stat_order, stats)
-- local out = {}
-- for i, key in ipairs(stat_order) do
-- local links = {}
-- for j, row in ipairs(stats[key]) do
-- links[#links+1] = string.format('[[%s|[%s]]]', row['passive_skills._pageName'], j)
-- end
-- out[i] = string.format('<span class="passive-line">%s <span class="passive-hover">%s</span></span>', key, table.concat(links, ' '))
-- end
-- return table.concat(out, '<hr>')
-- end
function h.effect_page_links(effects_order, effects_list)
local out = {}
for i, key in ipairs(effects_order) do
local links = {}
for j, row in ipairs(effects_list[key]) do
links[#links+1] = string.format('[[%s|[%s]]]', row['mastery_groups._pageName'], j)
end
out[i] = string.format('<span class="passive-line">%s <span class="passive-hover">%s</span></span>', key, table.concat(links, ' '))
end
return table.concat(out, '<hr>')
end
-- function h.intro_text(tpl_args, frame)
-- --[[
-- Display an introductory text about the passive skill.
-- ]]
-- local out = {}
-- if mw.ustring.find(tpl_args['id'], '_') then
-- out[#out+1] = frame:expandTemplate{
-- title='Incorrect title',
-- args = {title=tpl_args['id']}
-- }
-- end
-- if tpl_args['name'] then
-- out[#out+1] = string.format(
-- i18n.intro.text_with_name,
-- tpl_args['id'],
-- tpl_args['main_page'] or tostring(mw.title.getCurrentTitle()),
-- tpl_args['name']
-- )
-- else
-- out[#out+1] = string.format(
-- i18n.intro.text_without_name,
-- tpl_args['id']
-- )
-- end
-- return table.concat(out)
-- end
-- function h.stat_box(tpl_args, frame)
-- --[[
-- Display the stat box.
-- ]]
-- local container = mw.html.create('div')
-- container
-- :attr('class', 'modbox floatright')
-- -- stat table
-- tbl = container:tag('table')
-- tbl
-- :attr('class', 'wikitable sortable')
-- -- :attr('style', 'style="width: 100%;"')
-- :tag('tr')
-- :tag('th')
-- :attr('colspan', 3)
-- :wikitext('Stats')
-- :done()
-- :done()
-- :tag('tr')
-- :tag('th')
-- :wikitext('#')
-- :done()
-- :tag('th')
-- :wikitext('Stat Id')
-- :done()
-- :tag('th')
-- :wikitext('Value')
-- :done()
-- :done()
-- :done()
-- :done()
-- local i = 0
-- local value = nil
-- repeat
-- i = i + 1
-- value = {
-- id = tpl_args[string.format('stat%s_id', i)],
-- value = tpl_args[string.format('stat%s_value', i)],
-- }
-- if value.id then
-- tbl
-- :tag('tr')
-- :tag('td')
-- :wikitext(i)
-- :done()
-- :tag('td')
-- :wikitext(value.id)
-- :done()
-- :tag('td')
-- :wikitext(value.value)
-- :done()
-- :done()
-- :done()
-- end
-- until value.id == nil
-- return tostring(container)
-- end
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------
local p = {}
-- This way the helper functions can be used in other modules
p.h = h
-- Declare cargo tables:
p.table_mastery_groups = m_cargo.declare_factory{data=tables.mastery_groups}
function p.mastery_group(frame)
--[[
Stores data and displays a infobox about the passive skill.
Examples
--------
= p.mastery_group{
id = 'Armour',
mastery_effects = 'Armour1,Armour2,Armour3,Armour4,Armour5,Armour6',
}
]]
-- Get args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
-- parse and store mastery group into cargo table
m_util.args.from_cargo_map{
tpl_args=tpl_args,
frame=frame,
table_map=tables.mastery_groups,
}
--
-- Infobox
--
-- local passive = {}
-- for _, key in ipairs(display.map_to_property) do
-- local v = tpl_args[key]
-- if type(v) == 'boolean' then
-- if v then
-- v = 1
-- else
-- v = 0
-- end
-- end
-- passive[string.format('%s.%s', tables.passive_skills.table, tables.passive_skills.fields[key].field)] = v
-- end
-- local type_key = h.get_type(passive)
-- local infocard_args = {}
-- infocard_args.header = tpl_args.name
-- infocard_args.subheader = i18n.passive_box[type_key]
-- local tbl = mw.html.create('table')
-- for _, data in ipairs(display.tbl) do
-- local value = tpl_args[data.key]
-- -- if default is nil, this will be compared against nil which is what we want, so value ~= nil isn't needed
-- if value ~= tables.passive_skills.fields[data.key].default then
-- local dsp
-- if data.display then
-- dsp = data.display(tpl_args, frame, value)
-- else
-- dsp = value
-- end
-- tbl
-- :tag('tr')
-- :tag('th')
-- :wikitext(data.header)
-- :done()
-- :tag('td')
-- :attr('class', data.css)
-- :wikitext(dsp)
-- :done()
-- :done()
-- end
-- end
-- infocard_args[1] = tostring(tbl)
-- infocard_args[2] = tpl_args.stat_text
-- infocard_args[3] = h.format_mastery_icon(mastery_group)
-- local out = {
-- f_infocard(infocard_args),
-- h.intro_text(tpl_args, frame),
-- h.stat_box(tpl_args, frame),
-- }
-- local cats = {
-- i18n.cats.data,
-- }
-- return table.concat(out) .. m_util.misc.add_category(cats)
end
function p.mastery_group_box(frame)
--[[
Queries a mastery group and displays it.
Examples
--------
= p.mastery_group_box{name='Accuracy'}
]]
-- Get args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
tpl_args.name = tpl_args.name or tpl_args[1]
if not tpl_args.q_where and tpl_args.name then
tpl_args.q_where = string.format('mastery_groups.id="%s" AND mastery_groups.mastery_effects > ""', tpl_args.name)
elseif not (tpl_args.q_where and not tpl_args.name) then
error('q_where or name must be specified')
end
local results = m_cargo.query(
{'mastery_groups'},
{
'mastery_groups.icon',
'mastery_groups.mastery_effects',
'mastery_groups.id'
},
{
where=tpl_args.q_where,
orderBy='mastery_groups.id',
limit=5000,
}
)
if #results == 0 then
error(i18n.errors.no_passives_found)
end
local out = {}
local cats = {}
if #results > 0 then
cats[#cats+1] = i18n.cats[type_key]
local effects_list, effects_order = h.make_effects_order(results)
local mastery_group = results[1]
local infocard_args = {}
infocard_args.header = mastery_group['mastery_groups.id']
infocard_args[1] = h.format_mastery_icon(passive)
infocard_args[2] = h.effect_page_links(effects_order, effects_list)
infocard_args[3] = m_util.html.poe_color('flavour', passive['passive_skills.flavour_text'])
out[#out+1] = f_infocard(infocard_args)
-- Store as main page:
for _, v in ipairs(results) do
m_cargo.store(
frame,
{
_table='main_pages',
id=v['mastery_groups.id'],
}
)
end
end
if tpl_args.cats == nil or m_util.cast.boolean(tpl_args.cats) then
out[#out+1] = m_util.misc.add_category(cats)
end
return table.concat(out)
end
-- function p.passive_skill_link(frame)
-- --[[
-- Links a passive skill
-- Examples
-- --------
-- = p.passive_skill_link{id='AscendancyAscendant45', format='tablerow'}
-- ]]
-- -- Get args
-- tpl_args = getArgs(frame, {
-- parentFirst = true
-- })
-- frame = m_util.misc.get_frame(frame)
-- tpl_args.name = tpl_args.name or tpl_args[1]
-- if tpl_args.name then
-- tpl_args.q_where = string.format('passive_skills.name="%s"', tpl_args.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
-- else
-- error('Either name, id or q_where must be specified')
-- end
-- 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',
-- 'main_pages._pageName',
-- },
-- {
-- join='passive_skills.id=main_pages.id',
-- where=string.format('(%s) AND passive_skills.stat_text IS NOT NULL', tpl_args.q_where),
-- orderBy='passive_skills.stat_text',
-- limit=2,
-- }
-- )
-- if #results > 1 then
-- error('Too many passives found!')
-- elseif #results < 1 then
-- error('No passives found')
-- end
-- local passive = results[1]
-- if tpl_args.format == 'tablerow' then
-- local main_page = passive['passive_skills.main_page'] or passive['main_pages._pageName'] or passive['passive_skills.name']
-- return string.format(
-- '| [[%s|%s]]%s\n| %s',
-- main_page,
-- passive['passive_skills.name'],
-- h.format_mastery_icon(passive),
-- passive['passive_skills.stat_text']
-- )
-- elseif tpl_args.format == nil then
-- return
-- else
-- error(string.format('Invalid return format specified: %s', tpl_args.format))
-- end
-- end
-- -- Not sure whether we need a more sophisticated variant like item or mod tables here yet
-- function p.passive_skill_table2(frame)
-- -- Get args
-- tpl_args = getArgs(frame, {
-- parentFirst = true
-- })
-- frame = m_util.misc.get_frame(frame)
-- if tpl_args.q_tables then
-- tpl_args.q_tables = tpl_args.q_tables .. ',' .. 'passive_skill_stats'
-- else
-- tpl_args.q_tables = 'passive_skill_stats'
-- end
-- if tpl_args.q_join then
-- tpl_args.q_join = tpl_args.q_join .. ',' .. 'passive_skills._pageID=passive_skill_stats._pageID'
-- else
-- tpl_args.q_join = 'passive_skills._pageID=passive_skill_stats._pageID'
-- end
-- tpl_args.q_orderBy = 'passive_skills.ascendancy_class IS NULL DESC, passive_skills.is_keystone, passive_skills.is_notable, passive_skills.name'
-- return m_cargo.table_query{
-- tpl_args=tpl_args,
-- frame=frame,
-- main_table='passive_skills',
-- row_unique_fields = {'passive_skills.name'},
-- data={
-- tables = {
-- passive_skill_stats = {
-- join='passive_skills._pageID=passive_skill_stats._pageID',
-- },
-- },
-- -- display data
-- {
-- args = {'ascendancy'},
-- header = i18n.passive_table.ascendancy_class,
-- fields = {
-- 'passive_skills.ascendancy_class',
-- },
-- display = function (tpl_args, frame, tr, data)
-- local passive = data[1]
-- if passive['passive_skills.ascendancy_class'] then
-- tr:tag('td')
-- :wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class'], passive['passive_skills.ascendancy_class']))
-- else
-- tr:wikitext(m_util.html.td.na{})
-- end
-- end,
-- order = 0,
-- sort_type = 'text',
-- },
-- {
-- args = nil,
-- header = i18n.passive_table.name,
-- fields = {
-- 'passive_skills._pageName',
-- 'passive_skills.main_page',
-- 'passive_skills.name',
-- 'passive_skills.icon',
-- 'passive_skills.is_keystone',
-- 'passive_skills.is_notable',
-- 'passive_skills.ascendancy_class',
-- },
-- display = function (tpl_args, frame, tr, data)
-- local passive = data[1]
-- local type_key = h.get_type(passive)
-- tr
-- :tag('td')
-- :attr('data-sort-value', passive['passive_skills.name'] .. type_key)
-- :wikitext(string.format('[[%s|%s]]<br>%s', passive['passive_skills.main_page'] or passive['passive_skills.name'], passive['passive_skills.name'], h.format_mastery_icon(passive))
-- :done()
-- end,
-- order = 1000,
-- sort_type = 'text',
-- options = {
-- [7] = {
-- optional=true,
-- },
-- },
-- },
-- {
-- arg = {'default', 'stat', 'stats', 'stat_text'},
-- header = i18n.passive_table.stats,
-- fields = {
-- 'passive_skills.stat_text',
-- },
-- display = function (tpl_args, frame, tr, data)
-- local passive = data[1]
-- local stats, stat_order = h.make_stat_order(data)
-- tr
-- :tag('td')
-- :wikitext(h.stat_page_links(stat_order, stats))
-- :done()
-- end,
-- order = 1001,
-- sort_type = 'text',
-- }
-- },
-- }
-- end
-- function p.passive_skill_table(frame)
-- -- Get args
-- tpl_args = getArgs(frame, {
-- parentFirst = true
-- })
-- frame = m_util.misc.get_frame(frame)
-- tpl_args.ascendancy = m_util.cast.boolean(tpl_args.ascendancy)
-- local prepend = {
-- q_join=true,
-- }
-- local query = {
-- join='passive_skills._pageID=passive_skill_stats._pageID',
-- limit=5000,
-- groupBy='passive_skills._pageID',
-- }
-- for key, value in pairs(tpl_args) do
-- if string.sub(key, 0, 2) == 'q_' then
-- if prepend[key] then
-- value = ',' .. value
-- end
-- query[string.sub(key, 3)] = value
-- end
-- end
-- local results = m_cargo.query(
-- {'passive_skills', 'passive_skill_stats'},
-- {
-- 'passive_skills._pageName',
-- 'passive_skills.main_page',
-- 'passive_skills.name',
-- 'passive_skills.stat_text',
-- 'passive_skills.icon',
-- 'passive_skills.is_keystone',
-- 'passive_skills.is_notable',
-- 'passive_skills.ascendancy_class',
-- },
-- query
-- )
-- result_map = m_cargo.map_results_to_id{
-- results=results,
-- field='passive_skills.name',
-- keep_id_field=true,
-- }
-- for key, rows in pairs(result_map) do
-- result_map[key] = h.sort_by_type(rows)
-- end
-- -- header
-- local tbl = mw.html.create('table')
-- tbl:addClass('wikitable')
-- tbl:addClass('sortable')
-- local tr = tbl:tag('tr')
-- if tpl_args.ascendancy then
-- tr:tag('th')
-- :wikitext(i18n.passive_table.ascendancy_class)
-- end
-- tr
-- :tag('th')
-- :wikitext(i18n.passive_table.name)
-- :done()
-- :tag('th')
-- :wikitext(i18n.passive_table.stats)
-- :done()
-- -- rows
-- local used_names = {}
-- for _, passive_row in ipairs(results) do
-- local pn = passive_row['passive_skills.name']
-- if used_names[pn] == nil then
-- local type_results_map = result_map[passive_row['passive_skills.name']]
-- used_names[pn] = true
-- for _, type_key in ipairs(h.type_order) do
-- local type_results = type_results_map[type_key]
-- if #type_results > 0 then
-- local row = type_results[1]
-- tr = tbl:tag('tr')
-- if tpl_args.ascendancy then
-- if row['passive_skills.ascendancy_class'] then
-- tr:tag('td')
-- :wikitext(string.format('[[%s]]<br>[[File:%s avatar.png|link=%s]]', row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class'], row['passive_skills.ascendancy_class']))
-- else
-- tr:wikitext(m_util.html.td.na{})
-- end
-- end
-- local stats, stat_order = h.make_stat_order(type_results)
-- tr
-- :tag('td')
-- :attr('data-sort-value', row['passive_skills.name'] .. type_key)
-- :wikitext(string.format('[[%s|%s]]<br>%s', row['passive_skills.main_page'] or row['passive_skills.name'], row['passive_skills.name'], h.format_mastery_icon(row)))
-- :done()
-- :tag('td')
-- :wikitext(h.stat_page_links(stat_order, stats))
-- :done()
-- end
-- end
-- end
-- end
-- return tostring(tbl)
-- end
-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------
return p