Module:Miscellaneous: Difference between revisions
Jump to navigation
Jump to search
>OmegaK2 mNo edit summary |
>OmegaK2 m (removed version prefix from version property) |
||
Line 312: | Line 312: | ||
if g_args[arg] ~= nil then | if g_args[arg] ~= nil then | ||
properties['Has version ' .. arg] = 'Version ' .. g_args[arg] | properties['Has version ' .. arg] = 'Version ' .. g_args[arg] | ||
vargs[arg] = '[[Version ' .. g_args[arg] .. '|' .. vargs[arg] .. ' ' .. g_args[arg] .. ']] <br> ' .. g_frame:callParserFunction('#ask: [[Is version:: | vargs[arg] = '[[Version ' .. g_args[arg] .. '|' .. vargs[arg] .. ' ' .. g_args[arg] .. ']] <br> ' .. g_frame:callParserFunction('#ask: [[Is version::' .. g_args[arg] .. ']]', query) | ||
else | else | ||
vargs[arg] = nil | vargs[arg] = nil | ||
Line 318: | Line 318: | ||
end | end | ||
properties['Is version'] = | properties['Is version'] = g_args['patch'] | ||
properties['Has release date'] = g_args['patchdate'] | properties['Has release date'] = g_args['patchdate'] | ||
g_frame:callParserFunction('#set', properties) | g_frame:callParserFunction('#set', properties) |
Revision as of 07:20, 1 September 2015
Overview
Module for implementing various templates in lua that are not big/complex enough to warrent their own module.
List of currently implemented templates
The above documentation is transcluded from Module:Miscellaneous/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.
--[[
Module for implementing miscellaneous templates in lua.
Mostly exists here so we don't have hundred of module pages for templates that don't have a lot of code.
If a template requires a *lot* of coding consider moving it into it's own lua module.
]]--
local xtable = require('Module:Table')
local util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local game = require('Module:Game')
local p = {}
local g_frame, g_args
--
-- Template: GemLevelTable
--
function p.gem_level_table(frame)
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
g_args.width = g_args.width or 'auto'
local out = {}
out[#out+1] = '{| class="wikitable GemLevelTable" '
out[#out+1] = 'style="width: '
out[#out+1] = g_args.width
out[#out+1] = '; text-align: center"\n'
out[#out+1] = '! Level\n'
out[#out+1] = '!' .. util.html.abbr('[[Image:Level_up_icon_small.png|link=|Lvl.]]', 'Required Level', 'nounderline') .. '\n'
for i, v in ipairs(game.constants.attributes) do
if g_args[v['short_lower']] ~= nil then
out[#out+1] = '!' .. util.html.abbr('[[Image:' .. v['long_upper'].. 'Icon_small.png|link=|' .. v['short_upper'] .. '.]]', 'Required ' .. v['long_upper'], 'nounderline') .. '\n'
end
end
-- original had cost, reserve, duration, radius, unneeded I believe
i = 0
-- increase if necessary
while i < 25 do
local header = g_args['c' .. i]
if header ~= nil then
out[#out+1] = '! ' .. header .. '\n'
end
i = i + 1
end
out[#out+1] = '!' .. util.html.abbr('Exp.', 'Experience Needed to Level Up') .. '\n'
out[#out+1] = '!' .. util.html.abbr('Total Exp.', 'Total Experience Needed') .. '\n'
return table.concat(out)
end
--
-- Template: ItemFilterList
--
function p.filter_list(frame)
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
g_frame = frame
g_args.type = g_args.type or ''
tbl = mw.html.create('table')
tbl
:attr('class', 'wikitable sortable')
tblrow = tbl:tag('tr')
:tag('th')
:attr('rowspan', 2)
:wikitext('Name')
:done()
:tag('th')
:attr('rowspan', 2)
:wikitext('Author')
:done()
:tag('th')
:attr('rowspan', 2)
:wikitext('Release')
:done()
:tag('th')
:attr('colspan', 9)
:wikitext('Ingame Features')
:done()
:tag('th')
:attr('colspan', 1)
:wikitext('Other Features')
:done()
:tag('th')
:attr('colspan', 2)
:wikitext('Filtration Support')
:done()
if g_args.type == 'specialized' then
tblrow:tag('th')
:attr('rowspan', 2)
:wikitext('Description')
:done()
end
tblrow = tbl:tag('tr')
:tag('th')
:wikitext('Colours')
:done()
:tag('th')
:wikitext('Borders')
:done()
:tag('th')
:wikitext('Font<br>Size')
:done()
:tag('th')
:wikitext('Background')
:done()
:tag('th')
:wikitext('Item<br>Hiding')
:done()
:tag('th')
:wikitext('Leveling')
:done()
:tag('th')
:wikitext('Endgame')
:done()
:tag('th')
:wikitext('Vendor<br>recipes')
:done()
:tag('th')
:wikitext('Crafting')
:done()
-- Other Features
:tag('th')
:wikitext('Customizable')
:done()
-- Filtration
:tag('th')
:wikitext('General')
:done()
:tag('th')
:wikitext('Themes')
:done()
:done()
:wikitext(g_args.rows)
--return tostring(tbl) .. frame:extensionTag{ name = 'references', content = '', args = {group='note'}}
return tostring(tbl)
end
--
-- Template: ItemFilterListRow
--
local filter_list_required_args = xtable:new({'name', 'release_link', 'author', 'release', 'colour', 'border', 'font_size', 'background', 'item_hiding', 'leveling', 'endgame', 'vendor_recipes', 'crafting'})
local filter_list_range_args = xtable:new({'colour', 'border', 'font_size', 'background', 'item_hiding', 'leveling', 'endgame', 'vendor_recipes', 'crafting'})
local filter_list_range_values = xtable:new({'no', 'minor', 'partial', 'major', 'yes'})
local filter_list_yes_no_args = xtable:new({'customization', 'filtration_general', 'filtration_themes'})
local filter_list_yes_no = xtable:new({'no', 'partial', 'yes', 'unknown'})
-- Test: =p.filter_list{rows=p.filter_list_row{name='a', release_link='http://google.de', author='Mario', author_contact='No idea', direct_link='http://google.de', colour='yes', border='yes', font_size='no', item_hiding='yes', leveling=0, endgame=4, vendor_recipes='partial', crafting='no', release='2015'}}
-- =p.filter_list{type='specialized',rows=p.filter_list_row{type='specialized', name='a', release_link='http://google.de', author='Mario', author_contact='No idea', direct_link='http://google.de', colour='yes',colour_note="test", border='yes', font_size='no', background='no', item_hiding='yes', leveling=0, endgame=4, vendor_recipes='partial', crafting='no', release='2015', description='test'}}
function p.filter_list_row(frame)
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
g_frame = frame
-- Checking args
for _, arg in ipairs(filter_list_required_args) do
if g_args[arg] == nil then
error('Required argument ' .. arg .. ' is missing')
end
end
g_args.filtration_general = g_args.filtration_general or 'unknown'
g_args.filtration_themes = g_args.filtration_themes or 'unknown'
g_args.customization = g_args.customization or 'unknown'
g_args.descriptipon = g_args.description or '<br>'
g_args.type = g_args.type or ''
-- Checking & formatting args
for _, arg in ipairs(filter_list_range_args) do
local val = g_args[arg]
local index = filter_list_range_values:index(val)
if index then
g_args[arg] = index
else
index = util.cast.number(val)
if index ~= nil and index >= 0 and index < filter_list_range_values:size() then
-- Lua starts counting at 1
g_args[arg] = index+1
else
error('Argument ' .. arg .. ' requires one of the following arguments: ' .. table.concat(filter_list_range_values, ' '))
end
end
end
for _, arg in ipairs(filter_list_yes_no_args) do
local val = g_args[arg]
if not filter_list_yes_no:contains(val) then
error('Argument ' .. arg .. ' requires one of the following arguments: ' .. table.concat(filter_list_yes_no, ' '))
end
end
-- Output
tblrow = mw.html.create('tr')
tblrow
:tag('td')
:wikitext('[' .. g_args.release_link .. ' ' .. g_args.name .. ']')
:done()
:tag('td')
:wikitext(g_args.author)
:done()
:tag('td')
:wikitext(g_args.release)
:done()
-- Basic Features
for _, arg in ipairs(filter_list_range_args) do
local index = g_args[arg]
local text = filter_list_range_values[index] or ''
local note = g_args[arg .. '_note']
tblrow
:tag('td')
:attr('class', 'table-cell-coloured table-cell-' .. text )
:attr('data-sort-value', index)
:wikitext(filter_list_get_arg(arg))
:done()
end
-- Other Features
for _, arg in ipairs(filter_list_yes_no_args) do
local val = g_args[arg]
tblrow
:tag('td')
:attr('class', 'table-cell-coloured table-cell-' .. val)
:attr('data-sort-value', '' .. filter_list_yes_no:index(val))
:wikitext(filter_list_get_arg(arg))
:done()
end
if g_args.type == 'specialized' then
tblrow
:tag('td')
:wikitext(filter_list_get_arg('description'))
:done()
end
return tostring(tblrow)
end
function filter_list_get_arg(arg)
--[[
Return a formatted table cell for the given argument
]]--
local val = g_args[arg]
if type(val) == 'number' then
val = filter_list_range_values[val]
end
if g_args[arg .. '_note'] ~= nil then
abbr = mw.html.create('abbr')
abbr
:attr('title', g_args[arg .. '_note'])
:wikitext(val)
:done()
return tostring(abbr)
else
return val
end
end
--
-- Template: Version
--
function p.version(frame)
-- Get args
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
g_frame = frame
-- Parser
local properties = {}
local vargs = {before = '←', after = '→'}
local query = {}
query['?Has release date'] = ''
query['mainlabel'] = '-'
for arg, value in pairs(vargs) do
if g_args[arg] ~= nil then
properties['Has version ' .. arg] = 'Version ' .. g_args[arg]
vargs[arg] = '[[Version ' .. g_args[arg] .. '|' .. vargs[arg] .. ' ' .. g_args[arg] .. ']] <br> ' .. g_frame:callParserFunction('#ask: [[Is version::' .. g_args[arg] .. ']]', query)
else
vargs[arg] = nil
end
end
properties['Is version'] = g_args['patch']
properties['Has release date'] = g_args['patchdate']
g_frame:callParserFunction('#set', properties)
-- Output
tbl = mw.html.create('table')
tbl
:attr('class', 'wikitable successionbox')
:tag('tr')
:tag('th')
:attr('colspan', 3)
:wikitext('[[Version history|Version History]]')
:done()
:done()
:tag('tr')
:tag('td')
:attr('style', 'width: 30%;')
:wikitext(vargs['before'])
:done()
:tag('td')
:attr('style', 'width: 40%;')
:wikitext('[[Version ' .. g_args['patch'] .. ']] <br> ' .. g_args['patchdate'])
:done()
:tag('td')
:attr('style', 'width: 30%;')
:wikitext(vargs['after'])
:done()
:done()
:done()
return tostring(tbl)
end
return p