Skip to content

Commit 018f0ab

Browse files
committed
UPDATED - defense counter
defense counter work by hook to avoid problems with modules
1 parent a801692 commit 018f0ab

2 files changed

Lines changed: 48 additions & 60 deletions

File tree

src/animabf.mjs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { registerSettings, ABFSettingsKeys } from './utils/registerSettings';
22
import { Logger, preloadTemplates } from './utils';
33
import ABFActorSheet from './module/actor/ABFActorSheet';
4-
import ABFTokenHUD from './module/actor/ABFTokenHUD';
54
import ABFFoundryRoll from './module/rolls/ABFFoundryRoll';
65
import ABFCombat from './module/combat/ABFCombat';
76
import { ABFActor } from './module/actor/ABFActor';
@@ -55,7 +54,6 @@ Hooks.once('init', async () => {
5554

5655
CONFIG.Item.documentClass = ABFItem;
5756
CONFIG.ui.actors = ABFActorDirectory;
58-
CONFIG.Token.hudClass = ABFTokenHUD;
5957

6058
// Register custom sheets (if any)
6159
Actors.unregisterSheet('core', ActorSheet);
@@ -331,6 +329,54 @@ Hooks.on('renderActiveEffectConfig', (app, html) => {
331329
transfer.closest('.form-group').hide();
332330
});
333331

332+
Hooks.on('renderTokenHUD', async (hud, html) => {
333+
const root = hud.element ?? html?.[0];
334+
if (!root) return;
335+
336+
const token = hud.object;
337+
const actor = token?.actor;
338+
if (!actor) return;
339+
340+
const flagSystem = game.animabf.id;
341+
const flagKey = 'defensesCounter';
342+
343+
const defensesCounter = (await actor.getFlag(flagSystem, flagKey)) ?? {
344+
accumulated: 0,
345+
keepAccumulating: true
346+
};
347+
const currentValue = Number(defensesCounter.accumulated) || 0;
348+
349+
const middleCol = root.querySelector('.col.middle');
350+
if (!middleCol) return;
351+
352+
let control = middleCol.querySelector('.attribute.abf-flag-value');
353+
if (!control) {
354+
control = document.createElement('div');
355+
control.classList.add('attribute', 'abf-flag-value');
356+
control.dataset.tooltip = 'Defensas adicionales';
357+
control.innerHTML = `
358+
<label style="margin-right: 4px;">DEF</label>
359+
<input type="number" name="abfFlagValue" min="0" step="1" value="0">
360+
`;
361+
middleCol.prepend(control);
362+
}
363+
364+
const input = control.querySelector("input[name='abfFlagValue']");
365+
if (!input) return;
366+
367+
input.value = currentValue;
368+
369+
input.onchange = async ev => {
370+
ev.stopPropagation();
371+
const newValue = Number(ev.target.value) || 0;
372+
373+
await actor.setFlag(flagSystem, flagKey, {
374+
...defensesCounter,
375+
accumulated: newValue
376+
});
377+
};
378+
});
379+
334380
// // Auto-number unlinked tokens as "{name} (n)" when dropped
335381
// Hooks.on('createToken', async doc => {
336382
// // Ignore linked tokens

src/module/actor/ABFTokenHUD.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)