Skip to content

Commit 912f52b

Browse files
SnaveSutitgitbutler-client
authored andcommitted
🐛 Fix keyframe panel mods
1 parent a13a8bd commit 912f52b

4 files changed

Lines changed: 87 additions & 52 deletions

File tree

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ EVENTS.PLUGIN_FINISHED_LOADING.subscribe(() => {
129129
openChangelogDialog()
130130
}
131131
})
132+
133+
import './plugin'

src/interface/keyframeEasings.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { registerPatch } from 'blockbench-patch-manager'
22
import { injectComponent } from 'svelte-patching-tools'
3+
import { activeProjectIsBlueprintFormat } from '../formats/blueprint'
34
import KeyframeEasingsSvelte from '../svelteComponents/keyframeEasings.svelte'
45
import EVENTS from '../util/events'
56

@@ -12,24 +13,43 @@ function isFirstKeyframe(kf: _Keyframe) {
1213
}
1314

1415
let unmountCallback: (() => Promise<void>) | null = null
15-
let selectedKeyframe: _Keyframe | undefined
16+
let currentUpdatePromise: Promise<void> | null = null
1617

17-
registerPatch({
18-
id: 'animated_java:mounted-svelte/keyframe-easings',
19-
apply() {
20-
const unsub = EVENTS.UPDATE_KEYFRAME_SELECTION.subscribe(async () => {
21-
selectedKeyframe = Timeline.selected.at(0)
22-
await unmountCallback?.()
23-
if (!selectedKeyframe || isFirstKeyframe(selectedKeyframe)) return
18+
const updatePanel = () => {
19+
if (currentUpdatePromise) {
20+
return currentUpdatePromise.then(() => {
21+
void updatePanel()
22+
})
23+
}
2424

25+
currentUpdatePromise = new Promise(async resolve => {
26+
await unmountCallback?.()
27+
if (!activeProjectIsBlueprintFormat()) return
28+
29+
const selectedKeyframe = Timeline.selected.at(0)
30+
if (selectedKeyframe && !isFirstKeyframe(selectedKeyframe)) {
2531
unmountCallback = injectComponent({
2632
component: KeyframeEasingsSvelte,
2733
props: { selectedKeyframe },
28-
elementSelector(): HTMLElement | null {
29-
return document.querySelector('#panel_keyframe')
34+
elementSelector() {
35+
return Panels.keyframe.node
36+
},
37+
postMount() {
38+
currentUpdatePromise = null
39+
resolve()
3040
},
3141
})
32-
})
42+
} else {
43+
currentUpdatePromise = null
44+
resolve()
45+
}
46+
})
47+
}
48+
49+
registerPatch({
50+
id: 'animated_java:mounted-svelte/keyframe-easings',
51+
apply() {
52+
const unsub = EVENTS.UPDATE_KEYFRAME_SELECTION.subscribe(() => void updatePanel())
3353

3454
return { unsub }
3555
},

src/panels/customKeyframe/customKeyframe.ts

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
11
import { registerPatch } from 'blockbench-patch-manager'
22
import { injectComponent } from 'svelte-patching-tools'
3-
import { EFFECT_ANIMATOR_CHANNELS, isCustomKeyframeChannel } from '../../mods/customKeyframes'
3+
import { EFFECT_ANIMATOR_CHANNELS } from '../../mods/customKeyframes'
44
import EVENTS from '../../util/events'
55
import { localize as translate } from '../../util/lang'
66
import CommandsKeyframePanel from './commandsKeyframe.svelte'
77
import VariantKeyframePanel from './variantKeyframe.svelte'
88

99
let unmountCallback: (() => Promise<void>) | null = null
10+
let currentUpdatePromise: Promise<void> | null = null
11+
12+
const updatePanel = () => {
13+
if (currentUpdatePromise) {
14+
return currentUpdatePromise.then(() => {
15+
void updatePanel()
16+
})
17+
}
18+
19+
currentUpdatePromise = new Promise(async resolve => {
20+
await unmountCallback?.()
21+
22+
// if (!activeProjectIsBlueprintFormat()) return
23+
24+
const keyframe = Timeline.selected.at(0)
25+
if (keyframe) {
26+
let component: any
27+
switch (keyframe.channel) {
28+
case EFFECT_ANIMATOR_CHANNELS.VARIANT:
29+
component = VariantKeyframePanel
30+
break
31+
32+
case EFFECT_ANIMATOR_CHANNELS.FUNCTION:
33+
component = CommandsKeyframePanel
34+
break
35+
36+
default:
37+
currentUpdatePromise = null
38+
resolve()
39+
return
40+
}
41+
42+
unmountCallback = injectComponent({
43+
component,
44+
props: { keyframe },
45+
elementSelector() {
46+
return Panels.keyframe.node
47+
},
48+
postMount() {
49+
currentUpdatePromise = null
50+
resolve()
51+
},
52+
})
53+
} else {
54+
currentUpdatePromise = null
55+
resolve()
56+
}
57+
})
58+
}
1059

1160
registerPatch({
1261
id: 'animated_java:panel/custom-keyframe-data-points',
@@ -18,46 +67,8 @@ registerPatch({
1867
Language.data['timeline.function'] = translate('effect_animator.timeline.function')
1968

2069
const unsubs = [
21-
EVENTS.UPDATE_KEYFRAME_SELECTION.subscribe(async () => {
22-
await unmountCallback?.()
23-
unmountCallback = null
24-
25-
const keyframe = Timeline.selected.at(0)
26-
const isCustomKeyframe = isCustomKeyframeChannel(keyframe?.channel ?? '')
27-
28-
if (keyframe && isCustomKeyframe) {
29-
let component: any
30-
switch (keyframe.channel) {
31-
case EFFECT_ANIMATOR_CHANNELS.VARIANT:
32-
component = VariantKeyframePanel
33-
break
34-
35-
case EFFECT_ANIMATOR_CHANNELS.FUNCTION:
36-
component = CommandsKeyframePanel
37-
break
38-
39-
default:
40-
console.error(`Unknown custom keyframe channel: '${keyframe.channel}'`)
41-
return
42-
}
43-
44-
unmountCallback = injectComponent({
45-
component,
46-
props: { keyframe },
47-
elementSelector(): HTMLElement | null {
48-
return document.querySelector(
49-
'#panel_keyframe .panel_vue_wrapper .keyframe_data_point'
50-
)
51-
},
52-
// hideTargetChildren: true,
53-
})
54-
}
55-
}),
56-
57-
EVENTS.UNSELECT_AJ_PROJECT.subscribe(async () => {
58-
await unmountCallback?.()
59-
unmountCallback = null
60-
}),
70+
EVENTS.UPDATE_KEYFRAME_SELECTION.subscribe(() => void updatePanel()),
71+
EVENTS.UNSELECT_AJ_PROJECT.subscribe(() => void updatePanel()),
6172
]
6273

6374
return { unsubs }

src/svelteComponents/keyframeEasings.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
} else {
5959
kf.easing = getEasingFunctionName(type, mode)
6060
}
61+
Project.saved = false
6162
}
6263
6364
function setKeyframeEasingArg(kf: _Keyframe, arg: number | undefined) {
@@ -66,6 +67,7 @@
6667
} else {
6768
kf.easingArgs = [arg]
6869
}
70+
Project.saved = false
6971
}
7072
7173
function getEasingFunctionName(type: string, mode = 'inout') {

0 commit comments

Comments
 (0)