1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-22 17:52:57 +08:00

Rewrite fix in a more legible way

- Use better param name ("restoring" what bindings? the key information
  there is that the *defaults* are being restored)
- Split ugly and not easily understandable (but probably
  best-that-can-be-done) conditional out to a method and comment it
  appropriately
This commit is contained in:
Bartłomiej Dach 2024-11-01 19:26:59 +01:00
parent 0a33d71671
commit f5a2674f66
No known key found for this signature in database

View File

@ -222,7 +222,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
var button = buttons[i++];
button.UpdateKeyCombination(d);
tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false, restoringBinding: true);
tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false, restoringDefaults: true);
}
isDefault.Value = true;
@ -489,12 +489,25 @@ namespace osu.Game.Overlays.Settings.Sections.Input
base.OnFocusLost(e);
}
private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding, bool restoringBinding = false)
private bool isConflictingBinding(RealmKeyBinding first, RealmKeyBinding second, bool restoringDefaults)
{
if (first.ID == second.ID)
return false;
// ignore conflicts with same action bindings during revert. the assumption is that the other binding will be reverted subsequently in the same higher-level operation.
// this happens if the bindings for an action are rebound to the same keys, but the ordering of the bindings itself is different.
if (restoringDefaults && first.ActionInt == second.ActionInt)
return false;
return first.KeyCombination.Equals(second.KeyCombination);
}
private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding, bool restoringDefaults = false)
{
List<RealmKeyBinding> bindings = GetAllSectionBindings();
RealmKeyBinding? existingBinding = keyBinding.KeyCombination.Equals(new KeyCombination(InputKey.None))
? null
: bindings.FirstOrDefault(other => other.ID != keyBinding.ID && other.KeyCombination.Equals(keyBinding.KeyCombination) && (!restoringBinding || other.ActionInt != keyBinding.ActionInt));
: bindings.FirstOrDefault(other => isConflictingBinding(keyBinding, other, restoringDefaults));
if (existingBinding == null)
{