mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 10:12:53 +08:00
Completely remove subscription from MusicController
This commit is contained in:
parent
83b0e4572a
commit
1a776a9587
@ -34,13 +34,13 @@ namespace osu.Game.Overlays.Music
|
|||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmContextFactory realmFactory { get; set; }
|
private RealmAccess realm { get; set; }
|
||||||
|
|
||||||
private IDisposable beatmapSubscription;
|
private IDisposable beatmapSubscription;
|
||||||
|
|
||||||
private IQueryable<BeatmapSetInfo> availableBeatmaps => realmFactory.Context
|
private IQueryable<BeatmapSetInfo> availableBeatmaps => realm.Realm
|
||||||
.All<BeatmapSetInfo>()
|
.All<BeatmapSetInfo>()
|
||||||
.Where(s => !s.DeletePending);
|
.Where(s => !s.DeletePending);
|
||||||
|
|
||||||
private FilterControl filter;
|
private FilterControl filter;
|
||||||
private Playlist list;
|
private Playlist list;
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
// tests might bind externally, in which case we don't want to involve realm.
|
// tests might bind externally, in which case we don't want to involve realm.
|
||||||
if (beatmapSets.Count == 0)
|
if (beatmapSets.Count == 0)
|
||||||
beatmapSubscription = realmFactory.RegisterForNotifications(realm => availableBeatmaps, beatmapsChanged);
|
beatmapSubscription = realm.RegisterForNotifications(realm => availableBeatmaps, beatmapsChanged);
|
||||||
|
|
||||||
list.Items.BindTo(beatmapSets);
|
list.Items.BindTo(beatmapSets);
|
||||||
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true);
|
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true);
|
||||||
|
@ -16,7 +16,6 @@ using osu.Framework.Threading;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using Realms;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -25,8 +24,6 @@ namespace osu.Game.Overlays
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MusicController : CompositeDrawable
|
public class MusicController : CompositeDrawable
|
||||||
{
|
{
|
||||||
private IDisposable beatmapSubscription;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmaps { get; set; }
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
@ -35,8 +32,6 @@ namespace osu.Game.Overlays
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private const double restart_cutoff_point = 5000;
|
private const double restart_cutoff_point = 5000;
|
||||||
|
|
||||||
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the user has requested the track to be paused. Use <see cref="IsPlaying"/> to determine whether the track is still playing.
|
/// Whether the user has requested the track to be paused. Use <see cref="IsPlaying"/> to determine whether the track is still playing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -69,50 +64,11 @@ namespace osu.Game.Overlays
|
|||||||
mods.BindValueChanged(_ => ResetTrackAdjustments(), true);
|
mods.BindValueChanged(_ => ResetTrackAdjustments(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<BeatmapSetInfo> queryRealmBeatmapSets() =>
|
|
||||||
realm.Realm
|
|
||||||
.All<BeatmapSetInfo>()
|
|
||||||
.Where(s => !s.DeletePending);
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
beatmapSubscription = realm.RegisterForNotifications(r => queryRealmBeatmapSets(), beatmapsChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)
|
|
||||||
{
|
|
||||||
if (changes == null)
|
|
||||||
{
|
|
||||||
beatmapSets.Clear();
|
|
||||||
foreach (var s in sender)
|
|
||||||
beatmapSets.Add(s);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (int i in changes.InsertedIndices)
|
|
||||||
beatmapSets.Insert(i, sender[i]);
|
|
||||||
|
|
||||||
foreach (int i in changes.DeletedIndices.OrderByDescending(i => i))
|
|
||||||
beatmapSets.RemoveAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Forcefully reload the current <see cref="WorkingBeatmap"/>'s track from disk.
|
/// Forcefully reload the current <see cref="WorkingBeatmap"/>'s track from disk.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ReloadCurrentTrack() => changeTrack();
|
public void ReloadCurrentTrack() => changeTrack();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Change the position of a <see cref="BeatmapSetInfo"/> in the current playlist.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="beatmapSetInfo">The beatmap to move.</param>
|
|
||||||
/// <param name="index">The new position.</param>
|
|
||||||
public void ChangeBeatmapSetPosition(BeatmapSetInfo beatmapSetInfo, int index)
|
|
||||||
{
|
|
||||||
beatmapSets.Remove(beatmapSetInfo);
|
|
||||||
beatmapSets.Insert(index, beatmapSetInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether the beatmap track is playing.
|
/// Returns whether the beatmap track is playing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -238,11 +194,12 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
queuedDirection = TrackChangeDirection.Prev;
|
queuedDirection = TrackChangeDirection.Prev;
|
||||||
|
|
||||||
var playable = beatmapSets.TakeWhile(i => !i.Equals(current.BeatmapSetInfo)).LastOrDefault() ?? beatmapSets.LastOrDefault();
|
var playableSet = getBeatmapSets().AsEnumerable().TakeWhile(i => !i.Equals(current.BeatmapSetInfo)).LastOrDefault()
|
||||||
|
?? getBeatmapSets().LastOrDefault();
|
||||||
|
|
||||||
if (playable != null)
|
if (playableSet != null)
|
||||||
{
|
{
|
||||||
changeBeatmap(beatmaps.GetWorkingBeatmap(playable.Beatmaps.First()));
|
changeBeatmap(beatmaps.GetWorkingBeatmap(playableSet.Beatmaps.First()));
|
||||||
restartTrack();
|
restartTrack();
|
||||||
return PreviousTrackResult.Previous;
|
return PreviousTrackResult.Previous;
|
||||||
}
|
}
|
||||||
@ -269,7 +226,9 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
queuedDirection = TrackChangeDirection.Next;
|
queuedDirection = TrackChangeDirection.Next;
|
||||||
|
|
||||||
var playableSet = beatmapSets.SkipWhile(i => i.ID != current.BeatmapSetInfo.ID).ElementAtOrDefault(1) ?? beatmapSets.FirstOrDefault();
|
var playableSet = getBeatmapSets().AsEnumerable().SkipWhile(i => !i.Equals(current.BeatmapSetInfo)).ElementAtOrDefault(1)
|
||||||
|
?? getBeatmapSets().FirstOrDefault();
|
||||||
|
|
||||||
var playableBeatmap = playableSet?.Beatmaps.FirstOrDefault();
|
var playableBeatmap = playableSet?.Beatmaps.FirstOrDefault();
|
||||||
|
|
||||||
if (playableBeatmap != null)
|
if (playableBeatmap != null)
|
||||||
@ -293,6 +252,8 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private TrackChangeDirection? queuedDirection;
|
private TrackChangeDirection? queuedDirection;
|
||||||
|
|
||||||
|
private IQueryable<BeatmapSetInfo> getBeatmapSets() => realm.Realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending);
|
||||||
|
|
||||||
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap) => changeBeatmap(beatmap.NewValue);
|
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap) => changeBeatmap(beatmap.NewValue);
|
||||||
|
|
||||||
private void changeBeatmap(WorkingBeatmap newWorking)
|
private void changeBeatmap(WorkingBeatmap newWorking)
|
||||||
@ -320,8 +281,8 @@ namespace osu.Game.Overlays
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// figure out the best direction based on order in playlist.
|
// figure out the best direction based on order in playlist.
|
||||||
int last = beatmapSets.TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count();
|
int last = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count();
|
||||||
int next = newWorking == null ? -1 : beatmapSets.TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count();
|
int next = newWorking == null ? -1 : getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count();
|
||||||
|
|
||||||
direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next;
|
direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next;
|
||||||
}
|
}
|
||||||
@ -435,13 +396,6 @@ namespace osu.Game.Overlays
|
|||||||
mod.ApplyToTrack(CurrentTrack);
|
mod.ApplyToTrack(CurrentTrack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
|
||||||
{
|
|
||||||
base.Dispose(isDisposing);
|
|
||||||
|
|
||||||
beatmapSubscription?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TrackChangeDirection
|
public enum TrackChangeDirection
|
||||||
|
Loading…
Reference in New Issue
Block a user