foundryvtt-reve-de-dragon/module/rdd-token-hud.js
Vincent Vandemeulebrouck 3f62582af5 Améliorations du combat
- nettoyage des infos et messages de combat améliorés
- message de status envoyé uniquement par le GM (pour éviter les
doublons)
- stockage des infos de passes d'armes géré par RdDCombat

Déplacement des Hooks/notifications de messages socket:
- liés au combat dans la méthode RdDCombat.init

Convention de nommage: les méthodes de gestion de notification par
hook/socket sont préfixées 'on'
ex: onSocketMessage, onUpdateCombat, onPreDeleteCombat
2021-01-13 03:00:10 +01:00

86 lines
3.1 KiB
JavaScript

/* -------------------------------------------- */
import { HtmlUtility } from "./html-utility.js";
import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
export class RdDTokenHud {
static init(){
// Integration du TokenHUD
Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data._id) });
}
/* -------------------------------------------- */
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 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);
app.hasExtension = true;
let armesList = RdDUtility.buildListeActionsCombat(combatant) ;
const hudData = { combatant: combatant, armes: armesList };
// initiative
await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData,
(event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
let arme = armesList[armeIndex];
RdDUtility.rollInitiativeCompetence(combatantId, arme);
});
// combat
await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData,
(event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let arme = armesList[armeIndex];
actor.rollArme(arme.data.competence, arme.name);
});
}
/* -------------------------------------------- */
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));
const imgHud = hud.find('img.rdd-hud-togglebutton');
const list = hud.find('div.rdd-hud-list');
hud.toggleClass('active');
HtmlUtility._showControlWhen(list, hud.hasClass('active'));
imgHud.click(event => {
hud.toggleClass('active');
HtmlUtility._showControlWhen(list, hud.hasClass('active'));
});
list.find('.rdd-hud-menu').click(onMenuItem);
insertionPoint.after(hud);
}
}