Module:Infobox Spell
Documentation for this module may be created at Module:Infobox Spell/doc
--------------------------
-- Module for [[Template:Infobox Spell]]
------------------------
local p = {}
local onmain = require('Module:Mainonly').on_main
local infobox = require('Module:Infobox')
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
ret:defineParams{
{ name = 'name', func = 'name' },
{ name = 'image', func = 'image' },
{ name = 'release', func = 'release' },
{ name = 'level', func = 'has_content' },
{ name = 'runes', func = 'has_content' },
{ name = 'description', func = 'has_content' },
{ name = 'quest', func = 'has_content' },
{ name = 'experience', func = { name = experience_arg, params = { 'level' } } },
{ name = 'power', func = 'has_content' },
{ name = 'maxhit', func = 'has_content' },
{ name = 'id', func = 'has_content' },
}
ret:defineLinks({ hide = true })
ret:create()
ret:cleanParams()
ret:customButtonPlacement(true)
ret:addButtonsCaption()
ret:defineName('Infobox Spell')
ret:addClass('infobox-spell')
ret:addRow{
{ tag = 'argh', content = 'name', class='infobox-header', colspan = '20' }
}
:pad(20)
:addRow{
{ tag = 'argd', content = 'image', class='infobox-image infobox-full-width-content', colspan = '20' }
}
:pad(20)
:addRow{
{ tag = 'th', content = 'Released', colspan = '7' },
{ tag = 'argd', content = 'release', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Magic level', colspan = '7' },
{ tag = 'argd', content = 'level', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Description', colspan = '7' },
{ tag = 'argd', content = 'description', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Runes', colspan = '7' },
{ tag = 'argd', content = 'runes', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Experience', colspan = '7' },
{ tag = 'argd', content = 'experience', colspan = '13' }
}
if ret:paramDefined('quest') then
ret:addRow{
{ tag = 'th', content = 'Quest', colspan = '7' },
{ tag = 'argd', content = 'quest', colspan = '13' }
}
end
if ret:paramDefined('power') then
ret:addRow{
{ tag = 'th', content = 'Spell power', colspan = '7' },
{ tag = 'argd', content = 'power', colspan = '13' }
}
end
if ret:paramDefined('maxhit') then
ret:addRow{
{ tag = 'th', content = 'Base max hit', colspan = '7' },
{ tag = 'argd', content = 'maxhit', colspan = '13' }
}
end
ret:pad(20)
:addRow{
{ tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '20' },
meta = {addClass = 'advanced-data'}
}
:pad(20, 'advanced-data')
:addRow{
{ tag = 'th', content = 'Spell ID', colspan = '7' },
{ tag = 'argd', content = 'id', colspan = '13' },
meta = {addClass = 'advanced-data'}
}
ret:pad(20, 'advanced-data')
if onmain() then
local a1 = ret:param('all')
local a2 = ret:categoryData()
ret:wikitext(addcategories(a1, a2))
end
return ret:tostring()
end
function experience_arg(level)
if not infobox.isDefined(level) or not tonumber(level) then
return nil
end
return 2 * level + 20
end
function addcategories(args, catargs)
local ret = { 'Spells' }
-- Add the associated category if the parameter doesn't have content
local notdefined_args = {
release = 'Needs release date',
}
for n, v in pairs(notdefined_args) do
if catargs[n] and catargs[n].all_defined == false then
table.insert(ret, v)
end
end
-- combine table and format category wikicode
for i, v in ipairs(ret) do
if (v ~= '') then
ret[i] = string.format('[[Category:%s]]', v)
end
end
return table.concat(ret, '')
end
return p