1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 12:42:56 +08:00
osu-lazer/osu.Game/Tests/Visual/OnlinePlay/BasicTestRoomManager.cs

79 lines
2.5 KiB
C#
Raw Normal View History

2021-06-24 18:13:50 +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;
using System.Linq;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Screens.OnlinePlay;
2021-06-25 17:02:53 +08:00
using osu.Game.Screens.OnlinePlay.Components;
2021-06-24 18:13:50 +08:00
using osu.Game.Users;
namespace osu.Game.Tests.Visual.OnlinePlay
{
2021-06-25 17:02:53 +08:00
/// <summary>
/// A very simple <see cref="RoomManager"/> for use in online play test scenes.
2021-06-25 17:02:53 +08:00
/// </summary>
public class BasicTestRoomManager : IRoomManager
2021-06-24 18:13:50 +08:00
{
public event Action RoomsUpdated
{
add { }
remove { }
}
public readonly BindableList<Room> Rooms = new BindableList<Room>();
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
IBindableList<Room> IRoomManager.Rooms => Rooms;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1;
Rooms.Add(room);
onSuccess?.Invoke(room);
}
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => onSuccess?.Invoke(room);
public void PartRoom()
{
}
public void AddRooms(int count, RulesetInfo ruleset = null)
{
for (int i = 0; i < count; i++)
{
var room = new Room
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal }
};
if (ruleset != null)
{
room.Playlist.Add(new PlaylistItem
{
Ruleset = { Value = ruleset },
Beatmap =
{
Value = new BeatmapInfo
{
Metadata = new BeatmapMetadata()
}
}
});
}
CreateRoom(room);
}
}
}
}