Module:Constants: Difference between revisions

_getModifierText, getModifierSkills: Amend for new skill specific modifier values
(getSkillName: Fix again following adjustment in GameData module)
(_getModifierText, getModifierSkills: Amend for new skill specific modifier values)
Line 810: Line 810:
end
end


local result = modText
local valueArray, resultArray = nil, {}
if type(value) ~= 'table' then
valueArray = {value}
else
valueArray = value
end


if type(value) == 'table' then
for i, subVal in ipairs(valueArray) do
if Shared.tableCount(value) > 0 and type(value[1]) == 'table' then
local resultText = modText
--Potentially return multiple rows if necessary
local modMagnitude = nil
local resultArray = {}
if type(subVal) == 'table' and subVal.skillID ~= nil then
for i, subVal in Shared.skpairs(value) do
-- Modifier value is skill specific
table.insert(resultArray, p._getModifierText(modifier, subVal, doColor))
modMagnitude = subVal.value
local skillName = p.getSkillName(subVal.skillID)
if skillName ~= nil then
resultText = string.gsub(resultText, '{SV0}', skillName)
end
end
return table.concat(resultArray, '<br/>')
else
elseif Shared.contains(modText, '{SV0}') then
-- Modifier value is the magnitude only
-- If the value is a table and the mod text contains {SV0}, then
modMagnitude = subVal
-- the value is a {skillID, val} pair, otherwise it is a range of
-- values {minVal, maxVal}
if value[1] ~= nil then
local skillName = p.getSkillName(value[1])
if skillName ~= nil then
result = string.gsub(result, '{SV0}', p.getSkillName(value[1]))
end
end
if value[2] ~= nil then value = value[2] end
end
end
end
local valSign = (valueUnsigned and '' or sign)
result = string.gsub(result, '{(V[^}]*)}', function(rule) return valSign .. formatModValue(value, rule) end)
result = string.gsub(result, '{S}', sign)


if doColor then
local valSign = (valueUnsigned and '' or sign)
if isNegative ~= nil and isNegative then
resultText = string.gsub(resultText, '{(V[^}]*)}', function(rule) return valSign .. formatModValue(modMagnitude, rule) end)
result = '<span style="color:red">'..result..'</span>'
resultText = string.gsub(resultText, '{S}', sign)
else
 
result = '<span style="color:green">'..result..'</span>'
if doColor then
local colorCode = (isNegative ~= nil and isNegative and 'color:red' or 'color:green')
resultText = '<span style="' .. colorCode .. '">' .. resultText .. '</span>'
end
end
table.insert(resultArray, resultText)
end
end


return result
return table.concat(resultArray, '<br/>')
end
end


Line 867: Line 864:


function p.getModifiersText(modifiers, doColor)
function p.getModifiersText(modifiers, doColor)
if modifiers == nil or Shared.tableCount(modifiers) == 0 then
if modifiers == nil or Shared.tableIsEmpty(modifiers) then
return ''
return ''
end
end


local modArray = {}
local modArray = {}
for bonus, value in Shared.skpairs(modifiers) do
for bonus, value in ipairs(modifiers) do
table.insert(modArray, p._getModifierText(bonus, value, doColor))
table.insert(modArray, p._getModifierText(bonus, value, doColor))
end
end
Line 881: Line 878:
local skillArray = {}
local skillArray = {}


for modifier, value in Shared.skpairs(modifiers) do
for modifier, value in ipairs(modifiers) do
if type(value) == 'table' then
if type(value) == 'table' then
for i, subVal in Shared.skpairs(value) do
for i, subVal in ipairs(value) do
local skillName = p.getSkillName(subVal[1])
if type(subVal) == 'table' and subVal.skillID ~= nil then
if not Shared.contains(skillArray, skillName) then
local skillName = p.getSkillName(subVal.skillID)
table.insert(skillArray, skillName)
if not Shared.contains(skillArray, skillName) then
table.insert(skillArray, skillName)
end
end
end
end
end