1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Add room structure for countdown timers

This commit is contained in:
Dan Balasescu 2022-03-17 19:14:46 +09:00
parent efce471f0b
commit 3b938865a1
10 changed files with 125 additions and 1 deletions

View File

@ -0,0 +1,22 @@
// 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.
#nullable enable
using MessagePack;
namespace osu.Game.Online.Multiplayer.Countdown
{
/// <summary>
/// Indicates a change to the <see cref="MultiplayerRoom"/>'s countdown.
/// </summary>
[MessagePackObject]
public class CountdownChangedEvent : MatchServerEvent
{
/// <summary>
/// The new countdown.
/// </summary>
[Key(0)]
public MultiplayerCountdown? Countdown { get; set; }
}
}

View File

@ -0,0 +1,23 @@
// 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 MessagePack;
#nullable enable
namespace osu.Game.Online.Multiplayer.Countdown
{
/// <summary>
/// A request for a countdown to start the match.
/// </summary>
[MessagePackObject]
public class MatchStartCountdownRequest : MatchUserRequest
{
/// <summary>
/// How long the countdown should last.
/// </summary>
[Key(0)]
public TimeSpan Delay { get; set; }
}
}

View File

@ -0,0 +1,17 @@
// 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.
#nullable enable
using MessagePack;
namespace osu.Game.Online.Multiplayer.Countdown
{
/// <summary>
/// Request to stop the current countdown.
/// </summary>
[MessagePackObject]
public class StopCountdownRequest : MatchUserRequest
{
}
}

View File

@ -1,8 +1,11 @@
// 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.
#nullable enable
using System;
using MessagePack;
using osu.Game.Online.Multiplayer.Countdown;
namespace osu.Game.Online.Multiplayer
{
@ -11,6 +14,8 @@ namespace osu.Game.Online.Multiplayer
/// </summary>
[Serializable]
[MessagePackObject]
// IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
[Union(0, typeof(CountdownChangedEvent))]
public abstract class MatchServerEvent
{
}

View File

@ -0,0 +1,17 @@
// 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.
#nullable enable
using MessagePack;
namespace osu.Game.Online.Multiplayer
{
/// <summary>
/// A <see cref="MultiplayerCountdown"/> which will start the match after ending.
/// </summary>
[MessagePackObject]
public class MatchStartCountdown : MultiplayerCountdown
{
}
}

View File

@ -7,6 +7,7 @@ using MessagePack;
namespace osu.Game.Online.Multiplayer.MatchTypes.TeamVersus
{
[MessagePackObject]
public class ChangeTeamRequest : MatchUserRequest
{
[Key(0)]

View File

@ -3,6 +3,7 @@
using System;
using MessagePack;
using osu.Game.Online.Multiplayer.Countdown;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
namespace osu.Game.Online.Multiplayer
@ -12,7 +13,10 @@ namespace osu.Game.Online.Multiplayer
/// </summary>
[Serializable]
[MessagePackObject]
[Union(0, typeof(ChangeTeamRequest))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
// IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
[Union(0, typeof(ChangeTeamRequest))]
[Union(1, typeof(MatchStartCountdownRequest))]
[Union(2, typeof(StopCountdownRequest))]
public abstract class MatchUserRequest
{
}

View File

@ -0,0 +1,24 @@
// 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.
#nullable enable
using System;
using MessagePack;
namespace osu.Game.Online.Multiplayer
{
/// <summary>
/// Describes the current countdown in a <see cref="MultiplayerRoom"/>.
/// </summary>
[MessagePackObject]
[Union(0, typeof(MatchStartCountdown))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
public abstract class MultiplayerCountdown
{
/// <summary>
/// The time at which the countdown will end.
/// </summary>
[Key(0)]
public DateTimeOffset EndTime { get; set; }
}
}

View File

@ -54,6 +54,12 @@ namespace osu.Game.Online.Multiplayer
[Key(6)]
public IList<MultiplayerPlaylistItem> Playlist { get; set; } = new List<MultiplayerPlaylistItem>();
/// <summary>
/// The currently-running countdown.
/// </summary>
[Key(7)]
public MultiplayerCountdown? Countdown { get; set; }
[JsonConstructor]
[SerializationConstructor]
public MultiplayerRoom(long roomId)

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.Countdown;
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
namespace osu.Game.Online
@ -18,8 +19,12 @@ namespace osu.Game.Online
internal static readonly IReadOnlyList<(Type derivedType, Type baseType)> BASE_TYPE_MAPPING = new[]
{
(typeof(ChangeTeamRequest), typeof(MatchUserRequest)),
(typeof(MatchStartCountdownRequest), typeof(MatchUserRequest)),
(typeof(StopCountdownRequest), typeof(MatchUserRequest)),
(typeof(CountdownChangedEvent), typeof(MatchServerEvent)),
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),
(typeof(TeamVersusUserState), typeof(MatchUserState)),
(typeof(MatchStartCountdown), typeof(MultiplayerCountdown))
};
}
}