Skip to content

Commit 0bdb7f2

Browse files
committed
✨ Add support to blueprint dfu for config changes
1 parent 5bad9f0 commit 0bdb7f2

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/formats/blueprint/dfu.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type IBlueprintFormatJSON, getDefaultProjectSettings } from '.'
44
import TransparentTexture from '../../assets/transparent.png'
55
import { PACKAGE } from '../../constants'
66
import { openUnexpectedErrorDialog } from '../../interface/dialog/unexpectedError'
7-
import { BoneConfig } from '../../nodeConfigs'
7+
import { DisplayEntityConfig } from '../../nodeConfigs'
88

99
export function process(model: any): IBlueprintFormatJSON {
1010
if (model?.meta?.model_format === 'animatedJava/ajmodel') {
@@ -85,7 +85,7 @@ export function process(model: any): IBlueprintFormatJSON {
8585
delete model.blueprint_settings[key]
8686
}
8787

88-
model.meta.format_version = PACKAGE.version
88+
model.meta.format_version = '1.8.0'
8989
console.log('Upgrade complete', JSON.parse(JSON.stringify(model)))
9090

9191
return model
@@ -312,7 +312,7 @@ function updateModelTo1_0pre1(model: any) {
312312
if (typeof node === 'string') return
313313
bones.push(node.uuid as string)
314314
node.configs = {
315-
default: new BoneConfig().toJSON(),
315+
default: new DisplayEntityConfig().toJSON(),
316316
variants: {},
317317
}
318318
node.children.forEach((child: any) => {
@@ -625,6 +625,33 @@ function updateModelTo1_8_0(model: any) {
625625
delete display.backgroundAlpha
626626
}
627627
}
628+
// Update old config structure for display entities
629+
const displayEntities = fixed.elements.filter(
630+
e =>
631+
e.type === AnimatedJava.TextDisplay.type ||
632+
e.type === AnimatedJava.VanillaItemDisplay.type ||
633+
e.type === AnimatedJava.VanillaBlockDisplay.type
634+
)
635+
for (const displayEntity of displayEntities) {
636+
if (displayEntity.config) {
637+
if (displayEntity.config.custom_name !== undefined) {
638+
displayEntity.config.on_apply_function ??= ''
639+
displayEntity.config.on_apply_function += `\n# Auto-upgraded custom name setting (May need fixing):\ndata modify entity @s CustomName set value '${displayEntity.config.custom_name}'\n`
640+
delete displayEntity.config.custom_name
641+
}
642+
if (displayEntity.config.custom_name_visible) {
643+
displayEntity.config.on_apply_function ??= ''
644+
displayEntity.config.on_apply_function += `\n# Auto-upgraded custom name visibility setting:\ndata modify entity @s CustomNameVisible set value ${displayEntity.config.custom_name_visible}\n`
645+
delete displayEntity.config.custom_name_visible
646+
}
647+
648+
displayEntity.configs = {
649+
default: displayEntity.config,
650+
variants: {},
651+
}
652+
delete displayEntity.config
653+
}
654+
}
628655
// Update locators to use new event function names
629656
const locators = fixed.elements.filter(e => e.type === Locator.prototype.type)
630657
for (const locator of locators) {
@@ -641,7 +668,6 @@ function updateModelTo1_8_0(model: any) {
641668

642669
// Update commands keyframes to use new keyframe channel name
643670
if (Array.isArray(fixed.animations)) {
644-
debugger
645671
for (const animation of fixed.animations) {
646672
for (const animator of Object.values<any>(animation.animators ?? {})) {
647673
if (!Array.isArray(animator.keyframes)) continue

0 commit comments

Comments
 (0)