FANDOM


-- 
-- Part of [[Template:Questreq]]'s implementation
-- For information on how to update this page, please see [[Module talk:Questreq]]
-- <nowiki>
--
 
local p = {}
 
-- Load data from quest list
local quests = mw.loadData('Module:Questreq/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('th')
			:css('text-align','left')
			:wikitext('[[File:Quest.png|21px|link=]] Quests:')
			: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 'Started:' modifier and replace it
		-- If found, set boolean to true
		if quest:find('Started:') then
			quest = quest:gsub('Started:%s*','')
			started = true
		end
		-- Look for quest in the list
		local subreqs = quests[quest]
		if subreqs then
			if started then
				req_name = 'Started ' .. 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 subreqs[1] then
	            if level <= limit 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()
                else
                    req_name = req_name .. '…'
                end
			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('Recipe for Disaster%/') then
			alt = name:gsub('Recipe for Disaster%/','')
		end
 
		name = string.format('[[%s|%s]]',name,alt)
	end
	return name
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.