1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Setup all spectator model classes for MessagePack

This commit is contained in:
Dean Herbert 2021-01-26 16:39:35 +09:00
parent e4fc604163
commit 9537090d28
5 changed files with 35 additions and 1 deletions

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using osu.Game.Replays.Legacy;
using osu.Game.Scoring;
@ -12,10 +13,13 @@ using osu.Game.Scoring;
namespace osu.Game.Online.Spectator
{
[Serializable]
[MessagePackObject]
public class FrameDataBundle
{
[Key(0)]
public FrameHeader Header { get; set; }
[Key(1)]
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
public FrameDataBundle(ScoreInfo score, IEnumerable<LegacyReplayFrame> frames)

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
@ -12,31 +13,37 @@ using osu.Game.Scoring;
namespace osu.Game.Online.Spectator
{
[Serializable]
[MessagePackObject]
public class FrameHeader
{
/// <summary>
/// The current accuracy of the score.
/// </summary>
[Key(0)]
public double Accuracy { get; set; }
/// <summary>
/// The current combo of the score.
/// </summary>
[Key(1)]
public int Combo { get; set; }
/// <summary>
/// The maximum combo achieved up to the current point in time.
/// </summary>
[Key(2)]
public int MaxCombo { get; set; }
/// <summary>
/// Cumulative hit statistics.
/// </summary>
[Key(3)]
public Dictionary<HitResult, int> Statistics { get; set; }
/// <summary>
/// The time at which this frame was received by the server.
/// </summary>
[Key(4)]
public DateTimeOffset ReceivedTime { get; set; }
/// <summary>
@ -54,7 +61,8 @@ namespace osu.Game.Online.Spectator
}
[JsonConstructor]
public FrameHeader(int combo, int maxCombo, double accuracy, Dictionary<HitResult, int> statistics, DateTimeOffset receivedTime)
[SerializationConstructor]
public FrameHeader(double accuracy, int combo, int maxCombo, Dictionary<HitResult, int> statistics, DateTimeOffset receivedTime)
{
Combo = combo;
MaxCombo = maxCombo;

View File

@ -5,18 +5,23 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using MessagePack;
using osu.Game.Online.API;
namespace osu.Game.Online.Spectator
{
[Serializable]
[MessagePackObject]
public class SpectatorState : IEquatable<SpectatorState>
{
[Key(0)]
public int? BeatmapID { get; set; }
[Key(1)]
public int? RulesetID { get; set; }
[NotNull]
[Key(2)]
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
public bool Equals(SpectatorState other) => BeatmapID == other?.BeatmapID && Mods.SequenceEqual(other?.Mods) && RulesetID == other?.RulesetID;

View File

@ -1,38 +1,51 @@
// 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 MessagePack;
using Newtonsoft.Json;
using osu.Game.Rulesets.Replays;
using osuTK;
namespace osu.Game.Replays.Legacy
{
[MessagePackObject]
public class LegacyReplayFrame : ReplayFrame
{
[JsonIgnore]
[IgnoreMember]
public Vector2 Position => new Vector2(MouseX ?? 0, MouseY ?? 0);
[Key(1)]
public float? MouseX;
[Key(2)]
public float? MouseY;
[JsonIgnore]
[IgnoreMember]
public bool MouseLeft => MouseLeft1 || MouseLeft2;
[JsonIgnore]
[IgnoreMember]
public bool MouseRight => MouseRight1 || MouseRight2;
[JsonIgnore]
[IgnoreMember]
public bool MouseLeft1 => ButtonState.HasFlag(ReplayButtonState.Left1);
[JsonIgnore]
[IgnoreMember]
public bool MouseRight1 => ButtonState.HasFlag(ReplayButtonState.Right1);
[JsonIgnore]
[IgnoreMember]
public bool MouseLeft2 => ButtonState.HasFlag(ReplayButtonState.Left2);
[JsonIgnore]
[IgnoreMember]
public bool MouseRight2 => ButtonState.HasFlag(ReplayButtonState.Right2);
[Key(3)]
public ReplayButtonState ButtonState;
public LegacyReplayFrame(double time, float? mouseX, float? mouseY, ReplayButtonState buttonState)

View File

@ -1,10 +1,14 @@
// 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 MessagePack;
namespace osu.Game.Rulesets.Replays
{
[MessagePackObject]
public class ReplayFrame
{
[Key(0)]
public double Time;
public ReplayFrame()