diff --git a/osu.Game/Screens/Play/Spectator.cs b/osu.Game/Screens/Play/Spectator.cs index 2de6c16c45..51cd5b59aa 100644 --- a/osu.Game/Screens/Play/Spectator.cs +++ b/osu.Game/Screens/Play/Spectator.cs @@ -164,7 +164,7 @@ private void userBeganPlaying(int userId, SpectatorState state) this.state = state; - attemptStart(); + Schedule(attemptStart); } private void userFinishedPlaying(int userId, SpectatorState state) @@ -175,6 +175,7 @@ private void userFinishedPlaying(int userId, SpectatorState state) if (replay == null) return; replay.HasReceivedAllFrames = true; + replay = null; } private void attemptStart() @@ -188,8 +189,6 @@ private void attemptStart() if (state.BeatmapID == null) return; - this.MakeCurrent(); - var resolvedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == state.BeatmapID); if (resolvedBeatmap == null) @@ -201,6 +200,7 @@ private void attemptStart() var scoreInfo = new ScoreInfo { Beatmap = resolvedBeatmap, + User = targetUser, Mods = state.Mods.Select(m => m.ToMod(resolvedRuleset)).ToArray(), Ruleset = resolvedRuleset.RulesetInfo, }; diff --git a/osu.Game/Screens/Play/SpectatorPlayer.cs b/osu.Game/Screens/Play/SpectatorPlayer.cs index 89e5f8f2dc..fbd21b32ba 100644 --- a/osu.Game/Screens/Play/SpectatorPlayer.cs +++ b/osu.Game/Screens/Play/SpectatorPlayer.cs @@ -2,18 +2,36 @@ // See the LICENCE file in the repository root for full licence text. using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Screens; using osu.Game.Beatmaps; +using osu.Game.Online.Spectator; using osu.Game.Scoring; namespace osu.Game.Screens.Play { public class SpectatorPlayer : ReplayPlayer { + [Resolved] + private SpectatorStreamingClient spectatorStreaming { get; set; } + public SpectatorPlayer(Score score) : base(score) { } + [BackgroundDependencyLoader] + private void load() + { + spectatorStreaming.OnUserBeganPlaying += userBeganPlaying; + } + + private void userBeganPlaying(int userId, SpectatorState state) + { + if (userId == Score.ScoreInfo.UserID) + Schedule(this.Exit); + } + protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart) { // if we already have frames, start gameplay at the point in time they exist, should they be too far into the beatmap.