boardgame-core/README.md

53 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# boardgame-core
基于 [Preact Signals](https://preactjs.com/guide/v10/signals/) 的桌游状态管理库。
使用响应式状态、实体集合、空间区域和命令驱动的游戏循环来构建回合制桌游。
## 特性
- **响应式状态管理**:基于 [@preact/signals-core](https://preactjs.com/guide/v10/signals/) 的细粒度响应
- **类型安全**:完整的 TypeScript 支持,启用严格模式和泛型上下文扩展
- **区域系统**:支持多轴定位、对齐和洗牌的空间管理
- **命令系统**CLI 风格的命令解析,带 schema 校验、类型转换和玩家输入提示
- **游戏生命周期管理**`GameHost` 类提供清晰的游戏设置/重置/销毁生命周期
- **确定性 RNG**Mulberry32 种子伪随机数生成器,用于可复现的游戏状态
## 快速开始
```bash
npm install boardgame-core
```
```ts
import { createGameHost } from 'boardgame-core';
import * as tictactoe from 'boardgame-core/samples/tic-tac-toe';
const host = createGameHost(tictactoe);
await host.setup('setup');
// 监听状态变化
effect(() => {
const state = host.state.value;
console.log(`${state.currentPlayer}'s turn`);
});
// 处理玩家输入
const error = host.onInput('play X 1 2');
```
## 文档导航
| 文档 | 说明 |
|---|---|
| [使用 GameHost](docs/game-host.md) | GameHost 生命周期、响应式状态、事件处理 |
| [编写 GameModule](docs/game-module.md) | 定义状态、注册命令、prompt 系统、Part/Region 使用 |
| [棋子、区域与 RNG](docs/parts-regions-rng.md) | Part 创建、池管理、区域操作、RNG 使用 |
| [动画与状态同步](docs/animation-sync.md) | produceAsync 和中断机制 |
| [API 参考](docs/api-reference.md) | 所有导出 API 的完整列表 |
| [开发指南](docs/development.md) | 安装、构建脚本、测试命令 |
## License
MIT