1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-23 10:23:04 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs

165 lines
5.6 KiB
C#
Raw Normal View History

// 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;
2018-12-25 10:59:08 +08:00
using System.Linq;
2020-02-06 11:17:05 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
2020-02-06 12:03:15 +08:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
2020-02-06 12:03:15 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Multi;
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Users;
using osuTK.Graphics;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneLoungeRoomsContainer : MultiplayerTestScene
{
[Cached(Type = typeof(IRoomManager))]
private TestRoomManager roomManager = new TestRoomManager();
2020-02-06 11:17:05 +08:00
private RoomsContainer container;
[BackgroundDependencyLoader]
private void load()
{
2018-12-25 10:59:08 +08:00
Child = container = new RoomsContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
JoinRequested = joinRequested
};
2020-02-06 11:17:05 +08:00
}
public override void SetUpSteps()
{
base.SetUpSteps();
2018-12-25 10:59:08 +08:00
AddStep("clear rooms", () => roomManager.Rooms.Clear());
2020-02-06 11:17:05 +08:00
}
2020-02-06 11:17:05 +08:00
[Test]
public void TestBasicListChanges()
2020-02-06 11:26:08 +08:00
{
addRooms(3);
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
AddStep("select first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room selected", () => Room == roomManager.Rooms.First());
AddStep("join first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room joined", () => roomManager.Rooms.First().Status.Value is JoinedRoomStatus);
}
[Test]
public void TestStringFiltering()
{
addRooms(4);
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
AddStep("filter one room", () => container.Filter(new FilterCriteria { SearchString = "1" }));
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
AddStep("remove filter", () => container.Filter(null));
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
}
2020-02-06 12:03:15 +08:00
[Test]
public void TestRulesetFiltering()
{
addRooms(2, new OsuRuleset().RulesetInfo);
addRooms(3, new CatchRuleset().RulesetInfo);
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
AddStep("filter osu! rooms", () => container.Filter(new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo }));
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
AddStep("filter catch rooms", () => container.Filter(new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo }));
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
}
private void addRooms(int count, RulesetInfo ruleset = null)
2020-02-06 11:17:05 +08:00
{
2018-12-25 10:59:08 +08:00
AddStep("add rooms", () =>
{
2020-02-06 11:26:08 +08:00
for (int i = 0; i < count; i++)
2018-12-25 10:59:08 +08:00
{
2020-02-06 12:03:15 +08:00
var room = new Room
2018-12-25 10:59:08 +08:00
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
2020-02-06 12:03:15 +08:00
};
if (ruleset != null)
2020-02-06 12:04:29 +08:00
{
2020-02-06 12:03:15 +08:00
room.Playlist.Add(new PlaylistItem
{
Ruleset = { Value = ruleset },
Beatmap =
2020-02-06 12:03:15 +08:00
{
Value = new BeatmapInfo
{
Metadata = new BeatmapMetadata()
}
2020-02-06 12:03:15 +08:00
}
});
2020-02-06 12:04:29 +08:00
}
2020-02-06 12:03:15 +08:00
roomManager.Rooms.Add(room);
2018-12-25 10:59:08 +08:00
}
});
}
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
private class TestRoomManager : IRoomManager
{
2019-02-08 15:02:00 +08:00
public event Action RoomsUpdated
{
2019-02-08 15:02:14 +08:00
add { }
remove { }
2019-02-08 15:02:00 +08:00
}
2018-12-28 00:45:19 +08:00
2019-01-07 17:50:27 +08:00
public readonly BindableList<Room> Rooms = new BindableList<Room>();
IBindableList<Room> IRoomManager.Rooms => Rooms;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
}
public void PartRoom()
{
}
}
private class JoinedRoomStatus : RoomStatus
{
public override string Message => "Joined";
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Yellow;
}
}
}