#85 : Sous menus de tokens dynamiques

This commit is contained in:
sladecraven 2021-01-05 15:28:05 +01:00
parent 8b6ed4e172
commit b9db99544c

View File

@ -5,17 +5,21 @@ import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDTokenHud { 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 token = canvas.tokens.get(tokenId);
let actor = token.actor; let actor = token.actor;
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id); let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id);
app.hasExtension = true;
// Affichage seulement si le token est un combat et a un actor
if (actor === undefined) return;
if (!token.inCombat) return;
if (!combatant) return;
let armesList = RdDUtility.buildListeActionsCombat(combatant) ; let armesList = RdDUtility.buildListeActionsCombat(combatant) ;
const hudData = { combatant: combatant, armes: armesList }; 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) { static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) {
const hud = $(await renderTemplate(template, hudData)); const hud = $(await renderTemplate(template, hudData));