Migrating user position messages to protobuf
This commit is contained in:
parent
e9ca8721a6
commit
df0636c513
10 changed files with 202 additions and 46 deletions
34
front/src/Network/ProtobufClientUtils.ts
Normal file
34
front/src/Network/ProtobufClientUtils.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import {PositionMessage} from "../../../messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Connection";
|
||||
|
||||
export namespace ProtobufClientUtils {
|
||||
import Direction = PositionMessage.Direction;
|
||||
|
||||
export function 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(),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue