2020-12-19 01:59:11 +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.
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
using System;
|
2020-12-19 01:59:11 +08:00
|
|
|
using System.Linq;
|
2021-07-02 13:43:48 +08:00
|
|
|
using System.Threading.Tasks;
|
2020-12-19 01:59:11 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
2021-01-17 04:04:28 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-11-23 13:06:06 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-12-29 03:59:38 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-12-24 16:17:45 +08:00
|
|
|
using osu.Framework.Utils;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-29 03:59:38 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Game.Rulesets;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
2020-12-19 01:59:11 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
2020-12-25 12:20:37 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-19 01:59:11 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
|
2020-12-19 01:59:11 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
private MultiplayerReadyButton button;
|
2021-01-05 11:00:15 +08:00
|
|
|
private BeatmapSetInfo importedSet;
|
2020-12-19 01:59:11 +08:00
|
|
|
|
2021-01-17 04:04:28 +08:00
|
|
|
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
|
|
|
|
2020-12-19 01:59:11 +08:00
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
|
2020-12-31 01:00:57 +08:00
|
|
|
private IDisposable readyClickOperation;
|
2020-12-29 16:09:47 +08:00
|
|
|
|
2020-12-19 01:59:11 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
|
|
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
2021-05-31 17:37:32 +08:00
|
|
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
2021-02-22 13:53:32 +08:00
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
2020-12-19 01:59:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public new void Setup() => Schedule(() =>
|
|
|
|
{
|
2021-06-25 14:00:10 +08:00
|
|
|
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
|
|
|
|
2021-01-05 11:00:15 +08:00
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
|
|
|
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
2021-01-17 04:04:28 +08:00
|
|
|
selectedItem.Value = new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = Beatmap.Value.BeatmapInfo },
|
|
|
|
Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset },
|
|
|
|
};
|
2020-12-19 01:59:11 +08:00
|
|
|
|
2021-01-17 04:04:28 +08:00
|
|
|
if (button != null)
|
|
|
|
Remove(button);
|
|
|
|
|
|
|
|
Add(button = new MultiplayerReadyButton
|
2020-12-19 01:59:11 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(200, 50),
|
2021-07-02 15:04:51 +08:00
|
|
|
OnReadyClick = () =>
|
2020-12-29 16:09:47 +08:00
|
|
|
{
|
2021-01-09 05:28:21 +08:00
|
|
|
readyClickOperation = OngoingOperationTracker.BeginOperation();
|
2020-12-29 16:09:47 +08:00
|
|
|
|
2021-07-02 15:04:51 +08:00
|
|
|
Task.Run(async () =>
|
2020-12-31 01:00:57 +08:00
|
|
|
{
|
2021-07-02 15:04:51 +08:00
|
|
|
if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready)
|
|
|
|
{
|
|
|
|
await Client.StartMatch();
|
|
|
|
return;
|
|
|
|
}
|
2020-12-31 01:00:57 +08:00
|
|
|
|
2021-07-02 15:04:51 +08:00
|
|
|
await Client.ToggleReady();
|
|
|
|
|
|
|
|
readyClickOperation.Dispose();
|
|
|
|
});
|
|
|
|
}
|
2021-01-17 04:04:28 +08:00
|
|
|
});
|
2020-12-19 01:59:11 +08:00
|
|
|
});
|
|
|
|
|
2021-01-05 11:00:15 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDeletedBeatmapDisableReady()
|
|
|
|
{
|
|
|
|
OsuButton readyButton = null;
|
|
|
|
|
|
|
|
AddAssert("ensure ready button enabled", () =>
|
|
|
|
{
|
|
|
|
readyButton = button.ChildrenOfType<OsuButton>().Single();
|
|
|
|
return readyButton.Enabled.Value;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
|
|
|
AddAssert("ready button disabled", () => !readyButton.Enabled.Value);
|
|
|
|
AddStep("undelete beatmap", () => beatmaps.Undelete(importedSet));
|
|
|
|
AddAssert("ready button enabled back", () => readyButton.Enabled.Value);
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:59:11 +08:00
|
|
|
[Test]
|
|
|
|
public void TestToggleStateWhenNotHost()
|
|
|
|
{
|
|
|
|
AddStep("add second user as host", () =>
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
Client.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
2020-12-19 01:59:11 +08:00
|
|
|
Client.TransferHost(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
addClickButtonStep();
|
2021-07-06 16:52:27 +08:00
|
|
|
AddUntilStep("user is ready", () => Client.Room?.Users[0].State == MultiplayerUserState.Ready);
|
2020-12-19 01:59:11 +08:00
|
|
|
|
|
|
|
addClickButtonStep();
|
2021-07-06 16:52:27 +08:00
|
|
|
AddUntilStep("user is idle", () => Client.Room?.Users[0].State == MultiplayerUserState.Idle);
|
2020-12-19 01:59:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void TestToggleStateWhenHost(bool allReady)
|
|
|
|
{
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
Client.TransferHost(Client.Room?.Users[0].UserID ?? 0);
|
|
|
|
|
|
|
|
if (!allReady)
|
2021-11-04 17:02:44 +08:00
|
|
|
Client.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
2020-12-19 01:59:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
addClickButtonStep();
|
2021-07-06 16:52:27 +08:00
|
|
|
AddUntilStep("user is ready", () => Client.Room?.Users[0].State == MultiplayerUserState.Ready);
|
2020-12-19 01:59:11 +08:00
|
|
|
|
2020-12-29 03:59:38 +08:00
|
|
|
verifyGameplayStartFlow();
|
2020-12-19 01:59:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBecomeHostWhileReady()
|
|
|
|
{
|
2020-12-20 17:44:41 +08:00
|
|
|
AddStep("add host", () =>
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
Client.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
2020-12-20 17:44:41 +08:00
|
|
|
Client.TransferHost(2);
|
|
|
|
});
|
|
|
|
|
2020-12-19 01:59:11 +08:00
|
|
|
addClickButtonStep();
|
|
|
|
AddStep("make user host", () => Client.TransferHost(Client.Room?.Users[0].UserID ?? 0));
|
|
|
|
|
2020-12-29 03:59:38 +08:00
|
|
|
verifyGameplayStartFlow();
|
2020-12-19 01:59:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLoseHostWhileReady()
|
|
|
|
{
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
Client.TransferHost(Client.Room?.Users[0].UserID ?? 0);
|
2021-11-04 17:02:44 +08:00
|
|
|
Client.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
2020-12-19 01:59:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
addClickButtonStep();
|
|
|
|
AddStep("transfer host", () => Client.TransferHost(Client.Room?.Users[1].UserID ?? 0));
|
|
|
|
|
|
|
|
addClickButtonStep();
|
|
|
|
AddAssert("match not started", () => Client.Room?.Users[0].State == MultiplayerUserState.Idle);
|
|
|
|
}
|
|
|
|
|
2020-12-24 16:17:45 +08:00
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void TestManyUsersChangingState(bool isHost)
|
|
|
|
{
|
|
|
|
const int users = 10;
|
|
|
|
AddStep("setup", () =>
|
|
|
|
{
|
|
|
|
Client.TransferHost(Client.Room?.Users[0].UserID ?? 0);
|
|
|
|
for (int i = 0; i < users; i++)
|
2021-11-04 17:02:44 +08:00
|
|
|
Client.AddUser(new APIUser { Id = i, Username = "Another user" });
|
2020-12-24 16:17:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!isHost)
|
|
|
|
AddStep("transfer host", () => Client.TransferHost(2));
|
|
|
|
|
|
|
|
addClickButtonStep();
|
|
|
|
|
|
|
|
AddRepeatStep("change user ready state", () =>
|
|
|
|
{
|
|
|
|
Client.ChangeUserState(RNG.Next(0, users), RNG.NextBool() ? MultiplayerUserState.Ready : MultiplayerUserState.Idle);
|
|
|
|
}, 20);
|
|
|
|
|
|
|
|
AddRepeatStep("ready all users", () =>
|
|
|
|
{
|
|
|
|
var nextUnready = Client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
|
|
|
if (nextUnready != null)
|
|
|
|
Client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
|
|
|
}, users);
|
|
|
|
}
|
|
|
|
|
2021-11-23 13:06:06 +08:00
|
|
|
private void addClickButtonStep()
|
2020-12-19 01:59:11 +08:00
|
|
|
{
|
2021-11-23 13:06:06 +08:00
|
|
|
AddUntilStep("wait for button to be ready", () => button.ChildrenOfType<Button>().Single().Enabled.Value);
|
|
|
|
AddStep("click button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(button);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
}
|
2020-12-29 03:59:38 +08:00
|
|
|
|
|
|
|
private void verifyGameplayStartFlow()
|
|
|
|
{
|
2021-07-06 16:52:27 +08:00
|
|
|
AddUntilStep("user is ready", () => Client.Room?.Users[0].State == MultiplayerUserState.Ready);
|
2020-12-29 03:59:38 +08:00
|
|
|
addClickButtonStep();
|
2021-07-06 16:52:27 +08:00
|
|
|
AddUntilStep("user waiting for load", () => Client.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
2020-12-29 03:59:38 +08:00
|
|
|
|
2021-04-08 15:29:11 +08:00
|
|
|
AddAssert("ready button disabled", () => !button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
2020-12-31 01:00:57 +08:00
|
|
|
AddStep("transitioned to gameplay", () => readyClickOperation.Dispose());
|
2021-04-08 15:29:11 +08:00
|
|
|
|
|
|
|
AddStep("finish gameplay", () =>
|
|
|
|
{
|
|
|
|
Client.ChangeUserState(Client.Room?.Users[0].UserID ?? 0, MultiplayerUserState.Loaded);
|
|
|
|
Client.ChangeUserState(Client.Room?.Users[0].UserID ?? 0, MultiplayerUserState.FinishedPlay);
|
|
|
|
});
|
|
|
|
|
2021-07-06 16:57:24 +08:00
|
|
|
AddUntilStep("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
2020-12-29 03:59:38 +08:00
|
|
|
}
|
2020-12-19 01:59:11 +08:00
|
|
|
}
|
|
|
|
}
|