Loading Assets/Scripts/Domain/CustomInput.cs +5 −0 Original line number Diff line number Diff line Loading @@ -5,12 +5,17 @@ using Domain.Input; namespace Domain { public class CustomInput { private readonly Dictionary<Type, InputReader> _readers = new(); private readonly KeyHistory _history; public CustomInput() { _history = new KeyHistory(); _readers.Add(typeof(CedillaReader), new CedillaReader()); _readers.Add(typeof(GeminadaReader), new GeminadaReader(_history)); } public void UpdateInput() { _history.CheckPresses(); foreach (KeyValuePair<Type, InputReader> reader in _readers) { reader.Value.UpdateInput(); } Loading Assets/Scripts/Domain/Input/GeminadaReader.cs +15 −13 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ using System.Linq; namespace Domain.Input { public class GeminadaReader : InputReader { protected override int Key { get; } = 0x33; protected sealed override int Key { get; } = 0x33; private int LKey { get; } = 76; private bool _lPressed; Loading @@ -11,22 +11,24 @@ namespace Domain.Input { private bool _dotPressed; private bool _dotWasPressed; private List<int> _lastPresses; private readonly KeyHistory _history; private readonly List<int> _desiredSequence; public override void UpdateInput() { if (UpdateLInput()) { if (_lastPresses.Count == 0) { _lastPresses.Add(LKey); } else if (_lastPresses.Count >= 2) { if (_lastPresses[^1] == Key && _lastPresses[^2] == LKey) { IsPressed = true; } public GeminadaReader(KeyHistory history) { _history = history; _desiredSequence = new List<int> { LKey, Key, LKey }; } public override void UpdateInput() { if (UpdateDotInputDown()) { _history.KeyPressed(Key); } UpdateDotInput(); WasPressed = IsPressed; IsPressed = _history.ContainsSequence(_desiredSequence); } private bool UpdateDotInput() { private bool UpdateDotInputDown() { _dotWasPressed = _dotPressed; short dotState = Win32API.GetAsyncKeyState(Key); Loading @@ -40,7 +42,7 @@ namespace Domain.Input { return false; } private bool UpdateLInput() { private bool UpdateLInputDown() { _lWasPressed = _lPressed; short lState = Win32API.GetAsyncKeyState(LKey); Loading Assets/Scripts/Domain/KeyHistory.cs +27 −12 Original line number Diff line number Diff line using System.Collections.Generic; using Extensions; namespace Domain { public class KeyHistory { private readonly List<int> _lastPresses = new(); private readonly List<int> _desiredSequence; private readonly LimitedSizeList<int> _lastPresses = new(10); public KeyHistory(List<int> desiredSequence) { _desiredSequence = desiredSequence; } private readonly bool[] _isPressed = new bool[26]; private readonly bool[] _wasPressed = new bool[26]; public void KeyPressed(int key) => _lastPresses.Add(key); public void ClearPressed() => _lastPresses.Clear(); public bool ContainsSequence() { if (_lastPresses.Count < _desiredSequence.Count) public void CheckPresses() { const int aIndex = 0x41; const int zIndex = 0x5A; for (int i = aIndex, j = 0; i <= zIndex; i++, j++) { _wasPressed[j] = _isPressed[j]; short state = Win32API.GetAsyncKeyState(i); if (!_wasPressed[j] && state != 0) { _isPressed[j] = true; KeyPressed(i); }else if (_isPressed[j] && state == 0) { _isPressed[j] = false; } } } public bool ContainsSequence(List<int> sequence) { if (_lastPresses.List.Count < sequence.Count) return false; for (int i = 0; i < _lastPresses.Count; i++) { if (i >= _desiredSequence.Count) for (int i = 0; i < _lastPresses.List.Count; i++) { if (i >= sequence.Count) break; int keyPressed = _lastPresses[_lastPresses.Count - 1 - i]; int sequenceKey = _desiredSequence[_desiredSequence.Count - 1 - i]; int keyPressed = _lastPresses.List[_lastPresses.List.Count - 1 - i]; int sequenceKey = sequence[sequence.Count - 1 - i]; if (keyPressed != sequenceKey) { return false; Loading Assets/Scripts/Domain/SantJordi.Domain.asmdef +2 −1 Original line number Diff line number Diff line { "name": "SantJordi.Domain" "name": "SantJordi.Domain", "references":[ "GUID:b347d0ff97f738846abb5625028d64db" ] } Assets/Scripts/Extensions.meta 0 → 100644 +3 −0 Original line number Diff line number Diff line fileFormatVersion: 2 guid: bfb91da35c9749c980ab26f8e6b48dbe timeCreated: 1713127616 No newline at end of file Loading
Assets/Scripts/Domain/CustomInput.cs +5 −0 Original line number Diff line number Diff line Loading @@ -5,12 +5,17 @@ using Domain.Input; namespace Domain { public class CustomInput { private readonly Dictionary<Type, InputReader> _readers = new(); private readonly KeyHistory _history; public CustomInput() { _history = new KeyHistory(); _readers.Add(typeof(CedillaReader), new CedillaReader()); _readers.Add(typeof(GeminadaReader), new GeminadaReader(_history)); } public void UpdateInput() { _history.CheckPresses(); foreach (KeyValuePair<Type, InputReader> reader in _readers) { reader.Value.UpdateInput(); } Loading
Assets/Scripts/Domain/Input/GeminadaReader.cs +15 −13 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ using System.Linq; namespace Domain.Input { public class GeminadaReader : InputReader { protected override int Key { get; } = 0x33; protected sealed override int Key { get; } = 0x33; private int LKey { get; } = 76; private bool _lPressed; Loading @@ -11,22 +11,24 @@ namespace Domain.Input { private bool _dotPressed; private bool _dotWasPressed; private List<int> _lastPresses; private readonly KeyHistory _history; private readonly List<int> _desiredSequence; public override void UpdateInput() { if (UpdateLInput()) { if (_lastPresses.Count == 0) { _lastPresses.Add(LKey); } else if (_lastPresses.Count >= 2) { if (_lastPresses[^1] == Key && _lastPresses[^2] == LKey) { IsPressed = true; } public GeminadaReader(KeyHistory history) { _history = history; _desiredSequence = new List<int> { LKey, Key, LKey }; } public override void UpdateInput() { if (UpdateDotInputDown()) { _history.KeyPressed(Key); } UpdateDotInput(); WasPressed = IsPressed; IsPressed = _history.ContainsSequence(_desiredSequence); } private bool UpdateDotInput() { private bool UpdateDotInputDown() { _dotWasPressed = _dotPressed; short dotState = Win32API.GetAsyncKeyState(Key); Loading @@ -40,7 +42,7 @@ namespace Domain.Input { return false; } private bool UpdateLInput() { private bool UpdateLInputDown() { _lWasPressed = _lPressed; short lState = Win32API.GetAsyncKeyState(LKey); Loading
Assets/Scripts/Domain/KeyHistory.cs +27 −12 Original line number Diff line number Diff line using System.Collections.Generic; using Extensions; namespace Domain { public class KeyHistory { private readonly List<int> _lastPresses = new(); private readonly List<int> _desiredSequence; private readonly LimitedSizeList<int> _lastPresses = new(10); public KeyHistory(List<int> desiredSequence) { _desiredSequence = desiredSequence; } private readonly bool[] _isPressed = new bool[26]; private readonly bool[] _wasPressed = new bool[26]; public void KeyPressed(int key) => _lastPresses.Add(key); public void ClearPressed() => _lastPresses.Clear(); public bool ContainsSequence() { if (_lastPresses.Count < _desiredSequence.Count) public void CheckPresses() { const int aIndex = 0x41; const int zIndex = 0x5A; for (int i = aIndex, j = 0; i <= zIndex; i++, j++) { _wasPressed[j] = _isPressed[j]; short state = Win32API.GetAsyncKeyState(i); if (!_wasPressed[j] && state != 0) { _isPressed[j] = true; KeyPressed(i); }else if (_isPressed[j] && state == 0) { _isPressed[j] = false; } } } public bool ContainsSequence(List<int> sequence) { if (_lastPresses.List.Count < sequence.Count) return false; for (int i = 0; i < _lastPresses.Count; i++) { if (i >= _desiredSequence.Count) for (int i = 0; i < _lastPresses.List.Count; i++) { if (i >= sequence.Count) break; int keyPressed = _lastPresses[_lastPresses.Count - 1 - i]; int sequenceKey = _desiredSequence[_desiredSequence.Count - 1 - i]; int keyPressed = _lastPresses.List[_lastPresses.List.Count - 1 - i]; int sequenceKey = sequence[sequence.Count - 1 - i]; if (keyPressed != sequenceKey) { return false; Loading
Assets/Scripts/Domain/SantJordi.Domain.asmdef +2 −1 Original line number Diff line number Diff line { "name": "SantJordi.Domain" "name": "SantJordi.Domain", "references":[ "GUID:b347d0ff97f738846abb5625028d64db" ] }
Assets/Scripts/Extensions.meta 0 → 100644 +3 −0 Original line number Diff line number Diff line fileFormatVersion: 2 guid: bfb91da35c9749c980ab26f8e6b48dbe timeCreated: 1713127616 No newline at end of file