mirror of https://github.com/ppy/osu
Implement method to deduplicate keybindings
This commit is contained in:
parent
79273b88f6
commit
90c44cee54
|
@ -2,6 +2,7 @@
|
|||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Input;
|
||||
|
@ -24,7 +25,7 @@ public void TestBindingsWithoutDuplicatesAreNotModified()
|
|||
new RealmKeyBinding(GlobalAction.MusicNext, KeyCombination.FromKey(Key.F5))
|
||||
};
|
||||
|
||||
bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings);
|
||||
bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings.AsQueryable());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
|
@ -58,7 +59,7 @@ public void TestDuplicateBindingsAreCleared()
|
|||
new RealmKeyBinding(GlobalAction.TakeScreenshot, KeyCombination.FromKey(Key.PrintScreen)),
|
||||
};
|
||||
|
||||
bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings);
|
||||
bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings.AsQueryable());
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
|
|
|
@ -139,7 +139,22 @@ public static bool CheckValidForGameplay(KeyCombination combination)
|
|||
/// <returns>Whether any bindings have been cleared.</returns>
|
||||
public static bool ClearDuplicateBindings(IQueryable<RealmKeyBinding> keyBindings)
|
||||
{
|
||||
return false;
|
||||
bool anyRemoved = false;
|
||||
|
||||
var lookup = keyBindings.ToLookup(kb => kb.KeyCombination);
|
||||
|
||||
foreach (var group in lookup)
|
||||
{
|
||||
if (group.Count() <= 1)
|
||||
continue;
|
||||
|
||||
foreach (var binding in group)
|
||||
binding.KeyCombination = new KeyCombination(InputKey.None);
|
||||
|
||||
anyRemoved = true;
|
||||
}
|
||||
|
||||
return anyRemoved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue