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 crash on calculating playlist duration when rate-changing mods are present #28572

Merged
merged 1 commit into from
Jun 25, 2024
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
5 changes: 3 additions & 2 deletions 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.Rulesets;
using osu.Game.Utils;

namespace osu.Game.Online.Rooms
Expand Down Expand Up @@ -42,14 +43,14 @@ public static IEnumerable<PlaylistItem> GetUpcomingItems(this IEnumerable<Playli
/// <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) =>
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist, RulesetStore rulesetStore) =>
playlist.Select(p =>
{
double rate = 1;

if (p.RequiredMods.Length > 0)
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
var ruleset = rulesetStore.GetRuleset(p.RulesetID)!.CreateInstance();
rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;

namespace osu.Game.Screens.OnlinePlay.Components
{
public partial class OverlinedPlaylistHeader : OverlinedHeader
{
[Resolved]
private RulesetStore rulesets { get; set; } = null!;

public OverlinedPlaylistHeader()
: base("Playlist")
{
Expand All @@ -16,7 +21,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

Playlist.BindCollectionChanged((_, _) => Details.Value = Playlist.GetTotalDuration(), true);
Playlist.BindCollectionChanged((_, _) => Details.Value = Playlist.GetTotalDuration(rulesets), true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using osu.Game.Screens.OnlinePlay.Match.Components;
using osuTK;
using osu.Game.Localisation;
using osu.Game.Rulesets;

namespace osu.Game.Screens.OnlinePlay.Playlists
{
Expand Down Expand Up @@ -78,6 +79,9 @@ protected partial class MatchSettings : OnlinePlayComposite
[Resolved]
private IAPIProvider api { get; set; } = null!;

[Resolved]
private RulesetStore rulesets { get; set; } = null!;

private IBindable<APIUser> localUser = null!;

private readonly Room room;
Expand Down Expand Up @@ -366,7 +370,7 @@ protected override void Update()
public void SelectBeatmap() => editPlaylistButton.TriggerClick();

private void onPlaylistChanged(object? sender, NotifyCollectionChangedEventArgs e) =>
playlistLength.Text = $"Length: {Playlist.GetTotalDuration()}";
playlistLength.Text = $"Length: {Playlist.GetTotalDuration(rulesets)}";

private bool hasValidSettings => RoomID.Value == null && NameField.Text.Length > 0 && Playlist.Count > 0
&& hasValidDuration;
Expand Down
Loading