@casual-simulation/aux-runtime
Version:
Runtime for AUX projects
207 lines • 7.92 kB
TypeScript
import type { InterpreterContinuation, InterpreterStop } from '@casual-simulation/js-interpreter';
import type { DynamicListener } from '@casual-simulation/aux-common/bots';
import type { BotTags, Bot, BotTagMasks, RuntimeBot } from '@casual-simulation/aux-common/bots';
import type { CompiledBot } from './CompiledBot';
import type { RuntimeStateVersion } from './RuntimeStateVersion';
import type { RuntimeActions } from './RuntimeEvents';
/**
* Adds any known symbols that the given target contains to the end of the given list of keys and returns a new list containing the combination of both.
* @param target The target.
* @param keys The keys that the symbols should be added to.
*/
export declare function addKnownSymbolsToList(target: any, keys: string[]): (string | symbol)[];
/**
* Defines an interface that contains runtime bots state.
* That is, a map of bot IDs to the runtime bot instances.
*/
export interface RuntimeBotsState {
[id: string]: RuntimeBot;
}
/**
* Flattens the given tag masks into a normal tags object.
* Spaces are prioritized accoring to the TAG_MASK_SPACE_PRIORITIES_REVERSE list.
* @param masks The masks to flatten.
*/
export declare function flattenTagMasks(masks: BotTagMasks): BotTags;
/**
* Constructs a new script bot for the given bot.
* Script bots provide special behaviors by implemlementing getters and setters for tag values as well
* as handling extra compatibility concerns like serialization.
*
* @param bot The bot.
* @param manager The service that is able to track updates on a bot.
* @param context The global context.
*/
export declare function createRuntimeBot(bot: CompiledBot, manager: RuntimeBotInterface): RuntimeBot;
/**
* Defines an interface for an object that provides the API that script bots use for housekeeping.
*/
export interface RuntimeBotInterface extends RuntimeBatcher {
/**
* Updates the tag of the given bot.
* Returns the realtime edit mode that should be used for this particular assignment.
* @param bot The bot.
* @param tag The tag that should be updated.
* @param newValue The new tag value.
*/
updateTag(bot: CompiledBot, tag: string, newValue: any): RealtimeEditConfig;
/**
* Updates the tag mask of the given bot.
* @param bot The bot.
* @param tag The tag that should be updated.
* @param space The spaces that the tag mask should be applied in.
* @param value The new tag value. If null, then the mask will be deleted.
*/
updateTagMask(bot: CompiledBot, tag: string, spaces: string[], value: any): RealtimeEditConfig;
/**
* Gets the value for the given tag on the given bot.
* @param bot The bot.
* @param tag The tag.
*/
getValue(bot: CompiledBot, tag: string): any;
/**
* Gets the raw value for the given tag on the given bot.
* @param bot The bot.
* @param tag The tag.
*/
getRawValue(bot: CompiledBot, tag: string): any;
/**
* Gets the raw tag mask value for the given tag.
* @param bot The bot.
* @param tag The tag.
* @param space The space.
*/
getTagMask(bot: CompiledBot, tag: string): any;
/**
* Gets the tag link for the given tag.
* @param bot The bot.
* @param tag The tag.
*/
getTagLink(bot: CompiledBot, tag: string): RuntimeBot | RuntimeBot[];
/**
* Gets the listener for the given bot and tag, resolving any formulas that may be present.
* Returns null if no listener is available.
* @param bot The bot.
* @param tag The tag.
*/
getListener(bot: CompiledBot, tag: string): DynamicListener | null;
/**
* Sets the listener for the given bot and tag.
* If the listener is null, then the listener will be removed.
* @param bot The bot.
* @param tag The tag.
* @param listener The listener.
*/
setListener(bot: CompiledBot, tag: string, listener: DynamicListener | null): void;
/**
* Gets whether the given signature on the bot is valid.
* @param bot The bot.
* @param signature The tag.
*/
getSignature(bot: CompiledBot, signature: string): string;
/**
* Adds the given listener to the bot for the given tag.
* @param bot The bot that the listener should be added to.
* @param tag The tag that the listener should be added for.
* @param listener The listener that should be added.
*/
addDynamicListener(bot: CompiledBot, tag: string, listener: DynamicListener): void;
/**
* Removes the given listener from the bot for the given tag.
* @param bot The bot that the listener should be removed from.
* @param tag The tag that the listener should be removed for.
* @param listener The listener that should be removed.
*/
removeDynamicListener(bot: CompiledBot, tag: string, listener: DynamicListener): void;
/**
* Gets the dynamic listeners for the given bot and tag.
* @param bot The bot that the listeners should be retrieved for.
* @param tag The tag that the listeners should be retrieved for.
* @returns The list of dynamic listeners for the tag, or null if none are registered.
*/
getDynamicListeners(bot: CompiledBot, tag: string): DynamicListener[] | null;
/**
* Gets the current version that the interface is at.
*/
currentVersion: RuntimeStateVersion;
}
/**
* Defines an interface for an object that is able to manage the creation and destruction of script bots in the runtime.
*/
export interface RuntimeBotFactory {
/**
* Creates a new script bot from the given bot and adds it to the runtime.
*
* Returns null if a runtime bot could not be created for the given bot.
* This can happen when a bot is being created in a space that doesn't support immediate realtime edits.
*
* @param bot The bot.
*/
createRuntimeBot(bot: Bot): RuntimeBot;
/**
* Destroyes the given script bot and removes it from the runtime.
* Returns the realtime edit mode that should apply for this operation.
*
* @param bot The bot.
*/
destroyScriptBot(bot: RuntimeBot): RealtimeEditMode;
}
/**
* Defines an interface for an object that is able to batch script results.
*/
export interface RuntimeBatcher {
/**
* Notifies the batcher that a change has happened and that it should schedule
* a handler to grab the changes and apply them.
*/
notifyChange(): void;
/**
* Notifies the batcher of an action that was added.
*/
notifyActionEnqueued(action: RuntimeActions): void;
}
/**
* Defines an interface for an object that is able to process interpreter generators.
*/
export interface RuntimeInterpreterGeneratorProcessor {
/**
* Processes the given generator.
* @param generator The generator that should be processed.
*/
processGenerator<T>(generator: Generator<InterpreterStop, T, InterpreterContinuation>): void;
}
/**
* The list of possible realtime edit modes.
*/
export declare enum RealtimeEditMode {
/**
* Specifies that bots in this edit mode cannot be edited.
*/
None = 0,
/**
* Specifies that all changes to the bot will be accepted.
* This allows the changes to be immediately used.
*/
Immediate = 1,
/**
* Specifies that some changes to the bot may be rejected.
* This requires that changes be delayed until the related
* partition accepts/denies them.
*/
Delayed = 2
}
/**
* The options that should be used when editing a tag.
*/
export interface RealtimeEditConfig {
/**
* The edit mode that should be used.
*/
mode: RealtimeEditMode;
/**
* The value that should be used for the bot changes.
* If not included, then the value that was originally provided should be used.
*/
changedValue: any;
}
//# sourceMappingURL=RuntimeBot.d.ts.map