mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
[PR][Feature] Actor Sizes (#1433)
* Added support for adversary actor sizes * . * . * Finished token implementation * Fixed token-config * Updated SRD adversaries * . * Added size to Beastform tokenData * Fixed sizing for evolved beastforms * Beastform compendium update * .
This commit is contained in:
parent
7926c614e3
commit
8178fa5738
176 changed files with 1198 additions and 203 deletions
40
module/documents/scene.mjs
Normal file
40
module/documents/scene.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import DHToken from './token.mjs';
|
||||
|
||||
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, tokenSize) {
|
||||
if (!tokenDoc.parent?.tokens.has(tokenDoc.id)) return;
|
||||
const prototype = tokenDoc.actor?.prototypeToken ?? tokenDoc;
|
||||
this.#sizeSyncBatch.set(tokenDoc.id, {
|
||||
size: tokenSize,
|
||||
prototypeSize: { width: prototype.width, height: prototype.height },
|
||||
position: { x: tokenDoc.x, y: tokenDoc.y, elevation: tokenDoc.elevation }
|
||||
});
|
||||
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, { size, prototypeSize, position }]) => {
|
||||
const tokenSize = tokenSizes[size];
|
||||
const width = size !== CONFIG.DH.ACTOR.tokenSize.custom.id ? tokenSize : prototypeSize.width;
|
||||
const height = size !== CONFIG.DH.ACTOR.tokenSize.custom.id ? tokenSize : prototypeSize.height;
|
||||
const updatedPosition = DHToken.getSnappedPositionInSquareGrid(this.grid, position, width, height);
|
||||
return {
|
||||
_id,
|
||||
width,
|
||||
height,
|
||||
...updatedPosition
|
||||
};
|
||||
});
|
||||
this.#sizeSyncBatch.clear();
|
||||
this.updateEmbeddedDocuments('Token', entries, { animation: { movementSpeed: 1.5 } });
|
||||
}, 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue