1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 07:22:55 +08:00

Centralise room "creation"

This commit is contained in:
Dean Herbert 2021-10-27 14:11:07 +09:00
parent c4a253cc75
commit 84bb3a962b

View File

@ -47,18 +47,20 @@ namespace osu.Game.Tests.Visual.Playlists
[Test] [Test]
public void TestLoadSimpleMatch() public void TestLoadSimpleMatch()
{ {
AddStep("set room properties", () => setupRoom(room =>
{ {
SelectedRoom.Value.RoomID.Value = 1; room.RoomID.Value = 1; // forces room creation.
SelectedRoom.Value.Name.Value = "my awesome room"; room.Name.Value = "my awesome room";
SelectedRoom.Value.Host.Value = API.LocalUser.Value; room.Host.Value = API.LocalUser.Value;
SelectedRoom.Value.RecentParticipants.Add(SelectedRoom.Value.Host.Value); room.RecentParticipants.Add(room.Host.Value);
SelectedRoom.Value.EndDate.Value = DateTimeOffset.Now.AddMinutes(5); room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
SelectedRoom.Value.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo }, Beatmap = { Value = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
}); });
OnlinePlayDependencies.RoomManager.CreateRoom(SelectedRoom.Value);
}); });
AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick()); AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick());
@ -68,15 +70,17 @@ namespace osu.Game.Tests.Visual.Playlists
[Test] [Test]
public void TestPlaylistItemSelectedOnCreate() public void TestPlaylistItemSelectedOnCreate()
{ {
AddStep("set room properties", () => setupRoom(room =>
{ {
SelectedRoom.Value.Name.Value = "my awesome room"; room.Name.Value = "my awesome room";
SelectedRoom.Value.Host.Value = API.LocalUser.Value; room.Host.Value = API.LocalUser.Value;
SelectedRoom.Value.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo }, Beatmap = { Value = CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
}); });
OnlinePlayDependencies.RoomManager.CreateRoom(SelectedRoom.Value);
}); });
AddStep("move mouse to create button", () => AddStep("move mouse to create button", () =>
@ -119,11 +123,11 @@ namespace osu.Game.Tests.Visual.Playlists
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result.Value; importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result.Value;
}); });
AddStep("load room", () => setupRoom(room =>
{ {
SelectedRoom.Value.Name.Value = "my awesome room"; room.Name.Value = "my awesome room";
SelectedRoom.Value.Host.Value = API.LocalUser.Value; room.Host.Value = API.LocalUser.Value;
SelectedRoom.Value.Playlist.Add(new PlaylistItem room.Playlist.Add(new PlaylistItem
{ {
Beatmap = { Value = importedSet.Beatmaps[0] }, Beatmap = { Value = importedSet.Beatmaps[0] },
Ruleset = { Value = new OsuRuleset().RulesetInfo } Ruleset = { Value = new OsuRuleset().RulesetInfo }
@ -143,6 +147,18 @@ namespace osu.Game.Tests.Visual.Playlists
AddAssert("match has original beatmap", () => match.Beatmap.Value.Beatmap.Difficulty.CircleSize != 1); AddAssert("match has original beatmap", () => match.Beatmap.Value.Beatmap.Difficulty.CircleSize != 1);
} }
private void setupRoom(Action<Room> room)
{
AddStep("setup room", () =>
{
room(SelectedRoom.Value);
// if this isn't done the test will crash when a poll kicks in.
// probably not correct, but works for now.
OnlinePlayDependencies.RoomManager.CreateRoom(SelectedRoom.Value);
});
}
private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen
{ {
public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem; public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem;