refactor: remove Boop command registry and simplify exports

Remove the command registry from the Boop sample and export command
functions directly. This simplifies the command structure and replaces
dynamic imports with static imports.
This commit is contained in:
hyper
2026-04-23 15:21:13 +08:00
parent 1bd49c32e0
commit d932c2f5e2
+9 -79
View File
@@ -1,75 +1,11 @@
import { BoopGame } from "@/samples/boop/types-extensions";
import { PlayerType } from "@/samples/boop/types";
import { turn } from "@/samples/boop/commands/turn";
import {createGameCommandRegistry} from "@/core/game";
export const registry = createGameCommandRegistry<BoopGame['value']>();
/**
* 放置棋子到棋盘
*/
const placeCmd = registry.register({
schema: 'place <row:number> <col:number> <player> <type>',
run: async (game, row, col, player, type) => {
const {place} = await import('./place');
return place(game, row, col, player, type);
}
});
/**
* 执行boop - 推动周围棋子
*/
const boopCmd = registry.register({
schema: 'boop <row:number> <col:number> <type>',
run: async (game, row, col, type) => {
const {boop} = await import('./boop');
return boop(game, row, col, type);
}
});
/**
* 检查是否有玩家获胜(三个猫连线)
*/
const checkWinCmd = registry.register({
schema: 'check-win',
run: async (game) => {
const {checkWin} = await import('./win');
return checkWin(game);
}
});
/**
* 检查并执行小猫升级(三个小猫连线变成猫)
*/
const checkGraduatesCmd = registry.register({
schema: 'check-graduates',
run: async (game) => {
const {checkGraduates} = await import('./graduate');
return checkGraduates(game);
}
});
/**
* 检查并执行 8-piece 规则
*/
const checkFullBoardCmd = registry.register({
schema: 'check-full-board <player:string>',
run: async (game, player) => {
const {checkFullBoard} = await import('./full-board');
return checkFullBoard(game, player);
}
});
/**
* 处理一个回合
*/
const turnCmd = registry.register({
schema: 'turn <player:string>',
run: async (game, player) => {
const {turn} = await import('./turn');
return turn(game, player);
}
});
import { boop } from "./boop";
import { checkFullBoard } from "./full-board";
import { checkGraduates } from "./graduate";
import { place } from "./place";
import { checkWin } from "./win";
/**
* 启动游戏主循环
@@ -79,10 +15,11 @@ export async function start(game: BoopGame) {
const currentPlayer = game.value.currentPlayer;
const turnOutput = await turn(game, currentPlayer);
await game.produceAsync(state => {
await game.produceAsync((state) => {
state.winner = turnOutput.winner;
if (!state.winner) {
state.currentPlayer = state.currentPlayer === 'white' ? 'black' : 'white';
state.currentPlayer =
state.currentPlayer === "white" ? "black" : "white";
}
});
if (game.value.winner) break;
@@ -91,11 +28,4 @@ export async function start(game: BoopGame) {
return game.value;
}
export {
placeCmd as place,
boopCmd as boop,
checkWinCmd as checkWin,
checkGraduatesCmd as checkGraduates,
checkFullBoardCmd as checkFullBoard,
turnCmd as turn
};
export { place, boop, checkWin, checkGraduates, checkFullBoard, turn };