Module:Infobox NPC
Documentation for this module may be created at Module:Infobox NPC/doc
--------------------------
-- Module for [[Template:Infobox NPC]]
------------------------
local p = {}
local infobox = require('Module:Infobox')
local onmain = require('Module:Mainonly').on_main
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
ret:defineParams{
{ name = 'version', func = 'has_content' },
{ name = 'name', func = 'name' },
{ name = 'image', func = 'image' },
{ name = 'release', func = 'release' },
{ name = 'members', func = 'has_content' },
{ name = 'race', func = 'has_content' },
{ name = 'quest', func = 'has_content' },
{ name = 'location', func = 'has_content' },
{ name = 'shop', func = 'has_content' },
{ name = 'gender', func = 'has_content' },
{ name = 'actions', func = 'has_content' },
{ name = 'examine', func = 'has_content' },
{ name = 'skillrequired', func = 'has_content' },
{ name = 'questrequired', func = 'has_content' },
{ name = 'features', func = 'has_content' },
{ name = 'map', func = maparg },
{ name = 'id', func = 'has_content' },
{ name = 'id_smw', func = { name = idsmw, params = { 'id' }, flag = 'p' } },
}
ret:useSMWSubobject({
version = 'Version anchor',
members = 'Is members only',
id_smw = 'NPC ID',
})
ret:setMaxButtons(7)
ret:create()
ret:cleanParams()
ret:customButtonPlacement(true)
ret:defineLinks({ hide = true })
ret:addButtonsCaption()
ret:defineName('Infobox NPC')
ret:addClass('infobox-npc')
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 = '[[Members]]', colspan = '7' },
{ tag = 'argd', content = 'members', colspan = '13' }
}
:addRow{
{ tag = 'th', content = 'Race', colspan = '7' },
{ tag = 'argd', content = 'race', colspan = '13' }
}
if ret:paramDefined('quest') then
ret:addRow{
{ tag = 'th', content = '[[Quests|Quest NPC]]', colspan = '7' },
{ tag = 'argd', content = 'quest', colspan = '13' }
}
end
ret:addRow{
{ tag = 'th', content = 'Location', colspan = '7' },
{ tag = 'argd', content = 'location', colspan = '13' }
}
if ret:paramDefined('shop') then
ret:addRow{
{ tag = 'th', content = '[[Shop]]', colspan = '7' },
{ tag = 'argd', content = 'shop', colspan = '13' }
}
end
if ret:paramDefined('gender') then
ret:addRow{
{ tag = 'th', content = '[[Gender]]', colspan = '7' },
{ tag = 'argd', content = 'gender', colspan = '13' }
}
end
if ret:paramDefined('actions') then
ret:addRow{
{ tag = 'th', content = 'Actions', colspan = '7' },
{ tag = 'argd', content = 'actions', colspan = '13' }
}
end
ret:addRow{
{ tag = 'th', content = '[[Examine]]', colspan = '7' },
{ tag = 'argd', content = 'examine', colspan = '13' }
}
if ret:paramDefined('skillrequired') then
ret:addRow{
{ tag = 'th', content = '[[Skills|Skill required]]', colspan = '7' },
{ tag = 'argd', content = 'skillrequired', colspan = '13' }
}
end
if ret:paramDefined('questrequired') then
ret:addRow{
{ tag = 'th', content = '[[Quests|Quest required]]', colspan = '7' },
{ tag = 'argd', content = 'questrequired', colspan = '13' }
}
end
if ret:paramDefined('features') then
ret:addRow{
{ tag = 'th', content = 'Features', colspan = '7' },
{ tag = 'argd', content = 'features', colspan = '13' }
}
end
ret:pad(20)
local map_defined = ret:paramGrep('map', function(x) return (x or 'N/A') ~= 'N/A' end)
if map_defined then
ret:addRow{
{ tag = 'th', content = 'Map', class = 'infobox-subheader', colspan = '20' }
}
:addRow{
{ tag = 'argd', content = 'map', colspan = '20', class = 'infobox-full-width-content infobox-image' }
}
end
ret:addRow{
{ tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '20' },
meta = {addClass = 'advanced-data'}
}
:pad(20, 'advanced-data')
:addRow{
{ tag = 'th', content = 'NPC ID', colspan = '7' },
{ tag = 'argd', content = 'id', colspan = '13' },
meta = {addClass = 'advanced-data'}
}
: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 maparg(arg)
if not infobox.isDefined(arg) then
return nil
end
if string.lower(arg) == 'no' then
return 'N/A'
end
return arg
end
function idsmw(id)
if not infobox.isDefined(id) then
return nil
end
return string.gsub(id, ',', '&&SPLITPOINT&&')
end
function addcategories(args, catargs)
local ret = { 'Non-player characters' }
local cat_map = {
-- Added if the parameter has no content
notdefined = {
image = 'Needs image',
members = 'Needs members status',
release = 'Needs release date',
examine = 'Needs examine added',
id = 'Needs ID',
map = 'Needs map',
}
}
-- undefined categories
for n, v in pairs(cat_map.notdefined) 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
ret[i] = string.format('[[Category:%s]]', v)
end
return table.concat(ret, '')
end
return p