From 389757775647d97c37380cfed29546779a8a3d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Fri, 18 Jun 2021 13:36:29 +0200 Subject: [PATCH] Allow the "Monk's Active Tile Triggers" module to interrupt a token movement early --- src/foundry_imports.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/foundry_imports.js b/src/foundry_imports.js index 295e7e7..d91e860 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -72,6 +72,10 @@ async function animateEntities(entities, draggedEntity, draggedRays, wasPaused) const isToken = draggedEntity instanceof Token; const animate = isToken && !game.keyboard.isDown("Alt"); const startWaypoint = animate ? 0 : entityAnimationData[0].rays.length - 1; + + // This is a flag of the "Monk's Active Tile Triggers" module that signals that the movement should be cancelled early + this.cancelMovement = false; + for (let i = startWaypoint;i < entityAnimationData[0].rays.length; i++) { if (!wasPaused && game.paused) break; const entityPaths = entityAnimationData.map(({entity, rays, dx, dy}) => { @@ -86,6 +90,12 @@ async function animateEntities(entities, draggedEntity, draggedRays, wasPaused) await draggedEntity.scene.updateEmbeddedDocuments(draggedEntity.constructor.embeddedName, updates, {animate}); if (animate) await Promise.all(entityPaths.map(({entity, path}) => entity.animateMovement(path))); + + // This is a flag of the "Monk's Active Tile Triggers" module that signals that the movement should be cancelled early + if (this.cancelMovement) { + entityAnimationData.forEach(ead => ead.rays = ead.rays.slice(0, i + 1)); + break; + } } if (isToken) trackRays(entities, entityAnimationData.map(({rays}) => rays)).then(() => recalculate(entities));