refactor: remove host options
This commit is contained in:
parent
d7d484e4d3
commit
f930d2943e
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue