From c017b16570fd5314863647a9ea3fcdb2aac9c92a Mon Sep 17 00:00:00 2001 From: cadowtin Date: Thu, 11 Jul 2024 01:36:01 -0500 Subject: [PATCH 1/4] mild Code Cleanup --- scripts/systemCompatability.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/systemCompatability.js b/scripts/systemCompatability.js index 2c2ac5e..cca0dcd 100644 --- a/scripts/systemCompatability.js +++ b/scripts/systemCompatability.js @@ -14,10 +14,13 @@ export function isHealing(actor, update, status) { if (!keys.statusDamagePath) { const actorHP = foundry.utils.getProperty(actor, keys.hpPath); return updateHP > actorHP === keys.zeroIsBad; + } else { + const damageTaken = foundry.utils.getProperty( + status, + keys.statusDamagePath + ); + return damageTaken > 0 !== keys.zeroIsBad; } - - const damageTaken = foundry.utils.getProperty(status, keys.statusDamagePath); - return damageTaken > 0 !== keys.zeroIsBad; } /** From 2a49f03f019910e2faf0d6aca2e6341d3b6c0b31 Mon Sep 17 00:00:00 2001 From: cadowtin Date: Thu, 11 Jul 2024 01:36:14 -0500 Subject: [PATCH 2/4] code cleanup 2 --- scripts/module.js | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/scripts/module.js b/scripts/module.js index c976479..01c1ff2 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -6,7 +6,7 @@ import { isHealing } from "./systemCompatability.js"; // Define color constants const COLORS = { GREEN: "#ADFF2F", - RED: "#ff0000", + RED: "#FF0000", PURPLE: "#9370DB", WHITE: "#FFFFFF", DEEPSKYBLUE: "#00BFFF", @@ -15,30 +15,19 @@ const COLORS = { }; // Initialize module settings -Hooks.once("init", function () { - registerSettings(); -}); +Hooks.once("init", registerSettings); // Set up main functionality when Foundry VTT is ready -Hooks.once("ready", async function () { +Hooks.once("ready", async () => { // Handle actor updates Hooks.on("preUpdateActor", async (actor, update, status, _userID) => { - if (status.diff) { - const isHeal = isHealing(actor, update, status); - const token = canvas.tokens.placeables.find( - (t) => t.actor.id === actor.id - ); - - if (isHeal !== undefined) { - const color = isHeal ? COLORS.GREEN : COLORS.RED; - const situation = isHeal ? "heal" : "damage"; - flashColor( - token, - color, - getAnimationChanges(situation, { actor, status }) - ); - } - } + if (!status.diff) return; + const isHeal = isHealing(actor, update, status); + if (isHeal !== undefined) return; + const token = canvas.tokens.placeables.find((t) => t.actor.id === actor.id); + const color = isHeal ? COLORS.GREEN : COLORS.RED; + const situation = isHeal ? "heal" : "damage"; + flashColor(token, color, getAnimationChanges(situation, { actor, status })); }); // Handle token targeting @@ -98,7 +87,7 @@ async function flashColor(token, color, animationOverride = {}) { * @param {Object} data - Additional data for the animation * @returns {Object} Animation changes */ -function getAnimationChanges(situation, data) { +function getAnimationChanges(situation, { actor, status }) { const baseDuration = game.settings.get(MODULE_ID, "duration"); const result = {}; @@ -108,7 +97,7 @@ function getAnimationChanges(situation, data) { ) { if (game.settings.get(MODULE_ID, "damage-heal.scale-on-%-hp")) { const percentHealth = Math.abs( - data.status.damageTaken / data.actor.system.attributes.hp.max + status.damageTaken / actor.system.attributes.hp.max ); result.duration = getDurationMultiplier(percentHealth) * baseDuration; } @@ -123,11 +112,9 @@ function getAnimationChanges(situation, data) { * @returns {number} A value between 1 and 4 to scale duration */ function getDurationMultiplier(percentHealth) { - return ( - 1 + - ((Math.min(Math.max(0.1, percentHealth), 0.5) - 0.1) * (4 - 1)) / - (0.5 - 0.1) - ); + const clampedHealth = Math.min(Math.max(0.1, percentHealth), 0.5); + const scaledHealth = ((clampedHealth - 0.1) * 3) / 0.4; + return 1 + scaledHealth; } // Token ring effects (borrowed from DnD 5e system) From 3ef8bddb6c63377dddf6e429634e538a2afdcea7 Mon Sep 17 00:00:00 2001 From: cadowtin Date: Thu, 11 Jul 2024 15:06:30 -0500 Subject: [PATCH 3/4] Fix for targets flashing when detargetting --- scripts/module.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/module.js b/scripts/module.js index 01c1ff2..9c6cf62 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -31,10 +31,11 @@ Hooks.once("ready", async () => { }); // Handle token targeting - Hooks.on("targetToken", async (user, token) => { + Hooks.on("targetToken", async (user, token, isTargetting) => { if ( - user.id === game.user.id || - game.settings.get(MODULE_ID, "target.share-flash") + isTargetting && + (user.id === game.user.id || + game.settings.get(MODULE_ID, "target.share-flash")) ) { const color = game.settings.get(MODULE_ID, "target.player-color") ? user.color.css From 74f5b85e02d2f79eaa303506814850810ef3a829 Mon Sep 17 00:00:00 2001 From: cadowtin Date: Thu, 11 Jul 2024 15:09:11 -0500 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1854291..b70cc5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.1.4](https://github.com/ChasarooniZ/PF2e-Reactive-Token-Ring/compare/1.1.3...1.1.4) - Only on Target +- Tokens only flash when targetted now +- Minor Code Cleanup ## [1.1.3](https://github.com/ChasarooniZ/PF2e-Reactive-Token-Ring/compare/1.1.2...1.1.3) - Dragonbane - Support for Dragonbane - Drakar och Demoner (@xdy)