2020-09-24 11:16:08 +02:00
|
|
|
import {PositionMessage} from "../Messages/generated/messages_pb";
|
2020-09-18 18:16:26 +02:00
|
|
|
import Direction = PositionMessage.Direction;
|
2021-05-12 09:13:25 +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 {
|
2020-09-18 15:51:15 +02:00
|
|
|
|
2020-09-18 18:16:26 +02:00
|
|
|
public static toPointInterface(position: PositionMessage): PointInterface {
|
2020-09-18 15:51:15 +02:00
|
|
|
let direction: string;
|
|
|
|
switch (position.getDirection()) {
|
|
|
|
case Direction.UP:
|
|
|
|
direction = 'up';
|
|
|
|
break;
|
|
|
|
case Direction.DOWN:
|
|
|
|
direction = 'down';
|
|
|
|
break;
|
|
|
|
case Direction.LEFT:
|
|
|
|
direction = 'left';
|
|
|
|
break;
|
|
|
|
case Direction.RIGHT:
|
|
|
|
direction = 'right';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("Unexpected direction");
|
|
|
|
}
|
|
|
|
|
|
|
|
// sending to all clients in room except sender
|
|
|
|
return {
|
|
|
|
x: position.getX(),
|
|
|
|
y: position.getY(),
|
|
|
|
direction,
|
|
|
|
moving: position.getMoving(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|