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 reqData = mw.loadData('Module:Questreq/data')

-- Main function function p.main(frame) local args = frame:getParent.args local name = args[1] local req = args[2] local option if req == 'quests' then option = tonumber(args[3]) or 9 else option = args[3] end local closed = args[4] ~= 'open' return p._main(name,req,option,closed) end

function p._main(name,req,option,closed) -- someone better than me at Lua can make this function prettier with switchtables and whatnot if req == 'quests' then return p._main_quests(name,option,closed) elseif req == 'skills' then return p._main_skills(name) elseif req == 'ironmanskills' then elseif req == 'recommended' then elseif req == 'other' then else return 'failed p._main in Module:Questreq' end end

function p._main_quests(quest,limit,closed) local closedCss = '' if closed then closedCss = 'mw-collapsed' else closedCss = 'mw-open' end return mw.html.create('table') :addClass('mw-collapsible') :addClass(closedCss) :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 = reqData[quest]['quests'] 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',name,alt) end return name end

function p._main_skills(name) -- Look for skill reqs in quest local subreqs = reqData[name]['skills'] --construct a list of skill reqs local skill_reqs_template = '' local skill_reqs = '' for key, val in pairs(subreqs) do      skill_reqs = skill_reqs .. string.format(skill_reqs_template, key, val) .. '\n' end return skill_reqs end

return p