|
1 | 1 | import { registerSettings, ABFSettingsKeys } from './utils/registerSettings'; |
2 | 2 | import { Logger, preloadTemplates } from './utils'; |
3 | 3 | import ABFActorSheet from './module/actor/ABFActorSheet'; |
4 | | -import ABFTokenHUD from './module/actor/ABFTokenHUD'; |
5 | 4 | import ABFFoundryRoll from './module/rolls/ABFFoundryRoll'; |
6 | 5 | import ABFCombat from './module/combat/ABFCombat'; |
7 | 6 | import { ABFActor } from './module/actor/ABFActor'; |
@@ -55,7 +54,6 @@ Hooks.once('init', async () => { |
55 | 54 |
|
56 | 55 | CONFIG.Item.documentClass = ABFItem; |
57 | 56 | CONFIG.ui.actors = ABFActorDirectory; |
58 | | - CONFIG.Token.hudClass = ABFTokenHUD; |
59 | 57 |
|
60 | 58 | // Register custom sheets (if any) |
61 | 59 | Actors.unregisterSheet('core', ActorSheet); |
@@ -331,6 +329,54 @@ Hooks.on('renderActiveEffectConfig', (app, html) => { |
331 | 329 | transfer.closest('.form-group').hide(); |
332 | 330 | }); |
333 | 331 |
|
| 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 | + |
334 | 380 | // // Auto-number unlinked tokens as "{name} (n)" when dropped |
335 | 381 | // Hooks.on('createToken', async doc => { |
336 | 382 | // // Ignore linked tokens |
|
0 commit comments