diff --git a/osu.Game/Online/Spectator/FrameHeader.cs b/osu.Game/Online/Spectator/FrameHeader.cs index baebb28e4f..4d1c2c2cff 100644 --- a/osu.Game/Online/Spectator/FrameHeader.cs +++ b/osu.Game/Online/Spectator/FrameHeader.cs @@ -48,7 +48,7 @@ namespace osu.Game.Online.Spectator /// Additional statistics that guides the score processor to calculate the correct score for this frame. /// [Key(5)] - public Dictionary ScoreProcessorStatistics { get; set; } + public ScoreProcessorStatistics ScoreProcessorStatistics { get; set; } /// /// The time at which this frame was received by the server. @@ -71,13 +71,12 @@ namespace osu.Game.Online.Spectator // copy for safety Statistics = new Dictionary(score.Statistics); - ScoreProcessorStatistics = new Dictionary(); - scoreProcessor.WriteScoreProcessorStatistics(ScoreProcessorStatistics); + ScoreProcessorStatistics = scoreProcessor.GetScoreProcessorStatistics(); } [JsonConstructor] [SerializationConstructor] - public FrameHeader(long totalScore, double accuracy, int combo, int maxCombo, Dictionary statistics, Dictionary scoreProcessorStatistics, DateTimeOffset receivedTime) + public FrameHeader(long totalScore, double accuracy, int combo, int maxCombo, Dictionary statistics, ScoreProcessorStatistics scoreProcessorStatistics, DateTimeOffset receivedTime) { TotalScore = totalScore; Accuracy = accuracy; diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index f2b1607f5e..013dd4b8e7 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using MessagePack; using osu.Framework.Bindables; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -397,29 +398,29 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts.Clear(); scoreResultCounts.AddRange(frame.Header.Statistics); - ReadScoreProcessorStatistics(frame.Header.ScoreProcessorStatistics); + SetScoreProcessorStatistics(frame.Header.ScoreProcessorStatistics); updateScore(); OnResetFromReplayFrame?.Invoke(); } - public virtual void WriteScoreProcessorStatistics(IDictionary statistics) + public ScoreProcessorStatistics GetScoreProcessorStatistics() => new ScoreProcessorStatistics { - statistics.Add(nameof(currentMaximumBaseScore), currentMaximumBaseScore); - statistics.Add(nameof(currentBaseScore), currentBaseScore); - statistics.Add(nameof(currentCountBasicJudgements), currentCountBasicJudgements); - statistics.Add(nameof(currentComboPortion), currentComboPortion); - statistics.Add(nameof(currentBonusPortion), currentBonusPortion); - } + MaximumBaseScore = currentMaximumBaseScore, + BaseScore = currentBaseScore, + CountBasicJudgements = currentCountBasicJudgements, + ComboPortion = currentComboPortion, + BonusPortion = currentBonusPortion + }; - public virtual void ReadScoreProcessorStatistics(IReadOnlyDictionary statistics) + public void SetScoreProcessorStatistics(ScoreProcessorStatistics statistics) { - currentMaximumBaseScore = (double)statistics.GetValueOrDefault(nameof(currentMaximumBaseScore), 0); - currentBaseScore = (double)statistics.GetValueOrDefault(nameof(currentBaseScore), 0); - currentCountBasicJudgements = (int)statistics.GetValueOrDefault(nameof(currentCountBasicJudgements), 0); - currentComboPortion = (double)statistics.GetValueOrDefault(nameof(currentComboPortion), 0); - currentBonusPortion = (double)statistics.GetValueOrDefault(nameof(currentBonusPortion), 0); + currentMaximumBaseScore = statistics.MaximumBaseScore; + currentBaseScore = statistics.BaseScore; + currentCountBasicJudgements = statistics.CountBasicJudgements; + currentComboPortion = statistics.ComboPortion; + currentBonusPortion = statistics.BonusPortion; } #region Static helper methods @@ -493,4 +494,24 @@ namespace osu.Game.Rulesets.Scoring [LocalisableDescription(typeof(GameplaySettingsStrings), nameof(GameplaySettingsStrings.ClassicScoreDisplay))] Classic } + + [Serializable] + [MessagePackObject] + public class ScoreProcessorStatistics + { + [Key(0)] + public double MaximumBaseScore { get; set; } + + [Key(1)] + public double BaseScore { get; set; } + + [Key(2)] + public int CountBasicJudgements { get; set; } + + [Key(3)] + public double ComboPortion { get; set; } + + [Key(4)] + public double BonusPortion { get; set; } + } }