feat: add server and frontend initial - wood chopping

This commit is contained in:
2026-09-05 16:37:45 +05:00
parent c79681dc59
commit f6c338e1b0
28 changed files with 1857 additions and 195 deletions
+7 -3
View File
@@ -1,6 +1,5 @@
import { PROTOCOL_VERSION, type ClientMessage, type ServerMessage } from '@idle/shared';
import { PROTOCOL_VERSION, type ClientMessage, type DeltaMsg, type ServerMessage, type SnapshotMsg, type WelcomeMsg } from '@idle/shared';
export type Snapshot = Extract<ServerMessage, { t: 'snapshot' }>;
export type NetStatus = 'connecting' | 'online' | 'reconnecting';
export function wsUrl(): string {
@@ -13,7 +12,9 @@ export function wsUrl(): string {
export interface ConnectHandlers {
onStatus: (status: NetStatus) => void;
onSnapshot: (snap: Snapshot) => void;
onWelcome: (msg: WelcomeMsg) => void;
onSnapshot: (msg: SnapshotMsg) => void;
onDelta: (msg: DeltaMsg) => void;
}
/** Подключение к миру с автопереподключением; возвращает функцию закрытия. */
@@ -41,8 +42,11 @@ export function connectWorld(handlers: ConnectHandlers): () => void {
}
if (msg.t === 'welcome') {
handlers.onStatus('online');
handlers.onWelcome(msg);
} else if (msg.t === 'snapshot') {
handlers.onSnapshot(msg);
} else if (msg.t === 'delta') {
handlers.onDelta(msg);
}
};
ws.onclose = () => {