Skip to content

Commit

Permalink
Merge pull request #25998 from peppy/add-score-version
Browse files Browse the repository at this point in the history
Add versioning of local scores
  • Loading branch information
peppy authored Dec 21, 2023
2 parents 472a9da + fbf19ea commit 716d866
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ public void TestSoloScoreData()
{
new OsuModDoubleTime { SpeedChange = { Value = 1.1 } }
};
scoreInfo.OnlineID = 123123;
scoreInfo.ClientVersion = "2023.1221.0";

var beatmap = new TestBeatmap(ruleset);
var score = new Score
Expand All @@ -237,9 +239,11 @@ public void TestSoloScoreData()

Assert.Multiple(() =>
{
Assert.That(decodedAfterEncode.ScoreInfo.OnlineID, Is.EqualTo(123123));
Assert.That(decodedAfterEncode.ScoreInfo.Statistics, Is.EqualTo(scoreInfo.Statistics));
Assert.That(decodedAfterEncode.ScoreInfo.MaximumStatistics, Is.EqualTo(scoreInfo.MaximumStatistics));
Assert.That(decodedAfterEncode.ScoreInfo.Mods, Is.EqualTo(scoreInfo.Mods));
Assert.That(decodedAfterEncode.ScoreInfo.ClientVersion, Is.EqualTo("2023.1221.0"));
});
}

Expand Down
2 changes: 2 additions & 0 deletions osu.Game.Tests/Scores/IO/ImportScoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,15 @@ public void TestImportMods()
User = new APIUser { Username = "Test user" },
BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo,
ClientVersion = "12345",
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
};

var imported = LoadScoreIntoOsu(osu, toImport);

Assert.IsTrue(imported.Mods.Any(m => m is OsuModHardRock));
Assert.IsTrue(imported.Mods.Any(m => m is OsuModDoubleTime));
Assert.That(imported.ClientVersion, Is.EqualTo(toImport.ClientVersion));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public partial class TestScenePlayerLocalScoreImport : PlayerTestScene

private BeatmapSetInfo? importedSet;

[Resolved]
private OsuGameBase osu { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Expand Down Expand Up @@ -153,6 +156,7 @@ public void TestScoreStoredLocally()

AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
AddUntilStep("score in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null));
AddUntilStep("score has correct version", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID)!.ClientVersion), () => Is.EqualTo(osu.Version));
}

[Test]
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public class RealmAccess : IDisposable
/// 36 2023-10-26 Add LegacyOnlineID to ScoreInfo. Move osu_scores_*_high IDs stored in OnlineID to LegacyOnlineID. Reset anomalous OnlineIDs.
/// 38 2023-12-10 Add EndTimeObjectCount and TotalObjectCount to BeatmapInfo.
/// 39 2023-12-19 Migrate any EndTimeObjectCount and TotalObjectCount values of 0 to -1 to better identify non-calculated values.
/// 40 2023-12-21 Add ScoreInfo.Version to keep track of which build scores were set on.
/// </summary>
private const int schema_version = 39;
private const int schema_version = 40;

/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
Expand Down
4 changes: 4 additions & 0 deletions osu.Game/Scoring/Legacy/LegacyReplaySoloScoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public class LegacyReplaySoloScoreInfo
[JsonProperty("maximum_statistics")]
public Dictionary<HitResult, int> MaximumStatistics { get; set; } = new Dictionary<HitResult, int>();

[JsonProperty("client_version")]
public string ClientVersion = string.Empty;

public static LegacyReplaySoloScoreInfo FromScore(ScoreInfo score) => new LegacyReplaySoloScoreInfo
{
OnlineID = score.OnlineID,
Mods = score.APIMods,
Statistics = score.Statistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
MaximumStatistics = score.MaximumStatistics.Where(kvp => kvp.Value != 0).ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
ClientVersion = score.ClientVersion,
};
}
}
1 change: 1 addition & 0 deletions osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Score Parse(Stream stream)
score.ScoreInfo.Statistics = readScore.Statistics;
score.ScoreInfo.MaximumStatistics = readScore.MaximumStatistics;
score.ScoreInfo.Mods = readScore.Mods.Select(m => m.ToMod(currentRuleset)).ToArray();
score.ScoreInfo.ClientVersion = readScore.ClientVersion;
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Scoring/ScoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftD
/// </remarks>
public BeatmapInfo? BeatmapInfo { get; set; }

/// <summary>
/// The version of the client this score was set using.
/// Sourced from <see cref="OsuGameBase.Version"/> at the point of score submission.
/// </summary>
public string ClientVersion { get; set; } = string.Empty;

/// <summary>
/// The <see cref="osu.Game.Beatmaps.BeatmapInfo.Hash"/> at the point in time when the score was set.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion osu.Game/Screens/Play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public abstract partial class Player : ScreenWithBeatmapBackground, ISamplePlayb
[Resolved]
private MusicController musicController { get; set; }

[Resolved]
private OsuGameBase game { get; set; }

public GameplayState GameplayState { get; private set; }

private Ruleset ruleset;
Expand Down Expand Up @@ -1155,7 +1158,11 @@ public override bool OnExiting(ScreenExitEvent e)
/// <returns>The <see cref="Scoring.Score"/>.</returns>
protected virtual Score CreateScore(IBeatmap beatmap) => new Score
{
ScoreInfo = new ScoreInfo { User = api.LocalUser.Value },
ScoreInfo = new ScoreInfo
{
User = api.LocalUser.Value,
ClientVersion = game.Version,
},
};

/// <summary>
Expand Down

0 comments on commit 716d866

Please sign in to comment.