2026-04-04 12:14:26 +08:00
|
|
|
|
import {useComputed } from '@preact/signals';
|
|
|
|
|
|
import { createGameHost, GameModule } from "boardgame-core";
|
|
|
|
|
|
import Phaser from "phaser";
|
|
|
|
|
|
import {h} from "preact";
|
|
|
|
|
|
import {PhaserGame, PhaserScene} from "@/ui/PhaserGame";
|
|
|
|
|
|
|
|
|
|
|
|
export default function App<T extends Record<string, unknown>>(props: { gameModule: GameModule<T>, gameScene: {new(): Phaser.Scene} }) {
|
|
|
|
|
|
|
|
|
|
|
|
const gameHost = useComputed(() => {
|
2026-04-04 12:52:14 +08:00
|
|
|
|
const gameHost = createGameHost(props.gameModule);
|
|
|
|
|
|
gameHost.setup('setup');
|
2026-04-04 12:14:26 +08:00
|
|
|
|
return {
|
2026-04-04 12:52:14 +08:00
|
|
|
|
gameHost
|
2026-04-04 12:14:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const scene = useComputed(() => new props.gameScene());
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="flex flex-col h-screen">
|
|
|
|
|
|
<div className="flex-1 relative">
|
|
|
|
|
|
<PhaserGame>
|
|
|
|
|
|
<PhaserScene sceneKey="GameScene" scene={scene.value} autoStart data={gameHost.value}/>
|
|
|
|
|
|
</PhaserGame>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|