Skip to content

Commit

Permalink
#28
Browse files Browse the repository at this point in the history
- Handle unlinked tokens.
  • Loading branch information
Larkinabout committed Apr 6, 2023
1 parent 160803f commit 1843ecb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
*/
_getActors () {
const allowedTypes = ['character', 'npc']
const actors = canvas.tokens.controlled.map((token) => token.actor)
const actors = canvas.tokens.controlled.filter(token => token.actor).map((token) => token.actor)
if (actors.every((actor) => allowedTypes.includes(actor.type))) { return actors }
}

Expand All @@ -1136,7 +1136,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
_getTokens () {
const allowedTypes = ['character', 'npc']
const tokens = canvas.tokens.controlled
const actors = tokens.map((token) => token.actor)
const actors = tokens.filter(token => token.actor).map((token) => token.actor)
if (actors.every((actor) => allowedTypes.includes(actor.type))) { return tokens }
}

Expand Down
5 changes: 5 additions & 0 deletions scripts/roll-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @param {string} actionId The action id
*/
_rollAbility (event, actor, actionId) {
if (!actor) return
actor.rollAbility(actionId, { event })
}

Expand All @@ -95,6 +96,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @param {string} actionId The action id
*/
_rollAbilitySave (event, actor, actionId) {
if (!actor) return
actor.rollAbilitySave(actionId, { event })
}

Expand All @@ -106,6 +108,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @param {string} actionId The action id
*/
_rollAbilityTest (event, actor, actionId) {
if (!actor) return
actor.rollAbilityTest(actionId, { event })
}

Expand Down Expand Up @@ -137,6 +140,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @param {string} actionId The action id
*/
_rollSkill (event, actor, actionId) {
if (!actor) return
actor.rollSkill(actionId, { event })
}

Expand Down Expand Up @@ -217,6 +221,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @private
*/
async _rollInitiative (actor) {
if (!actor) return
await actor.rollInitiative({ createCombatants: true })

Hooks.callAll('forceUpdateTokenActionHud')
Expand Down
Loading

0 comments on commit 1843ecb

Please sign in to comment.