Module:ModifierTables: Difference between revisions

_getModifierTable: Add equipment slot links to type column
(Use printError function)
(_getModifierTable: Add equipment slot links to type column)
 
(9 intermediate revisions by 3 users not shown)
Line 6: Line 6:
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Common = require('Module:Common')
local Pets = require('Module:Pets')
local Pets = require('Module:Pets')
local Items = require('Module:Items')
local Items = require('Module:Items')
Line 13: Line 14:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Cartography = require('Module:Skills/Cartography')
local GameData = require('Module:GameData')


--First up, functions to get all the things in a category that have a given modifier:
--First up, functions to get all the things in a category that have a given modifier:
Line 197: Line 200:
end
end


function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
function p.getPOIsWithModifier(modifiers, skill, getOpposites)
if type(modifiers) == 'string' then
modifiers = {modifiers}
end
local POIList = Cartography.getPointsOfInterest(
function(POI)
if POI.activeModifiers == nil then
return false
end
for i, mod in ipairs(modifiers) do
if p.getModifierValue(POI.activeModifiers, mod, skill, getOpposites) ~= 0 then
return true
end
end
return false
end)
return POIList
end
 
function p.getCartoMasteryBonusesWithModifier(modifiers, skill, getOpposites)
if type(modifiers) == 'string' then
modifiers = {modifiers}
end
local bonusList = Cartography.getMasteryBonuses(
function(bonus)
if bonus.modifiers == nil or Shared.tableIsEmpty(bonus.modifiers) then
return false
end
for i, mod in ipairs(modifiers) do
if p.getModifierValue(bonus.modifiers, mod, skill, getOpposites) ~= 0 then
return true
end
end
return false
end)
return bonusList
end
 
function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods, forceMagnitudeSort)
local modifierNames = {}
local modifierNames = {}
if type(modifiers) == 'string' then
if type(modifiers) == 'string' then
Line 285: Line 330:
row.expIcon = Icons.getExpansionIcon(item.id)
row.expIcon = Icons.getExpansionIcon(item.id)
row.type = 'Item'
row.type = 'Item'
row.typeText = row.type
--For equipment, show the slot they go in
--For equipment, show the slot they go in
if item.validSlots ~= nil then
if item.validSlots ~= nil and not Shared.tableIsEmpty(item.validSlots) then
row.type = row.type..' ('..table.concat(Shared.clone(item.validSlots), ', ')..')'
local rowTypePart = {}
for j, slot in ipairs(item.validSlots) do
table.insert(rowTypePart, Common.getEquipmentSlotLink(slot))
end
row.typeText = row.typeText .. ' (' .. table.concat(item.validSlots, ', ') .. ')'
row.type = row.type .. ' (' .. table.concat(rowTypePart, ', ') .. ')'
end
end
row.typeText = row.type
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 329: Line 379:


local obstList = p.getObstaclesWithModifier(modifiers, skill, getOpposites)
local obstList = p.getObstaclesWithModifier(modifiers, skill, getOpposites)
table.sort(obstList, function(a, b) return a.category < b.category end)
for i, obst in Shared.skpairs(obstList) do
for i, obst in Shared.skpairs(obstList) do
local row = {}
local row = {}
row.name = obst.name
row.name = obst.name
row.icon = Icons.Icon({'Agility', obst.name, type='skill'})
row.icon = Icons.Icon({'Agility%23'..string.gsub(obst.name, ' ', ''), obst.name, type='skill', img='Agility'})
row.expIcon = Icons.getExpansionIcon(obst.id)
row.expIcon = Icons.getExpansionIcon(obst.id)
row.type = '[[Agility#Obstacles|Agility Obstacle '..tostring(tonumber(obst.category)+1)..']]'
row.type = '[[Agility#Obstacles|Agility Obstacle '..tostring(tonumber(obst.category)+1)..']]'
row.typeText = 'Agility Obstacle '..tostring(tonumber(obst.category)+1)
row.typeText = 'Agility Obstacle '..string.format("%02d", (obst.category + 1))
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 355: Line 406:
local row = {}
local row = {}
row.name = pillar.name
row.name = pillar.name
row.icon = Icons.Icon({'Agility', pillar.name, type='skill'})
row.icon = Icons.Icon({'Agility%23'..string.gsub(pillar.name, ' ', ''), pillar.name, type='skill', img='Agility'})
row.expIcon = Icons.getExpansionIcon(pillar.id)
row.expIcon = Icons.getExpansionIcon(pillar.id)
row.type = '[[Agility#Passive Pillars|Agility Pillar]]'
row.type = '[[Agility#Passive Pillars|Agility Pillar]]'
Line 422: Line 473:
local constellationList = p.getConstellationsWithModifier(modifiers, skill, getOpposites)
local constellationList = p.getConstellationsWithModifier(modifiers, skill, getOpposites)
for i, cons in ipairs(constellationList) do
for i, cons in ipairs(constellationList) do
local modList = Skills._buildAstrologyModifierArray(cons, nil, true, true, true, true)
local row = {}
local row = {}
row.name = cons.name
row.name = cons.name
Line 428: Line 480:
row.type = '[[Astrology#Constellations|Constellation]]'
row.type = '[[Astrology#Constellations|Constellation]]'
row.typeText = 'Constellation'
row.typeText = 'Constellation'
row.val = 15 -- Assume highest possible, the range is 1 to 15 inclusive
row.modifierText, row.otherModifiers = getModText(modList)
local totalVal = 0
for i, mod in pairs(modifiers) do
totalVal = totalVal + p.getModifierValue(modList, mod, skill, getOpposites)
end
row.val = totalVal


local modList = Skills._buildAstrologyModifierArray(cons, nil, true, true, true, true)
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
row.modifierText, row.otherModifiers = getModText(modList)
hasOtherModifiers = true
end
 
table.insert(tableArray, row)
end
local POIList = p.getPOIsWithModifier(modifiers, skill, getOpposites)
for i, POI in ipairs(POIList) do
local row = {}
row.name = POI.name
row.icon = Icons.Icon({POI.name, type='poi'})
row.expIcon = Icons.getExpansionIcon(POI.id)
row.type = '[[Cartography|Point of Interest]]'
row.typeText = 'Point of Interest'
local totalVal = 0
for i, mod in ipairs(modifiers) do
totalVal = totalVal + p.getModifierValue(POI.activeModifiers, mod, skill, getOpposites)
end
row.val = totalVal
 
row.modifierText, row.otherModifiers = getModText(POI.activeModifiers)


if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
Line 437: Line 515:
end
end


table.insert(tableArray, row)
end
local cartoBonusList = p.getCartoMasteryBonusesWithModifier(modifiers, skill, getOpposites)
for i, bonus in ipairs(cartoBonusList) do
local row = {}
row.name = Shared.formatnum(bonus.masteredHexes) .. ' Hexes Mastered'
row.icon = Icons.Icon({'Cartography', Shared.formatnum(bonus.masteredHexes) .. ' Hexes Mastered', type='skill'})
row.expIcon = Icons.getExpansionIcon(bonus.id)
row.type = Icons.Icon({'Cartography', 'Mastery Bonus', section='Mastery Unlocks', type='skill', noicon=true})
row.typeText = 'Mastery Bonus'
local totalVal = 0
for i, mod in ipairs(modifiers) do
totalVal = totalVal + p.getModifierValue(bonus.modifiers, mod, skill, getOpposites)
end
row.val = totalVal
row.modifierText, row.otherModifiers = getModText(bonus.modifiers)
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
hasOtherModifiers = true
end
table.insert(tableArray, row)
table.insert(tableArray, row)
end
end
Line 448: Line 549:
--Otherwise sort alphabetically by type, then name
--Otherwise sort alphabetically by type, then name
table.sort(tableArray, function(a, b)
table.sort(tableArray, function(a, b)
if modifierCount == 1 and a.val ~= b.val then
if (modifierCount == 1 or forceMagnitudeSort) and a.val ~= b.val then
return a.val > b.val
return a.val > b.val
elseif a.type ~= b.type then
elseif a.typeText ~= b.typeText then
return a.type < b.type
return a.typeText < b.typeText
else
else
return a.name < b.name
return a.name < b.name
Line 476: Line 577:
local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
local maxOtherMods = frame.args ~= nil and tonumber(frame.args.maxOtherMods) or 5
local maxOtherMods = frame.args ~= nil and tonumber(frame.args.maxOtherMods) or 5
local forceMagnitudeSort = frame.args ~= nil and string.upper(tostring(frame.args.forceMagnitudeSort)) == 'TRUE' or false


if Shared.contains(modifier, ',') then
if Shared.contains(modifier, ',') then
Line 493: Line 595:
end
end


return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods, maxOtherMods, forceMagnitudeSort)
end
end


-- Function to list all available modifiers for the relevant templates.
function p.getAllModifiers()
local tabl = mw.html.create('table')
:addClass('mw-collapsible mw-collapsed')
tabl:tag('caption')
:css('min-width', '200px')
:tag('b')
:wikitext('All Modifiers List')
-- First, sort modifiers
local modifierNames = {}
for k, _ in pairs(GameData.rawData.modifierData) do
table.insert(modifierNames, tostring(k))
end
table.sort(modifierNames)
-- Then add modifiers to output table
for _, v in pairs(modifierNames) do
tabl:tag('tr')
:tag('td')
:tag('code')
:wikitext(tostring(v)):done()
:done()
:done()
end
return tostring(tabl)
end
--Function for console testing of modifier tables
--Function for console testing of modifier tables
function p.getModifierTableTest()
function p.getModifierTableTest()