2020-12-05 00:04:40 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
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 ) {
|
|
|
|
let armesList = RdDUtility.buildArmeList( combatant );
|
2020-12-05 21:24:31 +01:00
|
|
|
// Create space for Hud Extensions next to combat icon
|
|
|
|
let htmlInit = '<div class="tokenhudext right">';
|
|
|
|
let htmlCombat = '<div class="tokenhudext rightright">';
|
2020-12-05 00:37:10 +01:00
|
|
|
console.log("Token !!!", combatant, armesList);
|
|
|
|
for( let armeIndex=0; armeIndex<armesList.length; armeIndex++) {
|
|
|
|
let arme = armesList[armeIndex];
|
2020-12-05 21:24:31 +01:00
|
|
|
htmlInit += '<div class="control-icon tokenhudicon right" title="'+ arme.name +'">';
|
|
|
|
htmlInit += '<label class="hud-text-small" data-combatant-id="'+combatant._id+'" data-arme-id="'+armeIndex+'"></i>I:'+arme.name+'</label></div>';
|
|
|
|
if ( !arme.data.initOnly) {
|
|
|
|
htmlCombat += '<div class="control-icon tokenhudicon right" title="'+ arme.name +'">';
|
|
|
|
htmlCombat += '<label class="hud-text-small" data-combatant-id="'+combatant._id+'" data-arme-id="'+armeIndex+'"></i>C:'+arme.name+'</label></div>';
|
|
|
|
}
|
2020-12-05 00:04:40 +01:00
|
|
|
}
|
2020-12-05 21:24:31 +01:00
|
|
|
htmlInit += "</div>";
|
|
|
|
htmlCombat += "</div>";
|
|
|
|
let hudInitiative = $(htmlInit);
|
2020-12-05 00:04:40 +01:00
|
|
|
html.find('.control-icon.combat').after(hudInitiative); // Add Initiative and Agility token tip
|
2020-12-05 21:24:31 +01:00
|
|
|
let hudCombat = $(htmlCombat);
|
|
|
|
html.find('.control-icon.combat').after(hudCombat); // Add Initiative and Agility token tip
|
|
|
|
|
|
|
|
// Add interactions for Initiative
|
2020-12-05 00:04:40 +01:00
|
|
|
hudInitiative.find('label').click(async (event) => {
|
2020-12-05 00:37:10 +01:00
|
|
|
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 );
|
2020-12-05 00:04:40 +01:00
|
|
|
});
|
2020-12-05 21:24:31 +01:00
|
|
|
// Add interactions for Combat
|
|
|
|
hudCombat.find('label').click(async (event) => {
|
|
|
|
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
|
|
|
|
let arme = armesList[armeIndex];
|
|
|
|
actor.rollArme( arme.name, arme.data.competence);
|
|
|
|
});
|
2020-12-05 00:04:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|