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, skillMdl = loader.require('String', 'Table', 'Yesno', 'Minion', 'Skillname') local minionData, minionAliases = loader.loadData('Minion/Data', 'Minion/Aliases')

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

local p = {}

function p.minionPageRow(frame) local args = getArgs(frame) return mw.getCurrentFrame:preprocess(p._minionPageRow(args.name or args[1])) end

function p._minionPageRow(name) local minionName = name local minionDt = minionData[minionName] local dropsData = minionDt.drops local rightSideTable = mw.html.create('table'):addClass('wikitable table-margin-off'):css('width', '100%') rightSideTable:tag('th'):wikitext('Condition') rightSideTable:tag('th'):wikitext('Resource') rightSideTable:tag('th'):wikitext('XP') for _, cond in ipairs(minionPageRowParams) do		if dropsData[cond.param] then local dd = dropsData[cond.param] for i, drop in ipairs(dd) do				local row = rightSideTable:tag('tr'):addClass('smalltxt') if i == 1 then row:tag('td'):attr('rowspan', table.length(dd)):wikitext(cond.condition) -- Condition end row:tag('td'):wikitext((''):format(drop.item)) -- Resource -- local experience = drop.exp and drop.exp:match('[%d,%.]+') or 0 -- row:tag('td'):wikitext(():format(experience)) -- XP				row:tag('td'):wikitext(drop.exp and ():format(drop.exp, { iconOnly = true }) or string.blankCell) -- XP			end end end local row1 = mw.html.create('tr'):attr('id', minionName) row1:tag('th'):wikitext((''):format(minionName)) row1:tag('th'):wikitext((' %s Max Tier:  '):format(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({ minionDt.collection and (' Collection: '):format(minionDt.collection) or '', minionDt.obtaining and (' Obtaining: %s '):format(minionDt.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

function p.minionPageRowAll return mw.getCurrentFrame:preprocess(p._minionPageRowAll) end

function p._minionPageRowAll local t = {} for minionName, minionDt in pairs(minionData) do		t[minionDt.type] = t[minionDt.type] or {} table.push(t[minionDt.type], minionName) end local ret = {} for minionType, minionList in pairs(t) do		table.push(ret, ('=== %s ===\n '):format(minionType, table.concat(table.map(minionList, function(v) return p._minionPageRow(v) end), '\n'))) end return table.concat(ret, '\n') end

return p