1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs

174 lines
6.1 KiB
C#
Raw Normal View History

2020-02-14 19:03:37 +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.
using System;
using System.Linq;
2020-02-14 19:03:37 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
2020-02-14 19:03:37 +08:00
using osu.Framework.Bindables;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
2020-02-14 19:03:37 +08:00
using osu.Game.Beatmaps;
2021-10-27 13:26:37 +08:00
using osu.Game.Database;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
2020-02-14 19:03:37 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Play;
2021-06-24 16:01:28 +08:00
using osu.Game.Tests.Visual.OnlinePlay;
using osuTK.Input;
2020-02-14 19:03:37 +08:00
namespace osu.Game.Tests.Visual.Playlists
2020-02-14 19:03:37 +08:00
{
2021-10-28 14:28:16 +08:00
public class TestScenePlaylistsRoomCreation : OnlinePlayTestScene
2020-02-14 19:03:37 +08:00
{
private BeatmapManager manager;
private RulesetStore rulesets;
2020-02-14 19:03:37 +08:00
2020-12-25 12:11:21 +08:00
private TestPlaylistsRoomSubScreen match;
2021-10-27 13:26:37 +08:00
private ILive<BeatmapSetInfo> importedBeatmap;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
}
[SetUpSteps]
public void SetupSteps()
2020-02-14 19:03:37 +08:00
{
AddStep("set room", () => SelectedRoom.Value = new Room());
2021-10-27 13:26:37 +08:00
importBeatmap();
AddStep("load match", () => LoadScreen(match = new TestPlaylistsRoomSubScreen(SelectedRoom.Value)));
AddUntilStep("wait for load", () => match.IsCurrentScreen());
2020-02-14 19:03:37 +08:00
}
2020-06-25 17:59:14 +08:00
[Test]
public void TestLoadSimpleMatch()
{
2021-10-27 13:26:37 +08:00
setupAndCreateRoom(room =>
2020-06-25 17:59:14 +08:00
{
2021-10-27 13:11:07 +08:00
room.RoomID.Value = 1; // forces room creation.
room.Name.Value = "my awesome room";
room.Host.Value = API.LocalUser.Value;
room.RecentParticipants.Add(room.Host.Value);
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
room.Playlist.Add(new PlaylistItem
2020-06-25 17:59:14 +08:00
{
2021-10-27 13:26:37 +08:00
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() },
2020-06-25 17:59:14 +08:00
Ruleset = { Value = new OsuRuleset().RulesetInfo }
});
});
2021-08-04 16:27:44 +08:00
AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick());
AddUntilStep("player loader loaded", () => Stack.CurrentScreen is PlayerLoader);
2020-06-25 17:59:14 +08:00
}
2020-02-14 19:03:37 +08:00
[Test]
public void TestPlaylistItemSelectedOnCreate()
2020-02-14 19:03:37 +08:00
{
2021-10-27 13:26:37 +08:00
setupAndCreateRoom(room =>
2020-02-14 19:03:37 +08:00
{
2021-10-27 13:11:07 +08:00
room.Name.Value = "my awesome room";
room.Host.Value = API.LocalUser.Value;
room.Playlist.Add(new PlaylistItem
2020-02-14 19:03:37 +08:00
{
2021-10-27 13:26:37 +08:00
Beatmap = { Value = importedBeatmap.Value.Beatmaps.First() },
Ruleset = { Value = new OsuRuleset().RulesetInfo }
2020-02-14 19:03:37 +08:00
});
});
2020-02-14 19:03:37 +08:00
AddStep("move mouse to create button", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<PlaylistsRoomSettingsOverlay.CreateRoomButton>().Single());
2020-02-14 19:03:37 +08:00
});
AddStep("click", () => InputManager.Click(MouseButton.Left));
AddAssert("first playlist item selected", () => match.SelectedItem.Value == SelectedRoom.Value.Playlist[0]);
2020-02-14 19:03:37 +08:00
}
[Test]
public void TestBeatmapUpdatedOnReImport()
{
BeatmapSetInfo importedSet = null;
// this step is required to make sure the further imports actually get online IDs.
// all the playlist logic relies on online ID matching.
AddStep("remove all matching online IDs", () =>
{
2021-10-27 13:26:37 +08:00
var existing = manager.QueryBeatmapSets(s => s.OnlineBeatmapSetID == importedBeatmap.Value.OnlineBeatmapSetID).ToList();
foreach (var s in existing)
{
s.OnlineBeatmapSetID = null;
foreach (var b in s.Beatmaps)
b.OnlineBeatmapID = null;
manager.Update(s);
}
});
AddStep("import altered beatmap", () =>
{
2021-10-27 13:26:37 +08:00
IBeatmap beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
beatmap.BeatmapInfo.BaseDifficulty.CircleSize = 1;
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result.Value;
});
2021-10-27 13:26:37 +08:00
setupAndCreateRoom(room =>
{
2021-10-27 13:11:07 +08:00
room.Name.Value = "my awesome room";
room.Host.Value = API.LocalUser.Value;
room.Playlist.Add(new PlaylistItem
{
Beatmap = { Value = importedSet.Beatmaps[0] },
Ruleset = { Value = new OsuRuleset().RulesetInfo }
});
});
AddAssert("match has altered beatmap", () => match.Beatmap.Value.Beatmap.Difficulty.CircleSize == 1);
2021-10-27 13:26:37 +08:00
importBeatmap();
AddAssert("match has original beatmap", () => match.Beatmap.Value.Beatmap.Difficulty.CircleSize != 1);
}
2021-10-27 13:26:37 +08:00
private void setupAndCreateRoom(Action<Room> room)
2021-10-27 13:11:07 +08:00
{
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);
});
}
2021-10-27 13:26:37 +08:00
private void importBeatmap()
{
AddStep("import beatmap", () => importedBeatmap = manager.Import(CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Result);
}
2020-12-25 12:11:21 +08:00
private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen
2020-02-14 19:03:37 +08:00
{
public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem;
public new Bindable<WorkingBeatmap> Beatmap => base.Beatmap;
2020-12-25 12:11:21 +08:00
public TestPlaylistsRoomSubScreen(Room room)
: base(room)
2020-02-14 19:03:37 +08:00
{
}
2020-02-14 19:03:37 +08:00
}
}
}