refactor: made all input readers sequential
This commit is contained in:
parent
5c721a3329
commit
2cae1eced7
18 changed files with 53 additions and 66 deletions
|
@ -1,15 +1,41 @@
|
|||
namespace Domain.Input {
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Domain.Input {
|
||||
public abstract class InputReader {
|
||||
protected bool WasPressed;
|
||||
protected bool IsPressed;
|
||||
private readonly KeyHistory _history;
|
||||
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() {
|
||||
WasPressed = IsPressed;
|
||||
IsPressed = Win32API.GetAsyncKeyState(Key) != 0;
|
||||
private bool _wasPressed;
|
||||
private bool _isPressed;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue