1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 11:32:54 +08:00

Fix broken spectator playback test scene

This commit is contained in:
Dan Balasescu 2022-02-04 19:03:52 +09:00
parent a289582f7c
commit dd63b1a350

View File

@ -3,12 +3,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -20,7 +16,6 @@ using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.Spectator;
using osu.Game.Replays;
using osu.Game.Replays.Legacy;
@ -32,6 +27,7 @@ using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.Spectator;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Graphics;
@ -47,68 +43,32 @@ namespace osu.Game.Tests.Visual.Gameplay
private Replay replay;
private readonly IBindableList<int> users = new BindableList<int>();
private TestReplayRecorder recorder;
private ManualClock manualClock;
private OsuSpriteText latencyDisplay;
private TestFramedReplayInputHandler replayHandler;
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private SpectatorClient spectatorClient { get; set; }
[Cached]
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Reset recorder state", cleanUpState);
AddStep("Setup containers", () =>
{
replay = new Replay();
manualClock = new ManualClock();
SpectatorClient spectatorClient;
spectatorClient.OnNewFrames += onNewFrames;
users.BindTo(spectatorClient.PlayingUsers);
users.BindCollectionChanged((obj, args) =>
Child = new DependencyProvidingContainer
{
switch (args.Action)
RelativeSizeAxes = Axes.Both,
CachedDependencies = new[]
{
case NotifyCollectionChangedAction.Add:
Debug.Assert(args.NewItems != null);
foreach (int user in args.NewItems)
{
if (user == api.LocalUser.Value.Id)
spectatorClient.WatchUser(user);
}
break;
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);
foreach (int user in args.OldItems)
{
if (user == api.LocalUser.Value.Id)
spectatorClient.StopWatchingUser(user);
}
break;
}
}, true);
(typeof(SpectatorClient), (object)(spectatorClient = new TestSpectatorClient())),
(typeof(GameplayState), new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>()))
},
Children = new Drawable[]
{
spectatorClient,
new GridContainer
{
RelativeSizeAxes = Axes.Both,
@ -118,7 +78,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
{
Recorder = recorder = new TestReplayRecorder
Recorder = new TestReplayRecorder
{
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
},
@ -178,7 +138,10 @@ namespace osu.Game.Tests.Visual.Gameplay
}
},
latencyDisplay = new OsuSpriteText()
}
};
spectatorClient.OnNewFrames += onNewFrames;
});
}
@ -238,20 +201,6 @@ namespace osu.Game.Tests.Visual.Gameplay
manualClock.CurrentTime = time.Value;
}
[TearDownSteps]
public void TearDown()
{
AddStep("stop recorder", cleanUpState);
}
private void cleanUpState()
{
// Ensure previous recorder is disposed else it may affect the global playing state of `SpectatorClient`.
recorder?.RemoveAndDisposeImmediately();
recorder = null;
spectatorClient.OnNewFrames -= onNewFrames;
}
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
{
public TestFramedReplayInputHandler(Replay replay)