From f282152f996b3e15dffa9ae7564c1e09788430dd Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sun, 14 Apr 2024 15:53:29 -0700 Subject: [PATCH] Enable NRT to `ScoreManager` --- .../Database/BackgroundDataStoreProcessor.cs | 17 ++++++++++------- osu.Game/Scoring/ScoreManager.cs | 18 ++++++++---------- osu.Game/Screens/Play/SaveFailedScoreButton.cs | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/osu.Game/Database/BackgroundDataStoreProcessor.cs b/osu.Game/Database/BackgroundDataStoreProcessor.cs index 872194aa1d..52336c0242 100644 --- a/osu.Game/Database/BackgroundDataStoreProcessor.cs +++ b/osu.Game/Database/BackgroundDataStoreProcessor.cs @@ -287,14 +287,17 @@ namespace osu.Game.Database { var score = scoreManager.Query(s => s.ID == id); - scoreManager.PopulateMaximumStatistics(score); - - // Can't use async overload because we're not on the update thread. - // ReSharper disable once MethodHasAsyncOverload - realmAccess.Write(r => + if (score != null) { - r.Find(id)!.MaximumStatisticsJson = JsonConvert.SerializeObject(score.MaximumStatistics); - }); + scoreManager.PopulateMaximumStatistics(score); + + // Can't use async overload because we're not on the update thread. + // ReSharper disable once MethodHasAsyncOverload + realmAccess.Write(r => + { + r.Find(id)!.MaximumStatisticsJson = JsonConvert.SerializeObject(score.MaximumStatistics); + }); + } ++processedCount; } diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 1ee99e9e93..1cdf4b0c13 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Diagnostics; @@ -28,7 +26,7 @@ namespace osu.Game.Scoring public class ScoreManager : ModelManager, IModelImporter { private readonly Func beatmaps; - private readonly OsuConfigManager configManager; + private readonly OsuConfigManager? configManager; private readonly ScoreImporter scoreImporter; private readonly LegacyScoreExporter scoreExporter; @@ -43,7 +41,7 @@ namespace osu.Game.Scoring } public ScoreManager(RulesetStore rulesets, Func beatmaps, Storage storage, RealmAccess realm, IAPIProvider api, - OsuConfigManager configManager = null) + OsuConfigManager? configManager = null) : base(storage, realm) { this.beatmaps = beatmaps; @@ -67,7 +65,7 @@ namespace osu.Game.Scoring /// /// The query. /// The first result for the provided query, or null if no results were found. - public ScoreInfo Query(Expression> query) + public ScoreInfo? Query(Expression> query) { return Realm.Run(r => r.All().FirstOrDefault(query)?.Detach()); } @@ -104,7 +102,7 @@ namespace osu.Game.Scoring /// /// The to provide the total score of. /// The config. - public TotalScoreBindable(ScoreInfo score, OsuConfigManager configManager) + public TotalScoreBindable(ScoreInfo score, OsuConfigManager? configManager) { configManager?.BindWith(OsuSetting.ScoreDisplayMode, scoringMode); scoringMode.BindValueChanged(mode => Value = score.GetDisplayScore(mode.NewValue), true); @@ -126,7 +124,7 @@ namespace osu.Game.Scoring } } - public void Delete([CanBeNull] Expression> filter = null, bool silent = false) + public void Delete(Expression>? filter = null, bool silent = false) { Realm.Run(r => { @@ -165,9 +163,9 @@ namespace osu.Game.Scoring public Task Export(ScoreInfo score) => scoreExporter.ExportAsync(score.ToLive(Realm)); - public Task> ImportAsUpdate(ProgressNotification notification, ImportTask task, ScoreInfo original) => scoreImporter.ImportAsUpdate(notification, task, original); + public Task?> ImportAsUpdate(ProgressNotification notification, ImportTask task, ScoreInfo original) => scoreImporter.ImportAsUpdate(notification, task, original); - public Live Import(ScoreInfo item, ArchiveReader archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => + public Live? Import(ScoreInfo item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => scoreImporter.ImportModel(item, archive, parameters, cancellationToken); /// @@ -182,7 +180,7 @@ namespace osu.Game.Scoring #region Implementation of IPresentImports - public Action>> PresentImport + public Action>>? PresentImport { set => scoreImporter.PresentImport = value; } diff --git a/osu.Game/Screens/Play/SaveFailedScoreButton.cs b/osu.Game/Screens/Play/SaveFailedScoreButton.cs index ef27aac1b9..4f665b87e8 100644 --- a/osu.Game/Screens/Play/SaveFailedScoreButton.cs +++ b/osu.Game/Screens/Play/SaveFailedScoreButton.cs @@ -137,7 +137,7 @@ namespace osu.Game.Screens.Play { if (state.NewValue != DownloadState.LocallyAvailable) return; - scoreManager.Export(importedScore); + if (importedScore != null) scoreManager.Export(importedScore); this.state.ValueChanged -= exportWhenReady; }