1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Merge pull request #16519 from peppy/fix-legacy-score-import-classic-mod

Fix legacy score imports not correctly getting classic mod assigned
This commit is contained in:
Dan Balasescu 2022-01-20 14:28:29 +09:00 committed by GitHub
commit 7509b31176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 6 deletions

View File

@ -12,6 +12,7 @@ using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.UI;
@ -51,6 +52,11 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(829_931, score.ScoreInfo.TotalScore);
Assert.AreEqual(3, score.ScoreInfo.MaxCombo);
Assert.IsTrue(score.ScoreInfo.Mods.Any(m => m is ManiaModClassic));
Assert.IsTrue(score.ScoreInfo.APIMods.Any(m => m.Acronym == "CL"));
Assert.IsTrue(score.ScoreInfo.ModsJson.Contains("CL"));
Assert.IsTrue(Precision.AlmostEquals(0.8889, score.ScoreInfo.Accuracy, 0.0001));
Assert.AreEqual(ScoreRank.B, score.ScoreInfo.Rank);

View File

@ -2,6 +2,10 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Game.Online.API;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
@ -29,5 +33,41 @@ namespace osu.Game.Tests.NonVisual
Assert.That(scoreCopy.Rank, Is.EqualTo(ScoreRank.B));
Assert.That(score.Rank, Is.EqualTo(ScoreRank.X));
}
[Test]
public void TestModsInitiallyEmpty()
{
var score = new ScoreInfo();
Assert.That(score.Mods, Is.Empty);
Assert.That(score.APIMods, Is.Empty);
Assert.That(score.ModsJson, Is.Empty);
}
[Test]
public void TestModsUpdatedCorrectly()
{
var score = new ScoreInfo
{
Mods = new Mod[] { new ManiaModClassic() },
Ruleset = new ManiaRuleset().RulesetInfo,
};
Assert.That(score.Mods, Contains.Item(new ManiaModClassic()));
Assert.That(score.APIMods, Contains.Item(new APIMod(new ManiaModClassic())));
Assert.That(score.ModsJson, Contains.Substring("CL"));
score.APIMods = new[] { new APIMod(new ManiaModDoubleTime()) };
Assert.That(score.Mods, Contains.Item(new ManiaModDoubleTime()));
Assert.That(score.APIMods, Contains.Item(new APIMod(new ManiaModDoubleTime())));
Assert.That(score.ModsJson, Contains.Substring("DT"));
score.Mods = new Mod[] { new ManiaModClassic() };
Assert.That(score.Mods, Contains.Item(new ManiaModClassic()));
Assert.That(score.APIMods, Contains.Item(new APIMod(new ManiaModClassic())));
Assert.That(score.ModsJson, Contains.Substring("CL"));
}
}
}

View File

@ -191,9 +191,8 @@ namespace osu.Game.Scoring
}
set
{
apiMods = null;
clearAllMods();
mods = value;
updateModsJson();
}
}
@ -220,17 +219,24 @@ namespace osu.Game.Scoring
}
set
{
clearAllMods();
apiMods = value;
mods = null;
// We potentially can't update this yet due to Ruleset being late-bound, so instead update on read as necessary.
updateModsJson();
}
}
private void clearAllMods()
{
ModsJson = string.Empty;
mods = null;
apiMods = null;
}
private void updateModsJson()
{
ModsJson = JsonConvert.SerializeObject(APIMods);
ModsJson = APIMods.Length > 0
? JsonConvert.SerializeObject(APIMods)
: string.Empty;
}
public IEnumerable<HitResultDisplayStatistic> GetStatisticsForDisplay()