Módulo:Quest navbox

De RuneScape Wiki
Ir para: navegação, pesquisa

A documentação para este módulo pode ser criada em Módulo:Quest navbox/doc

-- <nowiki>
-- Implements {{Quest navbox}}

local p = {}
local navbox = require( 'Módulo: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 = (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', 'Inimigos', groupnr)
	groupnr = showGroup(args, 'items', 'Objetos', groupnr)
	groupnr = showGroup(args, 'scenery', 'Cenário', groupnr)
	groupnr = showGroup(args, 'rewards', 'Recompensas', groupnr)
	groupnr = showGroup(args, 'locations', 'Locais', groupnr)
	groupnr = showGroup(args, 'music', 'Música', groupnr)

	local relatedline = getRelated(args)
	if isNotEmptyOrNil(relatedline) then
		nArgs['gtitle'..groupnr] = (isNotEmptyOrNil(args['related title']) and args['related title'] or 'Miscellaneous')
		
		if string.match(string.lower(relatedline), "navbox") then
			nArgs['gtype'..groupnr] = 'subgroup'
		end
		
		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 getHistoricTitle(args)
	local historictitle = ''

	if string.lower(args['former or replacement'] or '') == 'former' then
		historictitle = 'Substituído por'
	elseif string.lower(args['former or replacement'] or '') == 'replacement' then
		historictitle = 'Versão antiga'
	else
		--do nothing
	end

	return historictitle
end

function getRelated(args)
	local related = ''

	related = (isNotEmptyOrNil(args.related) and args.related or '')

	if string.lower(args['achievement'] or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and '\n' or '')..' * [['..args.name..' (conquista)|Conquista]]'
	end
	
	if string.lower(args['quick guide'] or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and '\n' or '')..' * [['..args.name..'/Guia rápido|Guia rápido]]'
	end

	if string.lower(args.transcript or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and '\n' or '')..' * [[Transcrição:'..args.name..'|Transcrição]]'
	end

	if string.lower(args.journal or '') == 'no' then
		--do nothing
	else
		related = related..(isNotEmptyOrNil(related) and '\n' or '')..' * [[Transcrição:'..args.name..'/Journal|Quest journal]]'
	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)
		
		if string.match(string.lower(args[groupname]), "navbox") then
			nArgs['gtype'..groupnr] = 'subgroup'
		end
		
		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>Parte '..snumber..' da '..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..' sub-missão da '..series..'</i>'
	else
		seriesstring = '<i>Relacionada à '..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 = '[[Categoria:Predefinições de minimissões|'..namewithoutarticle..']]'
	elseif string.lower(args['former or replacement'] or '') == 'former' then
		cats = '[[Categoria:Predefinições de missão histórica|'..namewithoutarticle..']]'
	else
		cats = '[[Categoria:Predefinições de missão|'..namewithoutarticle..']]'
	end
	
	return cats
end

function isNotEmptyOrNil(s)
        local bool = false
        bool = (s ~= nil and s ~= '')
        return bool
end

return p