Skip to content

Commit

Permalink
Rotate on attack addons (#51)
Browse files Browse the repository at this point in the history
* Added easing to roll scroll

* UUpdated Changelog

* Added Rotate on attack Stuff

* Fixed not gettin setting

* Fix import issue

* Fix base time so it is actually in MS

* Changed rotation scaling to be more subtle

* Fix for fix for fix

* Fix for colors again

* Update CHANGELOG.md
  • Loading branch information
ChasarooniZ authored May 29, 2024
1 parent 28b0ab2 commit aa49a81
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# 11.10.1 - Patch
# 11.12.0 - Token Turning Updates
- Turn on Token Attack _new options_
- **_New Setting._** Scale based on token size (scales how long it takes to turn based on the number of squares the token takes up)
- _Must be enabled in the settings_
- **_New setting._** Rotation time (set how long it takes for the token to rotate)
# 11.11.2 - Bug Fixes
- Fixed issue with **Damage Numbers** not resepcting message visibility (@Intervención)
- Updated parsing of `PF2e Toolbelt` msg falgs to grab targets on newer versions of pf2e Toolbelt
- Added manifest to `animated-spell-effects` to allow use of the **Basic Action Animations** feature
# 11.11.1 - Patch
- Fixed Issue with feint animation
- Added easing to roll scroll
# 11.11.0 - Basic Action Animations (WIP)
Expand Down
8 changes: 8 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@
"enabled": {
"name": "Enable Token rotating on attacking",
"hint": "When you attack the token turns towards who it attacks, then turns back to its original rotation. You can set the rotation offset to determine where the token faces."
},
"duration": {
"name": "Token Rotation Duration",
"hint": "How long it takes the token to turn towards the enemy in seconds (Default is 0.5 s, overall time to turn and turn back is 1.5 x the time here)"
},
"scale-on-size": {
"name": "Enable Token Rotation Duration Size Scaling",
"hint": "Allow Rotation to take longer based on the size of the attacker (scales on the number of squares it takes up)"
}
},
"critical": {
Expand Down
13 changes: 10 additions & 3 deletions scripts/helpers/animation/turnTokenOnAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
* @param {*} target Person they are attacking
*/

import { getSetting } from "../misc.js";

export function turnTokenOnAttack(token, target) {
if (!token || !target || token === target) return;
const angle = token.angle;
const rotationOffset = token.document.flags?.["pf2e-rpg-numbers"]?.rotationOffset ?? 0;
const tokWxH = (token.document.height + token.document.width)/2;
const baseTurnTime = getSetting("rotate-on-attack.duration") * 1000;
const scaleTurnTime = getSetting("rotate-on-attack.scale-on-size");
const turnTime = scaleTurnTime ? baseTurnTime * (1 + ((tokWxH - 1) / 2)) : baseTurnTime;

new Sequence()
.animation()
.on(token)
.rotateTowards(target, { duration: 500, ease: "easeInCubic", rotationOffset })
.waitUntilFinished(250)
.rotateTowards(target, { duration: turnTime, ease: "easeInCubic", rotationOffset })
.waitUntilFinished(turnTime/2)
.animation()
.on(token)
.rotateIn(angle, 500, { ease: "easeOutCubic" })
.rotateIn(angle, turnTime, { ease: "easeOutCubic" })
.play();
}
21 changes: 21 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,27 @@ Hooks.on("init", () => {
onChange: debouncedReload,
});

registerSetting("rotate-on-attack", "rotate-on-attack.duration", {
desc: "duration",
scope: "world",
config: true,
default: 0.5,
range: {
min: 0,
max: 2,
step: 0.1,
},
type: Number,
});

registerSetting("rotate-on-attack", "rotate-on-attack.scale-on-size", {
desc: "scale-on-size",
scope: "world",
config: true,
default: false,
type: Boolean,
});

//Critical Hit
registerSetting("critical", "critical.enabled", {
desc: "enabled",
Expand Down

0 comments on commit aa49a81

Please sign in to comment.