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 allData, allStats, allRarities = {}, {}, 0 -- allRarities is a number that stores the existence of every rarity in a binary way -- if 'common' exists, 2^0 (=1) is added; if 'uncommon' exists, 2^1 (=2) is added, etc.	local function statExt(s) return not not table.find(allStats, s)	end local function rarityExt(i) -- extract in a binary way whether one value exists -- here, for 'common', i = 0 if type(i) == 'string' then i = rarity._getTier(i).order end return math.floor(allRarities / (2^i)) % 2 == 1 end 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 searchTier(index, short) local v, k = rarity._getTier(index-1) return yesno(short, false) and v.short or k	end 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) if table.find(blankCellVals, arg:lower) then return end return table.find(infoNeededVals, arg:lower) and string.infoNeeded 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*')) else ret = {} for j = 1, table.length(rarityData), 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] end end return ret end local function dataProcessing -- main function to build allData table for rKey, rTable in rarity._getTierIterable do			table.insert(allData, { rKey }) end for statname, stattable in pairs(statData) do			local statlong = statname:gsub('_', ' ') local statshort = stattable.nameSuperShort:lower argsList = processStatArgs(statname, statlong, statshort) for j = 1, table.length(rarityData), 1 do				if argsList[j] then local arg, endNotice = extractEndNotice(argsList[j]) allData[j][statname] = (isNormal(arg) and not arg:match('([^%d%%%-%+%.%,]+)')) and ('%s%s'):format(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) if allData[j][statname] then if not statExt(statname) then table.insert(allStats, statname) end if not rarityExt(j-1) then allRarities = allRarities + 2^(j-1) end end end end end end local function trimdata -- removes all unused rarities do local i = 1 while i <= #allData do				local key = allData[i][1] if rarityExt(key) then i = i + 1 else table.remove(allData, i)				end end end end dataProcessing mw.logObject(allData) trimdata mw.logObject(allData) local lenX = #allData -- Process all data from main table 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(('%s%s'):format(			-- handles first rarity as ' (or below)' if it is not 'Common'			-- handles last rarity as ' (or above)' if it is not 'Very Special'			makeRarity(allData[i][1]),			i == 1 and allData[i][1] ~= 'common' and string.wrapHtml(' (or below)', 'small')			or i == lenX and allData[i][1] ~= 'very_special' and string.wrapHtml(' (or above)', 'small')			or ''		))):done if i == lenX then row:done end end for _, statname in ipairs(allStats) do		local statlong = statname:gsub('_', ' ') local row = wikitable:tag('tr'):tag('td'):wikitext(string.centerText(makeStat(statlong))):done for j = 1, lenX, 1 do			local score = allData[j][statname] row:tag('td'):wikitext(score and string.centerText(score) or string.blankCell):done end row:done end local row = wikitable:tag('tr') row:tag('th'):wikitext('Cost to apply'):done for i = 1, lenX, 1 do		row:tag('td'):wikitext(allData[i].__cost or string.blankCell):done end -- Process reforge special effect 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) -- creates an alias (shallow copy) of varStrs table.each(varStrs, function(v, i, t)					t[i] = v:gsub('%%', '')				end) else copy = table.from(varStrs) -- creates an alias (shallow copy) of 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 -- Process reforge special effect values if varStrs then local row = wikitable:tag('tr') row:tag('th') :wikitext('Reforge Special Effect Values') :done for i, v in pairs(varStrs) do				local t = varStrs if table.find(infoNeededVals, arg:lower) then t[i] = string.infoNeeded elseif table.find(blankCellVals, arg:lower) then t[i] = string.blankCell else t[i] = makeColor('Green', v)				end end for i, v in ipairs(copy) do				row:tag('td'):wikitext(v):done end row:done end end wikitable:done wikitable = string.wrapHtml(tostring(wikitable), 'div', {class='article-scrollable', style='overflow-x: auto;'}) return mw.getCurrentFrame:preprocess(tostring(wikitable)) end

return p