Module:Challenges

-- local p = {}

local data = require("Module:Challenges/Data") local all_challenges = data.challenges

Infobox local infobox_template = [=[]=]

function p.Infobox(frame) local challenge_name = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle.text if challenge_name == "...Maybe One More" or challenge_name == "Pause" then challenge_name = challenge_name .. "." elseif challenge_name == "REDACTED" then challenge_name = "[" .. challenge_name .. "]" end local challenge = all_challenges[challenge_name] return frame:preprocess(infobox_template:format( challenge_name, challenge.Desc:gsub("\r\n", " "):gsub("\u(%x%x%x%x)", function(s) return mw.ustring.char(tonumber(s, 16)) end), #challenge.Unlock == 1 and (challenge_name:match(":") and "2 = " .. challenge.Unlock[1] .. "\r\n| image = " .. challenge.Unlock[1] .. ".png" or " = " .. challenge.Unlock[1]) or "2 = " .. challenge.Unlock[1] .. " & " .. challenge.Unlock[2] .. "\r\n| image = " .. challenge.Unlock[1] .. ".png\r\n| image2 = " .. challenge.Unlock[2] .. ".png" )) end

Table local table_head = [=[{| class="wikitable sortable floatheader" style="width:100%;max-width:900px" ! style="width:20%" | Challenge ! class="unsortable" | Description ! style="width:20%" | Unlocks ]=]

local table_row = [=[|- ]=]
 * %s
 * %s
 * style="text-align:center;white-space:nowrap" data-sort-value="%s" | %s

function p.Table(frame) local type = frame.args[1] local table = table_head local t = type == "Skins" or type == "Artifacts" for i, challenge in ipairs(Sort(all_challenges)) do   if challenge.Type == type then table = table .. frame:preprocess(table_row:format( t and challenge.Name or "%1."):gsub("^%[(.+)%]$", "%1|[%1]") .. "", challenge.Desc:gsub("\r\n", " "):gsub("\u(%x%x%x%x)", function(s) return mw.ustring.char(tonumber(s, 16)) end), challenge.Unlock[1], Unlock(challenge.Unlock, type, challenge.Name) ))   end end return table .. "|}" end

Unlock local unlock_base = "%s" local unlock_base_alt = "%s" local unlock_two = "%s %s "

function Unlock(u, type, name) local unlock if type == "Skills" then local s = name:gsub(": .+", "#" .. u[1]) unlock = unlock_base_alt:format(u[1]:gsub(":", ""), s, s, u[1]) elseif type == "Skins" then local s = name:gsub(": .+", "#Gallery") unlock = unlock_base_alt:format(u[1], s, s, u[1]) elseif type == "Artifacts" then unlock = unlock_base_alt:format(u[1], "Artifacts", "Artifacts", u[1]) else if #u == 1 then unlock = unlock_base:format(u[1], u[1], u[1]) else unlock = unlock_two:format(unlock_base:format(u[1], u[1], u[1]), unlock_base:format(u[2], u[2], u[2])) end end return unlock end

Sort function Sort(list) local challenges = {} for name, challenge in pairs(list) do   challenge.Name = name table.insert(challenges, challenge) end table.sort(challenges, function(a, b) return a.Name < b.Name end) return challenges end

return p --