Skip to content

Commit adcc9b9

Browse files
committed
🛠️ Add NBT validation to bone configs
1 parent 5125830 commit adcc9b9

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed

src/components/boneConfigDialog.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
</script>
1313

1414
<script lang="ts">
15+
import { NbtCompound, NbtTag } from 'deepslate'
16+
1517
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1618
1719
export let variant: Variant
@@ -36,6 +38,26 @@
3638
horizontal: translate('dialog.bone_config.billboard.options.horizontal'),
3739
center: translate('dialog.bone_config.billboard.options.center'),
3840
}
41+
42+
const nbtChecker: DialogItemValueChecker<string> = value => {
43+
let parsedNbt: NbtTag | undefined
44+
try {
45+
parsedNbt = NbtTag.fromString(value)
46+
} catch (e: any) {
47+
return {
48+
type: 'error',
49+
message: translate('dialog.bone_config.nbt.invalid_nbt.error', e.message),
50+
}
51+
}
52+
if (!(parsedNbt instanceof NbtCompound)) {
53+
return {
54+
type: 'error',
55+
message: translate('dialog.bone_config.nbt.invalid_nbt.not_compound'),
56+
}
57+
}
58+
59+
return { type: 'success', message: '' }
60+
}
3961
</script>
4062

4163
<div>
@@ -150,6 +172,7 @@
150172
label={translate('dialog.bone_config.nbt.title')}
151173
tooltip={translate('dialog.bone_config.nbt.description')}
152174
bind:value={nbt}
175+
valueChecker={nbtChecker}
153176
/>
154177
{:else}
155178
<Select

src/components/dialogItems/baseDialogItem.svelte

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@
3737
<div class="base_dialog_item">
3838
{#if error_text}
3939
<div class="error_text">
40-
<i class="fa fa-exclamation-circle dialog_form_error text_icon" />{error_text}
40+
<i class="fa fa-exclamation-circle dialog_form_error text_icon" />
41+
<div class="error_lines">
42+
{#each error_text.split('\n') as text}
43+
<div>{text}</div>
44+
{/each}
45+
</div>
4146
</div>
4247
{:else if warning_text}
4348
<div class="warning_text">
44-
<i class="fa fa-exclamation-triangle dialog_form_warning text_icon" />{warning_text}
49+
<i class="fa fa-exclamation-triangle dialog_form_warning text_icon" />
50+
<div class="warning_lines">
51+
{#each warning_text.split('\n') as text}
52+
<div>{text}</div>
53+
{/each}
54+
</div>
4555
</div>
4656
{/if}
4757
</div>
@@ -57,15 +67,27 @@
5767
flex-grow: 1;
5868
}
5969
.warning_text {
70+
display: flex;
71+
align-items: center;
6072
color: var(--color-warning);
6173
font-family: var(--font-code);
6274
font-size: 0.8em;
6375
}
76+
.warning_lines {
77+
display: flex;
78+
flex-direction: column;
79+
}
6480
.error_text {
81+
display: flex;
82+
align-items: center;
6583
color: var(--color-error);
6684
font-family: var(--font-code);
6785
font-size: 0.8em;
6886
}
87+
.error_lines {
88+
display: flex;
89+
flex-direction: column;
90+
}
6991
.text_icon {
7092
margin-right: 8px;
7193
}

src/components/vanillaBlockDisplayConfigDialog.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</script>
1212

1313
<script lang="ts">
14+
import { NbtCompound, NbtTag } from 'deepslate'
15+
1416
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1517
1618
export let billboard: Valuable<string>
@@ -31,6 +33,26 @@
3133
horizontal: translate('dialog.bone_config.billboard.options.horizontal'),
3234
center: translate('dialog.bone_config.billboard.options.center'),
3335
}
36+
37+
const nbtChecker: DialogItemValueChecker<string> = value => {
38+
let parsedNbt: NbtTag | undefined
39+
try {
40+
parsedNbt = NbtTag.fromString(value)
41+
} catch (e: any) {
42+
return {
43+
type: 'error',
44+
message: translate('dialog.bone_config.nbt.invalid_nbt.error', e.message),
45+
}
46+
}
47+
if (!(parsedNbt instanceof NbtCompound)) {
48+
return {
49+
type: 'error',
50+
message: translate('dialog.bone_config.nbt.invalid_nbt.not_compound'),
51+
}
52+
}
53+
54+
return { type: 'success', message: '' }
55+
}
3456
</script>
3557

3658
<div>
@@ -114,6 +136,7 @@
114136
label={translate('dialog.bone_config.nbt.title')}
115137
tooltip={translate('dialog.bone_config.nbt.description')}
116138
bind:value={nbt}
139+
valueChecker={nbtChecker}
117140
/>
118141
{:else}
119142
<Select

src/components/vanillaItemDisplayConfigDialog.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</script>
1212

1313
<script lang="ts">
14+
import { NbtCompound, NbtTag } from 'deepslate'
15+
1416
const pluginModeEnabled = !!Project?.animated_java?.enable_plugin_mode
1517
1618
export let billboard: Valuable<string>
@@ -31,6 +33,26 @@
3133
horizontal: translate('dialog.bone_config.billboard.options.horizontal'),
3234
center: translate('dialog.bone_config.billboard.options.center'),
3335
}
36+
37+
const nbtChecker: DialogItemValueChecker<string> = value => {
38+
let parsedNbt: NbtTag | undefined
39+
try {
40+
parsedNbt = NbtTag.fromString(value)
41+
} catch (e: any) {
42+
return {
43+
type: 'error',
44+
message: translate('dialog.bone_config.nbt.invalid_nbt.error', e.message),
45+
}
46+
}
47+
if (!(parsedNbt instanceof NbtCompound)) {
48+
return {
49+
type: 'error',
50+
message: translate('dialog.bone_config.nbt.invalid_nbt.not_compound'),
51+
}
52+
}
53+
54+
return { type: 'success', message: '' }
55+
}
3456
</script>
3557

3658
<div>
@@ -114,6 +136,7 @@
114136
label={translate('dialog.bone_config.nbt.title')}
115137
tooltip={translate('dialog.bone_config.nbt.description')}
116138
bind:value={nbt}
139+
valueChecker={nbtChecker}
117140
/>
118141
{:else}
119142
<Select

src/lang/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ animated_java.dialog.bone_config.invisible.description: Whether or not the bone
194194

195195
animated_java.dialog.bone_config.nbt.title: NBT
196196
animated_java.dialog.bone_config.nbt.description: The NBT to apply to the bone.
197+
animated_java.dialog.bone_config.nbt.invalid_nbt.not_compound: The NBT must be a compound tag! Eg. {CustomName:'"my name"'}
198+
animated_java.dialog.bone_config.nbt.invalid_nbt.error: |-
199+
Invalid NBT!
200+
{0}
197201
198202
animated_java.dialog.bone_config.billboard.title: Billboard
199203
animated_java.dialog.bone_config.billboard.description: Controls if this bone should pivot to face player when rendered. It can be fixed (both vertical and horizontal angles are fixed), vertical (faces player around vertical axis), horizontal (pivots around horizontal axis), and center (pivots around center point).

0 commit comments

Comments
 (0)