🎉 initial commit
This commit is contained in:
19
src/NetworkAdapter.ts
Normal file
19
src/NetworkAdapter.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user