FANDOM


-- <nowiki>
-- Implements {{Quest navbox}}
 
local p = {}
local navbox = require( 'Module:Navbox' )._navbox
 
function p.main(frame)
	local args = frame:getParent().args
	local groupnr = 1
	nArgs = {}
 
	nArgs.doc = (isNotEmptyOrNil(args.doc) and args.doc or 'yes')
	nArgs.footer = args.footer
	nArgs.title = getIcon(args)..(isNotEmptyOrNil(args.title) and args.title or '[['..args.name..']]')
	nArgs.name = args.name
 
	local seriesoverride = (isNotEmptyOrNil(args['series override']) and args['series override'] or '')
	local seriesline = (isNotEmptyOrNil(seriesoverride) and seriesoverride or getSeriesLine(args))
	if isNotEmptyOrNil(seriesline) then
		nArgs['style'..groupnr] = 'text-align:center;'
		nArgs['group'..groupnr] = seriesline
		groupnr = groupnr + 1
	end
 
	groupnr = showGroup(args, 'npcs', 'NPCs', groupnr)
	groupnr = showGroup(args, 'enemies', 'Enemies', groupnr)
	groupnr = showGroup(args, 'items', 'Items', groupnr)
	groupnr = showGroup(args, 'scenery', 'Scenery', groupnr)
	groupnr = showGroup(args, 'rewards', 'Rewards', groupnr)
	groupnr = showGroup(args, 'locations', 'Locations', groupnr)
	groupnr = showGroup(args, 'music', 'Music', groupnr)
 
	local relatedline = getRelated(args)
	if isNotEmptyOrNil(relatedline) then
		nArgs['gtitle'..groupnr] = (isNotEmptyOrNil(args['related title']) and args['related title'] or 'Miscellaneous')
		nArgs['gtype'..groupnr] = 'subgroup'
		nArgs['group'..groupnr] = relatedline
		groupnr = groupnr + 1
	end
 
	groupnr = showGroup(args, 'historic', getHistoricTitle(args), groupnr)
 
	local cats = ''
	if string.lower(nArgs.doc) == 'yes' then
		cats = frame:expandTemplate{ title = 'Ctg', args = { args.name } }
		local templatecats = (isNotEmptyOrNil(categories(args)) and categories(args) or '')
		cats = cats..(isNotEmptyOrNil(templatecats) and frame:expandTemplate{title = 'Template only', args = {templatecats}} or '')
	end
 
	return navbox(nArgs)..cats
end
 
function getIcon(args)
    local result = ''
    local icon = ''
 
    icon = isNotEmptyOrNil(args.icon) and args.icon or ''
    link = isNotEmptyOrNil(args.iconlink) and args.iconlink or ''
 
    if link == '' then
        link = args.name
    end
 
    if icon == 'yes' then
        result = '[[File:'..args.name..' icon.png|link='..link..'|x20px]]'..'&#32;'
    elseif icon == 'no' then
        result = ''
    elseif icon == '' then
        result = '[[File:Quest.png|link='..link..'|x20px]]'..'&#32;'
    else
        result = '[[File:'..icon..'.png|link='..link..'|x20px]]'..'&#32;'
    end
 
    return result
end
 
function getHistoricTitle(args)
	local historictitle = ''
 
	if string.lower(args['former or replacement'] or '') == 'former' then
		historictitle = 'Replaced by'
	elseif string.lower(args['former or replacement'] or '') == 'replacement' then
		historictitle = 'Former version'
	else
		--do nothing
	end
 
	return historictitle
end
 
function getRelated(args)
	local related = ''
 
	related = (isNotEmptyOrNil(args.related) and args.related or '')
 
	if string.lower(args['quick guide'] or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and ' &bull; ' or '')..'[['..args.name..'/Quick guide|Quick guide]]'
	end
 
	if string.lower(args.transcript or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and ' &bull; ' or '')..'[[Transcript:'..args.name..'|Transcript]]'
	end
 
	return related
end
 
function showGroup(args, groupname, title, groupnr)
	if isNotEmptyOrNil(args[groupname]) then
		nArgs['gtitle'..groupnr] = (isNotEmptyOrNil(args[groupname..' title']) and args[groupname..' title'] or title)
		nArgs['gtype'..groupnr] = 'subgroup'
		nArgs['group'..groupnr] = args[groupname]
		groupnr = groupnr + 1
	end
	return groupnr
end
 
function getSeriesLine(args)
	local series = ''
 
	if isNotEmptyOrNil(args.series) then
		series = getSeries(args.series, args['series number'], args.subquest)
	end
 
	if isNotEmptyOrNil(args.series2) then
		series = series..' &bull; '..getSeries(args.series2, args['series2 number'], '')
	end
 
	if isNotEmptyOrNil(args.series3) then
		series = series..' &bull; '..getSeries(args.series3, args['series3 number'], '')
	end
 
	return series
end
 
function getSeries(series, snumber, subquest)
        local seriesstring = ''
 
	if isNotEmptyOrNil(snumber) then
		seriesstring = '<i>Part '..snumber..' of the '..series..'</i>'
	elseif isNotEmptyOrNil(subquest) then
		local sq = ''
 
		if subquest == 'first' then
			sq = 'Initial'
		elseif subquest == 'final' then
			sq = 'Final'
		else
			sq = 'A'
		end
 
		seriesstring = '<i>'..sq..' subquest of '..series..'</i>'
	else
		seriesstring = '<i>Related to the '..series..'</i>'
	end
 
        return seriesstring
end
 
function categories(args)
	local cats = ''
	local namewithoutarticle = string.match(args.name,'The (.+)') or
					string.match(args.name,'An? (.+)') or
					args.name
 
	if string.lower(args.miniquest or '') == 'yes' then
		cats = '[[Category:Miniquest templates|'..namewithoutarticle..']]'
	elseif string.lower(args['former or replacement'] or '') == 'former' then
		cats = '[[Category:Historic quest templates|'..namewithoutarticle..']]'
	else
		cats = '[[Category:Quest templates|'..namewithoutarticle..']]'
	end
 
	return cats
end
 
function isNotEmptyOrNil(s)
        local bool = false
        bool = (s ~= nil and s ~= '')
        return bool
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.