forked from public/foundryvtt-reve-de-dragon
Gestion attaques v2 et initiative
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
/* -------------------------------------------- */
|
||||
import { renderTemplate } from "./constants.js";
|
||||
import { HtmlUtility } from "./html-utility.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDCombatManager } from "./rdd-combat.js";
|
||||
import { OptionsAvancees, ROLL_DIALOG_V2 } from "./settings/options-avancees.js";
|
||||
import { Targets } from "./targets.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -31,43 +33,86 @@ export class RdDTokenHud {
|
||||
const combatant = game.combat.combatants.find(c => c.tokenId == tokenId)
|
||||
const actor = RdDCombatManager.getActorCombatant(combatant, { warning: false })
|
||||
if (actor) {
|
||||
const actions = RdDCombatManager.listActionsActorCombatant(actor)
|
||||
// initiative
|
||||
await RdDTokenHud.addExtensionHudInit(html, combatant, actions)
|
||||
// combat
|
||||
await RdDTokenHud.addExtensionHudCombat(html, combatant, token, actions.filter(it => !it.initOnly))
|
||||
if (OptionsAvancees.isUsing(ROLL_DIALOG_V2)) {
|
||||
await RdDTokenHud.addExtensionHudCombat(html, combatant, actor, token)
|
||||
}
|
||||
else {
|
||||
const actions = RdDCombatManager.listActionsActorCombatant(actor)
|
||||
// initiative
|
||||
await RdDTokenHud.addExtensionHudInit(html, combatant, actions)
|
||||
// combat
|
||||
await RdDTokenHud.addExtensionHudAttaques(html, combatant, token, actions.filter(it => !it.initOnly))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async addExtensionHudCombat(html, combatant, actor, token) {
|
||||
const actionsActor = actor.listActionsCombat();
|
||||
const ajustements = combatant?.initiative ?
|
||||
[
|
||||
{ label: 'Initiative +1', action: 'delta', value: 1 },
|
||||
{ label: 'Initiative -1', action: 'delta', value: -1 }
|
||||
] : []
|
||||
const autres = [{ label: "Autre action", action: 'autre' }]
|
||||
const actions = Misc.indexed(actionsActor.concat(ajustements).concat(autres))
|
||||
|
||||
const hudData = { combatant, token, actions };
|
||||
const hud = $(await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/hud-actor-combat.hbs', hudData))
|
||||
$(html).find('div.col.left').append(hud)
|
||||
|
||||
const list = hud.find('div.rdd-hud-list')
|
||||
RdDTokenHud.setupHudToggle(hud, list)
|
||||
|
||||
const selectInitiative = list.find('select[name="initiative"]');
|
||||
selectInitiative.change(event => {
|
||||
const action = actions.find(it => it.index == event.currentTarget.value)
|
||||
console.log('select initiative', combatant.id, action)
|
||||
if (action) {
|
||||
switch (action.action) {
|
||||
case 'delta':
|
||||
RdDCombatManager.incDecInit(combatant.id, action.value);
|
||||
break
|
||||
case 'autre':
|
||||
RdDCombatManager.rollInitiativeAction(combatant.id,
|
||||
{ label: "Autre action", action: 'autre', system: { initOnly: true, competence: "Autre action" } });
|
||||
break
|
||||
default:
|
||||
RdDCombatManager.rollInitiativeAction(combatant.id, action)
|
||||
}
|
||||
selectInitiative.select("")
|
||||
}
|
||||
})
|
||||
list.find('.rdd-attaque-v2').click(event => combatant.actor.rollAttaque(token))
|
||||
}
|
||||
|
||||
static async addExtensionHudInit(html, combatant, actions) {
|
||||
const hudData = {
|
||||
combatant, actions,
|
||||
commandes: [
|
||||
{ name: "Autre action", command: 'autre' },
|
||||
{ name: 'Initiative +1', command: 'inc', value: 0.01 },
|
||||
{ name: 'Initiative -1', command: 'dec', value: -0.01 }]
|
||||
{ label: "Autre action", command: 'autre' },
|
||||
{ label: 'Initiative +1', command: 'delta', value: 1 },
|
||||
{ label: 'Initiative -1', command: 'deltac', value: -1 }]
|
||||
};
|
||||
const controlIconCombat = $(html).find('.control-icon[data-action=combat]');
|
||||
await RdDTokenHud._configureSubMenu(it => controlIconCombat.after(it),
|
||||
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.hbs',
|
||||
hudData,
|
||||
(event) => {
|
||||
let initCommand = event.currentTarget.attributes['data-command']?.value;
|
||||
let combatantId = event.currentTarget.attributes['data-combatant-id']?.value;
|
||||
let initCommand = event.currentTarget.attributes['data-command']?.value
|
||||
let initCommandValue = Number(event.currentTarget.attributes['data-command-value']?.value ?? 0)
|
||||
let combatantId = event.currentTarget.attributes['data-combatant-id']?.value
|
||||
if (initCommand) {
|
||||
RdDTokenHud._initiativeCommand(initCommand, combatantId);
|
||||
RdDCombatManager.applyInitiativeCommand(combatantId, initCommand, initCommandValue)
|
||||
} else {
|
||||
let index = event.currentTarget.attributes['data-action-index'].value;
|
||||
let action = hudData.actions[index];
|
||||
RdDCombatManager.rollInitiativeAction(combatantId, action);
|
||||
let index = event.currentTarget.attributes['data-action-index'].value
|
||||
let action = hudData.actions[index]
|
||||
RdDCombatManager.rollInitiativeAction(combatantId, action)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
static async addExtensionHudCombat(html, combatant, token, actions) {
|
||||
static async addExtensionHudAttaques(html, combatant, token, actions) {
|
||||
|
||||
const hudData = { combatant, token, actions, commandes: [] };
|
||||
const divColLeft = $(html).find('div.col.left');
|
||||
@@ -104,15 +149,6 @@ export class RdDTokenHud {
|
||||
}
|
||||
}
|
||||
|
||||
static _initiativeCommand(initCommand, combatantId) {
|
||||
switch (initCommand) {
|
||||
case 'inc': return RdDCombatManager.incDecInit(combatantId, 0.01);
|
||||
case 'dec': return RdDCombatManager.incDecInit(combatantId, -0.01);
|
||||
case 'autre': return RdDCombatManager.rollInitiativeAction(combatantId,
|
||||
{ name: "Autre action", action: 'autre', system: { initOnly: true, competence: "Autre action" } });
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async addTokenHudExtensions(app, html, tokenId) {
|
||||
console.log(`Adding token HUD extensions for token ${tokenId}`);
|
||||
@@ -132,20 +168,24 @@ export class RdDTokenHud {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async _configureSubMenu(insertMethod, template, hudData, onMenuItem) {
|
||||
static async _configureSubMenu(callInsertion, template, hudData, onMenuItem) {
|
||||
const hud = $(await renderTemplate(template, hudData));
|
||||
const list = hud.find('div.rdd-hud-list');
|
||||
|
||||
RdDTokenHud._toggleHudListActive(hud, list);
|
||||
RdDTokenHud.setupHudToggle(hud, list)
|
||||
|
||||
hud.find('img.rdd-hud-togglebutton').click(event => RdDTokenHud._toggleHudListActive(hud, list));
|
||||
list.find('.rdd-hud-menu').click(onMenuItem);
|
||||
|
||||
insertMethod(hud);
|
||||
callInsertion(hud);
|
||||
}
|
||||
|
||||
static _toggleHudListActive(hud, list) {
|
||||
hud.toggleClass('active');
|
||||
HtmlUtility.showControlWhen(list, hud.hasClass('active'));
|
||||
static setupHudToggle(hud, list) {
|
||||
function toggleHudList(hud, list) {
|
||||
hud.toggleClass('active')
|
||||
HtmlUtility.showControlWhen(list, hud.hasClass('active'))
|
||||
}
|
||||
toggleHudList(hud, list)
|
||||
$(hud).find('img.rdd-hud-togglebutton').click(event => toggleHudList(hud, list))
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user