diff options
| author | William Hergès <william@herges.fr> | 2025-09-20 14:01:39 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-09-20 14:01:39 +0200 |
| commit | 8d6fa726069bd5364ada1521b400bb5eb7865d87 (patch) | |
| tree | 9d566cb4cdab6a7069826732ef6d602b40f71dcf /exp/functions.go | |
| parent | e8b91140fba414c2bd7e7f36e8cff95d7651732d (diff) | |
feat(stats): custom scale for Y to show level
Diffstat (limited to 'exp/functions.go')
| -rw-r--r-- | exp/functions.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/exp/functions.go b/exp/functions.go index 2608094..363aed8 100644 --- a/exp/functions.go +++ b/exp/functions.go @@ -33,12 +33,26 @@ func VocalXP(time uint) uint { )) } +type LevelScale struct{} + +func (LevelScale) Normalize(min, max, x float64) float64 { + if min < 0 || max < 0 || x < 0 { + panic("Values must be positive or null for a level scale.") + } + levelMin := LevelExact(min) + return (LevelExact(x) - levelMin) / (LevelExact(max) - levelMin) +} + // Level gives the level with the given XP. // See LevelXP to get the XP required to get a level. func Level(xp uint) uint { - return uint(math.Floor( - 0.2 * math.Sqrt(float64(xp)), - )) + return uint(math.Floor(LevelExact(float64(xp)))) +} + +// LevelExact gives the exact level with the given XP. +// See Level to get the floored level. +func LevelExact(xp float64) float64 { + return 0.2 * math.Sqrt(xp) } // LevelXP gives the XP required to get this level. |
