board game state management
Go to file
hyper fb3c98b1ef refactor: update GameHost to use generic state and result types
Decouple GameHost from GameState and GameResult types by introducing
generic parameters for TState and TResult. This improves type safety
and flexibility when defining GameModules.
2026-04-23 16:03:49 +08:00
.qwen/skills/create-game-module refactor: shorter skill 2026-04-10 15:56:57 +08:00
src refactor: update GameHost to use generic state and result types 2026-04-23 16:03:49 +08:00
tests Fix command prompt to properly return promise results 2026-04-23 14:44:24 +08:00
.gitignore Initial commit: boardgame-core with build fixes 2026-03-31 18:01:57 +08:00
.qwenignore refactor: add samples to export & use inline-schema's esbuild plugin 2026-04-07 11:37:05 +08:00
AGENTS.md docs: fleshed out agents.md 2026-04-19 18:36:10 +08:00
README.md refactor: renaming api 2026-04-06 09:48:20 +08:00
package-lock.json chore: add @types/node and update tsconfig 2026-04-20 11:34:40 +08:00
package.json chore: add @types/node and update tsconfig 2026-04-20 11:34:40 +08:00
tsconfig.json chore: add @types/node and update tsconfig 2026-04-20 11:34:40 +08:00
tsup.config.ts chore: add @types/node and update tsconfig 2026-04-20 11:34:40 +08:00
tsup.samples.config.ts build: update tsconfig and tsup sample configuration 2026-04-20 00:00:41 +08:00
vitest.config.ts feat: add yarn-spinner-loader 2026-04-14 20:53:21 +08:00

README.md

boardgame-core

基于 Preact Signals 的桌游状态管理库。

使用响应式状态、实体集合、空间区域和命令驱动的游戏循环来构建回合制桌游。

特性

  • 响应式状态管理:基于 @preact/signals-core 的细粒度响应
  • 类型安全:完整的 TypeScript 支持,启用严格模式和泛型上下文扩展
  • 区域系统:支持多轴定位、对齐和洗牌的空间管理
  • 命令系统CLI 风格的命令解析,带 schema 校验、类型转换和玩家输入提示
  • 游戏生命周期管理GameHost 类提供清晰的游戏设置/重置/销毁生命周期
  • 确定性 RNGMulberry32 种子伪随机数生成器,用于可复现的游戏状态

快速开始

npm install boardgame-core
import { createGameHost } from 'boardgame-core';
import * as tictactoe from 'boardgame-core/samples/tic-tac-toe';

const host = createGameHost(tictactoe);
await host.start('start');

// 监听状态变化
effect(() => {
    const state = host.state.value;
    console.log(`${state.currentPlayer}'s turn`);
});

// 处理玩家输入
const error = host.onInput('play X 1 2');

文档导航

文档 说明
使用 GameHost GameHost 生命周期、响应式状态、事件处理
编写 GameModule 定义状态、注册命令、prompt 系统、Part/Region 使用
棋子、区域与 RNG Part 创建、池管理、区域操作、RNG 使用
动画与状态同步 produceAsync 和中断机制
API 参考 所有导出 API 的完整列表
开发指南 安装、构建脚本、测试命令

License

MIT