17,030
edits
m (Fix case issue) |
(_getEquipmentTable: Avoid repeated string concatenation in an attempt to reduce memory usage) |
||
Line 69: | Line 69: | ||
--Alright, let's start the table by building the shared header | --Alright, let's start the table by building the shared header | ||
local | local resultPart = {} | ||
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"') | |||
if isWeaponType then | if isWeaponType then | ||
--Weapons have extra columns here for Attack Speed and "Two Handed?" | --Weapons have extra columns here for Attack Speed and "Two Handed?" | ||
table.insert(resultPart, '\r\n!colspan="4"|') | |||
else | else | ||
table.insert(resultPart, '\r\n!colspan="2"|') | |||
end | end | ||
if attBonusCols > 0 then | if attBonusCols > 0 then | ||
table.insert(resultPart, '\r\n!colspan="'..attBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Attack Bonus') | |||
end | end | ||
if strBonusCols > 0 then | if strBonusCols > 0 then | ||
table.insert(resultPart, '\r\n!colspan="'..strBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Str. Bonus') | |||
end | end | ||
if Shared.contains(statColumns, 'magicDamageBonus') then | if Shared.contains(statColumns, 'magicDamageBonus') then | ||
table.insert(resultPart, '\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|% Dmg Bonus') | |||
end | end | ||
if defBonusCols > 0 then | if defBonusCols > 0 then | ||
table.insert(resultPart, '\r\n!colspan="'..defBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Defence Bonus') | |||
end | end | ||
if Shared.contains(statColumns, 'damageReduction') then | if Shared.contains(statColumns, 'damageReduction') then | ||
table.insert(resultPart, '\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|DR') | |||
end | end | ||
if lvlReqCols > 0 then | if lvlReqCols > 0 then | ||
table.insert(resultPart, '\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req') | |||
end | end | ||
if includeModifiers and includeDescription then | if includeModifiers and includeDescription then | ||
table.insert(resultPart, '\r\n!colspan="3"|') | |||
elseif includeModifiers or includeDescription then | elseif includeModifiers or includeDescription then | ||
table.insert(resultPart, '\r\n!colspan="2"|') | |||
else | else | ||
table.insert(resultPart, '\r\n!colspan="1"|') | |||
end | end | ||
--One header row down, one to go | --One header row down, one to go | ||
table.insert(resultPart, '\r\n|-class="headerRow-1"') | |||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Item') | |||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Name') | |||
--Weapons have Attack Speed here | --Weapons have Attack Speed here | ||
if isWeaponType then | if isWeaponType then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Attack Speed') | |||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?') | |||
end | end | ||
--Attack bonuses | --Attack bonuses | ||
if Shared.contains(statColumns, 'slashAttackBonus') then | if Shared.contains(statColumns, 'slashAttackBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'stabAttackBonus') then | if Shared.contains(statColumns, 'stabAttackBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'blockAttackBonus') then | if Shared.contains(statColumns, 'blockAttackBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'rangedAttackBonus') then | if Shared.contains(statColumns, 'rangedAttackBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'magicAttackBonus') then | if Shared.contains(statColumns, 'magicAttackBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})) | |||
end | end | ||
--Strength bonuses | --Strength bonuses | ||
if Shared.contains(statColumns, 'strengthBonus') then | if Shared.contains(statColumns, 'strengthBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'rangedStrengthBonus') then | if Shared.contains(statColumns, 'rangedStrengthBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'magicDamageBonus') then | if Shared.contains(statColumns, 'magicDamageBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})) | |||
end | end | ||
--Defence bonuses | --Defence bonuses | ||
if Shared.contains(statColumns, 'defenceBonus') then | if Shared.contains(statColumns, 'defenceBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'rangedDefenceBonus') then | if Shared.contains(statColumns, 'rangedDefenceBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'magicDefenceBonus') then | if Shared.contains(statColumns, 'magicDefenceBonus') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'damageReduction') then | if Shared.contains(statColumns, 'damageReduction') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})) | |||
end | end | ||
--Level requirements | --Level requirements | ||
if Shared.contains(statColumns, 'attackLevelRequired') then | if Shared.contains(statColumns, 'attackLevelRequired') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'defenceLevelRequired') then | if Shared.contains(statColumns, 'defenceLevelRequired') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'rangedLevelRequired') then | if Shared.contains(statColumns, 'rangedLevelRequired') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})) | |||
end | end | ||
if Shared.contains(statColumns, 'magicLevelRequired') then | if Shared.contains(statColumns, 'magicLevelRequired') then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})) | |||
end | end | ||
--If includeModifiers is set to 'true', add the Modifiers column | --If includeModifiers is set to 'true', add the Modifiers column | ||
if includeModifiers then | if includeModifiers then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Modifiers') | |||
end | end | ||
--If includeDescription is set to 'true', add the Description column | --If includeDescription is set to 'true', add the Description column | ||
if includeDescription then | if includeDescription then | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Description') | |||
end | end | ||
--And finally Sources | --And finally Sources | ||
table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Sources') | |||
local getStatValue = function(item, statName, equipStats, levelReqs) | local getStatValue = function(item, statName, equipStats, levelReqs) | ||
Line 193: | Line 194: | ||
if isWeaponType then | if isWeaponType then | ||
--Building rows for weapons | --Building rows for weapons | ||
table.insert(resultPart, '\r\n|-') | |||
table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})) | |||
table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]') | |||
table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(equipStats.attackSpeed)) | |||
--That's the first list out of the way, now for 2-Handed | --That's the first list out of the way, now for 2-Handed | ||
table.insert(resultPart, '\r\n| style ="text-align: right;"|') | |||
table.insert(resultPart, Items._getItemStat(item, 'isTwoHanded') and 'Yes' or 'No') | |||
for j, statName in pairs(statColumns) do | for j, statName in pairs(statColumns) do | ||
local statValue = getStatValue(item, statName, equipStats, levelReqs) | local statValue = getStatValue(item, statName, equipStats, levelReqs) | ||
table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;') | |||
if string.find(statName, '^(.+)LevelRequired$') == nil then | if string.find(statName, '^(.+)LevelRequired$') == nil then | ||
if statValue > 0 then | if statValue > 0 then | ||
table.insert(resultPart, 'background-color:lightgreen;') | |||
elseif statValue < 0 then | elseif statValue < 0 then | ||
table.insert(resultPart, 'background-color:lightpink;') | |||
end | end | ||
end | end | ||
table.insert(resultPart, '"|'..Shared.formatnum(statValue)) | |||
if statName == 'magicDamageBonus' or statName == 'damageReduction' then | if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end | ||
end | end | ||
--If requested, add the item Modifiers | --If requested, add the item Modifiers | ||
if includeModifiers then | if includeModifiers then | ||
table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|') | |||
table.insert(resultPart, Constants.getModifiersText(item.modifiers, true)) | |||
end | end | ||
--If requested, add description | --If requested, add description | ||
if includeDescription then | if includeDescription then | ||
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|') | |||
table.insert(resultPart, item.description ~= nil and item.description or '') | |||
end | end | ||
--Finally, the Sources | --Finally, the Sources | ||
table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |') | |||
table.insert(resultPart, ItemSourceTables._getItemSources(item)) | |||
else | else | ||
--Building rows for armour | --Building rows for armour | ||
table.insert(resultPart, '\r\n|-') | |||
table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})) | |||
table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]') | |||
for j, statName in pairs(statColumns) do | for j, statName in pairs(statColumns) do | ||
local statValue = getStatValue(item, statName, equipStats, levelReqs) | local statValue = getStatValue(item, statName, equipStats, levelReqs) | ||
table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;') | |||
if statValue > 0 then | if statValue > 0 then | ||
table.insert(resultPart, 'background-color:lightgreen;') | |||
elseif statValue < 0 then | elseif statValue < 0 then | ||
table.insert(resultPart, 'background-color:lightpink;') | |||
end | end | ||
table.insert(resultPart, '"|'..Shared.formatnum(statValue)) | |||
if statName == 'magicDamageBonus' or statName == 'damageReduction' then | if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end | ||
end | end | ||
--If requested, add the item Modifiers | --If requested, add the item Modifiers | ||
if includeModifiers then | if includeModifiers then | ||
table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|') | |||
table.insert(resultPart, Constants.getModifiersText(item.modifiers, true)) | |||
end | end | ||
--If requested, add description | --If requested, add description | ||
if includeDescription then | if includeDescription then | ||
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|') | |||
table.insert(resultPart, item.description ~= nil and item.description or '') | |||
end | end | ||
--Finally, the Sources | --Finally, the Sources | ||
table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |') | |||
table.insert(resultPart, ItemSourceTables._getItemSources(item)) | |||
end | end | ||
end | end | ||
table.insert(resultPart, '\r\n|}') | |||
return | return table.concat(resultPart) | ||
end | end | ||