2021-08-17 13:39:08 +08: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.
|
|
|
|
|
2024-01-28 04:22:29 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2021-08-17 13:39:08 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2021-11-13 00:53:19 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-08-17 13:39:08 +08:00
|
|
|
using osu.Framework.Testing;
|
2021-11-13 00:53:19 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-12-10 19:08:59 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2024-01-28 04:22:29 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-08-17 13:39:08 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2024-01-28 04:22:29 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2021-08-17 13:39:08 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
2023-10-10 16:55:35 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2021-08-17 13:39:08 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public partial class TestSceneMultiplayerPlayer : MultiplayerTestScene
|
|
|
|
{
|
2024-11-13 16:15:50 +08:00
|
|
|
private MultiplayerPlayer player = null!;
|
2021-08-17 13:39:08 +08:00
|
|
|
|
2024-01-28 04:22:29 +08:00
|
|
|
[Test]
|
|
|
|
public void TestGameplay()
|
|
|
|
{
|
|
|
|
setup();
|
|
|
|
|
|
|
|
AddUntilStep("wait for gameplay start", () => player.LocalUserPlaying.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFail()
|
2021-08-17 13:39:08 +08:00
|
|
|
{
|
2024-01-28 04:22:29 +08:00
|
|
|
setup(() => new[] { new OsuModAutopilot() });
|
|
|
|
|
|
|
|
AddUntilStep("wait for gameplay start", () => player.LocalUserPlaying.Value);
|
|
|
|
AddStep("set health zero", () => player.ChildrenOfType<HealthProcessor>().Single().Health.Value = 0);
|
|
|
|
AddUntilStep("wait for fail", () => player.ChildrenOfType<HealthProcessor>().Single().HasFailed);
|
2024-01-28 05:34:23 +08:00
|
|
|
AddAssert("fail animation not shown", () => !player.GameplayState.HasFailed);
|
2021-08-17 13:39:08 +08:00
|
|
|
|
2024-01-28 04:22:29 +08:00
|
|
|
// ensure that even after reaching a failed state, score processor keeps accounting for new hit results.
|
|
|
|
// the testing method used here (autopilot + hold key) is sort-of dodgy, but works enough.
|
|
|
|
AddAssert("score is zero", () => player.GameplayState.ScoreProcessor.TotalScore.Value == 0);
|
|
|
|
AddStep("hold key", () => player.ChildrenOfType<OsuInputManager.RulesetKeyBindingContainer>().First().TriggerPressed(OsuAction.LeftButton));
|
|
|
|
AddUntilStep("score changed", () => player.GameplayState.ScoreProcessor.TotalScore.Value > 0);
|
|
|
|
}
|
|
|
|
|
2024-11-13 16:15:50 +08:00
|
|
|
private void setup(Func<IReadOnlyList<Mod>>? mods = null)
|
2024-01-28 04:22:29 +08:00
|
|
|
{
|
2021-08-17 13:39:08 +08:00
|
|
|
AddStep("set beatmap", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
2024-01-28 04:22:29 +08:00
|
|
|
SelectedMods.Value = mods?.Invoke() ?? Array.Empty<Mod>();
|
2021-08-17 13:39:08 +08:00
|
|
|
});
|
|
|
|
|
2023-10-10 16:55:35 +08:00
|
|
|
AddStep("Start track playing", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value.Track.Start();
|
|
|
|
});
|
|
|
|
|
2021-08-17 13:39:08 +08:00
|
|
|
AddStep("initialise gameplay", () =>
|
|
|
|
{
|
2024-11-13 16:15:50 +08:00
|
|
|
Stack.Push(player = new MultiplayerPlayer(MultiplayerClient.ServerAPIRoom!, new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
2021-12-10 19:08:59 +08:00
|
|
|
{
|
2022-02-15 15:01:14 +08:00
|
|
|
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID,
|
2024-11-13 16:15:50 +08:00
|
|
|
}, MultiplayerClient.ServerRoom!.Users.ToArray()));
|
2021-08-17 13:39:08 +08:00
|
|
|
});
|
2021-11-13 00:53:19 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen() && player.IsLoaded);
|
2023-10-10 16:55:35 +08:00
|
|
|
|
|
|
|
AddAssert("gameplay clock is paused", () => player.ChildrenOfType<GameplayClockContainer>().Single().IsPaused.Value);
|
|
|
|
AddAssert("gameplay clock is not running", () => !player.ChildrenOfType<GameplayClockContainer>().Single().IsRunning);
|
|
|
|
|
2022-04-21 21:37:26 +08:00
|
|
|
AddStep("start gameplay", () => ((IMultiplayerClient)MultiplayerClient).GameplayStarted());
|
2023-10-10 16:55:35 +08:00
|
|
|
|
|
|
|
AddUntilStep("gameplay clock is not paused", () => !player.ChildrenOfType<GameplayClockContainer>().Single().IsPaused.Value);
|
|
|
|
AddAssert("gameplay clock is running", () => player.ChildrenOfType<GameplayClockContainer>().Single().IsRunning);
|
2021-08-17 13:39:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|