diff --git a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs index ad2007f202..c8848ab7d8 100644 --- a/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs +++ b/osu.Game.Tests/Online/TestAPIModJsonSerialization.cs @@ -8,6 +8,7 @@ using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Online.API; +using osu.Game.Online.Solo; using osu.Game.Rulesets; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; @@ -88,33 +89,27 @@ public void TestDeserialiseDifficultyAdjustModWithExtendedLimits() } [Test] - public void TestDeserialiseScoreInfoWithEmptyMods() + public void TestDeserialiseSubmittableScoreWithEmptyMods() { - var score = new ScoreInfo { Ruleset = new OsuRuleset().RulesetInfo }; + var score = new SubmittableScore(new ScoreInfo { Ruleset = new OsuRuleset().RulesetInfo }); - var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); - - if (deserialised != null) - deserialised.Ruleset = new OsuRuleset().RulesetInfo; + var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); Assert.That(deserialised?.Mods.Length, Is.Zero); } [Test] - public void TestDeserialiseScoreInfoWithCustomModSetting() + public void TestDeserialiseSubmittableScoreWithCustomModSetting() { - var score = new ScoreInfo + var score = new SubmittableScore(new ScoreInfo { Ruleset = new OsuRuleset().RulesetInfo, Mods = new Mod[] { new OsuModDoubleTime { SpeedChange = { Value = 2 } } } - }; + }); - var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); + var deserialised = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(score)); - if (deserialised != null) - deserialised.Ruleset = new OsuRuleset().RulesetInfo; - - Assert.That(((OsuModDoubleTime)deserialised?.Mods[0])?.SpeedChange.Value, Is.EqualTo(2)); + Assert.That((deserialised?.Mods[0])?.Settings["speed_change"], Is.EqualTo(2)); } private class TestRuleset : Ruleset diff --git a/osu.Game/Online/Solo/SubmitSoloScoreRequest.cs b/osu.Game/Online/Solo/SubmitSoloScoreRequest.cs index 184dbc911d..25c2e5a61f 100644 --- a/osu.Game/Online/Solo/SubmitSoloScoreRequest.cs +++ b/osu.Game/Online/Solo/SubmitSoloScoreRequest.cs @@ -1,17 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Net.Http; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using osu.Framework.IO.Network; using osu.Game.Online.API; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Rooms; -using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; -using osu.Game.Users; namespace osu.Game.Online.Solo { @@ -47,57 +42,4 @@ protected override WebRequest CreateWebRequest() protected override string Target => $@"beatmaps/{beatmapId}/solo/scores/{scoreId}"; } - - /// - /// A class specifically for sending scores to the API during score submission. - /// This is used instead of due to marginally different serialisation naming requirements. - /// - public class SubmittableScore - { - [JsonProperty("rank")] - [JsonConverter(typeof(StringEnumConverter))] - public ScoreRank Rank { get; } - - [JsonProperty("total_score")] - public long TotalScore { get; } - - [JsonProperty("accuracy")] - public double Accuracy { get; } - - [JsonProperty(@"pp")] - public double? PP { get; } - - [JsonProperty("max_combo")] - public int MaxCombo { get; } - - [JsonProperty("ruleset_id")] - public int RulesetID { get; } - - [JsonProperty("passed")] - public bool Passed { get; } - - // Used for API serialisation/deserialisation. - [JsonProperty("mods")] - public APIMod[] Mods { get; } - - [JsonProperty("user")] - public User User { get; } - - [JsonProperty("statistics")] - public Dictionary Statistics { get; } - - public SubmittableScore(ScoreInfo score) - { - Rank = score.Rank; - TotalScore = score.TotalScore; - Accuracy = score.Accuracy; - PP = score.PP; - MaxCombo = score.MaxCombo; - RulesetID = score.RulesetID; - Passed = score.Passed; - Mods = score.APIMods; - User = score.User; - Statistics = score.Statistics; - } - } } diff --git a/osu.Game/Online/Solo/SubmittableScore.cs b/osu.Game/Online/Solo/SubmittableScore.cs new file mode 100644 index 0000000000..bafb308a13 --- /dev/null +++ b/osu.Game/Online/Solo/SubmittableScore.cs @@ -0,0 +1,75 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using JetBrains.Annotations; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Users; + +namespace osu.Game.Online.Solo +{ + /// + /// A class specifically for sending scores to the API during score submission. + /// This is used instead of due to marginally different serialisation naming requirements. + /// + [Serializable] + public class SubmittableScore + { + [JsonProperty("rank")] + [JsonConverter(typeof(StringEnumConverter))] + public ScoreRank Rank { get; set; } + + [JsonProperty("total_score")] + public long TotalScore { get; set; } + + [JsonProperty("accuracy")] + public double Accuracy { get; set; } + + [JsonProperty(@"pp")] + public double? PP { get; set; } + + [JsonProperty("max_combo")] + public int MaxCombo { get; set; } + + [JsonProperty("ruleset_id")] + public int RulesetID { get; set; } + + [JsonProperty("passed")] + public bool Passed { get; set; } + + // Used for API serialisation/deserialisation. + [JsonProperty("mods")] + public APIMod[] Mods { get; set; } + + [JsonProperty("user")] + public User User { get; set; } + + [JsonProperty("statistics")] + public Dictionary Statistics { get; set; } + + [UsedImplicitly] + public SubmittableScore() + { + } + + public SubmittableScore(ScoreInfo score) + { + Rank = score.Rank; + TotalScore = score.TotalScore; + Accuracy = score.Accuracy; + PP = score.PP; + MaxCombo = score.MaxCombo; + RulesetID = score.RulesetID; + Passed = score.Passed; + Mods = score.APIMods; + User = score.User; + Statistics = score.Statistics; + } + } +}