diff --git a/docs/src/content/docs/reference/dispatcher.mdx b/docs/src/content/docs/reference/dispatcher.mdx index 0a7048f2..0e0e8c72 100644 --- a/docs/src/content/docs/reference/dispatcher.mdx +++ b/docs/src/content/docs/reference/dispatcher.mdx @@ -2,48 +2,23 @@ title: Dispatcher --- -## BaseDispatcher - -`BaseDispatcher` is an abstract class. -`ServerDispatcher` and `ClientDispatcher` inherit from it. - -### `init(options)` - -Initializes the dispatcher. - -**Parameters**: -- `options` - The options object provided when starting Centurion. - ## ServerDispatcher -### `init(options)` - -Initializes the server dispatcher. Listens to remote events to handle -server command execution. - -**Parameters**: -- `options` - The options object provided when starting Centurion. - ### `run(path, executor, text)` Executes a command. **Parameters**: -- `path` - The path of the command. -- `executor` - The executor of the command. -- `text` - The input text +- `path` - The command's path +- `args` - The arguments to pass to the command +- `executor` - The command's executor, or `undefined` if the executor is the server **Returns**: -A promise that resolves when the command is executed. - -## ClientDispatcher +A `Promise` that resolves when the command has been executed. -### `init(options)` +The value contained in the Promise is a `CommandContext` instance containing the execution result. -Initializes the client dispatcher. - -**Parameters**: -- `options` - The options object provided when starting Centurion. +## ClientDispatcher ### `run(path, text)` @@ -51,12 +26,17 @@ Executes a command. If the path points to a server command, the command will be executed on the server. +If `runAsPlayer` is set to `false`, the command will be executed with no executor. This only +applies to commands registered on the client - commands registered on the server will always +execute with the local player as the executor. + **Parameters**: -- `path` - The path of the command. -- `text` - The input text +- `path` - The command's path +- `args` - The arguments to pass to the command +- `runAsPlayer` - Whether to run the command as the local player. **Returns**: -A promise that resolves when the command is executed. +A `Promise` that resolves when the command has been executed. -The value contained in the Promise is a HistoryEntry object containing +The value contained in the Promise is a `HistoryEntry` object containing the command's response and the time it was executed. diff --git a/docs/src/content/docs/reference/registry.mdx b/docs/src/content/docs/reference/registry.mdx index 2af33a35..fcdaac77 100644 --- a/docs/src/content/docs/reference/registry.mdx +++ b/docs/src/content/docs/reference/registry.mdx @@ -6,16 +6,6 @@ title: Registry `BaseRegistry` is an abstract class. `ServerRegistry` and `ClientRegistry` inherit from it. -### `init(options)` - -Initializes the registry and registers built-in types if the `registerBuiltInTypes` -option is true. - -This method is called when starting Centurion. - -**Parameters** -- `options` - The options object provided when starting Centurion. - ### `load(container, descendants)` Loads all `ModuleScript` instances in the given instance. @@ -46,7 +36,7 @@ Registers one or more argument types. ### `registerGroup(groups)` -Takes one or more [GroupOptions](#groupoptions) objects and registers them. +Registers one or more groups. **Parameters**: - `groups` - The groups to register. @@ -59,7 +49,7 @@ Returns a registered argument type with the given name. - `name` - The name of the type. **Returns**: -An `ArgumentType`, or `undefined` if it does not exist. +An `ArgumentType`, or `undefined` if no type with the given name is registered. ### `getTypes()` @@ -79,6 +69,17 @@ Returns a registered command with the given path. **Returns**: A `BaseCommand`, or `undefined` if no command with the given path is registered. +### `getCommand(path)` + +Returns a registered command with the given path as a string. + +**Parameters**: +- `path` - The command's path as a string. + +**Returns**: +A `BaseCommand`, or `undefined` if no command with the given path is registered. + + ### `getCommands()` Returns all registered commands. @@ -96,6 +97,16 @@ Returns a registered group with the given path. **Returns**: A `CommandGroup`, or `undefined` if no group with the given path is registered. +### `getGroup(path)` + +Returns a registered group with the given path as a string. + +**Parameters**: +- `path` - The group's path as a string. + +**Returns**: +A `CommandGroup`, or `undefined` if no group with the given path is registered. + ### `getGroups()` Returns all registered groups. @@ -116,7 +127,7 @@ Returns all paths that are children of the given path. **Parameters**: -- `path` - The path to get children for. +- `path` - The path to get the children of. **Returns**: An array of `RegistryPath` instances. diff --git a/packages/core/src/client/dispatcher.ts b/packages/core/src/client/dispatcher.ts index 5f451301..097613e4 100644 --- a/packages/core/src/client/dispatcher.ts +++ b/packages/core/src/client/dispatcher.ts @@ -24,14 +24,18 @@ export class ClientDispatcher extends BaseDispatcher { /** * Executes a command. * + * If the path points to a server command, the command will be executed on the server. + * * If `runAsPlayer` is set to `false`, the command will be executed with no executor. This only * applies to commands registered on the client - commands registered on the server will always * execute with the local player as the executor. * - * @param path The path of the command - * @param args The command's arguments + * @param path The command's path. + * @param args The arguments to pass to the command. * @param runAsPlayer Whether to run the command as the local player. * @returns A {@link HistoryEntry} containing the command's response + * @returns A {@link Promise} that resolves when the command has been executed. The value contained in the + * Promise is a `HistoryEntry` object containing the command's response and the time it was executed. */ async run(path: RegistryPath, args: string[] = [], runAsPlayer = true) { const inputText = getInputText(path, args); diff --git a/packages/core/src/server/dispatcher.ts b/packages/core/src/server/dispatcher.ts index 5678b929..83d26929 100644 --- a/packages/core/src/server/dispatcher.ts +++ b/packages/core/src/server/dispatcher.ts @@ -65,10 +65,11 @@ export class ServerDispatcher extends BaseDispatcher { /** * Executes a command. * - * @param path The path of the command - * @param args The command's arguments - * @param executor The command executor, or `undefined` if the executor is the server - * @returns A {@link CommandContext} determining the result of execution + * @param path The command's path. + * @param args The arguments to pass to the command. + * @param executor The command's executor, or `undefined` if the executor is the server. + * @returns A {@link Promise} that resolves when the command has been executed. The value contained in the + * Promise is a {@link CommandContext} instance containing the execution result. */ async run(path: RegistryPath, args: string[] = [], executor?: Player) { const inputText = getInputText(path, args); diff --git a/packages/core/src/shared/core/registry.ts b/packages/core/src/shared/core/registry.ts index ca0cad7b..719c384e 100644 --- a/packages/core/src/shared/core/registry.ts +++ b/packages/core/src/shared/core/registry.ts @@ -55,7 +55,7 @@ export abstract class BaseRegistry { } /** - * Loads all `ModuleScript` instances in the given instance. + * Loads all {@link ModuleScript} instances in the given instance. * * By default, only direct children of the container are loaded. If the `descendants` * parameter is true, all descendants of the container will be loaded. @@ -105,7 +105,7 @@ export abstract class BaseRegistry { } /** - * Registers one or more types from a list of {@link ArgumentType} objects. + * Registers one or more argument types. * * @param types The types to register */ @@ -116,7 +116,7 @@ export abstract class BaseRegistry { } /** - * Registers a list of groups. + * Registers one or more groups. * * @param groups The groups to register */ @@ -162,39 +162,39 @@ export abstract class BaseRegistry { } /** - * Gets a registered type. + * Returns a registered argument type with the given name. * - * @param name The name of the type - * @returns The registered {@link ArgumentType}, or `undefined` if it is not registered + * @param name The name of the type. + * @returns An {@link ArgumentType}, or `undefined` if no type with the given name is registered. */ getType(name: string) { return this.types.get(name); } /** - * Gets a registered command. + * Returns a registered command with the given path. * - * @param path The path of the command - * @returns A {@link BaseCommand} or `undefined` if no command with the given path is registered + * @param path The command's path. + * @returns A {@link BaseCommand}, or `undefined` if no command with the given path is registered. */ getCommand(path: RegistryPath) { return this.commands.get(path.toString()); } /** - * Gets a registered command. + * Returns a registered command with the given path as a string. * - * @param path The path of the command as a string - * @returns A {@link BaseCommand} or `undefined` if no command with the given path is registered + * @param path The command's path as a string. + * @returns A {@link BaseCommand}, or `undefined` if no command with the given path is registered. */ - getCommandByString(pathString: string) { - return this.commands.get(pathString); + getCommandByString(path: string) { + return this.commands.get(path); } /** - * Gets all registered commands. + * Returns all registered commands. * - * @returns An array of all registered commands + * @returns An array of {@link BaseCommand} instances. */ getCommands() { const commands: BaseCommand[] = []; @@ -205,29 +205,29 @@ export abstract class BaseRegistry { } /** - * Gets a registered {@link CommandGroup} from a given {@link RegistryPath}. + * Returns a registered group with the given path. * - * @param path The path of the group - * @returns A {@link CommandGroup} or `undefined` if no group is registered at the given path + * @param path The group's path. + * @returns A {@link CommandGroup}, or `undefined` if no group with the given path is registered. */ getGroup(path: RegistryPath) { return this.groups.get(path.toString()); } /** - * Gets a registered {@link GroupOptions} from a given path string. + * Returns a registered group with the given path as a string. * - * @param pathString The path of the group as a string - * @returns A {@link CommandGroup} or `undefined` if no group is registered at the given path + * @param path The group's path as a string. + * @returns A {@link CommandGroup}, or `undefined` if no group with the given path is registered. */ - getGroupByString(pathString: string) { - return this.groups.get(pathString); + getGroupByString(path: string) { + return this.groups.get(path); } /** - * Gets all registered groups. + * Returns all registered groups. * - * @returns An array of all registered groups + * @returns An array of {@link CommandGroup} instances. */ getGroups() { const groups: CommandGroup[] = []; @@ -238,9 +238,9 @@ export abstract class BaseRegistry { } /** - * Gets all registered types. + * Returns all registered types. * - * @returns An array of all registered types + * @returns An array of {@link ArgumentType} objects. */ getTypes() { const types: ArgumentType[] = []; @@ -251,19 +251,19 @@ export abstract class BaseRegistry { } /** - * Gets the root paths of all registered commands and groups. + * Returns all registered root paths - paths made up of a single part. * - * @returns An array of all root paths + * @returns An array of {@linkeRegistryPath} instances. */ getRootPaths() { return this.cachedPaths.get(BaseRegistry.ROOT_KEY) ?? []; } /** - * Gets all paths that are children of the given {@link RegistryPath}. + * Returns all paths that are children of the given path. * - * @param path The path to get the children of - * @returns The paths that are children of the given path + * @param path The path to get the children of. + * @returns An array of {@link RegistryPath} instances. */ getChildPaths(path: RegistryPath) { return this.cachedPaths.get(path.toString()) ?? [];