feat: most sequential characters working
This commit is contained in:
parent
77ee7a844e
commit
61c18429a2
20 changed files with 140 additions and 55 deletions
|
@ -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() {
|
||||
|
|
|
@ -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<int> _desiredSequence;
|
||||
|
||||
public GeminadaReader(KeyHistory history) {
|
||||
_history = history;
|
||||
_desiredSequence = new List<int> { 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<int>{ 76, 0x33, 76 }) { }
|
||||
}
|
||||
}
|
8
Assets/Scripts/Domain/Input/IxReader.cs
Normal file
8
Assets/Scripts/Domain/Input/IxReader.cs
Normal file
|
@ -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<int>{ 0x49, 0x58 }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/IxReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/IxReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 96e8ae30bc1b46a8bb80786992cffa75
|
||||
timeCreated: 1713130888
|
8
Assets/Scripts/Domain/Input/LlReader.cs
Normal file
8
Assets/Scripts/Domain/Input/LlReader.cs
Normal file
|
@ -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<int>{ 0x4C, 0x4C }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/LlReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/LlReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af7552f52e7148d3a2463b6e7183dee4
|
||||
timeCreated: 1713131073
|
8
Assets/Scripts/Domain/Input/NyReader.cs
Normal file
8
Assets/Scripts/Domain/Input/NyReader.cs
Normal file
|
@ -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<int>{ 0x4E, 0x59 }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/NyReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/NyReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd6b561b73234ad0a055bc9e1d5dfc7b
|
||||
timeCreated: 1713130925
|
20
Assets/Scripts/Domain/Input/SequentialInputReader.cs
Normal file
20
Assets/Scripts/Domain/Input/SequentialInputReader.cs
Normal file
|
@ -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<int> _desiredSequence;
|
||||
|
||||
protected SequentialInputReader(KeyHistory history, List<int> desiredSequence) {
|
||||
_history = history;
|
||||
_desiredSequence = desiredSequence;
|
||||
}
|
||||
|
||||
public override void UpdateInput() {
|
||||
WasPressed = IsPressed;
|
||||
IsPressed = _history.ContainsSequence(_desiredSequence);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9350ce8df7844ae59d38cb2fe6aad68d
|
||||
timeCreated: 1713129539
|
8
Assets/Scripts/Domain/Input/SsReader.cs
Normal file
8
Assets/Scripts/Domain/Input/SsReader.cs
Normal file
|
@ -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<int>{ 0x53, 0x53 }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/SsReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/SsReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a715c7dcbd2c450d96b3372615707171
|
||||
timeCreated: 1713131099
|
8
Assets/Scripts/Domain/Input/TgReader.cs
Normal file
8
Assets/Scripts/Domain/Input/TgReader.cs
Normal file
|
@ -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<int>{ 0x54, 0x47 }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/TgReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/TgReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b10833198463414a82b2a78934a59a51
|
||||
timeCreated: 1713130961
|
8
Assets/Scripts/Domain/Input/TjReader.cs
Normal file
8
Assets/Scripts/Domain/Input/TjReader.cs
Normal file
|
@ -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<int>{ 0x54, 0x4A }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/TjReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/TjReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d5480090308468fb5b5261d4c007b1e
|
||||
timeCreated: 1713130987
|
8
Assets/Scripts/Domain/Input/TxReader.cs
Normal file
8
Assets/Scripts/Domain/Input/TxReader.cs
Normal file
|
@ -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<int>{ 0x54, 0x58 }) { }
|
||||
}
|
||||
}
|
3
Assets/Scripts/Domain/Input/TxReader.cs.meta
Normal file
3
Assets/Scripts/Domain/Input/TxReader.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d9f83d5b77f947a98425a5651534d5c3
|
||||
timeCreated: 1713130823
|
|
@ -5,8 +5,9 @@ namespace Domain {
|
|||
public class KeyHistory {
|
||||
private readonly LimitedSizeList<int> _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<int> sequence) {
|
||||
|
@ -43,6 +57,7 @@ namespace Domain {
|
|||
}
|
||||
}
|
||||
|
||||
_lastPresses.List.Clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue