boardgame-phaser/packages/sample-game/src/scenes/GameHostScene.ts

26 lines
785 B
TypeScript
Raw Normal View History

import {DisposableBag, IDisposable} from "@/utils/disposable";
import type {GameHost} from "../../../../../boardgame-core/src";
import {effect} from "@preact/signals";
export abstract class GameHostScene<T extends Record<string,unknown>> extends Phaser.Scene implements IDisposable{
protected disposables = new DisposableBag();
protected gameHost!: GameHost<T>;
init(data: { gameHost: GameHost<T> }): void {
this.gameHost = data.gameHost;
}
create(){
this.events.on('shutdown', this.dispose, this);
}
dispose() {
this.disposables.dispose();
}
public get state(): T {
return this.gameHost.state.value;
}
protected watch(fn: () => void | (()=>void)){
this.disposables.add(effect(fn));
}
}