foundryvtt-reve-de-dragon/module/rdd-token-hud.js
Vincent Vandemeulebrouck 3ac2be74fd #97 particulière pour armes lentes
Pas de particulières en rapidité pour les armes lentes.

Le corps à corps est considéré comme rapide.

Standardise le corps à corps:  centraliser la construction d'un objet
pour le corps à corps

Convertion de compétences de créature en arme

Petit fix sur HUD: le click est sur le div uniquement (au lieu
du label avant, ou d'un mix avec un fix précédent...)
2021-01-04 00:31:10 +01:00

60 lines
2.2 KiB
JavaScript

/* -------------------------------------------- */
import { HtmlUtility } from "./html-utility.js";
import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
export class RdDTokenHud {
/* -------------------------------------------- */
static async addTokenHudExtensions(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;
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 _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);
}
}