@@ -121,7 +121,7 @@ export interface IBlueprintFormatJSON {
121
121
/**
122
122
* The project settings of the Blueprint
123
123
*/
124
- blueprint_settings ?: NonNullable < typeof Project > [ 'animated_java' ]
124
+ blueprint_settings ?: Partial < NonNullable < typeof Project > [ 'animated_java' ] >
125
125
/**
126
126
* The variants of the Blueprint
127
127
*/
@@ -154,6 +154,7 @@ export interface IBlueprintFormatJSON {
154
154
export function convertToBlueprint ( ) {
155
155
// Convert the current project to a Blueprint
156
156
Project ! . save_path = ''
157
+ Project ! . last_used_export_namespace = ''
157
158
158
159
for ( const group of Group . all ) {
159
160
group . createUniqueName ( Group . all . filter ( g => g !== group ) )
@@ -169,7 +170,17 @@ export function convertToBlueprint() {
169
170
}
170
171
171
172
export function getDefaultProjectSettings ( ) : ModelProject [ 'animated_java' ] {
172
- return blueprintSettings . defaultValues
173
+ return { ...blueprintSettings . defaultValues }
174
+ }
175
+
176
+ function initializeBoundingBoxUpdate ( ) {
177
+ if ( boundingBoxUpdateIntervalId == undefined ) {
178
+ boundingBoxUpdateIntervalId = setInterval ( ( ) => {
179
+ updateBoundingBox ( )
180
+ } , 500 )
181
+ events . UNLOAD . subscribe ( ( ) => clearInterval ( boundingBoxUpdateIntervalId ) , true )
182
+ events . UNINSTALL . subscribe ( ( ) => clearInterval ( boundingBoxUpdateIntervalId ) , true )
183
+ }
173
184
}
174
185
175
186
export function updateBoundingBox ( ) {
@@ -258,11 +269,14 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
258
269
}
259
270
260
271
if ( model . blueprint_settings ) {
261
- Project . animated_java = { ...Project . animated_java , ...model . blueprint_settings }
272
+ Project . animated_java = {
273
+ ...blueprintSettings . defaultValues ,
274
+ ...model . blueprint_settings ,
275
+ }
262
276
}
263
277
264
278
Project . last_used_export_namespace =
265
- model . meta . last_used_export_namespace || Project . animated_java . export_namespace
279
+ model . meta . last_used_export_namespace ?? Project . animated_java . export_namespace
266
280
267
281
if ( model . textures ) {
268
282
for ( const texture of model . textures ) {
@@ -408,7 +422,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
408
422
save_location : Project . save_path ,
409
423
last_used_export_namespace : Project . last_used_export_namespace ,
410
424
} ,
411
- blueprint_settings : Project . animated_java ,
425
+ blueprint_settings : { ... Project . animated_java } ,
412
426
resolution : {
413
427
width : Project . texture_width || 16 ,
414
428
height : Project . texture_height || 16 ,
@@ -552,25 +566,19 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
552
566
onSetup ( project , newModel ) {
553
567
if ( ! Project ) return
554
568
console . log ( 'Animated Java Blueprint format setup' )
569
+
555
570
const defaults = getDefaultProjectSettings ( )
556
- Project . animated_java ??= defaults
557
- for ( const [ key , value ] of Object . entries ( defaults ) as Array <
558
- [ keyof ModelProject [ 'animated_java' ] , any ]
559
- > ) {
560
- if ( Project . animated_java [ key ] === undefined ) {
561
- // @ts -ignore
562
- Project . animated_java [ key ] = value
563
- }
571
+ if ( newModel ) {
572
+ Project . animated_java = defaults
573
+ Project . last_used_export_namespace = ''
574
+ } else {
575
+ Project . animated_java = { ...defaults , ...Project ! . animated_java }
564
576
}
565
577
566
578
const thisProject = Project
567
579
Project . variants ??= [ ]
568
- Project . last_used_export_namespace = Project . animated_java . export_namespace
569
- const updateBoundingBoxIntervalId = setInterval ( ( ) => {
570
- updateBoundingBox ( )
571
- } , 500 )
572
- events . UNLOAD . subscribe ( ( ) => clearInterval ( updateBoundingBoxIntervalId ) , true )
573
- events . UNINSTALL . subscribe ( ( ) => clearInterval ( updateBoundingBoxIntervalId ) , true )
580
+
581
+ initializeBoundingBoxUpdate ( )
574
582
575
583
Project . loadingPromises ??= [ ]
576
584
Project . loadingPromises . push (
@@ -607,9 +615,13 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
607
615
)
608
616
} ,
609
617
610
- onActivation ( ) {
611
- console . log ( 'Animated Java Blueprint format activated' )
612
- } ,
618
+ // onActivation() {
619
+ // console.group('Animated Java Blueprint format activated')
620
+ // },
621
+
622
+ // onDeactivation() {
623
+ // console.group('Animated Java Blueprint format deactivated')
624
+ // },
613
625
614
626
codec : BLUEPRINT_CODEC ,
615
627
0 commit comments