docs: fix doc api

This commit is contained in:
hypercross 2026-04-03 16:19:33 +08:00
parent df2b839e07
commit 4d4889f825
1 changed files with 29 additions and 5 deletions

View File

@ -624,19 +624,36 @@ roll(dice, rng); // 使用 RNG 掷骰子
```ts
import { createGameContextFromModule } from 'boardgame-core';
import { ReactiveScene } from 'boardgame-phaser';
import { ReactiveScene, bindRegion, bindSignal } from 'boardgame-phaser';
import * as ticTacToe from './tic-tac-toe';
class TicTacToeScene extends ReactiveScene<typeof ticTacToe.createInitialState> {
type GameState = ReturnType<typeof ticTacToe.createInitialState>;
class TicTacToeScene extends ReactiveScene<GameState> {
protected onStateReady() {
// 初始化 Phaser 对象
}
protected setupBindings() {
// 绑定信号到 Phaser 对象
bindSignal(this, () => this.gameContext.state.value.winner, (winner) => {
// 绑定简单信号值
bindSignal(this.gameContext.state, state => state.winner, winner => {
if (winner) this.showWinMessage(winner);
});
// 绑定区域(响应 parts 数组变化)
bindRegion(
this.gameContext.state,
state => state.parts,
this.gameContext.state.value.board,
{
cellSize: { x: 100, y: 100 },
offset: { x: 50, y: 50 },
factory: (part, pos) => {
return this.add.text(pos.x, pos.y, part.player);
},
},
this.boardContainer,
);
}
}
@ -644,3 +661,10 @@ class TicTacToeScene extends ReactiveScene<typeof ticTacToe.createInitialState>
const gameContext = createGameContextFromModule(ticTacToe);
const scene = new TicTacToeScene(gameContext);
```
**bindRegion 参数说明:**
- `state` — MutableSignal 游戏状态
- `state => state.parts` — 获取 parts 数组的 gettereffect 会追踪此依赖)
- `region` — Region 对象
- `options` — 配置项cellSize, offset, factory
- `container` — Phaser 容器