Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
espositos committed Nov 21, 2020
2 parents e09b074 + a5a6798 commit 519da57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 19 additions & 27 deletions scripts/actions/dnd5e/dnd5e-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions scripts/rollHandlers/dnd5e/dnd5e-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down

0 comments on commit 519da57

Please sign in to comment.