Skip to content

Commit

Permalink
Parse localized number separators (Fixes #182)
Browse files Browse the repository at this point in the history
  • Loading branch information
raethkcj committed Jun 19, 2024
1 parent b900f4b commit b24dd7d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libs/StatLogic/StatLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1547,12 +1547,22 @@ end
do
local statTable, currentColor

local large_sep = LARGE_NUMBER_SEPERATOR:gsub("[-.]", "%%%1")
local dec_sep = DECIMAL_SEPERATOR:gsub("[-.]", "%%%1")
local number_pattern = "[+-]?[%d." .. large_sep .. dec_sep .. "]+%f[%D]"

local function AddStat(id, value, currentStats)
if id == StatLogic.Stats.Armor then
local base, bonus = StatLogic:GetArmorDistribution(statTable.link, value, currentColor)
value = base
AddStat(StatLogic.Stats.BonusArmor, bonus, currentStats)
end

if id == StatLogic.Stats.WeaponDPS and LARGE_NUMBER_SEPERATOR == "." then
-- Workaround for Blizzard forgetting to use DECIMAL_SEPERATOR for Weapon DPS
value = value / 10
end

statTable[id] = (statTable[id] or 0) + tonumber(value)
table.insert(currentStats, tostring(id) .. "=" .. tostring(value))
end
Expand Down Expand Up @@ -1652,7 +1662,8 @@ do
if not found then
-- Replace numbers with %s
local values = {}
local statText, count = text:gsub("[+-]?[%d%.]+%f[%D]", function(match)
local statText, count = text:gsub(number_pattern, function(match)
match = match:gsub(large_sep, ""):gsub(dec_sep, ".")
local value = tonumber(match)
if value then
values[#values + 1] = value
Expand Down

0 comments on commit b24dd7d

Please sign in to comment.