refactor: remove host options

This commit is contained in:
hypercross 2026-04-04 14:05:23 +08:00
parent d7d484e4d3
commit f930d2943e
2 changed files with 4 additions and 15 deletions

View File

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

View File

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