mirror of
https://github.com/ppy/osu
synced 2024-12-11 17:42:28 +00:00
Replace TopLocalRank
event flow with realm subscriptions
This commit is contained in:
parent
fe8a5e867d
commit
6d60aa7d9c
@ -1,6 +1,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -19,9 +20,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
private readonly BeatmapInfo beatmapInfo;
|
private readonly BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private ScoreManager scores { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
@ -40,26 +38,34 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
scores.ItemUpdated += scoreChanged;
|
|
||||||
scores.ItemRemoved += scoreChanged;
|
|
||||||
|
|
||||||
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
||||||
|
|
||||||
fetchAndLoadTopScore();
|
fetchAndLoadTopScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scoreChanged(ScoreInfo score)
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
if (score.BeatmapInfoID == beatmapInfo.ID)
|
base.LoadComplete();
|
||||||
fetchAndLoadTopScore();
|
|
||||||
|
scoreSubscription = realmFactory.Context.All<ScoreInfo>().Where(s => s.BeatmapInfo.ID == beatmapInfo.ID).QueryAsyncWithNotifications((_, changes, ___) =>
|
||||||
|
{
|
||||||
|
if (changes == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fetchTopScoreRank();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDisposable scoreSubscription;
|
||||||
|
|
||||||
private ScheduledDelegate scheduledRankUpdate;
|
private ScheduledDelegate scheduledRankUpdate;
|
||||||
|
|
||||||
private void fetchAndLoadTopScore()
|
private void fetchAndLoadTopScore()
|
||||||
{
|
{
|
||||||
|
// TODO: this lookup likely isn't required, we can use the results of the subscription directly.
|
||||||
var rank = fetchTopScoreRank();
|
var rank = fetchTopScoreRank();
|
||||||
scheduledRankUpdate = Schedule(() =>
|
|
||||||
|
scheduledRankUpdate = Scheduler.Add(() =>
|
||||||
{
|
{
|
||||||
Rank = rank;
|
Rank = rank;
|
||||||
|
|
||||||
@ -89,11 +95,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (scores != null)
|
scoreSubscription?.Dispose();
|
||||||
{
|
|
||||||
scores.ItemUpdated -= scoreChanged;
|
|
||||||
scores.ItemRemoved -= scoreChanged;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user