2020-12-05 00:04:40 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-20 02:07:27 +01:00
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
2020-12-05 00:04:40 +01:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDTokenHud {
|
2020-12-20 02:07:27 +01:00
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
static init(){
|
|
|
|
// Integration du TokenHUD
|
|
|
|
Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data._id) });
|
|
|
|
}
|
|
|
|
|
2021-01-05 15:28:05 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
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();
|
|
|
|
}
|
2020-12-05 00:04:40 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-05 15:28:05 +01:00
|
|
|
static async addExtensionHud( app, html, tokenId ) {
|
|
|
|
|
2020-12-20 21:54:09 +01:00
|
|
|
let token = canvas.tokens.get(tokenId);
|
2020-12-20 02:07:27 +01:00
|
|
|
let actor = token.actor;
|
|
|
|
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id);
|
2021-01-05 15:28:05 +01:00
|
|
|
app.hasExtension = true;
|
2020-12-20 02:07:27 +01:00
|
|
|
|
2021-01-04 00:17:22 +01:00
|
|
|
let armesList = RdDUtility.buildListeActionsCombat(combatant) ;
|
2020-12-21 23:41:17 +01:00
|
|
|
const hudData = { combatant: combatant, armes: armesList };
|
2020-12-20 02:07:27 +01:00
|
|
|
|
|
|
|
// initiative
|
2020-12-20 21:54:09 +01:00
|
|
|
await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData,
|
2020-12-20 02:07:27 +01:00
|
|
|
(event) => {
|
2020-12-05 00:37:10 +01:00
|
|
|
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
|
2020-12-20 02:07:27 +01:00
|
|
|
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
|
2020-12-21 23:10:18 +01:00
|
|
|
let arme = armesList[armeIndex];
|
2020-12-20 02:07:27 +01:00
|
|
|
RdDUtility.rollInitiativeCompetence(combatantId, arme);
|
2020-12-05 00:04:40 +01:00
|
|
|
});
|
2020-12-20 02:07:27 +01:00
|
|
|
|
|
|
|
// combat
|
2020-12-20 21:54:09 +01:00
|
|
|
await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData,
|
2020-12-20 02:07:27 +01:00
|
|
|
(event) => {
|
2020-12-05 21:24:31 +01:00
|
|
|
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
|
|
|
|
let arme = armesList[armeIndex];
|
2020-12-20 02:07:27 +01:00
|
|
|
actor.rollArme(arme.data.competence, arme.name);
|
2020-12-05 21:24:31 +01:00
|
|
|
});
|
2020-12-20 02:07:27 +01:00
|
|
|
}
|
|
|
|
|
2021-01-05 15:28:05 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:14:49 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-20 21:54:09 +01:00
|
|
|
static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) {
|
|
|
|
const hud = $(await renderTemplate(template, hudData));
|
2020-12-20 02:07:27 +01:00
|
|
|
const imgHud = hud.find('img.rdd-hud-togglebutton');
|
|
|
|
const list = hud.find('div.rdd-hud-list');
|
|
|
|
|
2020-12-21 23:41:17 +01:00
|
|
|
hud.toggleClass('active');
|
2020-12-20 02:07:27 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-12-05 00:04:40 +01:00
|
|
|
}
|