Module:Questreq

-- -- Part of Template:Questreq's implementation -- For information on how to update this page, please see Module talk:Questreq -- --

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(' 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 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('%(') then			name = name:gsub('(.*)%((.*)%)','%1(%2)|%1')		end		if name:find('Recipe for Disaster%/') then			name = name .. '|' .. name:gsub('Recipe for Disaster%/',)		end		if name:find('Full:') then			name = name:sub(6)		end		name = ..name..''	end	return name end

return p