mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-14 04:31:07 +01:00
Added support for adversary actor sizes
This commit is contained in:
parent
9b4249b100
commit
d38b924cad
15 changed files with 180 additions and 5 deletions
|
|
@ -4,6 +4,7 @@ export { default as DhpCombat } from './combat.mjs';
|
|||
export { default as DHCombatant } from './combatant.mjs';
|
||||
export { default as DhActiveEffect } from './activeEffect.mjs';
|
||||
export { default as DhChatMessage } from './chatMessage.mjs';
|
||||
export { default as DhScene } from './scene.mjs';
|
||||
export { default as DhToken } from './token.mjs';
|
||||
export { default as DhTooltipManager } from './tooltipManager.mjs';
|
||||
export { default as DhTemplateManager } from './templateManager.mjs';
|
||||
|
|
|
|||
22
module/documents/scene.mjs
Normal file
22
module/documents/scene.mjs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export default class DhScene extends Scene {
|
||||
/** A map of `TokenDocument` IDs embedded in this scene long with new dimensions from actor size-category changes */
|
||||
#sizeSyncBatch = new Map();
|
||||
|
||||
/** Synchronize a token's dimensions with its actor's size category. */
|
||||
syncTokenDimensions(tokenDoc, dimensions) {
|
||||
if (!tokenDoc.parent?.tokens.has(tokenDoc.id)) return;
|
||||
this.#sizeSyncBatch.set(tokenDoc.id, dimensions);
|
||||
this.#processSyncBatch();
|
||||
}
|
||||
|
||||
/** Retrieve size and clear size-sync batch, make updates. */
|
||||
#processSyncBatch = foundry.utils.debounce(() => {
|
||||
const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes;
|
||||
const entries = this.#sizeSyncBatch
|
||||
.entries()
|
||||
.toArray()
|
||||
.map(([_id, { width, height }]) => ({ _id, width: tokenSizes[width], height: tokenSizes[height] }));
|
||||
this.#sizeSyncBatch.clear();
|
||||
this.updateEmbeddedDocuments('Token', entries, { animation: { movementSpeed: 1 } });
|
||||
}, 0);
|
||||
}
|
||||
|
|
@ -100,4 +100,18 @@ export default class DHToken extends TokenDocument {
|
|||
}
|
||||
super.deleteCombatants(tokens, combat ?? {});
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
_onRelatedUpdate(update = {}, operation = {}) {
|
||||
super._onRelatedUpdate(update, operation);
|
||||
|
||||
if (!this.actor?.isOwner) return;
|
||||
const activeGM = game.users.activeGM; // Let the active GM take care of updates if available
|
||||
if (this.actor.system.metadata.usesSize && activeGM && game.user.id === activeGM.id) {
|
||||
const dimensions = { height: this.actor.system.size, width: this.actor.system.size };
|
||||
if (dimensions.width !== this.width || dimensions.height !== this.height) {
|
||||
this.parent?.syncTokenDimensions(this, dimensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue