refactor: converted vkeycode enum into a class

This commit is contained in:
Gerard Gascón 2024-04-17 18:01:33 +02:00
parent e3f6db7ae5
commit 68d3d8065e
19 changed files with 123 additions and 54 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Domain.Input;
using Extensions;
using UnityEngine;
@ -8,16 +9,16 @@ namespace Domain {
private readonly LimitedSizeList<int> _lastPressesWithSpecial = new(20);
private const int AlphabetSize = 26;
private const int CustomKeysSize = 5;
private const int CustomKeysSize = 4;
private const int SpecialKeysSize = 1;
private readonly VKeyCode[] _customKeys = {
private readonly int[] _customKeys = {
VKeyCode.Cedilla,
VKeyCode.Interpunct,
VKeyCode.AccentClosed,
VKeyCode.AccentOpen
};
private readonly VKeyCode[] _specialKeys = { VKeyCode.Shift };
private readonly int[] _specialKeys = { VKeyCode.Shift };
private readonly bool[] _isPressed = new bool[AlphabetSize + CustomKeysSize + SpecialKeysSize];
private readonly bool[] _wasPressed = new bool[AlphabetSize + CustomKeysSize + SpecialKeysSize];
@ -46,11 +47,11 @@ namespace Domain {
for (int i = 0; i < _customKeys.Length; i++) {
int pressIndex = AlphabetSize + i;
_wasPressed[pressIndex] = _isPressed[pressIndex];
short state = Win32API.GetAsyncKeyState((int)_customKeys[i]);
short state = Win32API.GetAsyncKeyState(_customKeys[i]);
if (!_wasPressed[pressIndex] && state != 0) {
_isPressed[pressIndex] = true;
KeyPressed((int)_customKeys[i]);
KeyPressed(_customKeys[i]);
}else if (_isPressed[pressIndex] && state == 0) {
_isPressed[pressIndex] = false;
}
@ -59,11 +60,11 @@ namespace Domain {
for (int i = 0; i < _specialKeys.Length; i++) {
int pressIndex = AlphabetSize + CustomKeysSize + i;
_wasPressed[pressIndex] = _isPressed[pressIndex];
short state = Win32API.GetAsyncKeyState((int)_specialKeys[i]);
short state = Win32API.GetAsyncKeyState(_specialKeys[i]);
if (!_wasPressed[pressIndex] && state != 0) {
_isPressed[pressIndex] = true;
KeyPressed((int)_specialKeys[i], true);
KeyPressed(_specialKeys[i], true);
}else if (_isPressed[pressIndex] && state == 0) {
_isPressed[pressIndex] = false;
}