Skip to content

Commit

Permalink
Merge pull request #28890 from bdach/protected-beatmaps-begone
Browse files Browse the repository at this point in the history
Exclude protected beatmaps from consideration in several places
  • Loading branch information
peppy authored Jul 17, 2024
2 parents 5633297 + e4ff6b5 commit 84a36a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Music/PlaylistOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

beatmapSubscription = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending), beatmapsChanged);
beatmapSubscription = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected), beatmapsChanged);

list.Items.BindTo(beatmapSets);
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo.ToLive(realm), true);
Expand Down
27 changes: 15 additions & 12 deletions osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void EnsurePlayingSomething()
return;

Logger.Log($"{nameof(MusicController)} skipping next track to {nameof(EnsurePlayingSomething)}");
NextTrack();
NextTrack(allowProtectedTracks: true);
}
else if (!IsPlaying)
{
Expand Down Expand Up @@ -207,18 +207,20 @@ public bool TogglePause()
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
/// </summary>
/// <param name="onSuccess">Invoked when the operation has been performed successfully.</param>
public void PreviousTrack(Action<PreviousTrackResult>? onSuccess = null) => Schedule(() =>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
public void PreviousTrack(Action<PreviousTrackResult>? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() =>
{
PreviousTrackResult res = prev();
PreviousTrackResult res = prev(allowProtectedTracks);
if (res != PreviousTrackResult.None)
onSuccess?.Invoke(res);
});

/// <summary>
/// Play the previous track or restart the current track if it's current time below <see cref="restart_cutoff_point"/>.
/// </summary>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
/// <returns>The <see cref="PreviousTrackResult"/> that indicate the decided action.</returns>
private PreviousTrackResult prev()
private PreviousTrackResult prev(bool allowProtectedTracks)
{
if (beatmap.Disabled || !AllowTrackControl.Value)
return PreviousTrackResult.None;
Expand All @@ -233,8 +235,8 @@ private PreviousTrackResult prev()

queuedDirection = TrackChangeDirection.Prev;

var playableSet = getBeatmapSets().AsEnumerable().TakeWhile(i => !i.Equals(current?.BeatmapSetInfo)).LastOrDefault()
?? getBeatmapSets().LastOrDefault();
var playableSet = getBeatmapSets().AsEnumerable().TakeWhile(i => !i.Equals(current?.BeatmapSetInfo)).LastOrDefault(s => !s.Protected || allowProtectedTracks)
?? getBeatmapSets().AsEnumerable().LastOrDefault(s => !s.Protected || allowProtectedTracks);

if (playableSet != null)
{
Expand All @@ -250,10 +252,11 @@ private PreviousTrackResult prev()
/// Play the next random or playlist track.
/// </summary>
/// <param name="onSuccess">Invoked when the operation has been performed successfully.</param>
/// <param name="allowProtectedTracks">Whether to include <see cref="BeatmapSetInfo.Protected"/> beatmap sets when navigating.</param>
/// <returns>A <see cref="ScheduledDelegate"/> of the operation.</returns>
public void NextTrack(Action? onSuccess = null) => Schedule(() =>
public void NextTrack(Action? onSuccess = null, bool allowProtectedTracks = false) => Schedule(() =>
{
bool res = next();
bool res = next(allowProtectedTracks);
if (res)
onSuccess?.Invoke();
});
Expand Down Expand Up @@ -306,15 +309,15 @@ public void DuckMomentarily(double delayUntilRestore, DuckParameters? parameters
Scheduler.AddDelayed(() => duckOperation.Dispose(), delayUntilRestore);
}

private bool next()
private bool next(bool allowProtectedTracks)
{
if (beatmap.Disabled || !AllowTrackControl.Value)
return false;

queuedDirection = TrackChangeDirection.Next;

var playableSet = getBeatmapSets().AsEnumerable().SkipWhile(i => !i.Equals(current?.BeatmapSetInfo)).ElementAtOrDefault(1)
?? getBeatmapSets().FirstOrDefault();
var playableSet = getBeatmapSets().AsEnumerable().SkipWhile(i => !i.Equals(current?.BeatmapSetInfo) && (!i.Protected || allowProtectedTracks)).ElementAtOrDefault(1)
?? getBeatmapSets().AsEnumerable().FirstOrDefault(i => !i.Protected || allowProtectedTracks);

var playableBeatmap = playableSet?.Beatmaps.FirstOrDefault();

Expand Down Expand Up @@ -432,7 +435,7 @@ private DrawableTrack getQueuedTrack()
private void onTrackCompleted()
{
if (!CurrentTrack.Looping && !beatmap.Disabled && AllowTrackControl.Value)
NextTrack();
NextTrack(allowProtectedTracks: true);
}

private bool applyModTrackAdjustments;
Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Screens/Select/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ private void updateCarouselSelection(ValueChangedEvent<WorkingBeatmap>? e = null
var beatmap = e?.NewValue ?? Beatmap.Value;
if (beatmap is DummyWorkingBeatmap || !this.IsCurrentScreen()) return;

if (beatmap.BeatmapSetInfo.Protected && e != null)
{
Logger.Log($"Denying working beatmap switch to protected beatmap {beatmap}");
Beatmap.Value = e.OldValue;
return;
}

Logger.Log($"Song select working beatmap updated to {beatmap}");

if (!Carousel.SelectBeatmap(beatmap.BeatmapInfo, false))
Expand Down

0 comments on commit 84a36a4

Please sign in to comment.