Files
nissefolk/src/NetworkAdapter.ts

20 lines
579 B
TypeScript
Raw Normal View History

2026-03-20 08:11:31 +00:00
import type { GameAction } from './types'
import { stateManager } from './StateManager'
/** All state mutations go through an adapter.
* Swap LocalAdapter for WebSocketAdapter to enable multiplayer. */
export interface NetworkAdapter {
send(action: GameAction): void
onAction?: (action: GameAction) => void
}
/** Singleplayer: apply actions immediately and synchronously */
export class LocalAdapter implements NetworkAdapter {
onAction?: (action: GameAction) => void
send(action: GameAction): void {
stateManager.apply(action)
this.onAction?.(action)
}
}