diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js index 84cfe534..c056c61d 100644 --- a/module/rdd-token-hud.js +++ b/module/rdd-token-hud.js @@ -5,17 +5,21 @@ import { RdDUtility } from "./rdd-utility.js"; /* -------------------------------------------- */ export class RdDTokenHud { + /* -------------------------------------------- */ + static async removeExtensionHud( app, html, tokenId) { + let combat = html.find('.control-icon.rdd-combat'); + combat.remove(); + let initiative = html.find('.control-icon.rdd-initiative'); + initiative.remove(); + } /* -------------------------------------------- */ - static async addTokenHudExtensions(app, html, tokenId) { + static async addExtensionHud( app, html, tokenId ) { + let token = canvas.tokens.get(tokenId); let actor = token.actor; let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id); - - // Affichage seulement si le token est un combat et a un actor - if (actor === undefined) return; - if (!token.inCombat) return; - if (!combatant) return; + app.hasExtension = true; let armesList = RdDUtility.buildListeActionsCombat(combatant) ; const hudData = { combatant: combatant, armes: armesList }; @@ -38,6 +42,23 @@ export class RdDTokenHud { }); } + /* -------------------------------------------- */ + static async addTokenHudExtensions(app, html, tokenId) { + + html.find('.control-icon.combat').click(event => { + if ( event.currentTarget.className.includes('active')) { + RdDTokenHud.removeExtensionHud( app, html, tokenId); + } else { + setTimeout( function() { RdDTokenHud.addExtensionHud( app, html, tokenId) } , 200 ); + } + } ); + + let combatIcon = html.find('.control-icon.combat'); + if ( combatIcon[0].className.includes('active') ) { + RdDTokenHud.addExtensionHud( app, html, tokenId); + } + } + /* -------------------------------------------- */ static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { const hud = $(await renderTemplate(template, hudData));