1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 00:02:54 +08:00

Apply NRT to BeatmapLeaderboard / MatchLeaderboard

This commit is contained in:
Dean Herbert 2022-09-26 16:15:18 +09:00
parent a1297af441
commit 5fc836d1f0
2 changed files with 19 additions and 22 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Threading; using System.Threading;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -16,7 +14,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate> public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
{ {
[Resolved(typeof(Room), nameof(Room.RoomID))] [Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<long?> roomId { get; set; } private Bindable<long?> roomId { get; set; } = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
@ -33,7 +31,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
protected override bool IsOnlineScope => true; protected override bool IsOnlineScope => true;
protected override APIRequest FetchScores(CancellationToken cancellationToken) protected override APIRequest? FetchScores(CancellationToken cancellationToken)
{ {
if (roomId.Value == null) if (roomId.Value == null)
return null; return null;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -25,11 +23,11 @@ namespace osu.Game.Screens.Select.Leaderboards
{ {
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo> public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
{ {
public Action<ScoreInfo> ScoreSelected; public Action<ScoreInfo>? ScoreSelected;
private BeatmapInfo beatmapInfo; private BeatmapInfo? beatmapInfo;
public BeatmapInfo BeatmapInfo public BeatmapInfo? BeatmapInfo
{ {
get => beatmapInfo; get => beatmapInfo;
set set
@ -70,26 +68,26 @@ namespace osu.Game.Screens.Select.Leaderboards
} }
[Resolved] [Resolved]
private ScoreManager scoreManager { get; set; } private ScoreManager scoreManager { get; set; } = null!;
[Resolved] [Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved] [Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; } = null!;
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; } = null!;
[Resolved] [Resolved]
private RealmAccess realm { get; set; } private RealmAccess realm { get; set; } = null!;
private IDisposable scoreSubscription; private IDisposable? scoreSubscription;
private GetScoresRequest scoreRetrievalRequest; private GetScoresRequest? scoreRetrievalRequest;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
@ -104,10 +102,9 @@ namespace osu.Game.Screens.Select.Leaderboards
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local; protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
protected override APIRequest FetchScores(CancellationToken cancellationToken) protected override APIRequest? FetchScores(CancellationToken cancellationToken)
{ {
var fetchBeatmapInfo = BeatmapInfo; var fetchBeatmapInfo = BeatmapInfo;
var fetchRuleset = ruleset.Value ?? fetchBeatmapInfo.Ruleset;
if (fetchBeatmapInfo == null) if (fetchBeatmapInfo == null)
{ {
@ -115,13 +112,15 @@ namespace osu.Game.Screens.Select.Leaderboards
return null; return null;
} }
var fetchRuleset = ruleset.Value ?? fetchBeatmapInfo.Ruleset;
if (Scope == BeatmapLeaderboardScope.Local) if (Scope == BeatmapLeaderboardScope.Local)
{ {
subscribeToLocalScores(fetchBeatmapInfo, cancellationToken); subscribeToLocalScores(fetchBeatmapInfo, cancellationToken);
return null; return null;
} }
if (api?.IsLoggedIn != true) if (!api.IsLoggedIn)
{ {
SetErrorState(LeaderboardState.NotLoggedIn); SetErrorState(LeaderboardState.NotLoggedIn);
return null; return null;
@ -145,7 +144,7 @@ namespace osu.Game.Screens.Select.Leaderboards
return null; return null;
} }
IReadOnlyList<Mod> requestMods = null; IReadOnlyList<Mod>? requestMods = null;
if (filterMods && !mods.Value.Any()) if (filterMods && !mods.Value.Any())
// add nomod for the request // add nomod for the request
@ -186,7 +185,7 @@ namespace osu.Game.Screens.Select.Leaderboards
+ $" AND {nameof(ScoreInfo.DeletePending)} == false" + $" AND {nameof(ScoreInfo.DeletePending)} == false"
, beatmapInfo.ID, ruleset.Value.ShortName), localScoresChanged); , beatmapInfo.ID, ruleset.Value.ShortName), localScoresChanged);
void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet changes, Exception exception) void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet? changes, Exception exception)
{ {
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
return; return;