@@ -123,7 +123,7 @@ export interface IBlueprintFormatJSON {
123123 /**
124124 * The project settings of the Blueprint
125125 */
126- blueprint_settings ?: NonNullable < typeof Project > [ 'animated_java' ]
126+ blueprint_settings ?: Partial < NonNullable < typeof Project > [ 'animated_java' ] >
127127 /**
128128 * The variants of the Blueprint
129129 */
@@ -156,6 +156,7 @@ export interface IBlueprintFormatJSON {
156156export function convertToBlueprint ( ) {
157157 // Convert the current project to a Blueprint
158158 Project ! . save_path = ''
159+ Project ! . last_used_export_namespace = ''
159160
160161 for ( const group of Group . all ) {
161162 group . createUniqueName ( Group . all . filter ( g => g !== group ) )
@@ -171,7 +172,17 @@ export function convertToBlueprint() {
171172}
172173
173174export 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+ }
175186}
176187
177188export function updateBoundingBox ( ) {
@@ -260,11 +271,14 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
260271 }
261272
262273 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+ }
264278 }
265279
266280 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
268282
269283 if ( model . textures ) {
270284 for ( const texture of model . textures ) {
@@ -410,7 +424,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
410424 save_location : Project . save_path ,
411425 last_used_export_namespace : Project . last_used_export_namespace ,
412426 } ,
413- blueprint_settings : Project . animated_java ,
427+ blueprint_settings : { ... Project . animated_java } ,
414428 resolution : {
415429 width : Project . texture_width || 16 ,
416430 height : Project . texture_height || 16 ,
@@ -562,25 +576,19 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
562576 onSetup ( project , newModel ) {
563577 if ( ! Project ) return
564578 console . log ( 'Animated Java Blueprint format setup' )
579+
565580 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 }
574586 }
575587
576588 const thisProject = Project
577589 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 ( )
584592
585593 Project . loadingPromises ??= [ ]
586594 Project . loadingPromises . push (
@@ -617,9 +625,13 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
617625 )
618626 } ,
619627
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+ // },
623635
624636 codec : BLUEPRINT_CODEC ,
625637
0 commit comments