@@ -123,7 +123,7 @@ export interface IBlueprintFormatJSON {
123
123
/**
124
124
* The project settings of the Blueprint
125
125
*/
126
- blueprint_settings ?: NonNullable < typeof Project > [ 'animated_java' ]
126
+ blueprint_settings ?: Partial < NonNullable < typeof Project > [ 'animated_java' ] >
127
127
/**
128
128
* The variants of the Blueprint
129
129
*/
@@ -156,6 +156,7 @@ export interface IBlueprintFormatJSON {
156
156
export function convertToBlueprint ( ) {
157
157
// Convert the current project to a Blueprint
158
158
Project ! . save_path = ''
159
+ Project ! . last_used_export_namespace = ''
159
160
160
161
for ( const group of Group . all ) {
161
162
group . createUniqueName ( Group . all . filter ( g => g !== group ) )
@@ -171,7 +172,17 @@ export function convertToBlueprint() {
171
172
}
172
173
173
174
export function getDefaultProjectSettings ( ) : ModelProject [ 'animated_java' ] {
174
- return blueprintSettings . defaultValues
175
+ return { ...blueprintSettings . defaultValues }
176
+ }
177
+
178
+ function initializeBoundingBoxUpdate ( ) {
179
+ if ( boundingBoxUpdateIntervalId == undefined ) {
180
+ boundingBoxUpdateIntervalId = setInterval ( ( ) => {
181
+ updateBoundingBox ( )
182
+ } , 500 )
183
+ events . UNLOAD . subscribe ( ( ) => clearInterval ( boundingBoxUpdateIntervalId ) , true )
184
+ events . UNINSTALL . subscribe ( ( ) => clearInterval ( boundingBoxUpdateIntervalId ) , true )
185
+ }
175
186
}
176
187
177
188
export function updateBoundingBox ( ) {
@@ -260,11 +271,14 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
260
271
}
261
272
262
273
if ( model . blueprint_settings ) {
263
- Project . animated_java = { ...Project . animated_java , ...model . blueprint_settings }
274
+ Project . animated_java = {
275
+ ...blueprintSettings . defaultValues ,
276
+ ...model . blueprint_settings ,
277
+ }
264
278
}
265
279
266
280
Project . last_used_export_namespace =
267
- model . meta . last_used_export_namespace || Project . animated_java . export_namespace
281
+ model . meta . last_used_export_namespace ?? Project . animated_java . export_namespace
268
282
269
283
if ( model . textures ) {
270
284
for ( const texture of model . textures ) {
@@ -410,7 +424,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
410
424
save_location : Project . save_path ,
411
425
last_used_export_namespace : Project . last_used_export_namespace ,
412
426
} ,
413
- blueprint_settings : Project . animated_java ,
427
+ blueprint_settings : { ... Project . animated_java } ,
414
428
resolution : {
415
429
width : Project . texture_width || 16 ,
416
430
height : Project . texture_height || 16 ,
@@ -562,25 +576,19 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
562
576
onSetup ( project , newModel ) {
563
577
if ( ! Project ) return
564
578
console . log ( 'Animated Java Blueprint format setup' )
579
+
565
580
const defaults = getDefaultProjectSettings ( )
566
- Project . animated_java ??= defaults
567
- for ( const [ key , value ] of Object . entries ( defaults ) as Array <
568
- [ keyof ModelProject [ 'animated_java' ] , any ]
569
- > ) {
570
- if ( Project . animated_java [ key ] === undefined ) {
571
- // @ts -ignore
572
- Project . animated_java [ key ] = value
573
- }
581
+ if ( newModel ) {
582
+ Project . animated_java = defaults
583
+ Project . last_used_export_namespace = ''
584
+ } else {
585
+ Project . animated_java = { ...defaults , ...Project ! . animated_java }
574
586
}
575
587
576
588
const thisProject = Project
577
589
Project . variants ??= [ ]
578
- Project . last_used_export_namespace = Project . animated_java . export_namespace
579
- const updateBoundingBoxIntervalId = setInterval ( ( ) => {
580
- updateBoundingBox ( )
581
- } , 500 )
582
- events . UNLOAD . subscribe ( ( ) => clearInterval ( updateBoundingBoxIntervalId ) , true )
583
- events . UNINSTALL . subscribe ( ( ) => clearInterval ( updateBoundingBoxIntervalId ) , true )
590
+
591
+ initializeBoundingBoxUpdate ( )
584
592
585
593
Project . loadingPromises ??= [ ]
586
594
Project . loadingPromises . push (
@@ -617,9 +625,13 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
617
625
)
618
626
} ,
619
627
620
- onActivation ( ) {
621
- console . log ( 'Animated Java Blueprint format activated' )
622
- } ,
628
+ // onActivation() {
629
+ // console.group('Animated Java Blueprint format activated')
630
+ // },
631
+
632
+ // onDeactivation() {
633
+ // console.group('Animated Java Blueprint format deactivated')
634
+ // },
623
635
624
636
codec : BLUEPRINT_CODEC ,
625
637
0 commit comments