mirror of https://github.com/ppy/osu
Track changes to mod settings in beatmap difficulty cache with 100ms debouncing
This commit is contained in:
parent
0291cd5ae2
commit
32ba525555
|
@ -14,6 +14,7 @@
|
|||
using osu.Framework.Logging;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
@ -56,12 +57,28 @@ public class BeatmapDifficultyCache : MemoryCachingComponent<BeatmapDifficultyCa
|
|||
[Resolved]
|
||||
private Bindable<IReadOnlyList<Mod>> currentMods { get; set; }
|
||||
|
||||
private ModSettingChangeTracker modSettingChangeTracker;
|
||||
private ScheduledDelegate debouncedModSettingsChange;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
currentRuleset.BindValueChanged(_ => updateTrackedBindables());
|
||||
currentMods.BindValueChanged(_ => updateTrackedBindables(), true);
|
||||
|
||||
currentMods.BindValueChanged(mods =>
|
||||
{
|
||||
modSettingChangeTracker?.Dispose();
|
||||
|
||||
updateTrackedBindables();
|
||||
|
||||
modSettingChangeTracker = new ModSettingChangeTracker(mods.NewValue);
|
||||
modSettingChangeTracker.SettingChanged += _ =>
|
||||
{
|
||||
debouncedModSettingsChange?.Cancel();
|
||||
debouncedModSettingsChange = Scheduler.AddDelayed(updateTrackedBindables, 100);
|
||||
};
|
||||
}, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -84,7 +101,7 @@ protected override void LoadComplete()
|
|||
/// Retrieves a bindable containing the star difficulty of a <see cref="BeatmapInfo"/> with a given <see cref="RulesetInfo"/> and <see cref="Mod"/> combination.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The bindable will not update to follow the currently-selected ruleset and mods.
|
||||
/// The bindable will not update to follow the currently-selected ruleset and mods or its settings.
|
||||
/// </remarks>
|
||||
/// <param name="beatmapInfo">The <see cref="BeatmapInfo"/> to get the difficulty of.</param>
|
||||
/// <param name="rulesetInfo">The <see cref="RulesetInfo"/> to get the difficulty with. If <c>null</c>, the <paramref name="beatmapInfo"/>'s ruleset is used.</param>
|
||||
|
@ -275,6 +292,8 @@ protected override void Dispose(bool isDisposing)
|
|||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
modSettingChangeTracker?.Dispose();
|
||||
|
||||
cancelTrackedBindableUpdate();
|
||||
updateScheduler?.Dispose();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue