1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Apply NRT to SpectatorScreen

This commit is contained in:
Dean Herbert 2023-11-22 15:14:25 +09:00
parent 537b0ae870
commit 4c7d2bb0fb
No known key found for this signature in database

View File

@ -1,13 +1,10 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
@ -33,22 +30,27 @@ namespace osu.Game.Screens.Spectate
private readonly List<int> users = new List<int>();
[Resolved]
private BeatmapManager beatmaps { get; set; }
private BeatmapManager beatmaps { get; set; } = null!;
[Resolved]
private RulesetStore rulesets { get; set; }
private RulesetStore rulesets { get; set; } = null!;
[Resolved]
private SpectatorClient spectatorClient { get; set; }
private SpectatorClient spectatorClient { get; set; } = null!;
[Resolved]
private UserLookupCache userLookupCache { get; set; }
private UserLookupCache userLookupCache { get; set; } = null!;
[Resolved]
private RealmAccess realm { get; set; } = null!;
private readonly IBindableDictionary<int, SpectatorState> userStates = new BindableDictionary<int, SpectatorState>();
private readonly Dictionary<int, APIUser> userMap = new Dictionary<int, APIUser>();
private readonly Dictionary<int, SpectatorGameplayState> gameplayStates = new Dictionary<int, SpectatorGameplayState>();
private IDisposable? realmSubscription;
/// <summary>
/// Creates a new <see cref="SpectatorScreen"/>.
/// </summary>
@ -58,11 +60,6 @@ namespace osu.Game.Screens.Spectate
this.users.AddRange(users);
}
[Resolved]
private RealmAccess realm { get; set; }
private IDisposable realmSubscription;
protected override void LoadComplete()
{
base.LoadComplete();
@ -90,7 +87,7 @@ namespace osu.Game.Screens.Spectate
}));
}
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> items, ChangeSet changes)
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> items, ChangeSet? changes)
{
if (changes?.InsertedIndices == null) return;
@ -109,7 +106,7 @@ namespace osu.Game.Screens.Spectate
}
}
private void onUserStatesChanged(object sender, NotifyDictionaryChangedEventArgs<int, SpectatorState> e)
private void onUserStatesChanged(object? sender, NotifyDictionaryChangedEventArgs<int, SpectatorState> e)
{
switch (e.Action)
{
@ -207,14 +204,14 @@ namespace osu.Game.Screens.Spectate
/// </summary>
/// <param name="userId">The user whose state has changed.</param>
/// <param name="spectatorState">The new state.</param>
protected abstract void OnNewPlayingUserState(int userId, [NotNull] SpectatorState spectatorState);
protected abstract void OnNewPlayingUserState(int userId, SpectatorState spectatorState);
/// <summary>
/// Starts gameplay for a user.
/// </summary>
/// <param name="userId">The user to start gameplay for.</param>
/// <param name="spectatorGameplayState">The gameplay state.</param>
protected abstract void StartGameplay(int userId, [NotNull] SpectatorGameplayState spectatorGameplayState);
protected abstract void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState);
/// <summary>
/// Quits gameplay for a user.
@ -243,7 +240,7 @@ namespace osu.Game.Screens.Spectate
{
base.Dispose(isDisposing);
if (spectatorClient != null)
if (spectatorClient.IsNotNull())
{
foreach ((int userId, var _) in userMap)
spectatorClient.StopWatchingUser(userId);