Module:Reward/ForgingBonds

local Reward = require 'Module:Reward' local RewardText = require 'Module:RewardText' local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local parseArgs = require 'Module:ObjectArg'.parse

local FB_COLORS = {'Red', 'Orange', 'Green', 'Blue'}

local main = function (args, frame) local wikiname = args.wikiname if not wikiname then return require 'Module:Error'.error('The "wikiname" parameter is missing.') end

local allRewards = {} for _, col in ipairs(FB_COLORS) do		local rewards, err = parseArgs(args[col] or '') if err then return require 'Module:Error'.error(err) elseif type(rewards) ~= 'table' then return require 'Module:Error'.error('Invalid reward format.') end

local rewardList = {} for k, v in pairs(rewards) do			local score = tonumber(k) if score then local reward, err = Reward.normalize(v) if err then return require 'Module:Error'.error(err) end rewardList[#rewardList + 1] = { score, RewardText._main({reward, size = args.iconsize, iconfirst = '1'}, frame), List.any(reward, function (r) return r.kind == 'Forging Bonds conversation' or r.kind == 'Accessory' end), }				Reward.define(reward, 'ForgingBonds', {wikiname = wikiname, color = mw.ustring.lower(col), score = score}, frame) end end

table.sort(rewardList, function (x, y) return x[1] < y[1] end) allRewards[col] = rewardList end

local lang = mw.language.getContentLanguage

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('reward-table'):css('text-align', 'center') local tr = tbl:tag('tr') for i, col in ipairs(FB_COLORS) do		if i > 1 then tr:tag('th'):attr('rowspan', 0):css('width', '.5em'):css('padding', '0') end tr:tag('th'):attr('colspan', '2'):attr('scope', 'colgroup'):wikitext((''):format(col)) end

tr = tbl:tag('tr') for i, col in ipairs(FB_COLORS) do		tr:tag('th'):wikitext('Points') tr:tag('th'):addClass('reward-table-header'):wikitext('Reward') end

local rowCount = select(2, List.max(List.map(Hash.values(allRewards), function (v) return #v end))) for y = 1, rowCount do		tr = tbl:tag('tr') for _, col in ipairs(FB_COLORS) do			local scoreCell = tr:tag('td') local rewardCell = tr:tag('td') local v = allRewards[col] and allRewards[col][y] if v then if v[3] then scoreCell = scoreCell:css('background', '#ee9'):tag('b') rewardCell:css('background', '#ee9') end scoreCell:wikitext(lang:formatNum(v[1])) rewardCell:wikitext(v[2]) end end end

return tostring(tbl) end

return require 'Module:MakeMWModule'.makeMWModule {main = main}