Skip to main content

CommandLibrary

aac-voice-api


Defined in: commandLibrary.ts:60

CommandLibrary contains a HashMap that: Maps synonyms to command names for flexible voice recognition Can be called by CommandMapper. Maps a String command to the corresponding GameCommand.

Constructors​

Constructor​

new CommandLibrary(): CommandLibrary;

Defined in: commandLibrary.ts:66

Returns​

CommandLibrary

Methods​

add()​

add(command): boolean;

Defined in: commandLibrary.ts:86

Add a command (returns false if name already exists)

Parameters​

ParameterType

command

GameCommand

Returns​

boolean


addSynonym()​

addSynonym(synonym, commandName): boolean;

Defined in: commandLibrary.ts:105

Adds a synonym mapping for a command. Maps a synonym word to a command name.

Example: addSynonym("leap", "jump") means "leap" will trigger "jump" command

Parameters​

ParameterTypeDescription

synonym

string

The synonym word (e.g., "leap")

commandName

string

The actual command name (e.g., "jump")

Returns​

boolean

True if added successfully, false if synonym already exists or command doesn't exist


addSynonyms()​

addSynonyms(synonyms, commandName): number;

Defined in: commandLibrary.ts:145

Adds multiple synonyms for a command at once.

Parameters​

ParameterTypeDescription

synonyms

string[]

Array of synonym words

commandName

string

The command name they should map to

Returns​

number

Number of synonyms successfully added


clear()​

clear(): void;

Defined in: commandLibrary.ts:245

Clear all commands

Returns​

void


findCommandBySynonym()​

findCommandBySynonym(word): GameCommand | undefined;

Defined in: commandLibrary.ts:206

Finds a command by checking if the word is a synonym. Returns the command that the synonym points to.

Example: findCommandBySynonym("leap") returns the "jump" command

Parameters​

ParameterTypeDescription

word

string

The word to look up (could be a synonym)

Returns​

GameCommand | undefined

The command if the word is a registered synonym


get()​

get(name): GameCommand | undefined;

Defined in: commandLibrary.ts:193

Get a command by name

Parameters​

ParameterType

name

string

Returns​

GameCommand | undefined


getSynonymCount()​

getSynonymCount(): number;

Defined in: commandLibrary.ts:255

Gets the total number of synonyms stored.

Returns​

number

Number of synonym mappings


getSynonymsForCommand()​

getSynonymsForCommand(commandName): string[];

Defined in: commandLibrary.ts:226

Gets all synonyms for a specific command.

Parameters​

ParameterTypeDescription

commandName

string

The command name

Returns​

string[]

Array of synonyms that map to this command


has()​

has(name): boolean;

Defined in: commandLibrary.ts:188

Check if a command exists

Parameters​

ParameterType

name

string

Returns​

boolean


list()​

list(): GameCommand[];

Defined in: commandLibrary.ts:240

List all commands

Returns​

GameCommand[]


remove()​

remove(name): boolean;

Defined in: commandLibrary.ts:162

Removes a command by name. Also removes all synonyms that point to this command.

Parameters​

ParameterTypeDescription

name

string

The command name to remove

Returns​

boolean

True if removed, false if not found


getInstance()​

static getInstance(): CommandLibrary;

Defined in: commandLibrary.ts:74

Returns​

CommandLibrary

The singleton instance of CommandLibrary.