feat: special key reading

This commit is contained in:
Gerard Gascón 2024-04-16 17:55:13 +02:00
parent c475204437
commit 2a6f41713e
5 changed files with 144 additions and 8 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using UnityEngine;
namespace Domain.Input {
public abstract class SequentialInputReader : InputReader {
@ -7,14 +8,31 @@ namespace Domain.Input {
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;
IsPressed = _history.ContainsSequence(_desiredSequence);
if (_useSpecial)
IsPressed = _history.ContainsSequence(_desiredSequence, _specialKey, _mustContain);
else
IsPressed = _history.ContainsSequence(_desiredSequence);
}
}
}