Module:Reforge

require('Module:LoadLib')(_G, {	rarityData = 'Module:RarityTier/Data',	statData = 'Module:Statname/Data', })

local p = {}

- -- Template:Reforge Stone Table -- -- Creates a table that formats the cost of a reforge stone - function p.reforgeStoneTable(frame) local args = getArgs(frame) local function searchTier(index, short) for k,v in pairs(rarityData) do			if v.order + 1 == index then return yesno(short, false) and v.short or k			end end end local statsMap = table.map(table.keys(statData), function(d)		return d:gsub(' ','_')	end) local statsMapShort = table.map(table.values(statData), function(d)		return d.nameSuperShort:lower	end) local statsListShowPerc = table.map(table.values(statData), function(d)		return d.percent or false	end) --Configuration for the size of the table local config = { lenX = #rarityData, lenY = #statsMapShort, }	local infoNeededVals = { ['in']=1, ['infoneeded']=1, ['ineeded']=1, ['infon']=1, ['moreinfoneeded']=1, ['moreinfo']=1, ['info needed']=1, ['more info needed']=1, ['more info']=1, ['info n']=1, ['?']=1,	}	local confirmVals = { ['confirm']=1, ['c']=1, ['con']=1, ['conf']=1, ['check']=1, ['not confirmed']=1, ['unconfirmed']=1, ['notconfirmed']=1, }	local srcNeededVals = { ['source needed']=1, ['src needed']=1, ['src n']=1, ['sn']=1, ['source n']=1, ['source?']=1, ['souce']=1, ['s?']=1, ['s']=1, }	local blankCellVals = { ['n/a']=1, ['no']=1, ['n']=1, ['none']=1, ['f']=1, ['fal']=1, ['false']=1, ['0']=1,		['-0']=1,		['+0']=1,		['-0%']=1,		['+0%']=1,		['0%']=1,		['']=1,		['unapplicable']=1, }	local function isNormal(arg) if not infoNeededVals[arg:lower] and not blankCellVals[arg:lower] then return true else return false end end

local function processOtherArg(arg) if infoNeededVals[arg:lower] then ret = string.infoNeeded elseif blankCellVals[arg:lower] then ret = string.blankCell

else ret = arg end return ret end local function extractEndNotice(arg) if arg:match('%s*;%s*') then arg, endNotice = arg:match('(.+)%s*;%s*(.*)') else endNotice = '' end if endNotice ~= '' then if confirmVals[endNotice:lower] then endNotice = '' elseif srcNeededVals[endNotice:lower] then endNotice = '' else endNotice = '' end end return arg, endNotice end local function processCostArgs(i) local argCase1 = args["cost_"..searchTier(i)] local argCase2 = args["cost_"..searchTier(i,true)] local argStorage = argCase1 or argCase2 if args["cost"] then local tmp = mw.text.split(args["cost"], '%s*,%s*') arg = tmp[i] else arg = argStorage or "" end return arg end local function processStatArgs(i) local argShort = args['stats_'..statsMap[i]] local argNormal = args['stats_'..statsMapShort[i]] if argNormal or argShort then ret = (mw.text.split(argNormal or argShort, '%s*\,%s*')) for j=1, config.lenX, 1 do						if not ret[j] or ret[j] == '' then ret[j] = string.blankCell end end else ret = {} for j=1, config.lenX ,1 do					local argCase1 = args[statsMapShort[i]..'_'..searchTier(i)] local argCase2 = args[statsMapShort[i]..'_'..searchTier(i,true)] local argCase3 = args[statsMap[i]..'_'..searchTier(i)] local argCase4 = args[statsMap[i]..'_'..searchTier(i,true)] local argRet = argCase2 or argCase1 or argCase3 or argCase4 ret[j] = argRet if not ret[j] then ret[j] = string.blankCell end end end return ret end local wikitable = mw.html.create('table'):addClass('wikitable') local row = wikitable:tag('tr') row:tag('th') :attr({ rowspan=2 }) :wikitext(string.centerText('Stat Bonus')) :done row:tag('th') :attr({ colspan=config.lenX, }) :wikitext(string.centerText('Rarity')) :done row:done local row = wikitable:tag('tr') for i=1, config.lenX, 1 do

row:tag('th'):wikitext(string.centerText(makeRarity(searchTier(i)))):done if i == config.lenX then row:done end end for i=1, config.lenY, 1 do		argsList = processStatArgs(i) local rowIsEmpty = (argsList[1] == string.blankCell 			and argsList[2] == string.blankCell 			and argsList[3] == string.blankCell 			and argsList[4] == string.blankCell 			and argsList[5] == string.blankCell 			and argsList[6] == string.blankCell) local row = not rowIsEmpty and wikitable:tag('tr'):tag('td'):wikitext(string.centerText(makeStat(statsMap[i]))):done or '' if not rowIsEmpty then for j=1, config.lenX, 1 do 				local arg, endNotice = extractEndNotice(argsList[j]) if isNormal(arg) and arg:match('([^%d%%%-%+%.%,]+)') then arg = arg end

row:tag('td') :wikitext(string.centerText( (isNormal(arg) and not arg:match('([^%d%%%-%+%.%,]+)')) and makeColor(							'green', 							arg:gsub('^([%+%-]*)(%d+)(%%?)$', function(prep, d)									local pattern = tostring(d) if statsListShowPerc[i] then pattern = pattern..'%' end return (prep == '-' and prep or '+')..pattern end )						)..endNotice or processOtherArg(arg) )):done end row:done end end local row = wikitable:tag('tr') row:tag('th'):wikitext(table.concat{'Cost to apply (in ', tostring(coins), ')'}):done for i=1, config.lenX, 1 do		local arg, endNotice = extractEndNotice(processCostArgs(i)) row:tag('td'):wikitext(			((arg and isNormal(arg)) and string.centerText(				tostring(coins{ arg, nil, true })..endNotice			) or processOtherArg(arg) ))	end local specialEffect = args["special effect"] or args["specialeff"] or args["special"] or args["eff"] or args["se"] if specialEffect then local name, desc = specialEffect:match('([%a ]+)%s*;%s*(.+)') local varStrs = desc:match(';\n') and mw.text.split(desc:match('.+;\n(.+)'), '%s*,%s*') local desc = varStrs and desc:match('(.+);\n.+') or desc local desc = desc :gsub('\n', ' ') local copy if varStrs then local showPerc = table.some(varStrs, 					function(_, v) 						return v:match('%%')					end				) if showPerc then copy = table.from(varStrs) table.each(varStrs, function(v, i, t)					t[i] = v:gsub('%%', '')				end) else copy = table.from(varStrs) end desc = desc:gsub('$VALUES', function				return makeColor('Green', { '+', 					table.concat(varStrs, '/'), showPerc and '%' or '', })			end) end local row = wikitable:tag('tr') row:tag('th') :wikitext('Reforge Special Effect') :done row:tag('td') :attr({ colspan=config.lenX }) :wikitext(table.concat{					makeColor('Blue', name),					': ',					desc,				}) :done row:done if varStrs then local row = wikitable:tag('tr') row:tag('th') :wikitext('Reforge Special effect values') :done for i = 1, table.length(varStrs), 1 do				mw.log(varStrs[i]) end for i, v in pairs(varStrs) do				local t = varStrs if infoNeededVals[v:lower] then t[i] = string.infoNeeded end end for i, v in ipairs(copy) do				row:tag('td') :wikitext((v ~= string.blankCell and v ~= string.infoNeeded) and makeColor('Green', v) or v)				:done end row:done end end wikitable:done wikitable = string.wrapHtml(tostring(wikitable), 'div', {class='article-scrollable', style='overflow-x: auto;'}) return frame:preprocess(tostring(wikitable)) end

--Finish Module return p