Module:Infobox non-player character

-- -- Module for Template:Infobox non-player character

local p = {}

-- "imports" local onmain = require('Module:Mainonly').on_main local paramtest = require('Module:Paramtest') local infobox = require('Module:Infobox') local clean_image = require('Module:Clean image').clean

-- Main function called with invokes function p.main(frame) local args = frame:getParent.args local ret = infobox.new(args)

ret:defineParams{ { name = 'name', func = 'name' }, { name = 'image', func = { name = imagearg, params = { 'image', 'imagewidth', 'imageheight', 150, 300 }, flag = { 'd', 'd', 'd', 'r', 'r' } } }, { name = 'release', func = 'release' }, { name = 'removal', func = 'removal' }, { name = 'aka', func = 'has_content' }, { name = 'level', func = 'has_content' }, { 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 = 'features', func = 'has_content' }, { name = 'examine', func = 'has_content' }, { name = 'map', func = maparg },

-- not used; only for categories { name = 'id', func = 'numbers' } }

ret:defineLinks( { links={{ 'Template:%s/FAQ', 'FAQ' },			{ 'Template:%s/doc', 'doc' }} })

ret:create ret:cleanParams

ret:defineName('Infobox non-player character') ret:addClass('infobox-non-player-character')

-- PARAMETER: name ret:addRow{ { tag = 'argh', content = 'name', class='infobox-header', colspan = '20' } }

-- PARAMETER: image ret:addRow{ { tag = 'argd', content = 'image', class='infobox-image', colspan = '20' } }

-- PARAMETER: release -- (update included automatically by infobox) ret:addRow{ { tag = 'th', content = 'Released', colspan = '6' }, { tag = 'argd', content = 'release', colspan = '14' } }

-- PARAMETER: removal if ret:paramDefined('removal') then ret:addRow{ { tag = 'th', content = 'Removal', colspan = '6' }, { tag = 'argd', content = 'removal', colspan = '14' } } end

-- PARAMETER: aka if ret:paramDefined('aka') then ret:addRow{ { tag = 'th', content = 'AKA', colspan = '6' }, { tag = 'argd', content = 'aka', colspan = '14' } } end

-- PARAMETER: level if ret:paramDefined('level') then ret:addRow{ { tag = 'th', content = 'Combat level', colspan = '6' }, { tag = 'argd', content = 'level', colspan = '14' } } end

-- PARAMETER: members ret:addRow{ { tag = 'th', content = 'Members only?', colspan = '6' }, { tag = 'argd', content = 'members', colspan = '14' } }

-- PARAMETER: race ret:addRow{ { tag = 'th', content = 'Race', colspan = '6' }, {tag = 'argd', content = 'race', colspan = '14' } }

-- PARAMETER: quest ret:addRow{ { tag = 'th', content = 'Quest NPC?', colspan = '6' }, {tag = 'argd', content = 'quest', colspan = '14' } }

-- PARAMETER: location ret:addRow{ { tag = 'th', content = 'Location', colspan = '6' }, {tag = 'argd', content = 'location', colspan = '14' } }

-- PARAMETER: shop ret:addRow{ { tag = 'th', content = 'Sells items?', colspan = '6' }, {tag = 'argd', content = 'shop', colspan = '14' } }

-- PARAMETER: gender ret:addRow{ { tag = 'th', content = 'Gender', colspan = '6' }, {tag = 'argd', content = 'gender', colspan = '14' } }

-- PARAMETER: features if ret:paramDefined('features') then ret:addRow{ { tag = 'th', content = 'Notable features', colspan = '6' }, {tag = 'argd', content = 'features', colspan = '14' } } end

-- SECTION: EXAMINE ret:addRow{ { tag = 'th', content = 'Examine', class = 'infobox-subheader', colspan = '20' } }

-- PARAMETER: examine ret:addRow{ { tag = 'argd', content = 'examine', colspan = '20', class = 'infobox-full-width-content' } }

-- PARAMETER: map if ret:paramDefined('map') then ret:addRow{ { tag = 'argd', content = 'map', colspan = '20', class = 'infobox-full-width-content' } } end

if onmain then local a1 = ret:param('all') local a2 = ret:categoryData ret:wikitext(addcategories(a1, a2)) end return ret:tostring end

function imagearg(img, imgw, imgh, w, h)	if infobox.isDefined(imgw) then w = imgw end if infobox.isDefined(imgh) then h = imgh end return clean_image({		file = img,		width = w,		height = h	}) end

function maparg(arg) if not infobox.isDefined(arg) or string.lower(arg) == 'no' then return nil end

if string.find(arg, '%[') then return arg end

local start = string.sub(arg, 1, 5) local filetext = '' if start ~= 'File:' then filetext = 'File:' end return ..filetext..arg.. end

function addcategories(args, catargs) local ret = { 'Non-player characters' }

-- Add the associated category if the parameter has content local defined_args = { aka = 'Pages with AKA', }	for n, v in pairs(defined_args) do		if catargs[n] and catargs[n].one_defined then table.insert(ret, v)		end end

-- Add the associated category if the parameter doesn't have content local notdefined_args = { image = 'Needs image', members = 'Needs members status', release = 'Needs release date', examine = 'Needs examine added', id = 'Needs ID' }	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('', v)		end end

return table.concat(ret, '') end

return p