1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-23 20:03:04 +08:00
osu-lazer/osu.Game.Tests/Visual/Playlists/TestScenePlaylistsRoomCreation.cs

230 lines
8.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;
2021-12-17 17:26:12 +08:00
using System.Diagnostics;
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.Rulesets.Osu.Objects;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps;
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;
private BeatmapSetInfo importedBeatmap;
2021-10-27 13:26:37 +08:00
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, API, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(Realm);
}
[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.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(importedBeatmap.Beatmaps.First())
2020-06-25 17:59:14 +08:00
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
2020-06-25 17:59:14 +08:00
});
});
AddUntilStep("Progress details are hidden", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 0);
AddUntilStep("Leaderboard shows two aggregate scores", () => match.ChildrenOfType<MatchLeaderboardScore>().Count(s => s.ScoreText.Text != "0") == 2);
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
}
[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);
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
});
});
AddUntilStep("Progress details are visible", () => match.ChildrenOfType<RoomLocalUserInfo>().FirstOrDefault()?.Parent.Alpha == 1);
}
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(importedBeatmap.Beatmaps.First())
2020-02-14 19:03:37 +08:00
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
2020-02-14 19:03:37 +08:00
});
});
2020-02-14 19:03:37 +08:00
AddAssert("first playlist item selected", () => match.SelectedItem.Value == SelectedRoom.Value.Playlist[0]);
2020-02-14 19:03:37 +08:00
}
[Test]
public void TestBeatmapUpdatedOnReImport()
{
string realHash = null;
int realOnlineId = 0;
int realOnlineSetId = 0;
AddStep("store real beatmap values", () =>
{
realHash = importedBeatmap.Beatmaps[0].MD5Hash;
realOnlineId = importedBeatmap.Beatmaps[0].OnlineID;
realOnlineSetId = importedBeatmap.OnlineID;
});
AddStep("import modified beatmap", () =>
{
var modifiedBeatmap = new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo =
{
OnlineID = realOnlineId,
Metadata = new BeatmapMetadata(),
BeatmapSet =
{
OnlineID = realOnlineSetId
}
},
};
modifiedBeatmap.HitObjects.Clear();
modifiedBeatmap.HitObjects.Add(new HitCircle { StartTime = 5000 });
2022-01-12 22:42:12 +08:00
Debug.Assert(modifiedBeatmap.BeatmapInfo.BeatmapSet != null);
manager.Import(modifiedBeatmap.BeatmapInfo.BeatmapSet);
});
// Create the room using the real beatmap values.
setupAndCreateRoom(room =>
{
room.Name.Value = "my awesome room";
room.Host.Value = API.LocalUser.Value;
room.Playlist.Add(new PlaylistItem(new BeatmapInfo
{
MD5Hash = realHash,
OnlineID = realOnlineId,
Metadata = new BeatmapMetadata(),
BeatmapSet = new BeatmapSetInfo
{
OnlineID = realOnlineSetId,
}
})
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
});
});
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 17:26:12 +08:00
Debug.Assert(originalBeatmap.BeatmapInfo.BeatmapSet != null);
manager.Import(originalBeatmap.BeatmapInfo.BeatmapSet);
});
AddUntilStep("match has correct beatmap", () => realHash == match.Beatmap.Value.BeatmapInfo.MD5Hash);
}
2021-10-27 13:26:37 +08:00
private void setupAndCreateRoom(Action<Room> room)
2021-10-27 13:11:07 +08:00
{
2021-10-28 14:41:59 +08:00
AddStep("setup room", () => room(SelectedRoom.Value));
2021-10-27 13:11:07 +08:00
2021-10-28 14:41:59 +08:00
AddStep("click create button", () =>
{
InputManager.MoveMouseTo(this.ChildrenOfType<PlaylistsRoomSettingsOverlay.CreateRoomButton>().Single());
InputManager.Click(MouseButton.Left);
2021-10-27 13:11:07 +08:00
});
}
2021-12-17 17:26:12 +08:00
private void importBeatmap() => AddStep("import beatmap", () =>
{
var beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
Debug.Assert(beatmap.BeatmapInfo.BeatmapSet != null);
importedBeatmap = manager.Import(beatmap.BeatmapInfo.BeatmapSet)?.Value.Detach();
2021-12-17 17:26:12 +08:00
});
2021-10-27 13:26:37 +08:00
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
}
}
}