Module:Sandbox/TheTrueShaman

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

local string, table, yesno = loader.require('String', 'Table', 'Yesno')

local p = {}

local collectionData local function getData if collectionData then return collectionData else collectionData = loader.loadData('Collection/Data') return collectionData end end

- -- 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] or mw.title.getCurrentTitle.fullText -- get collection data from database local rows = table.deepCopy(getData[collection] or {}, true) -- parse input into the collection data structure for i = 1, 16 do		local rewards = args['reward'..i]		if rewards then rows[i] = { 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 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 margin-centered') 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'):addClass('centertxt'):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) local pet = string.match(reward, 'Pet/g') if pet then name = 'This works maybe' return name end -- 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:match('[Ee]xperience') local unknownType = not not pType:match('[Cc]oming [Ss]oon') pComingSoon = unknownType or yesno(pComingSoon, false) 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 = pComingSoon and string.wrapHtml(string.wrapHtml('\'\'\'Coming Soon\'\'\'', 'span', { class = 'color-red' }), 'sup') or '' local noRewardYet = reward:lower:match('^coming soon$') return ('%s %s %s'):format(			noRewardYet and string.wrapHtml('Coming Soon', 'span', { class = 'color-red' }) or makeLink(reward, pLink, pNoLink),			string.wrapHtml((noRewardYet or unknownType) and '' or pType, 'i'),			comingSoonText) end end

-- Finish Module -- return p