refactor: make game host return the setup promise
This commit is contained in:
+11
-7
@@ -1,5 +1,11 @@
|
||||
import { ReadonlySignal, Signal } from '@preact/signals-core';
|
||||
import type {CommandSchema, CommandRegistry, PromptEvent, CommandRunnerContextExport} from '@/utils/command';
|
||||
import type {
|
||||
CommandSchema,
|
||||
CommandRegistry,
|
||||
PromptEvent,
|
||||
CommandRunnerContextExport,
|
||||
CommandResult
|
||||
} from '@/utils/command';
|
||||
import type { MutableSignal } from '@/utils/mutable-signal';
|
||||
import {createGameContext, IGameContext} from './game';
|
||||
|
||||
@@ -93,7 +99,7 @@ export class GameHost<TState extends Record<string, unknown>> {
|
||||
this._state.clearInterruptions();
|
||||
}
|
||||
|
||||
async setup(setupCommand: string): Promise<void> {
|
||||
setup(setupCommand: string): Promise<CommandResult<unknown>> {
|
||||
if (this._isDisposed) {
|
||||
throw new Error('GameHost is disposed');
|
||||
}
|
||||
@@ -103,14 +109,12 @@ export class GameHost<TState extends Record<string, unknown>> {
|
||||
const initialState = this._createInitialState();
|
||||
this._state.value = initialState as any;
|
||||
|
||||
// Start the setup command but don't wait for it to complete
|
||||
// The command will run in the background and prompt for input
|
||||
this._commands.run(setupCommand).catch(() => {
|
||||
// Command may be cancelled or fail, which is expected
|
||||
});
|
||||
const promise = this._commands.run(setupCommand);
|
||||
|
||||
this._status.value = 'running';
|
||||
this._emitEvent('setup');
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
Reference in New Issue
Block a user