Skip to content

Commit

Permalink
aight
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Jul 14, 2024
1 parent 3ba598d commit 39b5aed
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
10 changes: 6 additions & 4 deletions src/storage/AnimCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMsg, devMessage } from 'src/utils.ts'
import { ErrorMsg, dev, devMessage, findTokenByActor } from 'src/utils.ts'
import type { Entries, TokenOrDoc } from 'src/extensions'
import { settings } from 'src/settings'
import type { PresetKeys } from './presets'
Expand Down Expand Up @@ -141,16 +141,18 @@ export let AnimCore = class AnimCore {
data.sequence.preset(animation.preset, { file: animation.file, options: animation.options, ...data })
}

static testAnimation(animationData: AnimationDataObject) {
static testAnimation(animationData: AnimationDataObject, item: ItemPF2e) {
const sequence = new Sequence({ inModuleName: 'pf2e-graphics' })
this.animate(
animationData,
{
targets: Array.from(game.user.targets),
source: canvas.tokens.controlled[0],
source: findTokenByActor(item.actor) ?? canvas.tokens.controlled[0],
item,
sequence,
},
)

sequence.play({ local: true })

Check failure on line 156 in src/storage/AnimCore.ts

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'local' does not exist in type '{ remote?: boolean | undefined; }'.
}

Expand All @@ -161,7 +163,7 @@ export let AnimCore = class AnimCore {
...rest
}: { item?: ItemPF2e | null, rollOptions: string[], trigger: TriggerTypes }, narrow: (animation: AnimationDataObject) => boolean = () => true) {
const animationTree = this.getMatchingAnimationTrees(rollOptions, item, game.userId)
const sequence = new Sequence({ inModuleName: 'pf2e-graphics' })
const sequence = new Sequence({ inModuleName: 'pf2e-graphics', softFail: !dev })

devMessage('Animation Tree', animationTree, { trigger, rollOptions, item })

Expand Down
53 changes: 41 additions & 12 deletions src/storage/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ export const helpers = {
measureDistanceSpaces(token: TokenOrDoc, target: TokenOrDoc) {
return this.measureDistance(token, target).spaces
},
parseOffset(offset: Point & { flip: { x: true, y: true } }, source: Point, target: Point) {
const result = { x: offset.x, y: offset.y }
parseOffsetEmbedded(options: { offset?: Offset } | undefined, source: Point, target: Point) {
return { ...options, offset: (options?.offset ? this.parseOffset(options?.offset, source, target) : undefined) }
},
parseOffset(offset: Offset, source: Point, target: Point) {
const result = {
x: offset.x ?? 0,
y: offset.y ?? 0,
}
if (Array.isArray(result.x))
result.x = Sequencer.Helpers.random_float_between(result.x[0], result.x[1])
if (Array.isArray(result.y))
result.y = Sequencer.Helpers.random_float_between(result.y[0], result.y[1])

if (offset.flip?.x && source.x > target.x)
result.x *= -1
if (offset.flip?.y && source.y > target.y)
result.y *= -1

return result
},
getCenterCoords(target: Target): Point | undefined {
Expand Down Expand Up @@ -51,6 +63,14 @@ export const helpers = {
seq.belowTokens(options.belowTokens ?? false)
if (options?.duration)
seq.duration(options.duration)
if (options?.randomizeMirrorX)
seq.randomizeMirrorX(options.randomizeMirrorX)
if (options?.randomizeMirrorY)
seq.randomizeMirrorY(options.randomizeMirrorY)
if (options?.repeats)
seq.repeats(options.repeats.min, options.repeats.delay, options.repeats.max)
if (options?.template)
seq.template(options.template)

// Adds new effects
if (options?.shape)
Expand Down Expand Up @@ -84,6 +104,8 @@ interface EffectOptions<T extends PresetKeys> {
preset: presetOptions<T>
locally: boolean
id: string
randomizeMirrorX: boolean
randomizeMirrorY: boolean
remove: string | string[]
tieToDocuments: true
belowTokens: boolean
Expand All @@ -109,10 +131,17 @@ interface EffectOptions<T extends PresetKeys> {
stretchTo: Parameters<EffectSection['stretchTo']>[1]
rotateTowards: Parameters<EffectSection['rotateTowards']>[1]
anchor: Parameters<EffectSection['anchor']>[0]
shape: shape | shape[]
template: Parameters<EffectSection['template']>[0]
repeats: {
min: Parameters<EffectSection['repeats']>[0]
delay: Parameters<EffectSection['repeats']>[1]
max: Parameters<EffectSection['repeats']>[2]
}
shape: Shape | Shape[]
}

type shape = { value: Parameters<EffectSection['shape']>[0] } & Parameters<EffectSection['shape']>[1]
type Shape = { value: Parameters<EffectSection['shape']>[0] } & Parameters<EffectSection['shape']>[1]
type Offset = Point & { flip?: { x?: true, y?: true } }

export const presets = {
ranged: (seq: Sequence, { file, targets, source, options, item }: PresetIndex['ranged']) => {
Expand All @@ -123,9 +152,9 @@ export const presets = {

for (const [i, target] of targets.entries()) {
const section = seq.effect()
.stretchTo(target, options?.stretchTo)
.stretchTo(target, helpers.parseOffsetEmbedded(options?.stretchTo, source, target))

if (options?.preset.bounce && i > 0) {
if (options?.preset?.bounce && i > 0) {
section
.atLocation(targets[i - 1], options?.atLocation)
.file(options?.preset.file)
Expand All @@ -149,8 +178,8 @@ export const presets = {
for (const target of targets) {
const section = seq.effect()
.file(file)
.attachTo(source, options?.attachTo)
.rotateTowards(target, options?.rotateTowards)
.attachTo(source, helpers.parseOffsetEmbedded(options?.attachTo, source, target))
.rotateTowards(target, helpers.parseOffsetEmbedded(options?.rotateTowards, source, target))

helpers.genericSequencerFunctions(section, item, target, options)
}
Expand All @@ -166,11 +195,11 @@ export const presets = {

const result = seq.effect()
.file(file)
.attachTo(affectedToken, options?.attachTo)
.attachTo(affectedToken, helpers.parseOffsetEmbedded(options?.attachTo, affectedToken, target || affectedToken))
.anchor(foundry.utils.mergeObject({ x: 0.5, y: 0.5 }, options?.anchor || {}))

if (options?.rotateTowards)
result.rotateTowards(target, options?.rotateTowards)
result.rotateTowards(target, helpers.parseOffsetEmbedded(options?.rotateTowards, affectedToken, target || affectedToken))

return helpers.genericSequencerFunctions(result, item, affectedToken, options)
},
Expand All @@ -181,10 +210,10 @@ export const presets = {
for (const target of targets) {
const section = seq.effect()
.file(file)
.attachTo(target, options?.attachTo)
.attachTo(target, helpers.parseOffsetEmbedded(options?.attachTo, target, target))

if (target.type === 'line' || target.type === 'cone')
section.stretchTo(target, options?.stretchTo)
section.stretchTo(target, helpers.parseOffsetEmbedded(options?.stretchTo, target, target))

helpers.genericSequencerFunctions(section, item, target, options)
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export function i18n(string: string, format?: any) {
}
return game.i18n.format(string, format)
}

export const findTokenByActor = (actor?: ActorPF2e | null) => canvas.tokens.getDocuments().find(x => x.actor?.id === actor?.id)
2 changes: 1 addition & 1 deletion src/view/ItemAnimations/ItemAnimationsShell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<button
class='text-xs h-full'
on:click={() =>
window.pf2eGraphics.AnimCore.testAnimation(animation)}
window.pf2eGraphics.AnimCore.testAnimation(animation, item)}
>
Test
</button>
Expand Down

0 comments on commit 39b5aed

Please sign in to comment.