diff --git a/changelog.md b/changelog.md index 269c18a3..926e66a3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## [0.9.14] 2020-11-21 +### Changed +- DND5e - Restrict showing initative to current active encounter + ## [0.9.13] 2020-11-21 ### Added - DND5e - Initiative rolls under Utilities diff --git a/scripts/actions/dnd5e/dnd5e-actions.js b/scripts/actions/dnd5e/dnd5e-actions.js index 1a2da9a2..1e8fad6a 100644 --- a/scripts/actions/dnd5e/dnd5e-actions.js +++ b/scripts/actions/dnd5e/dnd5e-actions.js @@ -499,7 +499,7 @@ export class ActionHandler5e extends ActionHandler { let rests = this.initializeEmptySubcategory() let utility = this.initializeEmptySubcategory(); - this._addIntiativeSubcategory(result, tokenId); + this._addIntiativeSubcategory(macroType, result, tokenId); if (actor.data.type === 'character') { let shortRestValue = [macroType, tokenId, 'shortRest'].join(this.delimiter); @@ -526,34 +526,26 @@ export class ActionHandler5e extends ActionHandler { } /** @private */ - _addIntiativeSubcategory(category, tokenId) { - let initiative = this.initializeEmptySubcategory(); - - const sceneCombats = game.combats.filter(c => c.data.scene === canvas.scene.id); - let i = 0; - sceneCombats.forEach(c => { - i++; - c.tahName = `${this.i18n('tokenactionhud.encounter')} ${i}`; - }); - - const tokenCombats = sceneCombats.filter(c => c.combatants.some(c => c.tokenId === tokenId)); - - tokenCombats.forEach(c => { + _addIntiativeSubcategory(macroType, category, tokenId) { + const combat = game.combat; + const combatant = combat.combatants.find(c => c.tokenId === tokenId); + if (!combatant) + return; - const combatToken = c.combatants.find(c => c.tokenId === tokenId); - let initiativeValue = ['initiative', tokenId, c.id].join(this.delimiter); - let currentInitiative = combatToken.initiative; - let initiativeName = c.tahName; - - let initiativeAction = {id:'toggleVisibility', encodedValue: initiativeValue, name: initiativeName}; - - let hasInitiative = currentInitiative !== null; - if (hasInitiative) - initiativeAction.info1 = currentInitiative; - initiativeAction.cssClass = hasInitiative ? 'active' : ''; + let initiative = this.initializeEmptySubcategory(); + + let initiativeValue = [macroType, tokenId, 'initiative'].join(this.delimiter); + let currentInitiative = combatant.initiative; + let initiativeName = `${this.i18n('tokenactionhud.encounter')}`; + + let initiativeAction = {id:'toggleVisibility', encodedValue: initiativeValue, name: initiativeName}; + + let hasInitiative = currentInitiative !== null; + if (hasInitiative) + initiativeAction.info1 = currentInitiative; + initiativeAction.cssClass = hasInitiative ? 'active' : ''; - initiative.actions.push(initiativeAction); - }); + initiative.actions.push(initiativeAction); this._combineSubcategoryWithCategory(category, this.i18n('tokenactionhud.initiative'), initiative); } diff --git a/scripts/rollHandlers/dnd5e/dnd5e-base.js b/scripts/rollHandlers/dnd5e/dnd5e-base.js index c122d463..69088502 100644 --- a/scripts/rollHandlers/dnd5e/dnd5e-base.js +++ b/scripts/rollHandlers/dnd5e/dnd5e-base.js @@ -51,10 +51,8 @@ export class RollHandlerBase5e extends RollHandler { this.rollItemMacro(event, tokenId, actionId); break; case 'utility': - this.performUtilityMacro(event, tokenId, actionId); + await this.performUtilityMacro(event, tokenId, actionId); break; - case 'initiative': - await this.performInitiativeMacro(event, tokenId, actionId); default: break; } @@ -99,7 +97,7 @@ export class RollHandlerBase5e extends RollHandler { return (item.data.data.recharge && !item.data.data.recharge.charged && item.data.data.recharge.value); } - performUtilityMacro(event, tokenId, actionId) { + async performUtilityMacro(event, tokenId, actionId) { let actor = super.getActor(tokenId); let token = super.getToken(tokenId); @@ -124,11 +122,14 @@ export class RollHandlerBase5e extends RollHandler { case 'deathSave': actor.rollDeathSave(); break; + case 'initiative': + await this.performInitiativeMacro(tokenId); + break; } } - async performInitiativeMacro(event, tokenId, actionId) { - const combat = game.combats.find(c => c.id === actionId); + async performInitiativeMacro(tokenId) { + const combat = game.combat; if (!combat) return;