Skip to content

Commit

Permalink
add animation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Sep 28, 2024
1 parent 9c9abdc commit 4cad33f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 24 deletions.
28 changes: 16 additions & 12 deletions animations/spells/4th/dimensional-steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"options": {
"scaleToObject": 2,
"belowTokens": true,
"fadeIn": 1000,
"fadeOut": 1000,
"duration": 8000,
"scaleIn": { "scale": 0, "duration": 1000, "ease": "easeInOutElastic" },
"scaleOut": { "scale": 0, "duration": 1000, "ease": "easeInOutElastic" },
"fadeIn": { "value": 2000, "ease": "easeOutElastic" },
"fadeOut": { "value": 2000, "ease": "easeInElastic" },
"duration": 5000,
"opacity": 0.75,
"preset": {
"atLocation": true,
Expand All @@ -35,8 +37,6 @@
"preset": "animation",

Check failure on line 37 in animations/spells/4th/dimensional-steps.json

View workflow job for this annotation

GitHub Actions / Animation files

Invalid enum value. Expected 'onToken' | 'ranged' | 'melee' | 'template' | 'sound' | 'macro', received 'animation'

spell:dimensional-steps.0.contents.2.preset
"options": {
"delay": 1500,
"duration": 2500,
"fadeIn": 1000,
"fadeOut": 1000
}
},
Expand All @@ -45,13 +45,17 @@
"options": {
"delay": 2500,
"preset": {
"targets": [
"dimensional-step"
],
"type": "teleport",
"closestSquare": true,
"snapToGrid": true
}
"target": "dimensional-step",
"type": "teleport"
},

Check failure on line 50 in animations/spells/4th/dimensional-steps.json

View workflow job for this annotation

GitHub Actions / Animation files

Unrecognized key(s) in object: 'target', 'type'

spell:dimensional-steps.0.contents.3.options.preset

Check failure on line 50 in animations/spells/4th/dimensional-steps.json

View workflow job for this annotation

GitHub Actions / Animation files

Object must not be empty.

spell:dimensional-steps.0.contents.3.options.preset
"snapToGrid": true
}

Check failure on line 52 in animations/spells/4th/dimensional-steps.json

View workflow job for this annotation

GitHub Actions / Animation files

Unrecognized key(s) in object: 'snapToGrid'

spell:dimensional-steps.0.contents.3.options
},
{
"preset": "animation",

Check failure on line 55 in animations/spells/4th/dimensional-steps.json

View workflow job for this annotation

GitHub Actions / Animation files

Invalid enum value. Expected 'onToken' | 'ranged' | 'melee' | 'template' | 'sound' | 'macro', received 'animation'

spell:dimensional-steps.0.contents.4.preset
"options": {
"delay": 3000,
"fadeIn": 1000
}
}
]
Expand Down
64 changes: 64 additions & 0 deletions src/presets/animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { AnimationObject } from 'src/storage/AnimCore';
import type { GameData, SequencerTypes } from '.';
import { devLog, ErrorMsg, getPlayerOwners, i18n, isTrueish } from 'src/utils';

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / ESLint

'devLog' is defined but never used

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / ESLint

'ErrorMsg' is defined but never used

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / ESLint

'getPlayerOwners' is defined but never used

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / ESLint

'i18n' is defined but never used

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

'devLog' is declared but its value is never read.

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

'ErrorMsg' is declared but its value is never read.

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

'getPlayerOwners' is declared but its value is never read.

Check failure on line 3 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

'i18n' is declared but its value is never read.

export default async function animation(seq: SequencerTypes, animation: AnimationObject, data: GameData) {
const { sources } = data;
const { options = {} } = animation;

for (const source of sources) {
if ((source.actor as ActorPF2e)?.primaryUpdater?.id === game.userId) {
const ani = seq.animation()
.on(source);

if (isTrueish(options?.preset?.type)) {

Check failure on line 14 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'type' does not exist on type '{ atLocation?: true | { cacheLocation?: true | undefined; offset?: { x?: number | [number, number] | undefined; y?: number | [number, number] | undefined; } | undefined; randomOffset?: number | undefined; gridUnits?: true | undefined; local?: true | undefined; } | undefined; ... 6 more ...; targets?: string[] | unde...'.
switch (options?.preset?.type) {

Check failure on line 15 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'type' does not exist on type '{ atLocation?: true | { cacheLocation?: true | undefined; offset?: { x?: number | [number, number] | undefined; y?: number | [number, number] | undefined; } | undefined; randomOffset?: number | undefined; gridUnits?: true | undefined; local?: true | undefined; } | undefined; ... 6 more ...; targets?: string[] | unde...'.
case 'teleport':
ani.teleportTo(options?.preset?.target);

Check failure on line 17 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'target' does not exist on type '{ atLocation?: true | { cacheLocation?: true | undefined; offset?: { x?: number | [number, number] | undefined; y?: number | [number, number] | undefined; } | undefined; randomOffset?: number | undefined; gridUnits?: true | undefined; local?: true | undefined; } | undefined; ... 6 more ...; targets?: string[] | unde...'. Did you mean 'targets'?
break;
case 'move':
default:
ani.moveTowards(options?.preset?.target);

Check failure on line 21 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'target' does not exist on type '{ atLocation?: true | { cacheLocation?: true | undefined; offset?: { x?: number | [number, number] | undefined; y?: number | [number, number] | undefined; } | undefined; randomOffset?: number | undefined; gridUnits?: true | undefined; local?: true | undefined; } | undefined; ... 6 more ...; targets?: string[] | unde...'. Did you mean 'targets'?
break;
}
}

if (isTrueish(options?.duration)) ani.duration(options.duration);
if (isTrueish(options?.closestSquare)) ani.closestSquare(options.closestSquare);

Check failure on line 27 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'closestSquare' does not exist on type '{ filter?: { type: "ColorMatrix"; options: { hue?: number | undefined; brightness?: number | undefined; contrast?: number | undefined; saturate?: number | undefined; }; } | { type: "Glow"; options: { ...; }; } | { ...; } | { ...; } | { ...; } | undefined; ... 38 more ...; animateProperty?: { ...; }[] | undefined; }'.

Check failure on line 27 in src/presets/animation.ts

View workflow job for this annotation

GitHub Actions / Vite build

Property 'closestSquare' does not exist on type '{ filter?: { type: "ColorMatrix"; options: { hue?: number | undefined; brightness?: number | undefined; contrast?: number | undefined; saturate?: number | undefined; }; } | { type: "Glow"; options: { ...; }; } | { ...; } | { ...; } | { ...; } | undefined; ... 38 more ...; animateProperty?: { ...; }[] | undefined; }'.
if (isTrueish(options?.snapToGrid)) ani.snapToGrid(options.snapToGrid);

if (isTrueish(options?.repeats)) {
if (typeof options.repeats === 'object') {
ani.repeats(options.repeats.count, options.repeats.delayMin, options.repeats.delayMax);
} else {
ani.repeats(options.repeats);
}
}
if (isTrueish(options?.delay)) {
if (typeof options.delay === 'object') {
ani.delay(options.delay.min, options.delay?.max);
} else {
ani.delay(options.delay);
}
}
if (isTrueish(options?.fadeIn)) {
if (typeof options.fadeIn === 'object') {
ani.fadeIn(options.fadeIn?.value, options.fadeIn);
} else {
ani.fadeIn(options.fadeIn);
}
}
if (isTrueish(options?.fadeOut)) {
if (typeof options.fadeOut === 'object') {
ani.fadeOut(options.fadeOut?.value, options.fadeOut);
} else {
ani.fadeOut(options.fadeOut);
}
}
} else {
// Do I need to do anything here? I thought of adding some sort of socket in similar vein to crosshairs but... This doesn't seem to be needed?
}
}

return seq;
}
7 changes: 2 additions & 5 deletions src/presets/crosshair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ export default async function crosshair(seq: SequencerTypes, animation: Animatio

// Timeout after 30 seconds.
setTimeout(() => {
unsub();
// @ts-expect-error TODO: Sequencer types
if (!seq.status) {
// @ts-expect-error TODO: Sequencer types
seq._abort();
unsub();
}
if (!seq.status) seq._abort();
}, 30 * 1000);
}
});
Expand Down
20 changes: 13 additions & 7 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { TokenOrDoc } from 'src/extensions';
import type { AnimationObject } from 'src/storage/AnimCore.ts';
import { ErrorMsg, log } from 'src/utils.ts';
import { isTrueish } from '../utils';
import animationPreset from './animation.ts';
import crosshairPreset from './crosshair.ts';
import meleePreset from './melee.ts';
import onTokenPreset from './onToken.ts';
Expand Down Expand Up @@ -42,6 +43,9 @@ export async function addAnimationToSequence(seq: SequencerTypes, _animation: An
case 'crosshair':
await crosshairPreset(seq, animation, data);
break;
case 'animation':
await animationPreset(seq, animation, data);
break;
case 'macro':
if (animation.macro) {
seq.macro(animation.macro, { animation, data });
Expand Down Expand Up @@ -76,6 +80,8 @@ export function genericEffectOptions(seq: EffectSection, { options }: AnimationO
if (isTrueish(options?.mirrorX)) seq.mirrorX(options.mirrorX);
if (isTrueish(options?.mirrorY)) seq.mirrorY(options.mirrorY);
if (isTrueish(options?.template)) seq.template(options.template);
if (isTrueish(options?.scaleIn)) seq.scaleIn(options?.scaleIn.scale, options?.scaleIn.duration, options?.scaleIn);
if (isTrueish(options?.scaleOut)) seq.scaleOut(options?.scaleOut.scale, options?.scaleOut.duration, options?.scaleOut);
if (isTrueish(options?.tint)) seq.tint(options.tint);
// @ts-expect-error TODO: Fix in Sequencer types
if (isTrueish(options?.anchor)) seq.anchor(options.anchor);
Expand All @@ -96,6 +102,13 @@ export function genericEffectOptions(seq: EffectSection, { options }: AnimationO
seq.fadeIn(options.fadeIn);
}
}
if (isTrueish(options?.fadeOut)) {
if (typeof options.fadeOut === 'object') {
seq.fadeOut(options.fadeOut?.value, options.fadeOut);
} else {
seq.fadeOut(options.fadeOut);
}
}
if (isTrueish(options?.scale)) {
if (typeof options.scale === 'object') {
seq.scale(options.scale.min, options.scale.max);
Expand All @@ -110,13 +123,6 @@ export function genericEffectOptions(seq: EffectSection, { options }: AnimationO
seq.scaleToObject(options.scaleToObject);
}
}
if (isTrueish(options?.fadeOut)) {
if (typeof options.fadeOut === 'object') {
seq.fadeOut(options.fadeOut?.value, options.fadeOut);
} else {
seq.fadeOut(options.fadeOut);
}
}
if (isTrueish(options?.wait)) {
if (typeof options.wait === 'object') {
seq.wait(options.wait.min, options.wait?.max);
Expand Down

0 comments on commit 4cad33f

Please sign in to comment.