using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets;
namespace osu.Game.Input.Bindings
{
///
/// A KeyBindingInputManager with a database backing for custom overrides.
///
/// The type of the custom action.
public abstract class DatabasedKeyBindingInputManager : KeyBindingInputManager
where T : struct
{
private readonly RulesetInfo ruleset;
private readonly int? variant;
private BindingStore store;
///
/// Create a new instance.
///
/// A reference to identify the current . Used to lookup mappings. Null for global mappings.
/// An optional variant for the specified . Used when a ruleset has more than one possible keyboard layouts.
/// Specify how to deal with multiple matches of s and s.
protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int? variant = null, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None)
: base(simultaneousMode)
{
this.ruleset = ruleset;
this.variant = variant;
}
[BackgroundDependencyLoader]
private void load(BindingStore bindings)
{
store = bindings;
}
protected override void ReloadMappings()
{
// load defaults
base.ReloadMappings();
var rulesetId = ruleset?.ID;
// load from database if present.
if (store != null)
{
foreach (var b in store.Query(b => b.RulesetID == rulesetId && b.Variant == variant))
Mappings.Add(b);
}
}
}
}