Skip to content

Commit

Permalink
Use TAH Core's getControlledTokens()
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkinabout committed Sep 20, 2023
1 parent c353d00 commit 358ae27
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
const info1 = {}
let cssClass = ''
if (combatType[0] === 'initiative' && game.combat) {
const tokenIds = canvas.tokens.controlled.map((token) => token.id)
const tokens = coreModule.api.Utils.getControlledTokens()
const tokenIds = tokens?.map((token) => token.id)
const combatants = game.combat.combatants.filter((combatant) => tokenIds.includes(combatant.tokenId))

// Get initiative for single token
Expand Down Expand Up @@ -1201,7 +1202,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
*/
#getActors () {
const allowedTypes = ['character', 'npc']
const actors = canvas.tokens.controlled.filter(token => token.actor).map((token) => token.actor)
const tokens = coreModule.api.Utils.getControlledTokens()
const actors = tokens?.filter(token => token.actor).map((token) => token.actor)
if (actors.every((actor) => allowedTypes.includes(actor.type))) {
return actors
} else {
Expand All @@ -1216,8 +1218,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
*/
#getTokens () {
const allowedTypes = ['character', 'npc']
const tokens = canvas.tokens.controlled
const actors = tokens.filter(token => token.actor).map((token) => token.actor)
const tokens = coreModule.api.Utils.getControlledTokens()
const actors = tokens?.filter(token => token.actor).map((token) => token.actor)
if (actors.every((actor) => allowedTypes.includes(actor.type))) {
return tokens
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/roll-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
const actionId = payload[1]

if (!this.actor) {
for (const token of canvas.tokens.controlled) {
for (const token of coreModule.api.Utils.getControlledTokens()) {
const actor = token.actor
await this.#handleAction(event, actionType, actor, token, actionId)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/token-action-hud-dnd5e.min.js

Large diffs are not rendered by default.

0 comments on commit 358ae27

Please sign in to comment.