51 lines
2.3 KiB
JavaScript
51 lines
2.3 KiB
JavaScript
|
/* -------------------------------------------- */
|
||
|
import { RdDUtility } from "./rdd-utility.js";
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
export class RdDTokenHud {
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
static addTokenHudExtensions( app, html, data ) {
|
||
|
let token = canvas.tokens.get(data._id);
|
||
|
|
||
|
// Affichage seulement si le token est un combat
|
||
|
if ( token.inCombat) {
|
||
|
this.addInitiativeTokenTip(html, token);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* -------------------------------------------- */
|
||
|
static async addInitiativeTokenTip(html, token ) {
|
||
|
// Helper actor and sanity check
|
||
|
let actor = token.actor;
|
||
|
if (actor === undefined) return;
|
||
|
|
||
|
// Get combatant stuff
|
||
|
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id );
|
||
|
if ( combatant ) {
|
||
|
console.log("Token !!!", combatant);
|
||
|
// Create space for Hud Extensions next to combat icon
|
||
|
let divTokenHudExt = '<div class="tokenhudext right">';
|
||
|
html.find('.control-icon.combat').wrap(divTokenHudExt);
|
||
|
|
||
|
let armesList = RdDUtility.buildArmeList( combatant );
|
||
|
let htmlList = "";
|
||
|
for (let arme of armesList) {
|
||
|
htmlList += '<div class="control-icon tokenhudicon right" title="'+ arme.name +'">';
|
||
|
htmlList += '<label class="hud-text-small" data-combatant-id="'+combatant._id+'" data-arme-id="'+arme._id+'"></i>'+arme.name+'</label>';
|
||
|
}
|
||
|
let hudInitiative = $(htmlList);
|
||
|
//let hudInitiative = $('<div class="control-icon tokenhudicon right" title="' + TooltipInitiative + '"><i class="fas fa-spinner"></i> ' + Dague + '</div>');
|
||
|
//let hudInitiative = $('<div class="control-icon tokenhudicon right" title="Dague"><i class="fas fa-spinner"></i>Dague</div>');
|
||
|
html.find('.control-icon.combat').after(hudInitiative); // Add Initiative and Agility token tip
|
||
|
// Add interactions for Initiative and Agility
|
||
|
hudInitiative.find('label').click(async (event) => {
|
||
|
let armeId = event.currentTarget.attributes['data-arme-id'].value;
|
||
|
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
|
||
|
let arme = actor.getOwnedItem(armeId);
|
||
|
console.log("CLICKED !", actor, armeId, arme);
|
||
|
RdDUtility.rollInitiativeCompetence( combatantId, arme.data );
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|