Fix HUD lists on 0.8.2

This commit is contained in:
Vincent Vandemeulebrouck 2021-05-04 21:22:25 +02:00
parent d1802e7496
commit 74fc9a7af3

View File

@ -14,10 +14,8 @@ export class RdDTokenHud {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async removeExtensionHud(app, html, tokenId) { static async removeExtensionHud(app, html, tokenId) {
let combat = html.find('.control-icon.rdd-combat'); html.find('.control-icon.rdd-combat').remove();
combat.remove(); html.find('.control-icon.rdd-initiative').remove();
let initiative = html.find('.control-icon.rdd-initiative');
initiative.remove();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -29,11 +27,14 @@ export class RdDTokenHud {
app.hasExtension = true; app.hasExtension = true;
let armesList = RdDCombatManager.buildListeActionsCombat(combatant); let armesList = RdDCombatManager.buildListeActionsCombat(combatant);
const hudData = { combatant: combatant, armes: armesList, const hudData = {
commandes: [{ name: 'Initiative +1', command: 'inc', value: 0.01}, { name: 'Initiative -1',command: 'dec', value: -0.01}] }; combatant: combatant, armes: armesList,
commandes: [{ name: 'Initiative +1', command: 'inc', value: 0.01 }, { name: 'Initiative -1', command: 'dec', value: -0.01 }]
};
const controlIconCombat = html.find('.control-icon[data-action=combat]');
// initiative // initiative
await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData, await RdDTokenHud._configureSubMenu(controlIconCombat, 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData,
(event) => { (event) => {
let initCommand = event.currentTarget.attributes['data-command'].value; let initCommand = event.currentTarget.attributes['data-command'].value;
let combatantId = event.currentTarget.attributes['data-combatant-id'].value; let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
@ -48,8 +49,9 @@ export class RdDTokenHud {
} }
}); });
const controlIconTarget = html.find('.control-icon[data-action=target]');
// combat // combat
await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData, await RdDTokenHud._configureSubMenu(controlIconTarget, 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData,
(event) => { (event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value; let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let arme = armesList[armeIndex]; let arme = armesList[armeIndex];
@ -59,8 +61,8 @@ export class RdDTokenHud {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async addTokenHudExtensions(app, html, tokenId) { static async addTokenHudExtensions(app, html, tokenId) {
const controlIconCombat = html.find('.control-icon[data-action=combat]');
html.find('.control-icon.combat').click(event => { controlIconCombat.click(event => {
if (event.currentTarget.className.includes('active')) { if (event.currentTarget.className.includes('active')) {
RdDTokenHud.removeExtensionHud(app, html, tokenId); RdDTokenHud.removeExtensionHud(app, html, tokenId);
} else { } else {
@ -68,8 +70,7 @@ export class RdDTokenHud {
} }
}); });
let combatIcon = html.find('.control-icon.combat'); if (controlIconCombat.length>0 && controlIconCombat[0].className.includes('active')) {
if ( combatIcon[0].className.includes('active') ) {
RdDTokenHud.addExtensionHud(app, html, tokenId); RdDTokenHud.addExtensionHud(app, html, tokenId);
} }
} }
@ -77,20 +78,18 @@ export class RdDTokenHud {
/* -------------------------------------------- */ /* -------------------------------------------- */
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));
const imgHud = hud.find('img.rdd-hud-togglebutton');
const list = hud.find('div.rdd-hud-list'); const list = hud.find('div.rdd-hud-list');
hud.toggleClass('active'); RdDTokenHud._toggleHudListActive(hud, list);
HtmlUtility._showControlWhen(list, hud.hasClass('active'));
imgHud.click(event => {
hud.toggleClass('active');
HtmlUtility._showControlWhen(list, hud.hasClass('active'));
});
hud.find('img.rdd-hud-togglebutton').click(event => RdDTokenHud._toggleHudListActive(hud, list));
list.find('.rdd-hud-menu').click(onMenuItem); list.find('.rdd-hud-menu').click(onMenuItem);
insertionPoint.after(hud); insertionPoint.after(hud);
} }
static _toggleHudListActive(hud, list) {
hud.toggleClass('active');
HtmlUtility._showControlWhen(list, hud.hasClass('active'));
}
} }