From 10df3b194e0c225ee0982f9b6f657317de1d78f1 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 1 Mar 2020 15:59:30 -0600 Subject: [PATCH] simplify StickyAdapters a bit --- .../inputAdapters/StickyAdapters.cs | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/BizHawk.Client.Common/inputAdapters/StickyAdapters.cs b/BizHawk.Client.Common/inputAdapters/StickyAdapters.cs index 578bdb14ec..483d095dcb 100644 --- a/BizHawk.Client.Common/inputAdapters/StickyAdapters.cs +++ b/BizHawk.Client.Common/inputAdapters/StickyAdapters.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.Common public bool IsPressed(string button) { var source = Source.IsPressed(button); - source ^= _stickySet.Contains(button); + source ^= CurrentStickies.Contains(button); return source; } @@ -38,8 +38,6 @@ namespace BizHawk.Client.Common private List _justPressed = new List(); - private readonly HashSet _stickySet = new HashSet(); - // if SetFloat() is called (typically virtual pads), then that float will entirely override the Source input // otherwise, the source is passed thru. private readonly WorkingDictionary _floatSet = new WorkingDictionary(); @@ -56,39 +54,33 @@ namespace BizHawk.Client.Common } } - public void ClearStickyFloats() - { - _floatSet.Clear(); - } + public void ClearStickyFloats() => _floatSet.Clear(); public void SetSticky(string button, bool isSticky) { if (isSticky) { - _stickySet.Add(button); + CurrentStickies.Add(button); } else { - _stickySet.Remove(button); + CurrentStickies.Remove(button); } } public void Unset(string button) { - _stickySet.Remove(button); + CurrentStickies.Remove(button); _floatSet.Remove(button); } - public bool IsSticky(string button) - { - return _stickySet.Contains(button); - } + public bool IsSticky(string button) => CurrentStickies.Contains(button); - public HashSet CurrentStickies => _stickySet; + public HashSet CurrentStickies { get; } = new HashSet(); public void ClearStickies() { - _stickySet.Clear(); + CurrentStickies.Clear(); _floatSet.Clear(); } @@ -96,13 +88,13 @@ namespace BizHawk.Client.Common { foreach (var button in buttons.Where(button => !_justPressed.Contains(button))) { - if (_stickySet.Contains(button)) + if (CurrentStickies.Contains(button)) { - _stickySet.Remove(button); + CurrentStickies.Remove(button); } else { - _stickySet.Add(button); + CurrentStickies.Add(button); } }