41 lines
No EOL
1.1 KiB
C#
41 lines
No EOL
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Domain.Input {
|
|
public abstract class InputReader {
|
|
private readonly KeyHistory _history;
|
|
private readonly List<int> _desiredSequence;
|
|
|
|
private readonly bool _useSpecial;
|
|
private readonly int _specialKey;
|
|
private readonly bool _mustContain;
|
|
|
|
private bool _wasPressed;
|
|
private bool _isPressed;
|
|
|
|
public bool KeyDown() => _isPressed && !_wasPressed;
|
|
|
|
protected InputReader(KeyHistory history, List<int> desiredSequence) {
|
|
_useSpecial = false;
|
|
_history = history;
|
|
_desiredSequence = desiredSequence;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |