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 24, 2020
2 parents 2a69fb8 + 8fad5ad commit 7880310
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 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.21] 2020-11-24
### Changed
- Add multi rolling for initiative and update text on button

## [0.9.20] 2020-11-23
### Bugfix
- Again, categories should remain open if option is enabled
Expand Down
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"tokenactionhud.stats": "Stats",
"tokenactionhud.stat": "Stat",
"tokenactionhud.rank": "Rank",
"tokenactionhud.encounter": "Encounter",
"tokenactionhud.rollInitiative": "Roll initiative",
"tokenactionhud.initiative": "Initiative",

"tokenactionhud.mwa": "Melee Weapon Attacks",
Expand Down
46 changes: 35 additions & 11 deletions scripts/actions/dnd5e/dnd5e-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,25 +528,22 @@ export class ActionHandler5e extends ActionHandler {
/** @private */
_addIntiativeSubcategory(macroType, category, tokenId) {
const combat = game.combat;
if (!combat)
return;

const combatant = combat.combatants.find(c => c.tokenId === tokenId);
if (!combatant)
return;
let combatant, currentInitiative;
if (combat) {
combatant = combat.combatants.find(c => c.tokenId === tokenId);
currentInitiative = combatant?.initiative;
}

let initiative = this.initializeEmptySubcategory();

let initiativeValue = [macroType, tokenId, 'initiative'].join(this.delimiter);
let currentInitiative = combatant.initiative;
let initiativeName = `${this.i18n('tokenactionhud.encounter')}`;
let initiativeName = `${this.i18n('tokenactionhud.rollInitiative')}`;

let initiativeAction = {id:'toggleVisibility', encodedValue: initiativeValue, name: initiativeName};

let hasInitiative = currentInitiative !== null;
if (hasInitiative)
if (currentInitiative)
initiativeAction.info1 = currentInitiative;
initiativeAction.cssClass = hasInitiative ? 'active' : '';
initiativeAction.cssClass = currentInitiative ? 'active' : '';

initiative.actions.push(initiativeAction);

Expand All @@ -557,6 +554,8 @@ export class ActionHandler5e extends ActionHandler {
_addMultiUtilities(list, tokenId, actors) {
let category = this.initializeEmptyCategory('utility');
let macroType = 'utility';

this._addMultiIntiativeSubcategory(macroType, tokenId, category);

let rests = this.initializeEmptySubcategory();
let utility = this.initializeEmptySubcategory();
Expand All @@ -578,6 +577,31 @@ export class ActionHandler5e extends ActionHandler {
this._combineCategoryWithList(list, this.i18n('tokenactionhud.utility'), category)
}

/** @private */
_addMultiIntiativeSubcategory(macroType, tokenId, category) {
const combat = game.combat;

let initiative = this.initializeEmptySubcategory();

let initiativeValue = [macroType, tokenId, 'initiative'].join(this.delimiter);
let initiativeName = `${this.i18n('tokenactionhud.rollInitiative')}`;

let initiativeAction = {id:'toggleVisibility', encodedValue: initiativeValue, name: initiativeName};

let isActive;
if (combat) {
let tokenIds = canvas.tokens.controlled.map(t => t.id);
let tokenCombatants = tokenIds.map(id => combat.combatants.find(c => c.tokenId === id));
isActive = tokenCombatants.every(c => !!c?.initiative)
}

initiativeAction.cssClass = isActive ? 'active' : '';

initiative.actions.push(initiativeAction);

this._combineSubcategoryWithCategory(category, this.i18n('tokenactionhud.initiative'), initiative);
}


/** @private */
_buildItem(tokenId, actor, macroType, item) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Hooks.on('canvasReady', async () => {
game.tokenActionHUD.update();
});

Hooks.on('updateCombatant', (combat, combatant) => {
game.tokenActionHUD.update();
});

Hooks.on('forceUpdateTokenActionHUD', () => {
game.tokenActionHUD.update();
})
Expand Down
12 changes: 3 additions & 9 deletions scripts/rollHandlers/dnd5e/dnd5e-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,10 @@ export class RollHandlerBase5e extends RollHandler {
}

async performInitiativeMacro(tokenId) {
const combat = game.combat;
if (!combat)
return;

const combatant = combat.combatants.find(c => c.tokenId === tokenId);
if (!combatant || (combatant.initiative && !game.user.isGM))
return;

await combat.rollInitiative([combatant._id]);
let actor = super.getActor(tokenId);

await actor.rollInitiative({createCombatants: true});

Hooks.callAll('forceUpdateTokenActionHUD')
}
}

0 comments on commit 7880310

Please sign in to comment.