refactor: remove host options
This commit is contained in:
+2
-13
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+1
-1
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user