mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 14:37:30 +08:00
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
|
// 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.Collections.Generic;
|
||
|
using osu.Framework.Allocation;
|
||
|
using osu.Game.Beatmaps;
|
||
|
using osu.Game.Online.API;
|
||
|
using osu.Game.Online.Rooms;
|
||
|
using osu.Game.Rulesets;
|
||
|
using osu.Game.Screens.OnlinePlay.Components;
|
||
|
using osu.Game.Users;
|
||
|
|
||
|
namespace osu.Game.Tests.Visual.OnlinePlay
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// A very simple <see cref="RoomManager"/> for use in online play test scenes.
|
||
|
/// </summary>
|
||
|
public class TestRequestHandlingRoomManager : RoomManager
|
||
|
{
|
||
|
public Action<Room, string> JoinRoomRequested;
|
||
|
|
||
|
private int currentRoomId;
|
||
|
|
||
|
private readonly TestRoomRequestsHandler handler = new TestRoomRequestsHandler();
|
||
|
|
||
|
[BackgroundDependencyLoader]
|
||
|
private void load(IAPIProvider api, OsuGameBase game)
|
||
|
{
|
||
|
((DummyAPIAccess)api).HandleRequest = request => handler.HandleRequest(request, api.LocalUser.Value, game);
|
||
|
}
|
||
|
|
||
|
public override void JoinRoom(Room room, string password = null, Action<Room> onSuccess = null, Action<string> onError = null)
|
||
|
{
|
||
|
JoinRoomRequested?.Invoke(room, password);
|
||
|
base.JoinRoom(room, password, onSuccess, onError);
|
||
|
}
|
||
|
|
||
|
public void AddRooms(int count, RulesetInfo ruleset = null, bool withPassword = false)
|
||
|
{
|
||
|
for (int i = 0; i < count; i++)
|
||
|
{
|
||
|
var room = new Room
|
||
|
{
|
||
|
RoomID = { Value = -currentRoomId },
|
||
|
Name = { Value = $@"Room {currentRoomId}" },
|
||
|
Host = { Value = new User { Username = @"Host" } },
|
||
|
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
||
|
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
|
||
|
};
|
||
|
|
||
|
if (withPassword)
|
||
|
room.Password.Value = @"password";
|
||
|
|
||
|
if (ruleset != null)
|
||
|
{
|
||
|
room.Playlist.Add(new PlaylistItem
|
||
|
{
|
||
|
Ruleset = { Value = ruleset },
|
||
|
Beatmap =
|
||
|
{
|
||
|
Value = new BeatmapInfo
|
||
|
{
|
||
|
Metadata = new BeatmapMetadata()
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
CreateRoom(room);
|
||
|
|
||
|
currentRoomId++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|