1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 15:27:30 +08:00
Fix playlist total time not considering rate adjust mods
This commit is contained in:
Bartłomiej Dach 2024-06-07 07:24:55 +02:00 committed by GitHub
commit a6d0cd56b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 15 deletions

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
using osuTK;
namespace osu.Game.Beatmaps.Drawables
@ -124,12 +125,8 @@ namespace osu.Game.Beatmaps.Drawables
miscFillFlowContainer.Show();
double rate = 1;
if (displayedContent.Mods != null)
{
foreach (var mod in displayedContent.Mods.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
}
rate = ModUtils.CalculateRateWithMods(displayedContent.Mods);
double bpmAdjusted = displayedContent.BeatmapInfo.BPM * rate;

View File

@ -6,6 +6,7 @@ using System.Linq;
using Humanizer;
using Humanizer.Localisation;
using osu.Framework.Bindables;
using osu.Game.Utils;
namespace osu.Game.Online.Rooms
{
@ -38,7 +39,21 @@ namespace osu.Game.Online.Rooms
: GetUpcomingItems(playlist).First();
}
/// <summary>
/// Returns the total duration from the <see cref="PlaylistItem"/> in playlist order from the supplied <paramref name="playlist"/>,
/// </summary>
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
playlist.Select(p => p.Beatmap.Length).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
playlist.Select(p =>
{
double rate = 1;
if (p.RequiredMods.Length > 0)
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)));
}
return p.Beatmap.Length / rate;
}).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
}
}

View File

@ -165,9 +165,7 @@ namespace osu.Game.Overlays.Mods
starRatingDisplay.FinishTransforms(true);
});
double rate = 1;
foreach (var mod in Mods.Value.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
double rate = ModUtils.CalculateRateWithMods(Mods.Value);
bpmDisplay.Current.Value = FormatUtils.RoundBPM(BeatmapInfo.Value.BPM, rate);

View File

@ -402,9 +402,7 @@ namespace osu.Game.Screens.Select
return;
// this doesn't consider mods which apply variable rates, yet.
double rate = 1;
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
double rate = ModUtils.CalculateRateWithMods(mods.Value);
int bpmMax = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMaximum, rate);
int bpmMin = FormatUtils.RoundBPM(beatmap.ControlPointInfo.BPMMinimum, rate);

View File

@ -27,6 +27,7 @@ using osu.Game.Configuration;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osu.Game.Overlays.Mods;
using osu.Game.Utils;
namespace osu.Game.Screens.Select.Details
{
@ -179,9 +180,7 @@ namespace osu.Game.Screens.Select.Details
if (Ruleset.Value != null)
{
double rate = 1;
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
double rate = ModUtils.CalculateRateWithMods(mods.Value);
adjustedDifficulty = Ruleset.Value.CreateInstance().GetRateAdjustedDisplayDifficulty(originalDifficulty, rate);

View File

@ -276,5 +276,20 @@ namespace osu.Game.Utils
return scoreMultiplier.ToLocalisableString("0.00x");
}
/// <summary>
/// Calculate the rate for the song with the selected mods.
/// </summary>
/// <param name="mods">The list of selected mods.</param>
/// <returns>The rate with mods.</returns>
public static double CalculateRateWithMods(IEnumerable<Mod> mods)
{
double rate = 1;
foreach (var mod in mods.OfType<IApplicableToRate>())
rate = mod.ApplyToRate(0, rate);
return rate;
}
}
}