Skip to content

Commit

Permalink
Add versioning of local scores
Browse files Browse the repository at this point in the history
For any potential future usage
  • Loading branch information
peppy committed Dec 21, 2023
1 parent 0648201 commit a4baa0a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
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,
Version = "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.Version, Is.EqualTo(toImport.Version));
}
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)!.Version), () => 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
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 Version { 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,
Version = game.Version,
},
};

/// <summary>
Expand Down

0 comments on commit a4baa0a

Please sign in to comment.