Anonymous

Module:GolbinRaid: Difference between revisions

From Melvor Idle
getRaidModifierList: Condense modifiers of the same base name into a single row
(getRaidModifierList: Initial implementation)
(getRaidModifierList: Condense modifiers of the same base name into a single row)
Line 82: Line 82:


function p.getRaidModifierList()
function p.getRaidModifierList()
local modList = {}
for i, modDet in ipairs(RaidData.PossibleModifiers) do
local baseName, modText, modSign, isNeg, isUnsigned = Constants.getModifierDetails(modDet.key)
local prefix = ''
if Shared.startsWith(baseName, 'increased') or Shared.startsWith(baseName, 'decreased') then
prefix = string.sub(baseName, 1, 9)
end
if modList[baseName] == nil then
local modVal = {1, 5}
local mult = modDet.multiplier
if mult ~= nil then
modVal = {modVal[1] * mult, modVal[2] * mult}
end
modText = Constants._getModifierText(modDet.key, modVal, false)
modList[baseName] = {modText, ["ord"] = i, ["sign"] = {modSign}}
else
table.insert(modList[baseName]['sign'], modSign)
end
end
local resultTable = mw.html.create('table')
local resultTable = mw.html.create('table')
resultTable:addClass('wikitable'):addClass('stickyHeader'):addClass('sortable')
resultTable
:addClass('wikitable'):addClass('stickyHeader'):addClass('sortable')
:addClass('mw-collapsible'):addClass('mw-collapsed')
resultTable:tag('tr'):addClass('headerRow-0')
resultTable:tag('tr'):addClass('headerRow-0')
:tag('th'):wikitext('Modifier'):done()
:tag('th'):attr('style', 'min-width:400px'):wikitext('Modifier'):done()
for i, modDet in ipairs(RaidData.PossibleModifiers) do
local sortFunc = function(t, a, b) return t[a].ord < t[b].ord end
local modVal = {1, 5}
for baseName, modDet in Shared.spairs(modList, sortFunc) do
local mult = modDet.multiplier
local modText = modDet[1]
if mult ~= nil then
if #modDet['sign'] > 1 then
modVal = {modVal[1] * mult, modVal[2] * mult}
local replPat = modDet['sign'][1] .. '(%d)'
local signs = table.concat(modDet['sign'], '/')
modText = string.gsub(modDet[1], replPat, signs .. '%1', 1)
end
end
resultTable:tag('tr')
resultTable:tag('tr')
:tag('td'):wikitext(Constants._getModifierText(modDet.key, modVal, true)):done()
:tag('td'):wikitext(modText):done()
end
end
return tostring(resultTable)
return tostring(resultTable)
end
end


return p
return p