Fix issues with data serialisation

This commit is contained in:
Dean Herbert
2020-12-14 18:41:24 +09:00
parent ae22f75406
commit 0d9c1cb5d3
3 changed files with 43 additions and 5 deletions

View File

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Game.Replays.Legacy; using osu.Game.Replays.Legacy;
using osu.Game.Scoring; using osu.Game.Scoring;
@ -22,5 +23,12 @@ namespace osu.Game.Online.Spectator
Frames = frames; Frames = frames;
Header = new FrameHeader(score); Header = new FrameHeader(score);
} }
[JsonConstructor]
public FrameDataBundle(FrameHeader header, IEnumerable<LegacyReplayFrame> frames)
{
Header = header;
Frames = frames;
}
} }
} }

View File

@ -4,8 +4,8 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic; using System.Linq;
using osu.Game.Rulesets.Scoring; using Newtonsoft.Json;
using osu.Game.Scoring; using osu.Game.Scoring;
namespace osu.Game.Online.Spectator namespace osu.Game.Online.Spectator
@ -17,7 +17,7 @@ namespace osu.Game.Online.Spectator
public int MaxCombo { get; set; } public int MaxCombo { get; set; }
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>(); public StatisticPair[] Statistics { get; set; }
/// <summary> /// <summary>
/// Construct header summary information from a point-in-time reference to a score which is actively being played. /// Construct header summary information from a point-in-time reference to a score which is actively being played.
@ -28,8 +28,15 @@ namespace osu.Game.Online.Spectator
Combo = score.Combo; Combo = score.Combo;
MaxCombo = score.MaxCombo; MaxCombo = score.MaxCombo;
foreach (var kvp in score.Statistics) Statistics = score.Statistics.Select(kvp => new StatisticPair(kvp.Key, kvp.Value)).ToArray();
Statistics[kvp.Key] = kvp.Value; }
[JsonConstructor]
public FrameHeader(int combo, int maxCombo, StatisticPair[] statistics)
{
Combo = combo;
MaxCombo = maxCombo;
Statistics = statistics;
} }
} }
} }

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 osu.Game.Rulesets.Scoring;
namespace osu.Game.Online.Spectator
{
[Serializable]
public struct StatisticPair
{
public HitResult Result;
public int Count;
public StatisticPair(HitResult result, int count)
{
Result = result;
Count = count;
}
public override string ToString() => $"{Result}=>{Count}";
}
}