chore: clean up

This commit is contained in:
2026-04-04 13:48:48 +08:00
parent 2984d8b20d
commit 5fd2c3d208
8 changed files with 0 additions and 968 deletions
@@ -1,53 +0,0 @@
import Phaser from 'phaser';
import { effect } from '@preact/signals-core';
import type { MutableSignal, IGameContext, CommandResult } from 'boardgame-core';
type DisposeFn = () => void;
export interface ReactiveSceneOptions<TState extends Record<string, unknown>> {
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[] = [];
constructor(key: string) {
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);
return e;
}
protected async runCommand<T = unknown>(input: string): Promise<CommandResult<T>> {
return this.commands.run<T>(input);
}
create(): void {
this.events.on('shutdown', this.cleanupEffects, this);
this.onStateReady(this.state.value);
this.setupBindings();
}
private cleanupEffects(): void {
for (const e of this.effects) {
e();
}
this.effects = [];
}
protected abstract onStateReady(state: TState): void;
protected abstract setupBindings(): void;
}