Skip to content

Commit

Permalink
Health Formatting Update
Browse files Browse the repository at this point in the history
Update health formatting to have options and to work better with east asia number grouping.
  • Loading branch information
Grimsbain committed Dec 1, 2024
1 parent aebfeb7 commit e6a75ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
68 changes: 58 additions & 10 deletions Core/Functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,65 @@ function nPlates:RGBToHex(r, g, b)
return RGBToColorCode(r, g, b)
end

local AbbreviateNumbers = AbbreviateNumbers
local gameLocale = GetLocale()
if gameLocale == "koKR" or gameLocale == "zhCN" or gameLocale == "zhTW" then
-- Work around https://github.com/Stanzilla/WoWUIBugs/issues/515

local NUMBER_ABBREVIATION_DATA_FIXED={
[1]={
breakpoint = 10000 * 10000,
significandDivisor = 10000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 1
},
[2]={
breakpoint = 1000 * 10000,
significandDivisor = 1000 * 10000,
abbreviation = SECOND_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
},
[3]={
breakpoint = 10000,
significandDivisor = 1000,
abbreviation = FIRST_NUMBER_CAP_NO_SPACE,
fractionDivisor = 10
}
}

AbbreviateNumbers = function(value)
for i, data in ipairs(NUMBER_ABBREVIATION_DATA_FIXED) do
if value >= data.breakpoint then
local finalValue = math.floor(value / data.significandDivisor) / data.fractionDivisor;
return finalValue .. data.abbreviation;
end
end

return tostring(value);
end
end

-- if ( number < 1e3 ) then
-- return math.floor(number)
-- elseif ( number >= 1e12 ) then
-- return string.format("%.3ft", number / 1e12)
-- elseif ( number >= 1e9 ) then
-- return string.format("%.3fb", number / 1e9)
-- elseif ( number >= 1e6 ) then
-- return string.format("%.2fm", number / 1e6)
-- elseif ( number >= 1e3 ) then
-- return string.format("%.1fk", number / 1e3)
-- end

function nPlates:FormatValue(number)
if ( number < 1e3 ) then
return math.floor(number)
elseif ( number >= 1e12 ) then
return string.format("%.3ft", number / 1e12)
elseif ( number >= 1e9 ) then
return string.format("%.3fb", number / 1e9)
elseif ( number >= 1e6 ) then
return string.format("%.2fm", number / 1e6)
elseif ( number >= 1e3 ) then
return string.format("%.1fk", number / 1e3)
if type(number) == "string" then number = tonumber(number) end

local style = self:GetOption("FormattingStyle")

if ( style == "Short" ) then
return AbbreviateLargeNumbers(Round(number))
else
return AbbreviateNumbers(number)
end
end

Expand Down
2 changes: 1 addition & 1 deletion nPlates_Cata.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: |cffCC3333 n|rPlates
## Notes: Nameplates for NeavUI.
## Author: Grimsbain
## Version: 2.90
## Version: 2.91
## SavedVariablesPerCharacter: nPlatesDB
## RequiredDeps: Blizzard_NamePlates
## LoadWith: Blizzard_NamePlates
Expand Down

0 comments on commit e6a75ec

Please sign in to comment.