feat: special key reading
This commit is contained in:
parent
c475204437
commit
2a6f41713e
5 changed files with 144 additions and 8 deletions
|
@ -3,6 +3,6 @@ using System.Linq;
|
|||
|
||||
namespace Domain.Input {
|
||||
public class AObertaReader : SequentialInputReader {
|
||||
public AObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x41 }) { }
|
||||
public AObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x41 }, 0x10, false) { }
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue