workadventure/front/src/Network/ProtobufClientUtils.ts
David Négrier 4d4f845b9e Setting "importsNotUsedAsValues": "error"
Turning the "importsNotUsedAsValues" TS config value to "error".
This will require us to use `import type` instead of `import` when we are importing a value that is only used as a type (and therefore that is dropped by the Typescript compiler).

Why this change?
This is a requirement to be able to use Svelte in the future. See https://github.com/sveltejs/svelte-preprocess/issues/206#issuecomment-663193798
2021-05-12 09:13:25 +02:00

35 lines
1 KiB
TypeScript

import {PositionMessage} from "../Messages/generated/messages_pb";
import Direction = PositionMessage.Direction;
import type {PointInterface} from "../Connexion/ConnexionModels";
export class ProtobufClientUtils {
public static toPointInterface(position: PositionMessage): PointInterface {
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(),
};
}
}