fix: update according to boardgame-core

This commit is contained in:
2026-04-03 19:13:12 +08:00
parent cbee709a27
commit 5d4c169fea
7 changed files with 83 additions and 51 deletions
@@ -5,11 +5,11 @@ import type { MutableSignal, IGameContext, CommandResult } from 'boardgame-core'
type DisposeFn = () => void;
export interface ReactiveSceneOptions<TState extends Record<string, unknown>> {
state: MutableSignal<TState>;
commands: IGameContext<TState>['commands'];
gameContext: IGameContext<TState>;
}
export abstract class ReactiveScene<TState extends Record<string, unknown>> extends Phaser.Scene {
protected gameContext!: IGameContext<TState>;
protected state!: MutableSignal<TState>;
protected commands!: IGameContext<TState>['commands'];
private effects: DisposeFn[] = [];
@@ -18,6 +18,12 @@ export abstract class ReactiveScene<TState extends Record<string, unknown>> exte
super(key);
}
init(data: ReactiveSceneOptions<TState>): void {
this.gameContext = data.gameContext;
this.state = data.gameContext.state;
this.commands = data.gameContext.commands;
}
protected watch(fn: () => void): DisposeFn {
const e = effect(fn);
this.effects.push(e);