1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:57:24 +08:00

Add helper method for properly formatting score multiplier in ModUtils

This commit is contained in:
Salman Ahmed 2023-12-31 04:48:06 +03:00
parent bca0600482
commit 7cfb786b1a

View File

@ -5,6 +5,8 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Localisation;
using osu.Game.Online.API;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
@ -226,5 +228,21 @@ namespace osu.Game.Utils
return proposedWereValid;
}
/// <summary>
/// Given a value of a score multiplier, returns a string version with special handling for a value near 1.00x.
/// </summary>
/// <param name="scoreMultiplier">The value of the score multiplier.</param>
/// <returns>A formatted score multiplier with a trailing "x" symbol</returns>
public static LocalisableString FormatScoreMultiplier(double scoreMultiplier)
{
// Round multiplier values away from 1.00x to two significant digits.
if (scoreMultiplier > 1)
scoreMultiplier = Math.Ceiling(scoreMultiplier * 100) / 100;
else
scoreMultiplier = Math.Floor(scoreMultiplier * 100) / 100;
return scoreMultiplier.ToLocalisableString("0.00x");
}
}
}