Skip to content

Commit

Permalink
docs: remove init methods from reference, parity with code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Jul 8, 2024
1 parent 6557c30 commit c141f15
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 87 deletions.
50 changes: 15 additions & 35 deletions docs/src/content/docs/reference/dispatcher.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,41 @@
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)`

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.
37 changes: 24 additions & 13 deletions docs/src/content/docs/reference/registry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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()`

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/client/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/server/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
66 changes: 33 additions & 33 deletions packages/core/src/shared/core/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*/
Expand All @@ -116,7 +116,7 @@ export abstract class BaseRegistry {
}

/**
* Registers a list of groups.
* Registers one or more groups.
*
* @param groups The groups to register
*/
Expand Down Expand Up @@ -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[] = [];
Expand All @@ -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[] = [];
Expand All @@ -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<unknown>[] = [];
Expand All @@ -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()) ?? [];
Expand Down

0 comments on commit c141f15

Please sign in to comment.