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) local v, k = rarity._getTier(index-1) return yesno(short, false) and v.short or k	end --Configuration for the size of the table local lenX = table.length(rarityData) local infoNeededVals = { 'in', 'infoneeded', 'ineeded', 'infon', 'moreinfoneeded', 'moreinfo', 'info needed', 'more info needed', 'more info', 'info n', '?', } local confirmVals = { 'confirm', 'c', 'con', 'conf', 'check', 'not confirmed', 'unconfirmed', 'notconfirmed', } local srcNeededVals = { 'source needed', 'src needed', 'src n', 'sn', 'source n', 'source?', 'souce', 's?', 's', } local blankCellVals = { 'n/a', 'no', 'n', 'none', 'f', 'fal', 'false', '0', '-0', '+0', '-0%', '+0%', '0%', '', 'unapplicable', } local function isNormal(arg) if not table.find(infoNeededVals, arg:lower) and not table.find(blankCellVals, arg:lower) then return true else return false end end

local function processOtherArg(arg) return table.find(infoNeededVals, arg:lower) and string.infoNeeded or table.find(blankCellVals, arg:lower) and string.blankCell or arg end local function extractEndNotice(arg) if arg:match('%s*;%s*') then arg, endNotice = arg:match('(.+)%s*;%s*(.*)') else endNotice = '' end if endNotice ~= '' then endNotice = table.find(confirmVals, endNotice:lower) and  or table.find(srcNeededVals, endNotice:lower) and  or '' end return arg, endNotice end local function processCostArgs(i) if args.cost then local tmp = mw.text.split(args.cost, '%s*,%s*') arg = tmp[i] or '' else arg = args["cost_"..searchTier(i)] or args["cost_"..searchTier(i,true)] or '' end return arg end local function processStatArgs(statname, statlong, statshort) local argShort, argNormal = args['stats_'..statshort], args['stats_'..statlong] if argShort or argNormal then ret = (mw.text.split(argShort or argNormal, '%s*\,%s*')) for j=1, lenX, 1 do				if not ret[j] or ret[j] == '' then ret[j] = string.blankCell end end else ret = {} for j = 1, lenX, 1 do				local r, rshort = searchTier(j), searchTier(j,true) ret[j] = args[statshort..rshort] or args[statshort..r] or args[statlong..r] or args[statlong..rshort] or string.blankCell 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 = lenX, }) :wikitext(string.centerText('Rarity')) :done row:done local row = wikitable:tag('tr') for i = 1, lenX, 1 do		row:tag('th'):wikitext(string.centerText(makeRarity(searchTier(i)))):done if i == lenX then row:done end end for statname, stattable in pairs(statData) do		local statlong = statname:gsub('_', ' ') local statshort = stattable.nameSuperShort:lower argsList = processStatArgs(statname, statlong, statshort) local rowIsEmpty = true for i = 1, lenX, 1 do			if argsList[i] ~= string.blankCell then rowIsEmpty = false end end local row = not rowIsEmpty and wikitable:tag('tr'):tag('td'):wikitext(string.centerText(makeStat(statlong))):done or '' if not rowIsEmpty then for j = 1, 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 stattable.percent or false 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('Cost to apply'):done for i = 1, 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 = 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 table.find(infoNeededVals, arg: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