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

Fix weird access to userIds in MultiplayerSpectatorScreen

This commit is contained in:
Dean Herbert 2021-05-03 14:25:52 +09:00
parent dc5ee31d94
commit c065092e72
2 changed files with 9 additions and 13 deletions

View File

@ -27,8 +27,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// </summary>
public bool AllPlayersLoaded => instances.All(p => p?.PlayerLoaded == true);
private readonly int[] userIds;
[Resolved]
private SpectatorStreamingClient spectatorClient { get; set; }
@ -49,8 +47,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public MultiSpectatorScreen(int[] userIds)
: base(userIds.Take(PlayerGrid.MAX_PLAYERS).ToArray())
{
this.userIds = GetUserIds().ToArray();
instances = new PlayerArea[this.userIds.Length];
instances = new PlayerArea[UserIds.Count];
}
[BackgroundDependencyLoader]
@ -84,9 +81,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
})
};
for (int i = 0; i < userIds.Length; i++)
for (int i = 0; i < UserIds.Count; i++)
{
grid.Add(instances[i] = new PlayerArea(userIds[i], masterClockContainer.GameplayClock));
grid.Add(instances[i] = new PlayerArea(UserIds[i], masterClockContainer.GameplayClock));
syncManager.AddPlayerClock(instances[i].GameplayClock);
}
@ -95,7 +92,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
var scoreProcessor = Ruleset.Value.CreateInstance().CreateScoreProcessor();
scoreProcessor.ApplyBeatmap(playableBeatmap);
LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, userIds) { Expanded = { Value = true } }, leaderboardContainer.Add);
LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(scoreProcessor, UserIds.ToArray()) { Expanded = { Value = true } }, leaderboardContainer.Add);
}
protected override void LoadComplete()
@ -130,7 +127,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
protected override void StartGameplay(int userId, GameplayState gameplayState)
{
var instance = instances[getIndexForUser(userId)];
var instance = instances.Single(i => i.UserId == userId);
instance.LoadScore(gameplayState.Score);
syncManager.AddPlayerClock(instance.GameplayClock);
@ -149,7 +147,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
multiplayerClient.ChangeState(MultiplayerUserState.Idle);
return base.OnBackButton();
}
private int getIndexForUser(int userId) => Array.IndexOf(userIds, userId);
}
}

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NuGet.Packaging;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
@ -27,8 +26,9 @@ namespace osu.Game.Screens.Spectate
/// </summary>
public abstract class SpectatorScreen : OsuScreen
{
protected IEnumerable<int> GetUserIds() => userIds;
private readonly HashSet<int> userIds = new HashSet<int>();
protected IReadOnlyList<int> UserIds => userIds;
private readonly List<int> userIds = new List<int>();
[Resolved]
private BeatmapManager beatmaps { get; set; }