Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playlist total time not considering rate adjust mods #28399

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions osu.Game/Beatmaps/Drawables/DifficultyIconTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -124,12 +125,8 @@ public void SetContent(DifficultyIconTooltipContent content)
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;

Expand Down
17 changes: 16 additions & 1 deletion osu.Game/Online/Rooms/PlaylistExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Humanizer;
using Humanizer.Localisation;
using osu.Framework.Bindables;
using osu.Game.Utils;

namespace osu.Game.Online.Rooms
{
Expand Down Expand Up @@ -38,7 +39,21 @@ public static IEnumerable<PlaylistItem> GetUpcomingItems(this IEnumerable<Playli
: 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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to work for wind up/down but I guess this is better than nothing for now.

}

return p.Beatmap.Length / rate;
}).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
}
}
4 changes: 1 addition & 3 deletions osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ private void updateValues() => Scheduler.AddOnce(() =>
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);

Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Screens/Select/BeatmapInfoWedge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ private void refreshBPMAndLengthLabel()
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);
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Screens/Select/Details/AdvancedStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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
{
Expand Down Expand Up @@ -179,9 +180,7 @@ private void updateStatistics()

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);

Expand Down
15 changes: 15 additions & 0 deletions osu.Game/Utils/ModUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,20 @@ public static LocalisableString FormatScoreMultiplier(double scoreMultiplier)

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;
}
}
}
Loading