2020-02-14 08:20:38 +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 08:51:42 +00:00
|
|
|
using System.Linq;
|
2020-02-14 08:20:38 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2020-02-14 08:51:42 +00:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Utils;
|
2020-02-14 08:20:38 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-06-24 10:09:31 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-02-14 08:51:42 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-08-13 10:48:41 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-02-14 08:51:42 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-08-13 10:48:41 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
2021-02-01 11:16:58 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2021-11-24 08:59:23 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
2021-06-24 08:01:28 +00:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2020-02-14 08:20:38 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
2021-06-25 04:02:19 +00:00
|
|
|
public class TestScenePlaylistsSongSelect : OnlinePlayTestScene
|
2020-02-14 08:20:38 +00:00
|
|
|
{
|
2020-02-14 08:51:42 +00:00
|
|
|
private BeatmapManager manager;
|
|
|
|
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
|
2021-02-01 11:16:58 +00:00
|
|
|
private TestPlaylistsSongSelect songSelect;
|
2020-02-14 08:51:42 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
2022-02-16 08:13:51 +00:00
|
|
|
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
2022-01-25 03:58:15 +00:00
|
|
|
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
|
|
|
Dependencies.Cache(Realm);
|
2020-02-14 08:51:42 +00:00
|
|
|
|
2021-11-24 08:59:23 +00:00
|
|
|
var beatmapSet = TestResources.CreateTestBeatmapSetInfo();
|
2020-02-14 08:51:42 +00:00
|
|
|
|
2022-01-25 06:23:51 +00:00
|
|
|
manager.Import(beatmapSet);
|
2020-02-14 08:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("reset", () =>
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
SelectedRoom.Value = new Room();
|
2020-02-14 08:51:42 +00:00
|
|
|
Ruleset.Value = new OsuRuleset().RulesetInfo;
|
|
|
|
Beatmap.SetDefault();
|
2021-02-09 04:09:38 +00:00
|
|
|
SelectedMods.Value = Array.Empty<Mod>();
|
2020-02-14 08:51:42 +00:00
|
|
|
});
|
|
|
|
|
2021-08-24 04:34:23 +00:00
|
|
|
AddStep("create song select", () => LoadScreen(songSelect = new TestPlaylistsSongSelect(SelectedRoom.Value)));
|
2021-11-25 12:11:13 +00:00
|
|
|
AddUntilStep("wait for present", () => songSelect.IsCurrentScreen() && songSelect.BeatmapSetsLoaded);
|
2020-02-14 08:51:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 08:20:38 +00:00
|
|
|
[Test]
|
2020-02-14 08:51:42 +00:00
|
|
|
public void TestItemAddedIfEmptyOnStart()
|
|
|
|
{
|
|
|
|
AddStep("finalise selection", () => songSelect.FinaliseSelection());
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("playlist has 1 item", () => SelectedRoom.Value.Playlist.Count == 1);
|
2020-02-14 08:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestItemAddedWhenCreateNewItemClicked()
|
|
|
|
{
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("playlist has 1 item", () => SelectedRoom.Value.Playlist.Count == 1);
|
2020-02-14 08:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestItemNotAddedIfExistingOnStart()
|
|
|
|
{
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
AddStep("finalise selection", () => songSelect.FinaliseSelection());
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("playlist has 1 item", () => SelectedRoom.Value.Playlist.Count == 1);
|
2020-02-14 08:51:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 10:56:01 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAddSameItemMultipleTimes()
|
|
|
|
{
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("playlist has 2 items", () => SelectedRoom.Value.Playlist.Count == 2);
|
2020-02-14 10:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 08:04:58 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAddItemAfterRearrangement()
|
|
|
|
{
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
AddStep("rearrange", () =>
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
var item = SelectedRoom.Value.Playlist[0];
|
|
|
|
SelectedRoom.Value.Playlist.RemoveAt(0);
|
|
|
|
SelectedRoom.Value.Playlist.Add(item);
|
2020-02-17 08:04:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create new item", () => songSelect.BeatmapDetails.CreateNewItem());
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("new item has id 2", () => SelectedRoom.Value.Playlist.Last().ID == 2);
|
2020-02-17 08:04:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 10:48:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Tests that the same <see cref="Mod"/> instances are not shared between two playlist items.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestNewItemHasNewModInstances()
|
|
|
|
{
|
|
|
|
AddStep("set dt mod", () => SelectedMods.Value = new[] { new OsuModDoubleTime() });
|
|
|
|
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
AddStep("change mod rate", () => ((OsuModDoubleTime)SelectedMods.Value[0]).SpeedChange.Value = 2);
|
|
|
|
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
|
2022-02-15 07:01:14 +00:00
|
|
|
AddAssert("item 1 has rate 1.5", () =>
|
|
|
|
{
|
|
|
|
var mod = (OsuModDoubleTime)SelectedRoom.Value.Playlist.First().RequiredMods[0].ToMod(new OsuRuleset());
|
|
|
|
return Precision.AlmostEquals(1.5, mod.SpeedChange.Value);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("item 2 has rate 2", () =>
|
|
|
|
{
|
|
|
|
var mod = (OsuModDoubleTime)SelectedRoom.Value.Playlist.Last().RequiredMods[0].ToMod(new OsuRuleset());
|
|
|
|
return Precision.AlmostEquals(2, mod.SpeedChange.Value);
|
|
|
|
});
|
2020-08-13 10:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 06:20:55 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Tests that the global mod instances are not retained by the rooms, as global mod instances are retained and re-used by the mod select overlay.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGlobalModInstancesNotRetained()
|
|
|
|
{
|
|
|
|
OsuModDoubleTime mod = null;
|
|
|
|
|
|
|
|
AddStep("set dt mod and store", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
|
|
|
|
|
|
|
// Mod select overlay replaces our mod.
|
|
|
|
mod = (OsuModDoubleTime)SelectedMods.Value[0];
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create item", () => songSelect.BeatmapDetails.CreateNewItem());
|
|
|
|
|
|
|
|
AddStep("change stored mod rate", () => mod.SpeedChange.Value = 2);
|
2022-02-15 07:01:14 +00:00
|
|
|
AddAssert("item has rate 1.5", () =>
|
|
|
|
{
|
|
|
|
var m = (OsuModDoubleTime)SelectedRoom.Value.Playlist.First().RequiredMods[0].ToMod(new OsuRuleset());
|
|
|
|
return Precision.AlmostEquals(1.5, m.SpeedChange.Value);
|
|
|
|
});
|
2020-09-04 06:20:55 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 11:16:58 +00:00
|
|
|
private class TestPlaylistsSongSelect : PlaylistsSongSelect
|
2020-02-14 08:20:38 +00:00
|
|
|
{
|
2020-02-14 08:51:42 +00:00
|
|
|
public new MatchBeatmapDetailArea BeatmapDetails => (MatchBeatmapDetailArea)base.BeatmapDetails;
|
2021-08-24 04:34:23 +00:00
|
|
|
|
|
|
|
public TestPlaylistsSongSelect(Room room)
|
|
|
|
: base(room)
|
|
|
|
{
|
|
|
|
}
|
2020-02-14 08:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|