Módulo:Missões necessárias

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

A documentação para este módulo pode ser criada em Módulo:Missões necessárias/doc

-- 
-- [[Predefinição:Missões necessárias]]
-- <nowiki>
--

local p = {}

-- Load data from quest list
local quests = mw.loadData('Módulo:Missões necessárias/Data')

-- Main function
function p.main(frame)
	local args = frame:getParent().args
	local quest = args[1]
	local limit = tonumber(args[2]) or 9
	return p._main(quest,limit)
end

function p._main(quest,limit)
	return mw.html.create('table')
			:addClass('mw-collapsible')
			:addClass('mw-collapsed')
			:addClass('questreq')
			:css('background','none')
		:tag('tr')
			:tag('td')
			:css('text-align','left')
			:wikitext(' \'\'\'&nbsp;&nbsp;&nbsp;[[Arquivo:Missão.png|20px]] Missões necessárias\'\'\'')
			:done()
		:done()
		:tag('tr')
			:tag('td')
				:css('padding-left','25px')
				:tag('ul')
					:node( list_reqs(quest,1,limit) )
				:done()
			:done()
		:done()
end

--
-- Recursive list function
-- Level determines how deep the indentation is
-- Replaces 'Started:' modifier
-- If the quest just listed was found in the big list and the limit for level is not reached
-- the quest's requirements will be listed as a sublist 1 level deeper
--
function list_reqs(quest,level,limit)
	local req_name, sub_req_list
	if quest then
		local started
		-- Look for the 'Começado:' modifier and replace it
		-- If found, set boolean to true
		if quest:find('Começado:') then
			quest = quest:gsub('Começado:%s*','')
			started = true
		end
		-- Look for quest in the list
		local subreqs = quests[quest]
		if subreqs then
			if started then
				req_name = 'Começado ' .. tidy_link(quest)
			else
				req_name = tidy_link(quest)
			end
			-- For every requirement, call this function again
			-- Handled the same, but 1 level deeper
			-- If limit is reached, denote extra requirements exist with ellipses
			if level <= limit then
				if subreqs[1] then
					sub_req_list = mw.html.create('ul')
					for i, q in ipairs(subreqs) do
						local sub_list = list_reqs(q,level+1,limit)
						sub_req_list:node(sub_list)
					end
					sub_req_list:done()
				end
			else
				req_name = req_name .. '…'
			end
		else
		-- If the requirement can't be found in the big list
		-- Paste it as is and skip any attempt to make a sublist
			req_name =  quest
		end
	end

	local ret = mw.html.create('li')
				:wikitext(req_name)

	if sub_req_list then
		ret:node(sub_req_list)
	end

	return ret:done()
end

--
-- Function to tidy quest names into links
-- Any parenthetical (e.g. '(quest)') will be removed from the text, but remain in the link
-- 'Recipe for Disaster/' will be replaced in the RfD subquests, so that only the subquest name appears as text
-- Returns a link
-- The 'Full:' modifier is removed
--
function tidy_link(name)
	if name then
		if name:find('Full:') then
			name = name:sub(6)
		end
		local alt = name:match('(.*)%(.*%)') or name

		if name:find('A Receita do Desastre%/') then
			alt = name:gsub('A Receita do Desastre%/','')
		end

		name = string.format('[[%s|%s]]',name,alt)
	end
	return name
end

return p