Skip to content

Commit

Permalink
Added the Token to the hook parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lupestro committed Jan 19, 2025
1 parent 06f8068 commit 6dad095
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ Returns true if the specified light source is consumable, and the instance held
## Hooks for macro authors
Because sometimes you want to respond to somebody clicking on the torch in the HUD, we also provide the following hooks:

### "torch.changed" source, state
### `"torch.changed" token, source, state`
The light source state changed, either via toggling or by turning off directly.
* **token**: The token for which the light source state has changed
* **source**: The name of the light source
* **state**: The new state - "on", "dim", "off"

### "torch.selected" source
### `"torch.selected" token, source`
A new light source was selected.
* **token**: The token for which the light source has been selected
* **source**: The name of the light source now selected

## Changelog - now in [separate file](./CHANGELOG.md)
Expand Down
20 changes: 17 additions & 3 deletions src/torch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,34 @@ class Torch {
static async toggleLightSource(token) {
let newState = await token.advanceState();
debugLog(`${token.currentLightSource} is now ${newState}`);
Hooks.callAll("torch.changed", token.currentLightSource, newState);
Hooks.callAll(
"torch.changed",
token._token._object,
token.currentLightSource,
newState,
);
}

static async forceSourceOff(token) {
await token.forceSourceOff();
debugLog(`Forced ${token.currentLightSource} off`);
Hooks.callAll("torch.changed", token.currentLightSource, "off");
Hooks.callAll(
"torch.changed",
token._token._object,
token.currentLightSource,
"off",
);
}

static async toggleLightHeld(/*token*/) {}

static async changeLightSource(token, name) {
await token.setCurrentLightSource(name);
Hooks.callAll("torch.selected", token.currentLightSource);
Hooks.callAll(
"torch.selected",
token._token._object,
token.currentLightSource,
);
}

static setupQuenchTesting() {
Expand Down

0 comments on commit 6dad095

Please sign in to comment.