From acc880b53f9581b5270355381f98b89618e9927d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 10 Mar 2023 22:33:05 +0100 Subject: [PATCH] Preparation soins HUD --- module/rdd-token-hud.js | 69 ++++++++++++++++++-------------- styles/simple.css | 10 ++--- templates/hud-actor-attaque.html | 4 +- templates/hud-actor-init.html | 6 +-- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js index 6d29ecab..8ef426ef 100644 --- a/module/rdd-token-hud.js +++ b/module/rdd-token-hud.js @@ -18,29 +18,36 @@ export class RdDTokenHud { } /* -------------------------------------------- */ - static async addExtensionHud(app, html, tokenId) { + static async addExtensionHud(app, html, tokenId, isCombat) { let token = canvas.tokens.get(tokenId); let actor = token.actor; - let combatant = game.combat.combatants.find(c => c.tokenId == tokenId); - if (! (combatant?.actor) ) { + app.hasExtension = true; + if (isCombat) { + let combatant = game.combat.combatants.find(c => c.tokenId == tokenId); + if (!(combatant?.actor)) { ui.notifications.warn(`Le combatant ${token.name} n'est pas associé à un acteur, impossible de déterminer ses actions de combat!`) return; + } + let actions = RdDCombatManager.listActionsCombat(combatant); + // initiative + await RdDTokenHud.addExtensionHudInit(html, combatant, actions); + // combat + await RdDTokenHud.addExtensionHudCombat(html, combatant, actions); } - app.hasExtension = true; - let actionsCombat = RdDCombatManager.listActionsCombat(combatant); + + } + + static async addExtensionHudInit(html, combatant, actions) { const hudData = { - combatant: combatant, - actions: actionsCombat, + combatant, actions, commandes: [ { name: "Autre action", command: 'autre' }, - { name: 'Initiative +1', command: 'inc', value: 0.01 }, + { name: 'Initiative +1', command: 'inc', value: 0.01 }, { name: 'Initiative -1', command: 'dec', value: -0.01 }] }; - const controlIconCombat = html.find('.control-icon[data-action=combat]'); - // initiative await RdDTokenHud._configureSubMenu(controlIconCombat, 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData, @@ -51,22 +58,25 @@ export class RdDTokenHud { RdDTokenHud._initiativeCommand(initCommand, combatantId); } else { let index = event.currentTarget.attributes['data-action-index'].value; - let action = actionsCombat[index]; + let action = hudData.actions[index]; RdDCombatManager.rollInitiativeAction(combatantId, action); - } + } }); + } + static async addExtensionHudCombat(html, combatant, actions) { + const hudData = { combatant, actions, commandes: [] }; const controlIconTarget = html.find('.control-icon[data-action=target]'); - // combat await RdDTokenHud._configureSubMenu(controlIconTarget, 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData, (event) => { const actionIndex = event.currentTarget.attributes['data-action-index']?.value; - const action = actionsCombat[actionIndex]; + const action = hudData.actions[actionIndex]; if (action.action == 'conjurer') { - actor.conjurerPossession(actor.getPossession(action.system.possessionid)); + const possession = combatant.actor.getPossession(action.system.possessionid); + combatant.actor.conjurerPossession(possession); } else { - actor.rollArme(action); + combatant.actor.rollArme(action); } }); } @@ -75,24 +85,25 @@ export class RdDTokenHud { switch (initCommand) { case 'inc': return RdDCombatManager.incDecInit(combatantId, 0.01); case 'dec': return RdDCombatManager.incDecInit(combatantId, -0.01); - case 'autre': return RdDCombatManager.rollInitiativeAction(combatantId, + case 'autre': return RdDCombatManager.rollInitiativeAction(combatantId, { name: "Autre action", action: 'autre', system: { initOnly: true, competence: "Autre action" } }); } } /* -------------------------------------------- */ static async addTokenHudExtensions(app, html, tokenId) { - const controlIconCombat = html.find('.control-icon[data-action=combat]'); - controlIconCombat.click(event => { - if (event.currentTarget.className.includes('active')) { - RdDTokenHud.removeExtensionHud(app, html, tokenId); - } else { - setTimeout(function () { RdDTokenHud.addExtensionHud(app, html, tokenId) }, 200); - } - }); + const controlIconCombat = html.find('.control-icon[data-action=combat]'); + if (controlIconCombat.length > 0) { + controlIconCombat.click(event => { + if (event.currentTarget.className.includes('active')) { + RdDTokenHud.removeExtensionHud(app, html, tokenId); + } else { + setTimeout(() => RdDTokenHud.addExtensionHud(app, html, tokenId), 200); + } + }); - if (controlIconCombat.length>0 && controlIconCombat[0].className.includes('active')) { - RdDTokenHud.addExtensionHud(app, html, tokenId); + const isCombat = controlIconCombat[0].className.includes('active'); + RdDTokenHud.addExtensionHud(app, html, tokenId, isCombat); } } @@ -100,9 +111,9 @@ export class RdDTokenHud { static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { const hud = $(await renderTemplate(template, hudData)); const list = hud.find('div.rdd-hud-list'); - + RdDTokenHud._toggleHudListActive(hud, list); - + hud.find('img.rdd-hud-togglebutton').click(event => RdDTokenHud._toggleHudListActive(hud, list)); list.find('.rdd-hud-menu').click(onMenuItem); diff --git a/styles/simple.css b/styles/simple.css index c4adf335..5d2a90dc 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1390,27 +1390,27 @@ table.table-nombres-astraux tr:hover { } /* ======================================== */ -.tokenhudext { +.token-hud-ext { display: flex; flex: 0 !important; font-family: CaslonPro; font-weight: 600; } -.tokenhudext.left { +.token-hud-ext.left { justify-content: flex-start; flex-direction: column; position: absolute; top: 2.75rem; right: 4rem; } -.tokenhudext.right { +.token-hud-ext.right { justify-content: flex-start; flex-direction: column; position: absolute; top: 2.75rem; left: 4rem; } -.control-icon.tokenhudicon { +.control-icon.token-hud-icon { width: fit-content; height: fit-content; min-width: 6rem; @@ -1419,7 +1419,7 @@ table.table-nombres-astraux tr:hover { line-height: 1rem; margin: 0.2rem; } -.control-icon.tokenhudicon.right { +.control-icon.token-hud-icon.right { margin-left: 8px; } .rdd-hud-menu label { diff --git a/templates/hud-actor-attaque.html b/templates/hud-actor-attaque.html index 54689bba..4b9ac185 100644 --- a/templates/hud-actor-attaque.html +++ b/templates/hud-actor-attaque.html @@ -1,9 +1,9 @@
-
+
{{#each actions as |action key|}} {{#unless action.system.initOnly}} -
diff --git a/templates/hud-actor-init.html b/templates/hud-actor-init.html index 575beae3..421a60cc 100644 --- a/templates/hud-actor-init.html +++ b/templates/hud-actor-init.html @@ -1,8 +1,8 @@
-
+
{{#each actions as |action key|}} -
@@ -10,7 +10,7 @@
{{/each}} {{#each commandes as |commande key|}} -