2022-01-03 15:23:28 +01:00
|
|
|
import { PositionMessage, PositionMessage_Direction } from "../Messages/ts-proto-generated/messages";
|
|
|
|
|
2021-09-06 14:27:54 +02:00
|
|
|
import type { PointInterface } from "../Connexion/ConnexionModels";
|
2020-09-18 15:51:15 +02:00
|
|
|
|
2020-09-18 18:16:26 +02:00
|
|
|
export class ProtobufClientUtils {
|
|
|
|
public static toPointInterface(position: PositionMessage): PointInterface {
|
2020-09-18 15:51:15 +02:00
|
|
|
let direction: string;
|
2022-01-03 15:23:28 +01:00
|
|
|
switch (position.direction) {
|
|
|
|
case PositionMessage_Direction.UP:
|
2021-09-06 14:27:54 +02:00
|
|
|
direction = "up";
|
2020-09-18 15:51:15 +02:00
|
|
|
break;
|
2022-01-03 15:23:28 +01:00
|
|
|
case PositionMessage_Direction.DOWN:
|
2021-09-06 14:27:54 +02:00
|
|
|
direction = "down";
|
2020-09-18 15:51:15 +02:00
|
|
|
break;
|
2022-01-03 15:23:28 +01:00
|
|
|
case PositionMessage_Direction.LEFT:
|
2021-09-06 14:27:54 +02:00
|
|
|
direction = "left";
|
2020-09-18 15:51:15 +02:00
|
|
|
break;
|
2022-01-03 15:23:28 +01:00
|
|
|
case PositionMessage_Direction.RIGHT:
|
2021-09-06 14:27:54 +02:00
|
|
|
direction = "right";
|
2020-09-18 15:51:15 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("Unexpected direction");
|
|
|
|
}
|
|
|
|
|
|
|
|
// sending to all clients in room except sender
|
|
|
|
return {
|
2022-01-03 15:23:28 +01:00
|
|
|
x: position.x,
|
|
|
|
y: position.y,
|
2020-09-18 15:51:15 +02:00
|
|
|
direction,
|
2022-01-03 15:23:28 +01:00
|
|
|
moving: position.moving,
|
2020-09-18 15:51:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|