Move ruleset key binding registration to an explicit method rather than the constructor

This commit is contained in:
Dean Herbert 2021-01-12 14:59:48 +09:00
parent ff16d2f490
commit a6997a6fc6
2 changed files with 21 additions and 15 deletions

View File

@ -21,22 +21,9 @@ public class RealmKeyBindingStore : RealmBackedStore
/// </summary>
public event Action? KeyBindingChanged;
public RealmKeyBindingStore(RealmContextFactory contextFactory, RulesetStore? rulesets, Storage? storage = null)
public RealmKeyBindingStore(RealmContextFactory contextFactory, Storage? storage = null)
: base(contextFactory, storage)
{
if (rulesets != null)
{
// populate defaults from rulesets.
using (ContextFactory.GetForWrite())
{
foreach (RulesetInfo info in rulesets.AvailableRulesets)
{
var ruleset = info.CreateInstance();
foreach (var variant in ruleset.AvailableVariants)
insertDefaults(ruleset.GetDefaultKeyBindings(variant), info.ID, variant);
}
}
}
}
/// <summary>
@ -62,6 +49,21 @@ public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalActi
/// <param name="container">The container to populate defaults from.</param>
public void Register(KeyBindingContainer container) => insertDefaults(container.DefaultKeyBindings);
/// <summary>
/// Register a ruleset, adding default bindings for each of its variants.
/// </summary>
/// <param name="ruleset">The ruleset to populate defaults from.</param>
public void Register(RulesetInfo ruleset)
{
var instance = ruleset.CreateInstance();
using (ContextFactory.GetForWrite())
{
foreach (var variant in instance.AvailableVariants)
insertDefaults(instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
}
}
/// <summary>
/// Retrieve all key bindings for the provided specification.
/// </summary>

View File

@ -267,7 +267,7 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
migrateDataToRealm();
dependencies.CacheAs(KeyBindingStore = new RealmKeyBindingStore(realmFactory, RulesetStore));
dependencies.CacheAs(KeyBindingStore = new RealmKeyBindingStore(realmFactory));
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
@ -310,6 +310,10 @@ List<ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
base.Content.Add(CreateScalingContainer().WithChild(MenuCursorContainer));
KeyBindingStore.Register(globalBindings);
foreach (var r in RulesetStore.AvailableRulesets)
KeyBindingStore.Register(r);
dependencies.Cache(globalBindings);
PreviewTrackManager previewTrackManager;