refactor: remove host options

This commit is contained in:
hypercross 2026-04-04 14:05:23 +08:00
parent d7d484e4d3
commit 25f9992be6
4 changed files with 6 additions and 17 deletions

View File

@ -1,14 +1,10 @@
import { ReadonlySignal, signal, Signal } from '@preact/signals-core';
import type { CommandSchema, CommandRegistry, CommandResult, PromptEvent } from '@/utils/command';
import { ReadonlySignal, Signal } from '@preact/signals-core';
import type { CommandSchema, CommandRegistry, PromptEvent } from '@/utils/command';
import type { MutableSignal } from '@/utils/mutable-signal';
import { createGameContext } from './game';
export type GameHostStatus = 'created' | 'running' | 'disposed';
export interface GameHostOptions {
autoStart?: boolean;
}
export interface GameModule<TState extends Record<string, unknown>> {
registry: CommandRegistry<MutableSignal<TState>>;
createInitialState: () => TState;
@ -32,7 +28,6 @@ export class GameHost<TState extends Record<string, unknown>> {
constructor(
registry: CommandRegistry<MutableSignal<TState>>,
createInitialState: () => TState,
options?: GameHostOptions
) {
this._createInitialState = createInitialState;
this._eventListeners = new Map();
@ -55,10 +50,6 @@ export class GameHost<TState extends Record<string, unknown>> {
this.state = this._state;
this._setupPromptTracking();
if (options?.autoStart !== false) {
this._status.value = 'running';
}
}
private _setupPromptTracking() {
@ -145,11 +136,9 @@ export class GameHost<TState extends Record<string, unknown>> {
export function createGameHost<TState extends Record<string, unknown>>(
module: GameModule<TState>,
options?: GameHostOptions
): GameHost<TState> {
return new GameHost(
module.registry,
module.createInitialState,
options
);
}

View File

@ -70,7 +70,7 @@ export function createGameCommand<TState extends Record<string, unknown> = {} ,
}
export { GameHost, createGameHost } from './game-host';
export type { GameHostStatus, GameHostOptions, GameModule } from './game-host';
export type { GameHostStatus, GameModule } from './game-host';
export function createGameModule<TState extends Record<string, unknown>>(
module: GameModule<TState>

View File

@ -7,7 +7,7 @@
export type { IGameContext } from './core/game';
export { createGameContext, createGameCommandRegistry } from './core/game';
export type { GameHost, GameHostStatus, GameHostOptions, GameModule } from './core/game';
export type { GameHost, GameHostStatus, GameModule } from './core/game';
export { createGameHost, createGameModule } from './core/game';
export type { Part } from './core/part';

View File

@ -34,10 +34,10 @@ describe('GameHost', () => {
expect(Object.keys(host.state.value.parts).length).toBe(0);
});
it('should have status "running" by default', () => {
it('should have status "created" by default', () => {
const { host } = createTestHost();
expect(host.status.value).toBe('running');
expect(host.status.value).toBe('created');
});
it('should have null activePromptSchema initially', () => {