chore: update api / test
This commit is contained in:
@@ -68,7 +68,7 @@ export class GameHost<TState extends Record<string, unknown>, TResult=unknown> {
|
||||
this._activePromptPlayer.value = null;
|
||||
}
|
||||
|
||||
onInput(input: string): string | null {
|
||||
tryInput(input: string): string | null {
|
||||
if (this._isDisposed) {
|
||||
return 'GameHost is disposed';
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import type {
|
||||
import { parseCommand } from './command-parse';
|
||||
import { applyCommandSchema } from './command-validate';
|
||||
import { parseCommandSchema } from './schema-parse';
|
||||
import {AsyncQueue} from "@/utils/async-queue";
|
||||
|
||||
type CanRunParsed = {
|
||||
runParsed<T=unknown>(command: Command): Promise<CommandResult<T>>,
|
||||
@@ -89,7 +88,6 @@ type PromptEndListener = () => void;
|
||||
|
||||
export type CommandRunnerContextExport<TContext> = CommandRunnerContext<TContext> & {
|
||||
registry: CommandRegistry<TContext>;
|
||||
promptQueue: AsyncQueue<PromptEvent>;
|
||||
_activePrompt: PromptEvent | null;
|
||||
_tryCommit: (commandOrInput: Command | string) => string | null;
|
||||
_cancel: (reason?: string) => void;
|
||||
@@ -196,26 +194,12 @@ export function createCommandRunnerContext<TContext>(
|
||||
_tryCommit: tryCommit,
|
||||
_cancel: cancel,
|
||||
_pendingInput: null,
|
||||
promptQueue: null!
|
||||
};
|
||||
|
||||
Object.defineProperty(runnerCtx, '_activePrompt', {
|
||||
get: () => activePrompt,
|
||||
});
|
||||
|
||||
let promptQueue: AsyncQueue<PromptEvent>;
|
||||
Object.defineProperty(runnerCtx, 'promptQueue', {
|
||||
get(){
|
||||
if (!promptQueue) {
|
||||
promptQueue = new AsyncQueue();
|
||||
promptListeners.add(async (event) => {
|
||||
promptQueue.push(event);
|
||||
});
|
||||
}
|
||||
return promptQueue;
|
||||
}
|
||||
});
|
||||
|
||||
return runnerCtx;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import type { Command, CommandSchema } from './types';
|
||||
import { parseCommand } from './command-parse';
|
||||
import { applyCommandSchema } from './command-validate';
|
||||
|
||||
export type PromptEvent = {
|
||||
schema: CommandSchema;
|
||||
|
||||
Reference in New Issue
Block a user