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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-02-14 11:03:37 +00:00
|
|
|
using System;
|
2021-12-17 09:26:12 +00:00
|
|
|
using System.Diagnostics;
|
2020-02-14 14:39:39 +00:00
|
|
|
using System.Linq;
|
2022-07-30 08:49:33 +00:00
|
|
|
using JetBrains.Annotations;
|
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-10-27 05:26:37 +00:00
|
|
|
using osu.Game.Database;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2022-07-30 08:49:33 +00:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Dialog;
|
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;
|
2021-12-14 10:16:51 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2022-07-30 08:49:33 +00:00
|
|
|
using osu.Game.Screens.Menu;
|
2021-10-28 08:10:12 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
2022-01-18 04:58:12 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2021-05-14 06:02:36 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2021-12-14 10:16:51 +00:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2021-06-24 08:01:28 +00:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
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
|
|
|
{
|
2021-10-28 06:28:16 +00:00
|
|
|
public class TestScenePlaylistsRoomCreation : OnlinePlayTestScene
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2020-06-02 08:02:01 +00:00
|
|
|
private BeatmapManager manager;
|
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
|
|
|
|
2022-01-10 08:21:29 +00:00
|
|
|
private BeatmapSetInfo importedBeatmap;
|
2021-10-27 05:26:37 +00:00
|
|
|
|
2020-06-02 08:02:01 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
2022-07-28 07:19:05 +00:00
|
|
|
Dependencies.Cache(new RealmRulesetStore(Realm));
|
|
|
|
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default));
|
2022-01-25 03:58:15 +00:00
|
|
|
Dependencies.Cache(Realm);
|
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
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("set room", () => SelectedRoom.Value = new Room());
|
2021-10-27 05:26:37 +00:00
|
|
|
|
|
|
|
importBeatmap();
|
|
|
|
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("load match", () => LoadScreen(match = new TestPlaylistsRoomSubScreen(SelectedRoom.Value)));
|
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()
|
|
|
|
{
|
2021-10-27 05:26:37 +00:00
|
|
|
setupAndCreateRoom(room =>
|
2020-06-25 09:59:14 +00:00
|
|
|
{
|
2021-10-27 05:11:07 +00:00
|
|
|
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);
|
2022-02-15 14:33:26 +00:00
|
|
|
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
|
2020-06-25 09:59:14 +00:00
|
|
|
{
|
2022-02-15 07:01:14 +00:00
|
|
|
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
|
2020-06-25 09:59:14 +00:00
|
|
|
});
|
|
|
|
});
|
2021-05-14 06:02:36 +00:00
|
|
|
|
2021-10-28 08:10:12 +00:00
|
|
|
AddUntilStep("Progress details are hidden", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 0);
|
|
|
|
|
2022-01-18 04:58:12 +00:00
|
|
|
AddUntilStep("Leaderboard shows two aggregate scores", () => match.ChildrenOfType<MatchLeaderboardScore>().Count(s => s.ScoreText.Text != "0") == 2);
|
|
|
|
|
2021-08-04 08:27:44 +00:00
|
|
|
AddStep("start match", () => match.ChildrenOfType<PlaylistsReadyButton>().First().TriggerClick());
|
2021-05-14 06:02:36 +00:00
|
|
|
AddUntilStep("player loader loaded", () => Stack.CurrentScreen is PlayerLoader);
|
2020-06-25 09:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-28 08:10:12 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAttemptLimitedMatch()
|
|
|
|
{
|
|
|
|
setupAndCreateRoom(room =>
|
|
|
|
{
|
|
|
|
room.Name.Value = "my awesome room";
|
|
|
|
room.MaxAttempts.Value = 5;
|
|
|
|
room.Host.Value = API.LocalUser.Value;
|
|
|
|
room.RecentParticipants.Add(room.Host.Value);
|
|
|
|
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
|
2022-02-15 14:33:26 +00:00
|
|
|
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
|
2021-10-28 08:10:12 +00:00
|
|
|
{
|
2022-02-15 07:01:14 +00:00
|
|
|
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
|
2021-10-28 08:10:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("Progress details are visible", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-10-27 05:26:37 +00:00
|
|
|
setupAndCreateRoom(room =>
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2021-10-27 05:11:07 +00:00
|
|
|
room.Name.Value = "my awesome room";
|
|
|
|
room.Host.Value = API.LocalUser.Value;
|
2022-02-15 14:33:26 +00:00
|
|
|
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
|
2020-02-14 11:03:37 +00:00
|
|
|
{
|
2022-02-15 07:01:14 +00:00
|
|
|
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
|
2020-02-14 11:03:37 +00:00
|
|
|
});
|
2020-02-14 14:39:39 +00:00
|
|
|
});
|
2020-02-14 11:03:37 +00:00
|
|
|
|
2021-06-24 10:09:31 +00:00
|
|
|
AddAssert("first playlist item selected", () => match.SelectedItem.Value == SelectedRoom.Value.Playlist[0]);
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 10:16:51 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapUpdatedOnReImport()
|
|
|
|
{
|
|
|
|
string realHash = null;
|
|
|
|
int realOnlineId = 0;
|
|
|
|
int realOnlineSetId = 0;
|
|
|
|
|
|
|
|
AddStep("store real beatmap values", () =>
|
|
|
|
{
|
2022-01-10 08:21:29 +00:00
|
|
|
realHash = importedBeatmap.Beatmaps[0].MD5Hash;
|
|
|
|
realOnlineId = importedBeatmap.Beatmaps[0].OnlineID;
|
|
|
|
realOnlineSetId = importedBeatmap.OnlineID;
|
2021-12-14 10:16:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("import modified beatmap", () =>
|
|
|
|
{
|
|
|
|
var modifiedBeatmap = new TestBeatmap(new OsuRuleset().RulesetInfo)
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
OnlineID = realOnlineId,
|
2022-01-10 08:21:29 +00:00
|
|
|
Metadata = new BeatmapMetadata(),
|
2021-12-14 10:16:51 +00:00
|
|
|
BeatmapSet =
|
|
|
|
{
|
|
|
|
OnlineID = realOnlineSetId
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
modifiedBeatmap.HitObjects.Clear();
|
|
|
|
modifiedBeatmap.HitObjects.Add(new HitCircle { StartTime = 5000 });
|
|
|
|
|
2022-01-12 14:42:12 +00:00
|
|
|
Debug.Assert(modifiedBeatmap.BeatmapInfo.BeatmapSet != null);
|
|
|
|
|
2022-01-25 06:23:51 +00:00
|
|
|
manager.Import(modifiedBeatmap.BeatmapInfo.BeatmapSet);
|
2021-12-14 10:16:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Create the room using the real beatmap values.
|
|
|
|
setupAndCreateRoom(room =>
|
|
|
|
{
|
|
|
|
room.Name.Value = "my awesome room";
|
|
|
|
room.Host.Value = API.LocalUser.Value;
|
2022-02-15 14:33:26 +00:00
|
|
|
room.Playlist.Add(new PlaylistItem(new BeatmapInfo
|
2021-12-14 10:16:51 +00:00
|
|
|
{
|
2022-02-15 14:33:26 +00:00
|
|
|
MD5Hash = realHash,
|
|
|
|
OnlineID = realOnlineId,
|
|
|
|
Metadata = new BeatmapMetadata(),
|
|
|
|
BeatmapSet = new BeatmapSetInfo
|
2021-12-14 10:16:51 +00:00
|
|
|
{
|
2022-02-15 14:33:26 +00:00
|
|
|
OnlineID = realOnlineSetId,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
{
|
2022-02-15 07:01:14 +00:00
|
|
|
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
|
2021-12-14 10:16:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("match has default beatmap", () => match.Beatmap.IsDefault);
|
|
|
|
|
|
|
|
AddStep("reimport original beatmap", () =>
|
|
|
|
{
|
|
|
|
var originalBeatmap = new TestBeatmap(new OsuRuleset().RulesetInfo)
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
OnlineID = realOnlineId,
|
|
|
|
BeatmapSet =
|
|
|
|
{
|
|
|
|
OnlineID = realOnlineSetId
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-12-17 09:26:12 +00:00
|
|
|
Debug.Assert(originalBeatmap.BeatmapInfo.BeatmapSet != null);
|
|
|
|
|
2022-01-25 06:23:51 +00:00
|
|
|
manager.Import(originalBeatmap.BeatmapInfo.BeatmapSet);
|
2021-12-14 10:16:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("match has correct beatmap", () => realHash == match.Beatmap.Value.BeatmapInfo.MD5Hash);
|
|
|
|
}
|
|
|
|
|
2021-10-27 05:26:37 +00:00
|
|
|
private void setupAndCreateRoom(Action<Room> room)
|
2021-10-27 05:11:07 +00:00
|
|
|
{
|
2021-10-28 06:41:59 +00:00
|
|
|
AddStep("setup room", () => room(SelectedRoom.Value));
|
2021-10-27 05:11:07 +00:00
|
|
|
|
2021-10-28 06:41:59 +00:00
|
|
|
AddStep("click create button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<PlaylistsRoomSettingsOverlay.CreateRoomButton>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
2021-10-27 05:11:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-17 09:26:12 +00:00
|
|
|
private void importBeatmap() => AddStep("import beatmap", () =>
|
|
|
|
{
|
|
|
|
var beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
|
|
|
|
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
|
|
|
|
|
2022-01-25 06:23:51 +00:00
|
|
|
importedBeatmap = manager.Import(beatmap.BeatmapInfo.BeatmapSet)?.Value.Detach();
|
2021-12-17 09:26:12 +00:00
|
|
|
});
|
2021-10-27 05:26:37 +00:00
|
|
|
|
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;
|
|
|
|
|
2022-07-30 08:49:33 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
[CanBeNull]
|
|
|
|
private IDialogOverlay dialogOverlay { get; set; }
|
|
|
|
|
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
|
|
|
}
|
2022-07-30 08:49:33 +00:00
|
|
|
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
|
|
|
{
|
|
|
|
// For testing purposes allow the screen to exit without confirming on second attempt.
|
|
|
|
if (!ExitConfirmed && dialogOverlay?.CurrentDialog is ConfirmDiscardChangesDialog confirmDialog)
|
|
|
|
{
|
|
|
|
confirmDialog.PerformAction<PopupDialogDangerousButton>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnExiting(e);
|
|
|
|
}
|
2020-02-14 11:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|