2023-07-02 23:17:37 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class InputParser
|
2023-01-15 01:54:52 +02:00
|
|
|
{
|
|
|
|
|
public static long GetInput(int id)
|
|
|
|
|
{
|
|
|
|
|
long input = 0;
|
|
|
|
|
if (id == 0)
|
|
|
|
|
{
|
2023-07-01 23:48:47 +03:00
|
|
|
if (UnityEngine.Input.anyKeyDown)
|
2023-01-15 01:54:52 +02:00
|
|
|
input |= NetworkInput.SKIP_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_UP_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_DOWN_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.RIGHT_BYTE;
|
2023-10-26 22:42:28 +03:00
|
|
|
if (NetworkInput.ONE_NEUTRAL_INPUT)
|
|
|
|
|
input |= NetworkInput.NEUTRAL_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_UP_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_RIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_UP_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_DOWN_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_RIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_DOWN_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_NEUTRAL_INPUT)
|
|
|
|
|
input |= NetworkInput.NEUTRAL_BYTE;
|
|
|
|
|
|
2023-01-15 01:54:52 +02:00
|
|
|
if (NetworkInput.ONE_LIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.LIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_MEDIUM_INPUT)
|
|
|
|
|
input |= NetworkInput.MEDIUM_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_HEAVY_INPUT)
|
|
|
|
|
input |= NetworkInput.HEAVY_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_ARCANA_INPUT)
|
|
|
|
|
input |= NetworkInput.ARCANA_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_SHADOW_INPUT)
|
|
|
|
|
input |= NetworkInput.SHADOW_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_GRAB_INPUT)
|
|
|
|
|
input |= NetworkInput.GRAB_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_BLUE_FRENZY_INPUT)
|
|
|
|
|
input |= NetworkInput.BLUE_FRENZY_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_RED_FRENZY_INPUT)
|
|
|
|
|
input |= NetworkInput.RED_FRENZY_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_DASH_FORWARD_INPUT)
|
|
|
|
|
input |= NetworkInput.DASH_FORWARD_BYTE;
|
|
|
|
|
if (NetworkInput.ONE_DASH_BACKWARD_INPUT)
|
|
|
|
|
input |= NetworkInput.DASH_BACKWARD_BYTE;
|
|
|
|
|
}
|
|
|
|
|
if (id == 1)
|
|
|
|
|
{
|
2023-07-01 23:48:47 +03:00
|
|
|
if (UnityEngine.Input.anyKeyDown)
|
2023-01-15 01:54:52 +02:00
|
|
|
input |= NetworkInput.SKIP_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_UP_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_DOWN_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.RIGHT_BYTE;
|
2023-10-26 22:42:28 +03:00
|
|
|
if (NetworkInput.TWO_UP_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_RIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_UP_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.UP_LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_DOWN_RIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_RIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_DOWN_LEFT_INPUT)
|
|
|
|
|
input |= NetworkInput.DOWN_LEFT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_NEUTRAL_INPUT)
|
|
|
|
|
input |= NetworkInput.NEUTRAL_BYTE;
|
|
|
|
|
|
2023-01-15 01:54:52 +02:00
|
|
|
if (NetworkInput.TWO_LIGHT_INPUT)
|
|
|
|
|
input |= NetworkInput.LIGHT_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_MEDIUM_INPUT)
|
|
|
|
|
input |= NetworkInput.MEDIUM_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_HEAVY_INPUT)
|
|
|
|
|
input |= NetworkInput.HEAVY_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_ARCANA_INPUT)
|
|
|
|
|
input |= NetworkInput.ARCANA_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_SHADOW_INPUT)
|
|
|
|
|
input |= NetworkInput.SHADOW_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_GRAB_INPUT)
|
|
|
|
|
input |= NetworkInput.GRAB_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_BLUE_FRENZY_INPUT)
|
|
|
|
|
input |= NetworkInput.BLUE_FRENZY_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_RED_FRENZY_INPUT)
|
|
|
|
|
input |= NetworkInput.RED_FRENZY_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_DASH_FORWARD_INPUT)
|
|
|
|
|
input |= NetworkInput.DASH_FORWARD_BYTE;
|
|
|
|
|
if (NetworkInput.TWO_DASH_BACKWARD_INPUT)
|
|
|
|
|
input |= NetworkInput.DASH_BACKWARD_BYTE;
|
|
|
|
|
}
|
|
|
|
|
return input;
|
|
|
|
|
}
|
2023-01-15 02:29:53 +02:00
|
|
|
|
2023-07-02 23:17:37 +03:00
|
|
|
public static void ParseInput(long inputs, out bool skip, ref InputList inputTriggers)
|
2023-01-15 02:29:53 +02:00
|
|
|
{
|
|
|
|
|
if ((inputs & NetworkInput.SKIP_BYTE) != 0)
|
|
|
|
|
skip = true;
|
|
|
|
|
else
|
|
|
|
|
skip = false;
|
2023-07-02 23:17:37 +03:00
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[0], NetworkInput.LIGHT_BYTE, NetworkInput.BLUE_FRENZY_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[1], NetworkInput.MEDIUM_BYTE, NetworkInput.BLUE_FRENZY_BYTE);
|
2023-07-03 00:44:54 +03:00
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[2], NetworkInput.SHADOW_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[3], NetworkInput.HEAVY_BYTE, NetworkInput.RED_FRENZY_BYTE);
|
2023-07-02 23:17:37 +03:00
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[4], NetworkInput.ARCANA_BYTE, NetworkInput.RED_FRENZY_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[5], NetworkInput.GRAB_BYTE);
|
2023-07-03 00:44:54 +03:00
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[6], NetworkInput.DASH_FORWARD_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[7], NetworkInput.DASH_BACKWARD_BYTE);
|
2023-10-26 22:42:28 +03:00
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[8], NetworkInput.UP_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[9], NetworkInput.DOWN_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[10], NetworkInput.LEFT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[11], NetworkInput.RIGHT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[12], NetworkInput.UP_RIGHT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[13], NetworkInput.UP_LEFT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[14], NetworkInput.DOWN_RIGHT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[15], NetworkInput.DOWN_LEFT_BYTE);
|
|
|
|
|
ParseTrigger(inputs, ref inputTriggers.inputTriggers[16], NetworkInput.NEUTRAL_BYTE);
|
2023-07-02 23:17:37 +03:00
|
|
|
}
|
2023-07-01 23:48:47 +03:00
|
|
|
|
2023-07-02 23:17:37 +03:00
|
|
|
private static void ParseTrigger(long inputs, ref InputTrigger inputTrigger, int inputByte, int optionalInputByte = 0)
|
2023-07-01 23:48:47 +03:00
|
|
|
{
|
|
|
|
|
if ((inputs & inputByte) != 0 || (inputs & optionalInputByte) != 0)
|
2023-01-15 02:29:53 +02:00
|
|
|
{
|
2023-07-01 23:48:47 +03:00
|
|
|
if (!inputTrigger.held)
|
|
|
|
|
inputTrigger.pressed = true;
|
|
|
|
|
inputTrigger.held = true;
|
2023-01-15 02:29:53 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-01 23:48:47 +03:00
|
|
|
inputTrigger.held = false;
|
|
|
|
|
inputTrigger.pressed = false;
|
2023-01-15 02:29:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-15 01:54:52 +02:00
|
|
|
}
|