2019-05-06 02:07:55 +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.
2023-12-07 01:16:45 +08:00
using System ;
using MessagePack ;
2019-05-06 02:07:55 +08:00
using osu.Game.Beatmaps ;
using osu.Game.Graphics ;
2023-12-07 01:16:45 +08:00
using osu.Game.Online ;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms ;
2020-01-03 23:22:33 +08:00
using osu.Game.Rulesets ;
2023-02-06 20:44:00 +08:00
using osu.Game.Scoring ;
2019-05-06 02:07:55 +08:00
using osuTK.Graphics ;
namespace osu.Game.Users
{
2023-12-07 01:16:45 +08:00
/// <summary>
/// Base class for all structures describing the user's current activity.
/// </summary>
/// <remarks>
/// Warning: keep <see cref="UnionAttribute"/> specs consistent with
/// <see cref="SignalRWorkaroundTypes.BASE_TYPE_MAPPING"/>.
/// </remarks>
[Serializable]
[MessagePackObject]
[Union(11, typeof(ChoosingBeatmap))]
[Union(12, typeof(InSoloGame))]
[Union(13, typeof(WatchingReplay))]
[Union(14, typeof(SpectatingUser))]
[Union(21, typeof(SearchingForLobby))]
[Union(22, typeof(InLobby))]
[Union(23, typeof(InMultiplayerGame))]
[Union(24, typeof(SpectatingMultiplayerGame))]
[Union(31, typeof(InPlaylistGame))]
[Union(41, typeof(EditingBeatmap))]
[Union(42, typeof(ModdingBeatmap))]
[Union(43, typeof(TestingBeatmap))]
2019-05-06 02:07:55 +08:00
public abstract class UserActivity
{
2023-02-07 05:30:55 +08:00
public abstract string GetStatus ( bool hideIdentifiableInformation = false ) ;
2023-12-07 01:16:45 +08:00
public virtual string? GetDetails ( bool hideIdentifiableInformation = false ) = > null ;
2023-02-06 20:44:00 +08:00
2019-05-06 02:07:55 +08:00
public virtual Color4 GetAppropriateColour ( OsuColour colours ) = > colours . GreenDarker ;
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2019-06-12 01:41:48 +08:00
public class ChoosingBeatmap : UserActivity
2019-05-12 23:38:02 +08:00
{
2023-02-07 05:30:55 +08:00
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > "Choosing a beatmap" ;
2019-05-12 23:38:02 +08:00
}
2019-05-06 02:07:55 +08:00
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2021-08-18 08:13:53 +08:00
public abstract class InGame : UserActivity
2019-05-06 02:07:55 +08:00
{
2023-12-07 01:16:45 +08:00
[Key(0)]
public int BeatmapID { get ; set ; }
[Key(1)]
public string BeatmapDisplayTitle { get ; set ; } = string . Empty ;
[Key(2)]
public int RulesetID { get ; set ; }
2021-08-16 06:32:33 +08:00
2023-12-07 01:16:45 +08:00
[Key(3)]
public string RulesetPlayingVerb { get ; set ; } = string . Empty ; // TODO: i'm going with this for now, but this is wasteful
2021-08-16 06:32:33 +08:00
2021-12-03 17:14:44 +08:00
protected InGame ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
2021-08-16 06:32:33 +08:00
{
2023-12-07 01:16:45 +08:00
BeatmapID = beatmapInfo . OnlineID ;
BeatmapDisplayTitle = beatmapInfo . GetDisplayTitle ( ) ;
RulesetID = ruleset . OnlineID ;
RulesetPlayingVerb = ruleset . CreateInstance ( ) . PlayingVerb ;
2021-08-16 06:32:33 +08:00
}
2021-08-16 07:06:23 +08:00
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
protected InGame ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > RulesetPlayingVerb ;
public override string GetDetails ( bool hideIdentifiableInformation = false ) = > BeatmapDisplayTitle ;
2021-08-16 06:32:33 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
public class InSoloGame : InGame
2021-08-16 06:32:33 +08:00
{
2023-12-07 01:16:45 +08:00
public InSoloGame ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
2021-10-02 23:55:29 +08:00
: base ( beatmapInfo , ruleset )
2021-08-14 13:20:36 +08:00
{
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public InSoloGame ( ) { }
2019-05-06 02:07:55 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
public class InMultiplayerGame : InGame
2022-02-25 15:03:46 +08:00
{
2023-12-07 01:16:45 +08:00
public InMultiplayerGame ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
2022-02-25 15:03:46 +08:00
: base ( beatmapInfo , ruleset )
{
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public InMultiplayerGame ( )
{
}
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > $@"{base.GetStatus(hideIdentifiableInformation)} with others" ;
2022-02-25 15:03:46 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2021-08-22 09:54:07 +08:00
public class InPlaylistGame : InGame
{
2021-12-03 17:14:44 +08:00
public InPlaylistGame ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
2021-10-02 23:55:29 +08:00
: base ( beatmapInfo , ruleset )
2021-08-22 09:54:07 +08:00
{
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public InPlaylistGame ( ) { }
2019-05-06 02:07:55 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2023-02-13 05:04:12 +08:00
public class TestingBeatmap : InGame
{
public TestingBeatmap ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
: base ( beatmapInfo , ruleset )
{
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public TestingBeatmap ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > "Testing a beatmap" ;
2023-02-13 05:04:12 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2023-02-13 04:32:17 +08:00
public class EditingBeatmap : UserActivity
2019-05-12 23:38:02 +08:00
{
2023-12-07 01:16:45 +08:00
[Key(0)]
public int BeatmapID { get ; set ; }
[Key(1)]
public string BeatmapDisplayTitle { get ; set ; } = string . Empty ;
2019-06-12 15:33:15 +08:00
2023-02-13 04:32:17 +08:00
public EditingBeatmap ( IBeatmapInfo info )
2019-05-12 23:38:02 +08:00
{
2023-12-07 01:16:45 +08:00
BeatmapID = info . OnlineID ;
BeatmapDisplayTitle = info . GetDisplayTitle ( ) ;
2019-05-12 23:38:02 +08:00
}
2019-05-06 02:07:55 +08:00
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public EditingBeatmap ( ) { }
2023-02-07 05:30:55 +08:00
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > @"Editing a beatmap" ;
2023-12-07 01:16:45 +08:00
public override string GetDetails ( bool hideIdentifiableInformation = false ) = > BeatmapDisplayTitle ;
2019-05-12 23:38:02 +08:00
}
2019-05-06 02:07:55 +08:00
2023-12-07 01:16:45 +08:00
[MessagePackObject]
public class ModdingBeatmap : EditingBeatmap
{
public ModdingBeatmap ( IBeatmapInfo info )
: base ( info )
{
}
[SerializationConstructor]
public ModdingBeatmap ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > "Modding a beatmap" ;
public override Color4 GetAppropriateColour ( OsuColour colours ) = > colours . PurpleDark ;
}
[MessagePackObject]
2023-02-13 04:32:17 +08:00
public class WatchingReplay : UserActivity
2019-05-12 23:38:02 +08:00
{
2023-12-07 01:16:45 +08:00
[Key(0)]
public long ScoreID { get ; set ; }
2023-02-06 20:44:00 +08:00
2023-12-07 01:16:45 +08:00
[Key(1)]
public string PlayerName { get ; set ; } = string . Empty ;
2023-02-06 20:44:00 +08:00
2023-12-07 01:16:45 +08:00
[Key(2)]
public int BeatmapID { get ; set ; }
[Key(3)]
public string? BeatmapDisplayTitle { get ; set ; }
2023-02-06 20:44:00 +08:00
2023-02-13 04:32:17 +08:00
public WatchingReplay ( ScoreInfo score )
2023-02-06 20:44:00 +08:00
{
2023-12-07 01:16:45 +08:00
ScoreID = score . OnlineID ;
PlayerName = score . User . Username ;
BeatmapID = score . BeatmapInfo ? . OnlineID ? ? - 1 ;
BeatmapDisplayTitle = score . BeatmapInfo ? . GetDisplayTitle ( ) ;
2023-02-06 20:44:00 +08:00
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public WatchingReplay ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > hideIdentifiableInformation ? @"Watching a replay" : $@"Watching {PlayerName}'s replay" ;
public override string? GetDetails ( bool hideIdentifiableInformation = false ) = > BeatmapDisplayTitle ;
2023-02-06 08:41:10 +08:00
}
2023-02-06 07:58:08 +08:00
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2023-02-13 04:32:17 +08:00
public class SpectatingUser : WatchingReplay
2023-02-06 08:41:10 +08:00
{
2023-02-13 04:32:17 +08:00
public SpectatingUser ( ScoreInfo score )
2023-02-06 20:44:00 +08:00
: base ( score )
{
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public SpectatingUser ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > hideIdentifiableInformation ? @"Spectating a user" : $@"Spectating {PlayerName}" ;
2019-05-12 23:38:02 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
public class SpectatingMultiplayerGame : InGame
{
public SpectatingMultiplayerGame ( IBeatmapInfo beatmapInfo , IRulesetInfo ruleset )
: base ( beatmapInfo , ruleset )
{
}
[SerializationConstructor]
public SpectatingMultiplayerGame ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > $"Watching others {base.GetStatus(hideIdentifiableInformation).ToLowerInvariant()}" ;
}
[MessagePackObject]
2020-11-08 20:21:21 +08:00
public class SearchingForLobby : UserActivity
{
2023-02-07 05:30:55 +08:00
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > @"Looking for a lobby" ;
2020-11-08 20:21:21 +08:00
}
2023-12-07 01:16:45 +08:00
[MessagePackObject]
2019-06-12 01:41:48 +08:00
public class InLobby : UserActivity
2019-05-12 23:38:02 +08:00
{
2023-12-07 01:16:45 +08:00
[Key(0)]
public long RoomID { get ; set ; }
2020-11-08 20:21:21 +08:00
2023-12-07 01:16:45 +08:00
[Key(1)]
public string RoomName { get ; set ; } = string . Empty ;
2020-11-08 20:21:21 +08:00
public InLobby ( Room room )
{
2023-12-07 01:16:45 +08:00
RoomID = room . RoomID . Value ? ? - 1 ;
RoomName = room . Name . Value ;
2020-11-08 20:21:21 +08:00
}
2023-12-07 01:16:45 +08:00
[SerializationConstructor]
public InLobby ( ) { }
public override string GetStatus ( bool hideIdentifiableInformation = false ) = > @"In a lobby" ;
public override string? GetDetails ( bool hideIdentifiableInformation = false ) = > hideIdentifiableInformation
? null
: RoomName ;
2019-05-12 23:38:02 +08:00
}
2019-05-06 02:07:55 +08:00
}
}