Skip to content

Commit 7cba78e

Browse files
committed
🩹 Update old code to new Blockbench Types
1 parent d058fee commit 7cba78e

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

src/components/dialogItems/select.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
options,
1818
value: value.get(),
1919
onChange() {
20-
value.set(selectInput.node.getAttribute('value'))
20+
const v = selectInput.node.getAttribute('value')
21+
if (v == undefined) {
22+
console.warn('Select value is undefined')
23+
return
24+
}
25+
value.set(v)
2126
},
2227
})
2328

src/components/dialogItems/vector2d.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
target: HTMLElement,
4444
value: Valuable<number>,
4545
min?: number,
46-
max?: number,
46+
max?: number
4747
) {
4848
addEventListeners(target, 'mousedown touchstart', (e1: any) => {
4949
convertTouchEvent(e1)
@@ -56,15 +56,15 @@
5656
Math.clamp(
5757
value.get() + (difference - last_difference),
5858
min !== undefined ? min : -Infinity,
59-
max !== undefined ? max : Infinity,
60-
),
59+
max !== undefined ? max : Infinity
60+
)
6161
)
6262
last_difference = difference
6363
}
6464
}
6565
function stop(e2: any) {
66-
removeEventListeners(document, 'mousemove touchmove', move, null)
67-
removeEventListeners(document, 'mouseup touchend', stop, null)
66+
removeEventListeners(document, 'mousemove touchmove', move)
67+
removeEventListeners(document, 'mouseup touchend', stop)
6868
}
6969
addEventListeners(document as unknown as any, 'mousemove touchmove', move)
7070
addEventListeners(document as unknown as any, 'mouseup touchend', stop)
@@ -75,8 +75,8 @@
7575
Math.clamp(
7676
molangParser.parse(value.get()),
7777
min !== undefined ? min : -Infinity,
78-
max !== undefined ? max : Infinity,
79-
),
78+
max !== undefined ? max : Infinity
79+
)
8080
)
8181
})
8282
}

src/components/dialogItems/vector3d.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
target: HTMLElement,
5353
value: Valuable<number>,
5454
min?: number,
55-
max?: number,
55+
max?: number
5656
) {
5757
addEventListeners(target, 'mousedown touchstart', (e1: any) => {
5858
convertTouchEvent(e1)
@@ -65,15 +65,15 @@
6565
Math.clamp(
6666
value.get() + (difference - last_difference),
6767
min !== undefined ? min : -Infinity,
68-
max !== undefined ? max : Infinity,
69-
),
68+
max !== undefined ? max : Infinity
69+
)
7070
)
7171
last_difference = difference
7272
}
7373
}
7474
function stop(e2: any) {
75-
removeEventListeners(document, 'mousemove touchmove', move, null)
76-
removeEventListeners(document, 'mouseup touchend', stop, null)
75+
removeEventListeners(document, 'mousemove touchmove', move)
76+
removeEventListeners(document, 'mouseup touchend', stop)
7777
}
7878
addEventListeners(document as unknown as any, 'mousemove touchmove', move)
7979
addEventListeners(document as unknown as any, 'mouseup touchend', stop)
@@ -84,8 +84,8 @@
8484
Math.clamp(
8585
molangParser.parse(value.get()),
8686
min !== undefined ? min : -Infinity,
87-
max !== undefined ? max : Infinity,
88-
),
87+
max !== undefined ? max : Infinity
88+
)
8989
)
9090
})
9191
}

src/components/keyframePanels/variantKeyframePanel.svelte

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
<script lang="ts" context="module">
1+
<script lang="ts">
2+
import { getKeyframeVariant, setKeyframeVariant } from '../../mods/customKeyframesMod'
23
import { Valuable } from '../../util/stores'
34
import { translate } from '../../util/translation'
45
import { Variant } from '../../variants'
5-
import { getKeyframeVariant, setKeyframeVariant } from '../../mods/customKeyframesMod'
6-
</script>
7-
8-
<script lang="ts">
96
export let selectedKeyframe: _Keyframe
107
const keyframeValue = new Valuable<string>(getKeyframeVariant(selectedKeyframe) as string)
118
let selectContainer: HTMLDivElement
@@ -15,15 +12,20 @@
1512
})
1613
1714
const options = Object.fromEntries(
18-
Variant.all.map(variant => [variant.uuid, variant.displayName]),
15+
Variant.all.map(variant => [variant.uuid, variant.displayName])
1916
)
2017
2118
// @ts-ignore
2219
const selectInput = new Interface.CustomElements.SelectInput('keyframe-variant-selector', {
2320
options,
2421
value: keyframeValue.get(),
2522
onChange() {
26-
keyframeValue.set(selectInput.node.getAttribute('value'))
23+
const value = selectInput.node.getAttribute('value')
24+
if (value == undefined) {
25+
console.warn('Variant value is undefined')
26+
return
27+
}
28+
keyframeValue.set(value)
2729
Animator.preview()
2830
},
2931
})

src/mods/panelMod.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ createBlockbenchMod(
88
panel: Interface.Panels.animations,
99
},
1010
context => {
11-
const originalFilesFunction = context.panel.inside_vue.$options.computed.files
11+
const originalFilesFunction = context.panel.inside_vue.$options.computed!.files as () => any
1212

13-
context.panel.inside_vue.$options.computed.files = function (this) {
13+
context.panel.inside_vue.$options.computed!.files = function (this) {
1414
if (Format.id === BLUEPRINT_FORMAT.id) {
1515
return {
1616
'': {
@@ -23,13 +23,12 @@ createBlockbenchMod(
2323
},
2424
}
2525
}
26-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
2726
return originalFilesFunction.call(this)
2827
}
2928

3029
return { ...context, originalFilesFunction }
3130
},
3231
context => {
33-
context.panel.inside_vue.$options.computed.files = context.originalFilesFunction
32+
context.panel.inside_vue.$options.computed!.files = context.originalFilesFunction
3433
}
3534
)

src/mods/pluginsDialogMod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ injectSvelteCompomponentMod({
1919
createBlockbenchMod(
2020
`${PACKAGE.name}:pluginsDialogMod`,
2121
{
22+
// @ts-expect-error
2223
originalSelect: Plugins.dialog.component.methods.selectPlugin,
2324
},
2425
context => {
26+
// @ts-expect-error
2527
Plugins.dialog.component.methods.selectPlugin = function (this, plugin: BBPlugin) {
2628
const result = context.originalSelect.call(this, plugin)
2729
SELECTED_PLUGIN.set(plugin)
@@ -32,6 +34,7 @@ createBlockbenchMod(
3234
return context
3335
},
3436
context => {
37+
// @ts-expect-error
3538
Plugins.dialog.component.methods.selectPlugin = context.originalSelect
3639
}
3740
)

0 commit comments

Comments
 (0)