Module:Infobox Quest

-- -- Module for Template:Infobox Quest

local p = {}

local onmain = require('Module:Mainonly').on_main local yesno = require('Module:Yesno') local paramtest = require('Module:Paramtest') local infobox = require('Module:Infobox') local cleanimg = require('Module:Clean image').clean local commas = require('Module:Addcommas')._add

-- 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 = 'startshop', func = 'has_content' }, { name = 'minlevel', func = { name = levelarg, params = { 'minlevel' } } }, { name = 'maxlevel', func = { name = levelarg, params = { 'maxlevel' } } }, { name = 'rponly', func = { name = yesnoparam, params = { 'rponly' } } }, { name = 'precededby', func = 'has_content' }, { name = 'succeededby', func = 'has_content' }, { name = 'id', func = { name = iddisp, params = { 'id' }, flag = 'p' } }, }

ret:create ret:cleanParams

ret:defineLinks({ links = {{ 'Template:%s/doc', 'Infobox' },		{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })

ret:defineName('Infobox Quest') ret:addButtonsCaption -- PARAMETER: name ret:addRow{ { tag = 'argh', content = 'name', class='infobox-header', colspan = '2' } }	-- PARAMETER: startshop ret:addRow{ { tag = 'th', content = 'Start' }, { tag = 'argd', content = 'startshop' } }	-- PARAMETER: minlevel ret:addRow{ { tag = 'th', content = 'Min level' }, { tag = 'argd', content = 'minlevel' } }	-- PARAMETER: maxlevel ret:addRow{ { tag = 'th', content = 'Max level' }, { tag = 'argd', content = 'maxlevel' } }	-- PARAMETER: rponly ret:addRow{ { tag = 'th', content = 'RP only' }, { tag = 'argd', content = 'rponly' } }	if ret:paramDefined('precededby') or ret:paramDefined('succeededby') then ret:addRow{ { tag = 'th', content = 'Chain', class = 'infobox-subheader', colspan = '2' } }		if ret:paramDefined('precededby') then ret:addRow{ { tag = 'th', content = 'Preceded by' }, { tag = 'argd', content = 'precededby' } }		end if ret:paramDefined('succeededby') then ret:addRow{ { tag = 'th', content = 'Succeeded by' }, { tag = 'argd', content = 'succeededby' } }		end end ret:addRow{ { tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '2' }, meta = {addClass = 'advanced-data'} }

-- PARAMETER: id	:addRow{ { tag = 'th', content = 'ID' }, { tag = 'argd', content = 'id' }, meta = {addClass = 'advanced-data'} }	ret:finish if onmain then local a1 = ret:param('all') local a2 = ret:categoryData ret:wikitext(addcategories(a1, a2)) end return ret:tostring end

function levelarg(c) if type(c) ~= 'number' then c = tonumber(c,10) or 0 end

if c == -1 then --c == 0 or		return '-' -- all other numbers elseif c > -1 then return commas(c) -- not a number = nil -- shouldn't be used, but it's a fallback else return nil end end

function yesnoparam(p) if infobox.isDefined(p) then local b = yesno(p) if b then return 'Yes' elseif not b then return 'No' else return nil end end return nil end

function iddisp(id) if infobox.isDefined(id) then if id:lower ~= 'no' then local r = string.gsub(id, ', *', ', ') return r		elseif id:lower == 'no' then return 'None' end end return nil end

function addcategories(args, catargs) local ret = { 'Quests' } local cat_map = { -- Added if the parameter has content defined = { precededby = 'Chain quests', succeededby = 'Chain quests', },		-- Added if the parameter has no content notdefined = { id = 'Needs ID', },	}	-- Run and add mapped categories for n, v in pairs(cat_map.defined) do		if catargs[n] and catargs[n].one_defined then table.insert(ret,v) end end 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		if (v ~= '') then ret[i] = string.format('', v)		end end

return table.concat(ret, '') end

return p