feat: add superlatives socket methods to client

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 04:45:23 +00:00
parent 951b9cc701
commit b3a74e40e1
+14 -1
View File
@@ -1,5 +1,5 @@
import { io, Socket } from 'socket.io-client';
import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput } from '@dflike/shared';
import type { ServerEvents, ClientEvents, WorldState, StateUpdate, PlayerJoined, PlayerLeft, PlayerInput, SuperlativesData } from '@dflike/shared';
type TypedSocket = Socket<ServerEvents, ClientEvents>;
@@ -13,6 +13,7 @@ export class SocketClient {
onStateUpdate: ((data: StateUpdate) => void) | null = null;
onPlayerJoined: ((data: PlayerJoined) => void) | null = null;
onPlayerLeft: ((data: PlayerLeft) => void) | null = null;
onSuperlativesUpdate: ((data: SuperlativesData) => void) | null = null;
constructor(url: string) {
this.socket = io(url);
@@ -36,6 +37,10 @@ export class SocketClient {
this.socket.on('player-left', (data) => {
this.onPlayerLeft?.(data);
});
this.socket.on('superlatives-update', (data) => {
this.onSuperlativesUpdate?.(data);
});
}
get playerId(): string | null { return this._playerId; }
@@ -49,6 +54,14 @@ export class SocketClient {
this.socket.emit('spawn-npc', { x, y });
}
subscribeSuperlatives(): void {
this.socket.emit('superlatives-subscribe');
}
unsubscribeSuperlatives(): void {
this.socket.emit('superlatives-unsubscribe');
}
disconnect(): void {
this.socket.disconnect();
}