Skip to content

Add versioning of local scores #25998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess probably the only question I'd have here is - do we wanna put this in replays too (and decode it from there on import)? We can probably put this in LegacyReplaySoloScoreInfo with practically zero effort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah. I didn't realise this was so low effort, if so then let's do it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have done so in 2baf579 (with test coverage in 5ff95db).


/// <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