/* -------------------------------------------- */ /* -------------------------------------------- */ export class HeritiersTokenHud { static init() { // Integration du TokenHUD Hooks.on('renderTokenHUD', (app, html, data) => { HeritiersTokenHud.addTokenHudExtensions(app, html, data._id) }); } /* -------------------------------------------- */ static async removeExtensionHud(app, html, tokenId) { html.find('.control-icon.heritiers-adversite').remove() } /* -------------------------------------------- */ static async addExtensionHud(app, html, tokenId) { let token = canvas.tokens.get(tokenId) let actor = token.actor app.hasExtension = true const hudData = { actor: actor } const controlIconActions = html.find('.control-icon[data-action=combat]'); // initiative await HeritiersTokenHud._configureSubMenu(controlIconActions, 'systems/fvtt-les-heritiers/templates/hud-adversites.html', hudData, (event) => { let adversite = event.currentTarget.attributes['data-action-index'].value let value = Number(event.currentTarget.attributes['data-action-value'].value) hudData.actor.incDecAdversite( adversite, value) } ) } /* -------------------------------------------- */ static async addTokenHudExtensions(app, html, tokenId) { const controlIconCombat = html.find('.control-icon[data-action=combat]') if (controlIconCombat.length>0 ) { HeritiersTokenHud.addExtensionHud(app, html, tokenId); } } /* -------------------------------------------- */ static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { const hud = $(await renderTemplate(template, hudData)) const list = hud.find('div.heritiers-hud-list') HeritiersTokenHud._toggleHudListActive(hud, list); hud.find('img.heritiers-hud-togglebutton').click(event => HeritiersTokenHud._toggleHudListActive(hud, list)); list.find('.heritiers-hud-adversite').click(onMenuItem); insertionPoint.after(hud); } /* -------------------------------------------- */ static _showControlWhen(control, condition) { if (condition) { control.show() } else { control.hide() } } /* -------------------------------------------- */ static _toggleHudListActive(hud, list) { hud.toggleClass('active') HeritiersTokenHud._showControlWhen(list, hud.hasClass('active')) } }