Module:Collection

-- local p = {} local yesno = require('Module:Yesno') local string = require('Module:String')

local TIERS = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI" } local TIERS_NUM = { ["I"]=1, ["II"]=2, ["III"]=3, ["IV"]=4, ["V"]=5, ["VI"]=6, ["VII"]=7, ["VIII"]=8, ["IX"]=9, ["X"]=10, ["XI"]=11, ["XII"]=12, ["XIII"]=13, ["XIV"]=14, ["XV"]=15, ["XVI"]=16 } function p.toTierNum(val) val = mw.text.trim(val) return tonumber(TIERS_NUM[string.upper(val)] or val) end

- -- Template:CollectionList -- -- Makes a simple table that lists each reward from a collection for use on it's collection page - function p.collectionTable( frame ) --local parameters = frame.args local args = frame:getParent.args local collection = args["collection"] local rows = {} for i = 1,16,1 do        if args["reward"..i] then rows[#rows+1] = { TIERS[i], args["required"..i], args["reward"..i], rewardType=args["type"..i] or "Recipe", cs=args["comingsoon"..i], nolink=args["nolink"..i], }       end end return p._collectionTable( collection, rows ) end function p._collectionTable( collection, colRowData ) local lang = mw.language.getContentLanguage local wikitable = mw.html.create('table'):addClass('wikitable') local row = wikitable:tag("tr") row:tag("th"):wikitext("LVL"):done row:tag("th"):wikitext(" Required "):done row:tag("th"):wikitext("Reward"):done row:done for i,data in pairs(colRowData) do	   local row = wikitable:tag("tr"):attr("id", data[1]) -- Tier row:tag("td"):css({ ["text-align"]="center" }):wikitext(data[1]):done -- Requirement row:tag("td"):wikitext(string._formatNum(data[2])):done -- Reward local rewardType = data.rewardType or "" local comingSoon = data.cs or "" local nolink = data.nolink or 'no' local rewards = mw.text.split(data[3], ";"); if #rewards == 1 then row:tag("td"):wikitext(collTableGetRewardLine(lang, data[3], rewardType, comingSoon, nolink)):done else local rewardTypes = mw.text.split(rewardType, ";"); local comingSoons = mw.text.split(comingSoon, ";"); local nolinks = mw.text.split(nolink, ";"); local td = row:tag("td") local cellData = {} for i,reward in pairs(rewards) do               reward = mw.text.trim(reward) local rewardTypeSub = mw.text.trim(rewardTypes[i] or rewardType) local comingSoonSub = mw.text.trim(comingSoons[i] or comingSoon) local nolinkSub = mw.text.trim(nolinks[i] or nolink) cellData[#cellData+1] = collTableGetRewardLine(lang, reward, rewardTypeSub, comingSoonSub, nolinkSub) end td:wikitext(table.concat(cellData, " ")):done end row:done end wikitable:done return tostring(wikitable) end -- If the reward is a special link, parse it. Otherwise return it back function collectionTableRewardToLink(reward, nolink) -- Check if it's a supplied link if reward:match('^%[%[.-%]%]$') then return reward end local nolink = yesno(nolink, false) -- Check if it's a coming soon if string.trim(reward:lower):match('coming soon') then return (string.wrapHtml('Coming Soon','span',{style='color:#FF5555;'})) end -- Check if it's an enchanted book enchant, tier = string.match(reward, "^Enchanted Book %((.+) ([%dIVXivx]+)%)$") if enchant then return nolink and ("Enchanted Book (%s %s)"):format(enchant, tier) or ("Enchanted Book (%s %s)"):format(enchant, enchant, tier) end return nolink and reward or ("%s"):format(reward) end function collTableGetRewardLine(lang, reward, pType, pComingSoon, pNoLink) local isExp = not not string.find(string.lower(pType), "experience") if isExp then local mytype = pType if string.find(pType, " [eE]xperience$") then mytype = ""..string.gsub(pType, " [eE]xperience$", "").." Experience" end return "+"..string._formatNum(reward).." "..mytype else local comingSoon = yesno(pComingSoon, false) and string.wrapHtml(string.wrapHtml("Coming Soon",'font',{color='red'}), 'sup') or "" return ('%s %s %s'):format(collectionTableRewardToLink(reward, pNoLink), string.wrapHtml(pType,'i'), comingSoon) end end

-- Finish Module -- return p