Skip to content

Commit

Permalink
remove flip
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Sep 22, 2024
1 parent 26de3b4 commit dc80bfc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
5 changes: 2 additions & 3 deletions animations/spells/1st/telekinetic-projectile.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"atLocation": {
"offset": {
"x": [
-0.25,
-1,
1
],
"y": [
-1,
1
],
"flipX": true
]
},
"gridUnits": true
},
Expand Down
25 changes: 25 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,28 @@ export function genericEffectOptions(seq: EffectSection, { options }: AnimationO

return seq;
}

function checkIfOffset(obj: any): obj is {
offset: {
x: number | [number, number] | undefined;
y: number | [number, number] | undefined;
};
} {
return 'offset' in obj;
}

export function parseOffsets<T>(obj: T) {
if (!obj || !(typeof obj === 'object')) return {};

if (checkIfOffset(obj)) {
if (Array.isArray(obj.offset.x)) {
obj.offset.x = Sequencer.Helpers.random_float_between(obj.offset.x[0], obj.offset.x[1]);
}
if (Array.isArray(obj.offset.y)) {
obj.offset.y = Sequencer.Helpers.random_float_between(obj.offset.y[0], obj.offset.y[1]);
}
return obj as { offset: Vector2 };
} else {
return obj;
}
}
8 changes: 5 additions & 3 deletions src/presets/onToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnimationObject } from 'src/storage/animCore';
import { type GameData, genericEffectOptions, type SequencerTypes } from '.';
import { type GameData, genericEffectOptions, parseOffsets, type SequencerTypes } from '.';

export default function ranged(seq: SequencerTypes, animation: AnimationObject, data: GameData) {
const { options } = animation;
Expand Down Expand Up @@ -53,8 +53,10 @@ export default function ranged(seq: SequencerTypes, animation: AnimationObject,

if (options?.preset?.rotateTowards) {
effect.rotateTowards(
options?.preset?.location === 'target' ? Sequencer.Helpers.random_array_element(sources) : Sequencer.Helpers.random_array_element(targets),
options?.preset?.rotateTowards, // TODO: Parse random number arrays
options?.preset?.location === 'target'
? Sequencer.Helpers.random_array_element(sources)
: Sequencer.Helpers.random_array_element(targets),
parseOffsets(options?.preset?.rotateTowards),
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/storage/animationsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ const offset = z
.refine(arr => arr[0] !== arr[1], 'Offset range cannot be zero.'),
)
.optional(),
flipX: z.literal(true).optional(),
flipY: z.literal(true).optional(),
})
.strict()
.refine(...nonEmpty)
Expand Down

0 comments on commit dc80bfc

Please sign in to comment.