Module:Incursion/sandbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- | ------------------------------------------------------------------------------- | ||
-- Module | -- | ||
-- | -- Module:Incursion | ||
-- | |||
-- This module implements Template:Incursion room | |||
------------------------------------------------------------------------------- | |||
local m_util = require('Module:Util/sandbox') | |||
local m_cargo = require('Module:Cargo') | |||
local f_infocard = require('Module:Infocard')._main | local f_infocard = require('Module:Infocard')._main | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
Line 53: | Line 55: | ||
field = 'description', | field = 'description', | ||
type = 'Text', | type = 'Text', | ||
display = function (tpl_args | display = function (tpl_args) | ||
return m_util.html.poe_color('mod', tpl_args.description) | return m_util.html.poe_color('mod', tpl_args.description) | ||
end | end | ||
Line 60: | Line 62: | ||
field = 'flavour_text', | field = 'flavour_text', | ||
type = 'Text', | type = 'Text', | ||
display = function (tpl_args | display = function (tpl_args) | ||
return m_util.html.poe_color('flavour', tpl_args.flavour_text) | return m_util.html.poe_color('flavour', tpl_args.flavour_text) | ||
end | end | ||
Line 73: | Line 75: | ||
field = 'upgrade_room_id', | field = 'upgrade_room_id', | ||
type = 'String', | type = 'String', | ||
func = function (tpl_args | func = function (tpl_args, value) | ||
if value == nil then | if value == nil then | ||
return | return | ||
Line 93: | Line 95: | ||
header = i18n.headers.upgrade_room_id, | header = i18n.headers.upgrade_room_id, | ||
display = function(tpl_args | display = function(tpl_args) | ||
if tpl_args.upgrade_room == nil then | if tpl_args.upgrade_room == nil then | ||
if tpl_args.upgrade_room_id == nil then | if tpl_args.upgrade_room_id == nil then | ||
Line 107: | Line 109: | ||
field = 'icon', | field = 'icon', | ||
type = 'Page', | type = 'Page', | ||
func = function (tpl_args | func = function (tpl_args, value) | ||
if value == nil then | if value == nil then | ||
return | return | ||
Line 115: | Line 117: | ||
end, | end, | ||
display = function (tpl_args | display = function (tpl_args) | ||
return string.format('[[%s]]', tpl_args.icon) | return string.format('[[%s]]', tpl_args.icon) | ||
end, | end, | ||
Line 135: | Line 137: | ||
type = 'String', | type = 'String', | ||
header = i18n.headers.architect, | header = i18n.headers.architect, | ||
display = function (tpl_args | display = function (tpl_args) | ||
return string.format('[[%s]]', tpl_args.architect_name) | return string.format('[[%s]]', tpl_args.architect_name) | ||
end, | end, | ||
Line 142: | Line 144: | ||
field = 'modifier_ids', | field = 'modifier_ids', | ||
type = 'List (,) of String', | type = 'List (,) of String', | ||
func = function (tpl_args | func = function (tpl_args, value) | ||
if value == nil then | if value == nil then | ||
return | return | ||
Line 161: | Line 163: | ||
field = 'stat_text', | field = 'stat_text', | ||
type = 'Text', | type = 'Text', | ||
func = function (tpl_args, | func = function (tpl_args, value) | ||
if tpl_args.mods == nil then | if tpl_args.mods == nil then | ||
return | return | ||
Line 183: | Line 185: | ||
local h = {} | local h = {} | ||
function h.check_args(tpl_args | function h.check_args(tpl_args, key, data) | ||
local value = tpl_args[key] | local value = tpl_args[key] | ||
if value == nil then | if value == nil then | ||
Line 197: | Line 199: | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- | -- Main functions | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
local function _incursion_room(tpl_args) | |||
function | |||
--[[ | --[[ | ||
Stores cargo data for incursion rooms and displays it in a infobox. | Stores cargo data for incursion rooms and displays it in a infobox. | ||
Line 221: | Line 221: | ||
]] | ]] | ||
m_util.args.from_cargo_map{ | m_util.args.from_cargo_map{ | ||
tpl_args=tpl_args, | tpl_args=tpl_args, | ||
table_map=tables.incursion_rooms, | table_map=tables.incursion_rooms, | ||
} | } | ||
Line 243: | Line 235: | ||
local function display (value, data) | local function display (value, data) | ||
if data.display then | if data.display then | ||
return data.display(tpl_args | return data.display(tpl_args) or '' | ||
end | end | ||
Line 258: | Line 250: | ||
for _, key in ipairs(tables.incursion_rooms.display_table_order) do | for _, key in ipairs(tables.incursion_rooms.display_table_order) do | ||
local data = tables.incursion_rooms.fields[key] | local data = tables.incursion_rooms.fields[key] | ||
if h.check_args(tpl_args | if h.check_args(tpl_args, key, data) then | ||
tbl | tbl | ||
:tag('tr') | :tag('tr') | ||
Line 276: | Line 268: | ||
for _, key in ipairs(tables.incursion_rooms.display_list_order) do | for _, key in ipairs(tables.incursion_rooms.display_list_order) do | ||
local data = tables.incursion_rooms.fields[key] | local data = tables.incursion_rooms.fields[key] | ||
if h.check_args(tpl_args | if h.check_args(tpl_args, key, data) then | ||
infocard_args[i] = display(tpl_args[key], data) | infocard_args[i] = display(tpl_args[key], data) | ||
i = i + 1 | i = i + 1 | ||
Line 298: | Line 290: | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- | -- Exported functions | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
local p = {} | |||
p.table_incursion_rooms = m_cargo.declare_factory{data=tables.incursion_rooms} | |||
-- | |||
-- Template:Incursion room | |||
-- | |||
p.incursion_room = m_util.misc.invoker_factory(_incursion_room, { | |||
wrappers = 'Template:Incursion room', | |||
}) | |||
return p | return p |
Revision as of 17:56, 13 June 2022
![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Edit_In_Sandbox_Icon_-_Color.svg/45px-Edit_In_Sandbox_Icon_-_Color.svg.png)
This is the module sandbox page for Module:Incursion (diff).
Handles various incursion related templates:
The above documentation is transcluded from Module:Incursion/doc.
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:Incursion
--
-- This module implements Template:Incursion room
-------------------------------------------------------------------------------
local m_util = require('Module:Util/sandbox')
local m_cargo = require('Module:Cargo')
local f_infocard = require('Module:Infocard')._main
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
local i18n = {
icon_format = 'File:%s incursion room icon.png',
headers = {
id = 'Id',
tier = 'Tier',
upgrade_room_id = 'Upgrades to',
min_level = 'Min. Level',
max_level = 'Max. Level',
weight = 'Weight',
architect = 'Architect',
modifier_ids = 'Modifiers',
},
}
-- ----------------------------------------------------------------------------
-- Tables
-- ----------------------------------------------------------------------------
local tables = {
incursion_rooms = {
table = 'incursion_rooms',
order = {'id', 'name', 'description', 'flavour_text', 'tier', 'upgrade_room_id', 'icon', 'min_level', 'architect_metadata_id', 'architect_name', 'modifier_ids', 'stat_text'},
display_table_order = {'id', 'tier', 'upgrade_room_id', 'min_level', 'architect_name'},
display_list_order = {'description', 'stat_text', 'icon', 'flavour_text',},
fields = {
id = {
field = 'id',
type = 'String(size=100; unique)',
required = true,
header = i18n.headers.id,
},
name = {
field = 'name',
type = 'String',
},
description = {
field = 'description',
type = 'Text',
display = function (tpl_args)
return m_util.html.poe_color('mod', tpl_args.description)
end
},
flavour_text = {
field = 'flavour_text',
type = 'Text',
display = function (tpl_args)
return m_util.html.poe_color('flavour', tpl_args.flavour_text)
end
},
tier = {
field = 'tier',
type = 'Integer',
header = i18n.headers.tier,
},
upgrade_room_id = {
field = 'upgrade_room_id',
type = 'String',
func = function (tpl_args, value)
if value == nil then
return
end
local results = m_cargo.query(
{'incursion_rooms'},
{'incursion_rooms._pageName', 'incursion_rooms.name'},
{
where=string.format('incursion_rooms.id="%s"', value)
}
)
if #results == 0 then
return
end
-- Save the upgrade room to tpl_args so we can make a link for it in the display
tpl_args.upgrade_room = results[1]
return value
end,
header = i18n.headers.upgrade_room_id,
display = function(tpl_args)
if tpl_args.upgrade_room == nil then
if tpl_args.upgrade_room_id == nil then
return
else
return tpl_args.upgrade_room_id
end
end
return string.format('[[%s|%s]]', tpl_args.upgrade_room['incursion_rooms._pageName'], tpl_args.upgrade_room['incursion_rooms.name'])
end
},
icon = {
field = 'icon',
type = 'Page',
func = function (tpl_args, value)
if value == nil then
return
end
return string.format(i18n.icon_format, value)
end,
display = function (tpl_args)
return string.format('[[%s]]', tpl_args.icon)
end,
},
min_level = {
field = 'min_level',
type = 'Integer',
default = 0,
header = i18n.headers.min_level,
},
-- architect_name is temporary until monsters are added to the wiki
architect_metadata_id = {
field = 'architect_metadata_id',
type = 'String',
},
architect_name = {
field = 'architect_name',
type = 'String',
header = i18n.headers.architect,
display = function (tpl_args)
return string.format('[[%s]]', tpl_args.architect_name)
end,
},
modifier_ids = {
field = 'modifier_ids',
type = 'List (,) of String',
func = function (tpl_args, value)
if value == nil then
return
end
tpl_args.mods = m_cargo.array_query{
tables={'mods'},
fields={'mods.stat_text'},
id_field='mods.id',
id_array=value
}
return value
end,
header = i18n.headers.modifier_ids,
},
stat_text = {
field = 'stat_text',
type = 'Text',
func = function (tpl_args, value)
if tpl_args.mods == nil then
return
end
local text = {}
for page, row in pairs(tpl_args.mods) do
if row['mods.stat_text'] then
text[#text+1] = row['mods.stat_text']
end
end
return table.concat(text, '<br>')
end,
},
},
},
}
-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------
local h = {}
function h.check_args(tpl_args, key, data)
local value = tpl_args[key]
if value == nil then
return false
end
if data.default == value then
return false
end
return true
end
-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------
local function _incursion_room(tpl_args)
--[[
Stores cargo data for incursion rooms and displays it in a infobox.
Examples
--------
= p.incursion_room{
id = 'CorruptionRoomIII',
name = 'Locus of Corruption',
description = 'Reduces player maximum resistances throughout the Temple.<br />Contains an Altar of Corruption.',
flavour_text = 'Darkness coalesces, imbues, and blesses.',
tier = '3',
icon = 'CorruptionRoom3',
modifier_ids = 'MapPlayerMaxResists3__',
architect_metadata_id = 'Metadata/Monsters/VaalArchitect/VaalArchitect8',
architect_name = 'Paquate, Architect of Corruption',
}
]]
m_util.args.from_cargo_map{
tpl_args=tpl_args,
table_map=tables.incursion_rooms,
}
--
-- infobox
--
local infocard_args = {}
infocard_args.header = tpl_args.name
local function display (value, data)
if data.display then
return data.display(tpl_args) or ''
end
if type(value) == 'table' then
return table.concat(value, ', ')
end
return value or ''
end
-- Main sections, loop through
local tbl = mw.html.create('table')
tbl:attr('style', 'width: 100%;')
for _, key in ipairs(tables.incursion_rooms.display_table_order) do
local data = tables.incursion_rooms.fields[key]
if h.check_args(tpl_args, key, data) then
tbl
:tag('tr')
:tag('th')
:wikitext(data.header or '')
:done()
:tag('td')
:wikitext(display(tpl_args[key], data))
:done()
:done()
end
end
infocard_args[1] = tostring(tbl)
local i = 2
for _, key in ipairs(tables.incursion_rooms.display_list_order) do
local data = tables.incursion_rooms.fields[key]
if h.check_args(tpl_args, key, data) then
infocard_args[i] = display(tpl_args[key], data)
i = i + 1
end
end
--
-- Categories
--
local cats = {
'Incursion rooms',
}
--
-- Done - output
--
return f_infocard(infocard_args) .. m_util.misc.add_category(cats)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
p.table_incursion_rooms = m_cargo.declare_factory{data=tables.incursion_rooms}
--
-- Template:Incursion room
--
p.incursion_room = m_util.misc.invoker_factory(_incursion_room, {
wrappers = 'Template:Incursion room',
})
return p