2020-10-27 09:56:28 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System.Linq;
|
2020-10-28 08:42:04 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Screens;
|
2020-10-27 09:56:28 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2020-10-28 08:42:04 +00:00
|
|
|
using osu.Game.Online.Spectator;
|
2020-10-27 09:56:28 +00:00
|
|
|
using osu.Game.Scoring;
|
2020-10-28 09:05:15 +00:00
|
|
|
using osu.Game.Screens.Ranking;
|
2020-10-27 09:56:28 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
2020-10-28 09:40:06 +00:00
|
|
|
public class SpectatorPlayer : Player
|
2020-10-27 09:56:28 +00:00
|
|
|
{
|
2020-10-28 09:40:06 +00:00
|
|
|
private readonly Score score;
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => false; // todo: better support starting mid-way through beatmap
|
|
|
|
|
2020-10-27 09:56:28 +00:00
|
|
|
public SpectatorPlayer(Score score)
|
2020-10-28 09:40:06 +00:00
|
|
|
: base(true, true)
|
2020-10-27 09:56:28 +00:00
|
|
|
{
|
2020-10-28 09:40:06 +00:00
|
|
|
this.score = score;
|
2020-10-27 09:56:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:05:15 +00:00
|
|
|
protected override ResultsScreen CreateResults(ScoreInfo score)
|
|
|
|
{
|
|
|
|
return new SpectatorResultsScreen(score);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private SpectatorStreamingClient spectatorStreaming { get; set; }
|
|
|
|
|
2020-10-28 08:42:04 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
spectatorStreaming.OnUserBeganPlaying += userBeganPlaying;
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:40:06 +00:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
|
|
|
DrawableRuleset?.SetReplayScore(score);
|
|
|
|
}
|
|
|
|
|
2020-10-28 08:42:04 +00:00
|
|
|
private void userBeganPlaying(int userId, SpectatorState state)
|
|
|
|
{
|
2020-10-28 09:40:06 +00:00
|
|
|
if (userId == score.ScoreInfo.UserID)
|
2020-10-28 09:47:15 +00:00
|
|
|
{
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen()) this.Exit();
|
|
|
|
});
|
|
|
|
}
|
2020-10-28 08:42:04 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:05:15 +00:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (spectatorStreaming != null)
|
|
|
|
spectatorStreaming.OnUserBeganPlaying -= userBeganPlaying;
|
|
|
|
}
|
|
|
|
|
2020-10-27 09:56:28 +00:00
|
|
|
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.
|
2020-10-28 09:40:06 +00:00
|
|
|
double? firstFrameTime = score.Replay.Frames.FirstOrDefault()?.Time;
|
2020-10-27 09:56:28 +00:00
|
|
|
|
|
|
|
if (firstFrameTime == null || firstFrameTime <= gameplayStart + 5000)
|
|
|
|
return base.CreateGameplayClockContainer(beatmap, gameplayStart);
|
|
|
|
|
|
|
|
return new GameplayClockContainer(beatmap, firstFrameTime.Value, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|