diff --git a/Assets/Scripts/Domain/CustomInput.cs b/Assets/Scripts/Domain/CustomInput.cs index 1609cb6..73a25f3 100644 --- a/Assets/Scripts/Domain/CustomInput.cs +++ b/Assets/Scripts/Domain/CustomInput.cs @@ -12,6 +12,13 @@ namespace Domain { _readers.Add(typeof(CedillaReader), new CedillaReader()); _readers.Add(typeof(GeminadaReader), new GeminadaReader(_history)); + _readers.Add(typeof(TxReader), new TxReader(_history)); + _readers.Add(typeof(IxReader), new IxReader(_history)); + _readers.Add(typeof(NyReader), new NyReader(_history)); + _readers.Add(typeof(TgReader), new TgReader(_history)); + _readers.Add(typeof(TjReader), new TjReader(_history)); + _readers.Add(typeof(LlReader), new LlReader(_history)); + _readers.Add(typeof(SsReader), new SsReader(_history)); } public void UpdateInput() { diff --git a/Assets/Scripts/Domain/Input/GeminadaReader.cs b/Assets/Scripts/Domain/Input/GeminadaReader.cs index 2da065b..204b172 100644 --- a/Assets/Scripts/Domain/Input/GeminadaReader.cs +++ b/Assets/Scripts/Domain/Input/GeminadaReader.cs @@ -2,58 +2,7 @@ using System.Linq; namespace Domain.Input { - public class GeminadaReader : InputReader { - protected sealed override int Key { get; } = 0x33; - private int LKey { get; } = 76; - - private bool _lPressed; - private bool _lWasPressed; - private bool _dotPressed; - private bool _dotWasPressed; - - private readonly KeyHistory _history; - private readonly List _desiredSequence; - - public GeminadaReader(KeyHistory history) { - _history = history; - _desiredSequence = new List { LKey, Key, LKey }; - } - - public override void UpdateInput() { - if (UpdateDotInputDown()) { - _history.KeyPressed(Key); - } - - WasPressed = IsPressed; - IsPressed = _history.ContainsSequence(_desiredSequence); - } - - private bool UpdateDotInputDown() { - _dotWasPressed = _dotPressed; - short dotState = Win32API.GetAsyncKeyState(Key); - - if (!_dotWasPressed && dotState != 0) { - _dotPressed = true; - return true; - } - if (_dotPressed && dotState == 0) { - _dotPressed = false; - } - return false; - } - - private bool UpdateLInputDown() { - _lWasPressed = _lPressed; - short lState = Win32API.GetAsyncKeyState(LKey); - - if (!_lWasPressed && lState != 0) { - _lPressed = true; - return true; - } - if (_lPressed && lState == 0) { - _lPressed = false; - } - return false; - } + public class GeminadaReader : SequentialInputReader { + public GeminadaReader(KeyHistory history) : base(history, new List{ 76, 0x33, 76 }) { } } } \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/IxReader.cs b/Assets/Scripts/Domain/Input/IxReader.cs new file mode 100644 index 0000000..c2b9c84 --- /dev/null +++ b/Assets/Scripts/Domain/Input/IxReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class IxReader : SequentialInputReader { + public IxReader(KeyHistory history) : base(history, new List{ 0x49, 0x58 }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/IxReader.cs.meta b/Assets/Scripts/Domain/Input/IxReader.cs.meta new file mode 100644 index 0000000..9296a8a --- /dev/null +++ b/Assets/Scripts/Domain/Input/IxReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 96e8ae30bc1b46a8bb80786992cffa75 +timeCreated: 1713130888 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/LlReader.cs b/Assets/Scripts/Domain/Input/LlReader.cs new file mode 100644 index 0000000..39800e8 --- /dev/null +++ b/Assets/Scripts/Domain/Input/LlReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class LlReader : SequentialInputReader { + public LlReader(KeyHistory history) : base(history, new List{ 0x4C, 0x4C }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/LlReader.cs.meta b/Assets/Scripts/Domain/Input/LlReader.cs.meta new file mode 100644 index 0000000..9db6c10 --- /dev/null +++ b/Assets/Scripts/Domain/Input/LlReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: af7552f52e7148d3a2463b6e7183dee4 +timeCreated: 1713131073 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/NyReader.cs b/Assets/Scripts/Domain/Input/NyReader.cs new file mode 100644 index 0000000..6df1493 --- /dev/null +++ b/Assets/Scripts/Domain/Input/NyReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class NyReader : SequentialInputReader { + public NyReader(KeyHistory history) : base(history, new List{ 0x4E, 0x59 }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/NyReader.cs.meta b/Assets/Scripts/Domain/Input/NyReader.cs.meta new file mode 100644 index 0000000..1d4052a --- /dev/null +++ b/Assets/Scripts/Domain/Input/NyReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cd6b561b73234ad0a055bc9e1d5dfc7b +timeCreated: 1713130925 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/SequentialInputReader.cs b/Assets/Scripts/Domain/Input/SequentialInputReader.cs new file mode 100644 index 0000000..0832de8 --- /dev/null +++ b/Assets/Scripts/Domain/Input/SequentialInputReader.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Domain.Input { + public abstract class SequentialInputReader : InputReader { + protected override int Key => 0; + + private readonly KeyHistory _history; + private readonly List _desiredSequence; + + protected SequentialInputReader(KeyHistory history, List desiredSequence) { + _history = history; + _desiredSequence = desiredSequence; + } + + public override void UpdateInput() { + WasPressed = IsPressed; + IsPressed = _history.ContainsSequence(_desiredSequence); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/SequentialInputReader.cs.meta b/Assets/Scripts/Domain/Input/SequentialInputReader.cs.meta new file mode 100644 index 0000000..c05d45c --- /dev/null +++ b/Assets/Scripts/Domain/Input/SequentialInputReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9350ce8df7844ae59d38cb2fe6aad68d +timeCreated: 1713129539 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/SsReader.cs b/Assets/Scripts/Domain/Input/SsReader.cs new file mode 100644 index 0000000..0bf6dd4 --- /dev/null +++ b/Assets/Scripts/Domain/Input/SsReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class SsReader : SequentialInputReader { + public SsReader(KeyHistory history) : base(history, new List{ 0x53, 0x53 }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/SsReader.cs.meta b/Assets/Scripts/Domain/Input/SsReader.cs.meta new file mode 100644 index 0000000..90f2618 --- /dev/null +++ b/Assets/Scripts/Domain/Input/SsReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a715c7dcbd2c450d96b3372615707171 +timeCreated: 1713131099 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TgReader.cs b/Assets/Scripts/Domain/Input/TgReader.cs new file mode 100644 index 0000000..7e9c932 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TgReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class TgReader : SequentialInputReader { + public TgReader(KeyHistory history) : base(history, new List{ 0x54, 0x47 }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TgReader.cs.meta b/Assets/Scripts/Domain/Input/TgReader.cs.meta new file mode 100644 index 0000000..2a5c726 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TgReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b10833198463414a82b2a78934a59a51 +timeCreated: 1713130961 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TjReader.cs b/Assets/Scripts/Domain/Input/TjReader.cs new file mode 100644 index 0000000..1ab5b31 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TjReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class TjReader : SequentialInputReader { + public TjReader(KeyHistory history) : base(history, new List{ 0x54, 0x4A }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TjReader.cs.meta b/Assets/Scripts/Domain/Input/TjReader.cs.meta new file mode 100644 index 0000000..f81ad68 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TjReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4d5480090308468fb5b5261d4c007b1e +timeCreated: 1713130987 \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TxReader.cs b/Assets/Scripts/Domain/Input/TxReader.cs new file mode 100644 index 0000000..3c60ec3 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TxReader.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Domain.Input { + public class TxReader : SequentialInputReader { + public TxReader(KeyHistory history) : base(history, new List{ 0x54, 0x58 }) { } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Domain/Input/TxReader.cs.meta b/Assets/Scripts/Domain/Input/TxReader.cs.meta new file mode 100644 index 0000000..a65ee06 --- /dev/null +++ b/Assets/Scripts/Domain/Input/TxReader.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d9f83d5b77f947a98425a5651534d5c3 +timeCreated: 1713130823 \ No newline at end of file diff --git a/Assets/Scripts/Domain/KeyHistory.cs b/Assets/Scripts/Domain/KeyHistory.cs index 5bb66a0..5e4704a 100644 --- a/Assets/Scripts/Domain/KeyHistory.cs +++ b/Assets/Scripts/Domain/KeyHistory.cs @@ -5,8 +5,9 @@ namespace Domain { public class KeyHistory { private readonly LimitedSizeList _lastPresses = new(10); - private readonly bool[] _isPressed = new bool[26]; - private readonly bool[] _wasPressed = new bool[26]; + private readonly int[] _customKeys = { 191, 51, 222, 186 }; + private readonly bool[] _isPressed = new bool[26 + 5]; + private readonly bool[] _wasPressed = new bool[26 + 5]; public void KeyPressed(int key) => _lastPresses.Add(key); @@ -25,6 +26,19 @@ namespace Domain { _isPressed[j] = false; } } + + for (int i = 0; i < _customKeys.Length; i++) { + int pressIndex = 26 + i; + _wasPressed[pressIndex] = _isPressed[pressIndex]; + short state = Win32API.GetAsyncKeyState(_customKeys[i]); + + if (!_wasPressed[pressIndex] && state != 0) { + _isPressed[pressIndex] = true; + KeyPressed(_customKeys[i]); + }else if (_isPressed[pressIndex] && state == 0) { + _isPressed[pressIndex] = false; + } + } } public bool ContainsSequence(List sequence) { @@ -43,6 +57,7 @@ namespace Domain { } } + _lastPresses.List.Clear(); return true; } } diff --git a/Assets/Scripts/View/CTrencadaInput.cs b/Assets/Scripts/View/CTrencadaInput.cs index 200b4b8..725d8f8 100644 --- a/Assets/Scripts/View/CTrencadaInput.cs +++ b/Assets/Scripts/View/CTrencadaInput.cs @@ -26,6 +26,20 @@ namespace View { _click.Execute(); if (_customInput.KeyDown(typeof(CedillaReader))) _click.Execute(); + if (_customInput.KeyDown(typeof(IxReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(LlReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(NyReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(SsReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(TgReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(TjReader))) + _click.Execute(); + if (_customInput.KeyDown(typeof(TxReader))) + _click.Execute(); } public void UpdateView(int score) {