diff --git a/osu.Game/Input/KeyBindingStore.cs b/osu.Game/Input/KeyBindingStore.cs index 5cc018ff2c..9edab896b3 100644 --- a/osu.Game/Input/KeyBindingStore.cs +++ b/osu.Game/Input/KeyBindingStore.cs @@ -38,11 +38,13 @@ namespace osu.Game.Input // compare counts in database vs defaults foreach (var group in defaults.GroupBy(k => k.Action)) { - int count; - while (group.Count() > (count = Query(rulesetId, variant).Count(k => (int)k.Action == (int)group.Key))) - { - var insertable = group.Skip(count).First(); + int count = Query(rulesetId, variant).Count(k => (int)k.Action == (int)group.Key); + int aimCount = group.Count(); + if (aimCount <= count) + continue; + + foreach (var insertable in group.Skip(count).Take(aimCount - count)) // insert any defaults which are missing. Connection.DatabasedKeyBinding.Add(new DatabasedKeyBinding { @@ -51,22 +53,22 @@ namespace osu.Game.Input RulesetID = rulesetId, Variant = variant }); - Connection.SaveChanges(); - } } + + Connection.SaveChanges(); } - public List Query(int? rulesetId = null, int? variant = null) => - new List(Connection.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant)); + /// + /// Retrieve s for a specified ruleset/variant content. + /// + /// The ruleset's internal ID. + /// An optional variant. + /// + public IEnumerable Query(int? rulesetId = null, int? variant = null) => Connection.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant); public void Update(KeyBinding keyBinding) { - var dbKeyBinding = Connection.DatabasedKeyBinding.FirstOrDefault(kb => kb.ToString() == keyBinding.ToString()); - if (dbKeyBinding != null) - { - dbKeyBinding.KeyCombination = keyBinding.KeyCombination; - dbKeyBinding.Action = keyBinding.Action; - } + Connection.Update(keyBinding); Connection.SaveChanges(); } } diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs b/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs index bd69403831..128b5e2f09 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs @@ -37,8 +37,10 @@ namespace osu.Game.Overlays.KeyBinding foreach (var defaultGroup in Defaults.GroupBy(d => d.Action)) { + int intKey = (int)defaultGroup.Key; + // one row per valid action. - Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.Action.Equals((int)defaultGroup.Key))) + Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => ((int)b.Action).Equals(intKey))) { AllowMainMouseButtons = Ruleset != null, Defaults = defaultGroup.Select(d => d.KeyCombination)