refactor: made all input readers sequential
This commit is contained in:
parent
5c721a3329
commit
2cae1eced7
18 changed files with 53 additions and 66 deletions
|
@ -10,7 +10,7 @@ namespace Domain {
|
||||||
public CustomInput() {
|
public CustomInput() {
|
||||||
_history = new KeyHistory();
|
_history = new KeyHistory();
|
||||||
|
|
||||||
_readers.Add(new CedillaReader());
|
_readers.Add(new CedillaReader(_history));
|
||||||
_readers.Add(new GeminadaReader(_history));
|
_readers.Add(new GeminadaReader(_history));
|
||||||
_readers.Add(new TxReader(_history));
|
_readers.Add(new TxReader(_history));
|
||||||
_readers.Add(new IxReader(_history));
|
_readers.Add(new IxReader(_history));
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class AObertaReader : SequentialInputReader {
|
public class AObertaReader : InputReader {
|
||||||
public AObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x41 }, 0x10, false) { }
|
public AObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x41 }, 0x10, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
namespace Domain.Input {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Domain.Input {
|
||||||
public class CedillaReader : InputReader {
|
public class CedillaReader : InputReader {
|
||||||
protected override int Key { get; } = 0xBF; //VK_OEM_2 | cedilla
|
public CedillaReader(KeyHistory history) : base(history, new List<int>{ 0xBF }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class EObertaReader : SequentialInputReader {
|
public class EObertaReader : InputReader {
|
||||||
public EObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x45 }, 0x10, false) { }
|
public EObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x45 }, 0x10, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class GeminadaReader : SequentialInputReader {
|
public class GeminadaReader : InputReader {
|
||||||
public GeminadaReader(KeyHistory history) : base(history, new List<int>{ 76, 0x33, 76 }) { }
|
public GeminadaReader(KeyHistory history) : base(history, new List<int>{ 76, 0x33, 76 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class IDieresiReader : SequentialInputReader {
|
public class IDieresiReader : InputReader {
|
||||||
public IDieresiReader(KeyHistory history) : base(history, new List<int>{ 0xDE, 0x49 }, 0x10, true) { }
|
public IDieresiReader(KeyHistory history) : base(history, new List<int>{ 0xDE, 0x49 }, 0x10, true) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,41 @@
|
||||||
namespace Domain.Input {
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Domain.Input {
|
||||||
public abstract class InputReader {
|
public abstract class InputReader {
|
||||||
protected bool WasPressed;
|
private readonly KeyHistory _history;
|
||||||
protected bool IsPressed;
|
private readonly List<int> _desiredSequence;
|
||||||
|
|
||||||
protected abstract int Key { get; }
|
private readonly bool _useSpecial;
|
||||||
|
private readonly int _specialKey;
|
||||||
|
private readonly bool _mustContain;
|
||||||
|
|
||||||
public virtual void UpdateInput() {
|
private bool _wasPressed;
|
||||||
WasPressed = IsPressed;
|
private bool _isPressed;
|
||||||
IsPressed = Win32API.GetAsyncKeyState(Key) != 0;
|
|
||||||
|
public bool KeyDown() => _isPressed && !_wasPressed;
|
||||||
|
|
||||||
|
protected InputReader(KeyHistory history, List<int> desiredSequence) {
|
||||||
|
_useSpecial = false;
|
||||||
|
_history = history;
|
||||||
|
_desiredSequence = desiredSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool KeyDown() => IsPressed && !WasPressed;
|
protected InputReader(KeyHistory history, List<int> desiredSequence, int specialKey, bool mustContain) {
|
||||||
|
_useSpecial = true;
|
||||||
|
_history = history;
|
||||||
|
_desiredSequence = desiredSequence;
|
||||||
|
|
||||||
|
_specialKey = specialKey;
|
||||||
|
_mustContain = mustContain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateInput() {
|
||||||
|
_wasPressed = _isPressed;
|
||||||
|
if (_useSpecial)
|
||||||
|
_isPressed = _history.ContainsSequence(_desiredSequence, _specialKey, _mustContain);
|
||||||
|
else
|
||||||
|
_isPressed = _history.ContainsSequence(_desiredSequence);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 3b3b656d6cb1415eab0de81628a5b54e
|
guid: 9350ce8df7844ae59d38cb2fe6aad68d
|
||||||
timeCreated: 1713112368
|
timeCreated: 1713129539
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class IxReader : SequentialInputReader {
|
public class IxReader : InputReader {
|
||||||
public IxReader(KeyHistory history) : base(history, new List<int>{ 0x49, 0x58 }) { }
|
public IxReader(KeyHistory history) : base(history, new List<int>{ 0x49, 0x58 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class LlReader : SequentialInputReader {
|
public class LlReader : InputReader {
|
||||||
public LlReader(KeyHistory history) : base(history, new List<int>{ 0x4C, 0x4C }) { }
|
public LlReader(KeyHistory history) : base(history, new List<int>{ 0x4C, 0x4C }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class NyReader : SequentialInputReader {
|
public class NyReader : InputReader {
|
||||||
public NyReader(KeyHistory history) : base(history, new List<int>{ 0x4E, 0x59 }) { }
|
public NyReader(KeyHistory history) : base(history, new List<int>{ 0x4E, 0x59 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class OObertaReader : SequentialInputReader {
|
public class OObertaReader : InputReader {
|
||||||
public OObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x4F }, 0x10, false) { }
|
public OObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x4F }, 0x10, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,38 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Domain.Input {
|
|
||||||
public abstract class SequentialInputReader : InputReader {
|
|
||||||
protected override int Key => 0;
|
|
||||||
|
|
||||||
private readonly KeyHistory _history;
|
|
||||||
private readonly List<int> _desiredSequence;
|
|
||||||
|
|
||||||
private readonly bool _useSpecial;
|
|
||||||
private readonly int _specialKey;
|
|
||||||
private readonly bool _mustContain;
|
|
||||||
|
|
||||||
protected SequentialInputReader(KeyHistory history, List<int> desiredSequence) {
|
|
||||||
_useSpecial = false;
|
|
||||||
_history = history;
|
|
||||||
_desiredSequence = desiredSequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SequentialInputReader(KeyHistory history, List<int> desiredSequence, int specialKey, bool mustContain) {
|
|
||||||
_useSpecial = true;
|
|
||||||
_history = history;
|
|
||||||
_desiredSequence = desiredSequence;
|
|
||||||
|
|
||||||
_specialKey = specialKey;
|
|
||||||
_mustContain = mustContain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void UpdateInput() {
|
|
||||||
WasPressed = IsPressed;
|
|
||||||
if (_useSpecial)
|
|
||||||
IsPressed = _history.ContainsSequence(_desiredSequence, _specialKey, _mustContain);
|
|
||||||
else
|
|
||||||
IsPressed = _history.ContainsSequence(_desiredSequence);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 9350ce8df7844ae59d38cb2fe6aad68d
|
|
||||||
timeCreated: 1713129539
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class SsReader : SequentialInputReader {
|
public class SsReader : InputReader {
|
||||||
public SsReader(KeyHistory history) : base(history, new List<int>{ 0x53, 0x53 }) { }
|
public SsReader(KeyHistory history) : base(history, new List<int>{ 0x53, 0x53 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TgReader : SequentialInputReader {
|
public class TgReader : InputReader {
|
||||||
public TgReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x47 }) { }
|
public TgReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x47 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TjReader : SequentialInputReader {
|
public class TjReader : InputReader {
|
||||||
public TjReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x4A }) { }
|
public TjReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x4A }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TxReader : SequentialInputReader {
|
public class TxReader : InputReader {
|
||||||
public TxReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x58 }) { }
|
public TxReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x58 }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue