vertecs
Version:
A typescript entity-component-system framework
80 lines (60 loc) • 1.93 kB
text/typescript
import { WebSocket } from "ws";
import { EcsManager, Entity } from "../../core";
import GameState from "../GameState";
import type { CustomData } from "../GameState";
export default class ClientHandler {
protected ecsManager: EcsManager;
protected $webSocket: WebSocket;
readonly
readonly $clientEntity: Entity;
public constructor(
clientEntity: Entity,
ecsManager: EcsManager,
webSocket: WebSocket
) {
this.$clientEntity = clientEntity;
this.ecsManager = ecsManager;
this.$webSocket = webSocket;
this.
this.$webSocket.on("message", (data: any) => {
this.
data.toString(),
GameState.reviver
);
});
this.
this.
}
public onConnect(): void {}
public onDisconnect(): void {}
public sendMessage(message: GameState): void {
this.webSocket.send(JSON.stringify(message));
}
public sendCustomData(data: any): void {
this.customData.push(data);
}
public onPrivateCustomData(data: any): void {}
public get webSocket(): WebSocket {
return this.$webSocket;
}
public get forceUpdate(): boolean {
return this.
}
public set forceUpdate(forceUpdate: boolean) {
this.
}
public get clientSnapshot(): GameState | undefined {
return this.
}
public set clientSnapshot(snapshot: GameState | undefined) {
this.
}
public get clientEntity(): Entity {
return this.$clientEntity;
}
public get customData(): CustomData[] {
return this.
}
}