Skip to content

Commit

Permalink
Added Rotate on attack Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasarooniZ committed May 28, 2024
1 parent 1411c10 commit abab83b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
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";

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("")
const scaleTurnTime = getSetting("");
const turnTime = scaleTurnTime ? baseTurnTime * tokWxH : 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 abab83b

Please sign in to comment.