Module:Collection

local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno = loader.require('String', 'Table', 'Yesno') local collectionData = loader.loadData('Collection/Data')

local p = {}

- -- Template:CollectionTable -- -- Makes a simple table that lists each reward from a collection for use on it's collection page - function p.collectionTable( frame ) local function split(s) return string.split(s, '%s*;%s*') end local function getlist(arg, i)		local temp = arg and split(arg) return temp and (temp[i] or temp[1]) or nil end local args = getArgs(frame) local collection = args['collection'] or args[1] -- get collection data from database local rows = collectionData[collection] -- parse input into the collection data structure if not rows then rows = {} for i = 1, 16 do			local rewards = args['reward'..i]			if rewards then table.push(rows, {					required = args['required' .. i],					reward = table.map(split(rewards), function(reward, j)						return { reward, type = getlist(args['type' .. i], j), comingsoon = getlist(args['comingsoon' .. i], j), link = getlist(args['link' .. i], j), nolink = getlist(args['nolink' .. i], j), }					end),				}) end end end return mw.getCurrentFrame:preprocess(p._collectionTable( collection, rows )) end

function p._collectionTable( collection, colRowData ) local function trim(s) return type(s) == 'string' and string.trim(s) or s	end 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 ipairs(colRowData) do		local tier = string._toRoman(i) local row = wikitable:tag('tr'):attr('id', tier) -- Tier row:tag('td'):css({ ['text-align'] = 'center' }):wikitext(tier):done -- Requirement row:tag('td'):wikitext(string._formatNum(data.required)):done -- Reward local td = row:tag('td') local cellData = {} for i, reward in pairs(data.reward) do			local _name, _type, _comingsoon, _link, _nolink = trim(reward[1]), trim(reward.type or data.type or 'Recipe'), trim(reward.comingsoon or data.comingsoon), trim(reward.link or data.link), trim(reward.nolink or data.nolink) table.push(cellData, getRewardLine(_name, _type, _comingsoon, _link, _nolink)) end td:wikitext(table.concat(cellData, ' ')):done row:done end wikitable:done return tostring(wikitable) end

function getRewardLine(reward, pType, pComingSoon, pLink, pNoLink) local function makeLink(reward, link, nolink) local name = reward nolink = yesno(nolink, false) -- For supplied link, no processing if reward:match('^%[%[.-%]%]$') then return reward end -- Check if it's an enchanted book local enchant, tier = string.match(reward, '^Enchanted Book %((.+) ([%dIVXivx]+)%)$') if enchant then name = ('Enchanted Book &%s %s&'):format(enchant, tier) end -- Output return ():format(link or name, name, nolink and '|nolink=y' or ) end local isExp = pType:lower:match('experience') if isExp then local temp = pType if string.find(pType, ' [eE]xperience$') then temp = (' Experience'):format(string.gsub(pType, '%s*[eE]xperience$', '')) end return ('+%s %s'):format(string._formatNum(reward), temp) else local comingSoonText = yesno(pComingSoon, false) and string.wrapHtml(string.wrapHtml('\'\'\'Coming Soon\'\'\'', 'font', { color = 'red' }), 'sup') or '' local noRewardYet = reward:lower:match('^coming soon$') return ('%s %s %s'):format(			noRewardYet and string.wrapHtml('Coming Soon', 'span', { style = 'color:#FF5555;' }) or makeLink(reward, pLink, pNoLink),			string.wrapHtml(noRewardYet and '' or pType, 'i'),			comingSoonText) end end

-- Finish Module -- return p