2020-02-14 11:03:37 +00: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;
|
2020-02-14 14:39:39 +00:00
|
|
|
using System.Linq;
|
2020-02-14 11:03:37 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2020-06-02 08:02:01 +00:00
|
|
|
using osu.Framework.Audio;
|
2020-02-14 11:03:37 +00:00
|
|
|
using osu.Framework.Bindables;
|
2020-06-02 08:02:01 +00:00
|
|
|
using osu.Framework.Platform;
|
2020-02-14 14:39:39 +00:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2020-02-14 11:03:37 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-05-14 06:02:36 +00:00
|
|
|
using osu.Game.Online.API;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-02-14 11:03:37 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-02-14 14:39:39 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2021-05-14 06:02:36 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2020-02-14 14:39:39 +00:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2020-02-14 11:03:37 +00:00
|
|
|
using osu.Game.Users;
|
2020-02-14 14:39:39 +00:00
|
|
|
using osuTK.Input;
|
2020-02-14 11:03:37 +00:00
|
|
|
|
2020-12-25 04:20:37 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Playlists
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-12-25 04:38:11 +00:00
|
|
|
public class TestScenePlaylistsRoomSubScreen : RoomTestScene
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
[Cached(typeof(IRoomManager))]
|
|
|
|
private readonly TestRoomManager roomManager = new TestRoomManager();
|
2020-02-14 11:03:37 +00:00
|
|
|
|
2020-06-02 08:02:01 +00:00
|
|
|
private BeatmapManager manager;
|
|
|
|
private RulesetStore rulesets;
|
2020-02-14 11:03:37 +00:00
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
private TestPlaylistsRoomSubScreen match;
|
2020-02-14 14:39:39 +00:00
|
|
|
|
2020-06-02 08:02:01 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
|
|
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
2021-05-31 09:37:32 +00:00
|
|
|
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
2020-06-02 08:02:01 +00:00
|
|
|
|
|
|
|
manager.Import(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Wait();
|
2021-05-14 06:02:36 +00:00
|
|
|
|
|
|
|
((DummyAPIAccess)API).HandleRequest = req =>
|
|
|
|
{
|
|
|
|
switch (req)
|
|
|
|
{
|
|
|
|
case CreateRoomScoreRequest createRoomScoreRequest:
|
|
|
|
createRoomScoreRequest.TriggerSuccess(new APIScoreToken { ID = 1 });
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
2020-06-02 08:02:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:39:39 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetupSteps()
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-12-25 04:11:21 +00:00
|
|
|
AddStep("load match", () => LoadScreen(match = new TestPlaylistsRoomSubScreen(Room)));
|
2020-02-14 14:39:39 +00:00
|
|
|
AddUntilStep("wait for load", () => match.IsCurrentScreen());
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 09:59:14 +00:00
|
|
|
[Test]
|
|
|
|
public void TestLoadSimpleMatch()
|
|
|
|
{
|
|
|
|
AddStep("set room properties", () =>
|
|
|
|
{
|
|
|
|
Room.RoomID.Value = 1;
|
|
|
|
Room.Name.Value = "my awesome room";
|
|
|
|
Room.Host.Value = new User { Id = 2, Username = "peppy" };
|
2020-06-25 11:53:48 +00:00
|
|
|
Room.RecentParticipants.Add(Room.Host.Value);
|
2021-05-14 06:02:36 +00:00
|
|
|
Room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
|
2020-06-25 09:59:14 +00:00
|
|
|
Room.Playlist.Add(new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
|
|
|
});
|
|
|
|
});
|
2021-05-14 06:02:36 +00:00
|
|
|
|
|
|
|
AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().Click());
|
|
|
|
AddUntilStep("player loader loaded", () => Stack.CurrentScreen is PlayerLoader);
|
2020-06-25 09:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 11:03:37 +00:00
|
|
|
[Test]
|
2020-02-14 14:39:39 +00:00
|
|
|
public void TestPlaylistItemSelectedOnCreate()
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
AddStep("set room properties", () =>
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
Room.Name.Value = "my awesome room";
|
|
|
|
Room.Host.Value = new User { Id = 2, Username = "peppy" };
|
|
|
|
Room.Playlist.Add(new PlaylistItem
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
2020-02-14 11:03:37 +00:00
|
|
|
});
|
2020-02-14 14:39:39 +00:00
|
|
|
});
|
2020-02-14 11:03:37 +00:00
|
|
|
|
2020-02-14 14:39:39 +00:00
|
|
|
AddStep("move mouse to create button", () =>
|
|
|
|
{
|
2021-01-20 12:27:16 +00:00
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<PlaylistsMatchSettingsOverlay.CreateRoomButton>().Single());
|
2020-02-14 11:03:37 +00:00
|
|
|
});
|
2020-02-14 14:39:39 +00:00
|
|
|
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
|
|
|
AddAssert("first playlist item selected", () => match.SelectedItem.Value == Room.Playlist[0]);
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 08:02:01 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapUpdatedOnReImport()
|
|
|
|
{
|
|
|
|
BeatmapSetInfo importedSet = null;
|
2021-06-23 10:30:08 +00:00
|
|
|
TestBeatmap beatmap = 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", () =>
|
|
|
|
{
|
|
|
|
beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
|
|
|
|
var existing = manager.QueryBeatmapSets(s => s.OnlineBeatmapSetID == beatmap.BeatmapInfo.BeatmapSet.OnlineBeatmapSetID).ToList();
|
|
|
|
|
|
|
|
foreach (var s in existing)
|
|
|
|
{
|
|
|
|
s.OnlineBeatmapSetID = null;
|
|
|
|
foreach (var b in s.Beatmaps)
|
|
|
|
b.OnlineBeatmapID = null;
|
|
|
|
manager.Update(s);
|
|
|
|
}
|
|
|
|
});
|
2020-06-02 08:02:01 +00:00
|
|
|
|
|
|
|
AddStep("import altered beatmap", () =>
|
|
|
|
{
|
|
|
|
beatmap.BeatmapInfo.BaseDifficulty.CircleSize = 1;
|
|
|
|
|
|
|
|
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("load room", () =>
|
|
|
|
{
|
|
|
|
Room.Name.Value = "my awesome room";
|
|
|
|
Room.Host.Value = new User { Id = 2, Username = "peppy" };
|
|
|
|
Room.Playlist.Add(new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = importedSet.Beatmaps[0] },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
2020-12-25 04:11:21 +00:00
|
|
|
InputManager.MoveMouseTo(match.ChildrenOfType<PlaylistsMatchSettingsOverlay.CreateRoomButton>().Single());
|
2020-06-02 08:02:01 +00:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("match has altered beatmap", () => match.Beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize == 1);
|
|
|
|
|
|
|
|
AddStep("re-import original beatmap", () => manager.Import(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapSet).Wait());
|
|
|
|
|
|
|
|
AddAssert("match has original beatmap", () => match.Beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize != 1);
|
|
|
|
}
|
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
private class TestPlaylistsRoomSubScreen : PlaylistsRoomSubScreen
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
public new Bindable<PlaylistItem> SelectedItem => base.SelectedItem;
|
|
|
|
|
2020-06-02 08:02:01 +00:00
|
|
|
public new Bindable<WorkingBeatmap> Beatmap => base.Beatmap;
|
|
|
|
|
2020-12-25 04:11:21 +00:00
|
|
|
public TestPlaylistsRoomSubScreen(Room room)
|
2020-02-14 14:39:39 +00:00
|
|
|
: base(room)
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
}
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:39:39 +00:00
|
|
|
private class TestRoomManager : IRoomManager
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-02-14 14:39:39 +00:00
|
|
|
public event Action RoomsUpdated
|
|
|
|
{
|
|
|
|
add => throw new NotImplementedException();
|
|
|
|
remove => throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:05:17 +00:00
|
|
|
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
2020-06-05 11:52:27 +00:00
|
|
|
|
2020-02-14 14:39:39 +00:00
|
|
|
public IBindableList<Room> Rooms { get; } = new BindableList<Room>();
|
|
|
|
|
|
|
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
|
|
|
{
|
|
|
|
room.RoomID.Value = 1;
|
|
|
|
onSuccess?.Invoke(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => onSuccess?.Invoke(room);
|
|
|
|
|
|
|
|
public void PartRoom()
|
|
|
|
{
|
|
|
|
}
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|