Skip to content

Commit

Permalink
Apply migration to new standardised score on normal reimport too
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach authored and peppy committed Jun 16, 2023
1 parent 5a45476 commit 9b3ab2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 1 addition & 6 deletions osu.Game/Database/RealmAccess.cs
Expand Up @@ -949,12 +949,7 @@ private void applyMigrationsForVersion(Migration migration, ulong targetVersion)
{
try
{
// Recalculate the old-style standardised score to see if this was an old lazer score.
bool oldScoreMatchesExpectations = StandardisedScoreMigrationTools.GetOldStandardised(score) == score.TotalScore;
// Some older scores don't have correct statistics populated, so let's give them benefit of doubt.
bool scoreIsVeryOld = score.Date < new DateTime(2023, 1, 1, 0, 0, 0);

if (oldScoreMatchesExpectations || scoreIsVeryOld)
if (StandardisedScoreMigrationTools.ShouldMigrateToNewStandardised(score))
{
try
{
Expand Down
14 changes: 14 additions & 0 deletions osu.Game/Database/StandardisedScoreMigrationTools.cs
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
Expand All @@ -13,6 +14,19 @@ namespace osu.Game.Database
{
public static class StandardisedScoreMigrationTools
{
public static bool ShouldMigrateToNewStandardised(ScoreInfo score)
{
if (score.IsLegacyScore)
return false;

// Recalculate the old-style standardised score to see if this was an old lazer score.
bool oldScoreMatchesExpectations = GetOldStandardised(score) == score.TotalScore;
// Some older scores don't have correct statistics populated, so let's give them benefit of doubt.
bool scoreIsVeryOld = score.Date < new DateTime(2023, 1, 1, 0, 0, 0);

return oldScoreMatchesExpectations || scoreIsVeryOld;
}

public static long GetNewStandardised(ScoreInfo score)
{
int maxJudgementIndex = 0;
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Scoring/ScoreImporter.cs
Expand Up @@ -83,6 +83,11 @@ protected override void Populate(ScoreInfo model, ArchiveReader? archive, Realm

if (string.IsNullOrEmpty(model.MaximumStatisticsJson))
model.MaximumStatisticsJson = JsonConvert.SerializeObject(model.MaximumStatistics);

// for pre-ScoreV2 lazer scores, apply a best-effort conversion of total score to ScoreV2.
// this requires: max combo, statistics, max statistics (where available), and mods to already be populated on the score.
if (StandardisedScoreMigrationTools.ShouldMigrateToNewStandardised(model))
model.TotalScore = StandardisedScoreMigrationTools.GetNewStandardised(model);
}

/// <summary>
Expand Down

0 comments on commit 9b3ab2f

Please sign in to comment.