Module:Sandbox/MonkeysHK/4

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

local string, table, yesno, minionMdl = loader.require('String', 'Table', 'Yesno', 'Minion') local minionAliases = loader.loadData('Minion/Aliases')

local minionPageRowParams = minionAliases.minionPageRowParams local arrowSymbol = '➜'

local p = {}

-- utility function local function parseXPList(list, condition) local ls = mergeArgsSyntax({ list }) local res = {} for _, v in ipairs(ls) do		local item, xp = v:match('^%s*(.-)%s*([%d%.]+)%s*$') if item and xp then table.push(res, { item, xp }) end end return table.concat(table.map(res, function(v, i)		local td = ('   '):format(v[1], v[2]) if i == 1 then return (' %s %s '):format(#res, condition, td) else return (' %s '):format(td) end end)) end

function p.minionPageRow(frame) local args = getArgs(frame) return mw.getCurrentFrame:preprocess(p._minionPageRow(args)) end

function p._minionPageRow(args) local minionName = args.name local rightSideTable = mw.html.create('table'):addClass('wikitable table-margin-off') local ls = { ' Condition  Resources  XP  ' }	for _, v in ipairs(minionPageRowParams) do		if args[v.param] then table.push(ls, parseXPList(args[v.param], v.condition)) end end rightSideTable:wikitext(table.concat(ls)) local row1 = mw.html.create('tr') row1:tag('th'):wikitext((''):format(minionName)) row1:tag('th'):wikitext((' Max Tier:   '):format(minionName, minionName, minionName, string._toRoman(minionMdl._getMinionData(minionName, 'tiers')))) row1:tag('td'):addClass('table-margin-off'):attr('rowspan', 2):node(rightSideTable) local row2 = mw.html.create('tr') row2:tag('td'):attr('colspan', 2):wikitext(table.concat({ args.collection and (' Collection: '):format(args.collection) or '', args.obtaining and (' Obtaining: %s '):format(args.obtaining) or '', (' Cooldown: %s%s%ss '):format(			minionMdl._getMinionData(minionName, 'time between actions', 'max'),			arrowSymbol,			minionMdl._getMinionData(minionName, 'time between actions', 1)		), (' Storage: %s%s%ss'):format(			minionMdl._getMinionData(minionName, 'storage', 'max'),			arrowSymbol,			minionMdl._getMinionData(minionName, 'storage', 1)		), }))	return tostring(row1) .. tostring(row2) end

return p