mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 15:43:18 +08:00
Add beatmap availability change state & event methods
This commit is contained in:
parent
09e5e2629a
commit
dfa8be9173
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
@ -47,6 +48,13 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <param name="state">The new state of the user.</param>
|
/// <param name="state">The new state of the user.</param>
|
||||||
Task UserStateChanged(int userId, MultiplayerUserState state);
|
Task UserStateChanged(int userId, MultiplayerUserState state);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that a user in this room has their beatmap availability state changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The ID of the user whose beatmap availability state has changed.</param>
|
||||||
|
/// <param name="beatmapAvailability">The new beatmap availability state of the user.</param>
|
||||||
|
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.
|
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
@ -40,6 +41,13 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <exception cref="NotJoinedRoomException">If the user is not in a room.</exception>
|
/// <exception cref="NotJoinedRoomException">If the user is not in a room.</exception>
|
||||||
Task ChangeState(MultiplayerUserState newState);
|
Task ChangeState(MultiplayerUserState newState);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Change the user's local availability state of the beatmap set in joined room.
|
||||||
|
/// This will also force user state back to <see cref="MultiplayerUserState.Idle"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param>
|
||||||
|
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// As the host of a room, start the match.
|
/// As the host of a room, start the match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -14,6 +14,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
@ -173,6 +174,14 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeState), newState);
|
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeState), newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability)
|
||||||
|
{
|
||||||
|
if (!isConnected.Value)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability);
|
||||||
|
}
|
||||||
|
|
||||||
public override Task StartMatch()
|
public override Task StartMatch()
|
||||||
{
|
{
|
||||||
if (!isConnected.Value)
|
if (!isConnected.Value)
|
||||||
|
@ -184,6 +184,8 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
public abstract Task ChangeState(MultiplayerUserState newState);
|
public abstract Task ChangeState(MultiplayerUserState newState);
|
||||||
|
|
||||||
|
public abstract Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||||
|
|
||||||
public abstract Task StartMatch();
|
public abstract Task StartMatch();
|
||||||
|
|
||||||
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
||||||
@ -311,6 +313,24 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Task IMultiplayerClient.UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability)
|
||||||
|
{
|
||||||
|
if (Room == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
Scheduler.Add(() =>
|
||||||
|
{
|
||||||
|
if (Room == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Room.Users.Single(u => u.UserID == userId).BeatmapAvailability = beatmapAvailability;
|
||||||
|
|
||||||
|
RoomUpdated?.Invoke();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
Task IMultiplayerClient.LoadRequested()
|
Task IMultiplayerClient.LoadRequested()
|
||||||
{
|
{
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
|
@ -10,6 +10,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
@ -77,6 +78,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeUserBeatmapAvailability(int userId, BeatmapAvailability newBeatmapAvailability)
|
||||||
|
{
|
||||||
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
|
((IMultiplayerClient)this).UserBeatmapAvailabilityChanged(userId, newBeatmapAvailability);
|
||||||
|
ChangeUserState(userId, MultiplayerUserState.Idle);
|
||||||
|
}
|
||||||
|
|
||||||
protected override Task<MultiplayerRoom> JoinRoom(long roomId)
|
protected override Task<MultiplayerRoom> JoinRoom(long roomId)
|
||||||
{
|
{
|
||||||
var user = new MultiplayerRoomUser(api.LocalUser.Value.Id) { User = api.LocalUser.Value };
|
var user = new MultiplayerRoomUser(api.LocalUser.Value.Id) { User = api.LocalUser.Value };
|
||||||
@ -108,6 +117,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability)
|
||||||
|
{
|
||||||
|
ChangeUserBeatmapAvailability(api.LocalUser.Value.Id, newBeatmapAvailability);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
public override Task StartMatch()
|
public override Task StartMatch()
|
||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
Loading…
Reference in New Issue
Block a user