@@ -121,7 +121,7 @@ export interface IBlueprintFormatJSON {
121121 /**
122122 * The project settings of the Blueprint
123123 */
124- blueprint_settings ?: NonNullable < typeof Project > [ 'animated_java' ]
124+ blueprint_settings ?: Partial < NonNullable < typeof Project > [ 'animated_java' ] >
125125 /**
126126 * The variants of the Blueprint
127127 */
@@ -154,6 +154,7 @@ export interface IBlueprintFormatJSON {
154154export function convertToBlueprint ( ) {
155155 // Convert the current project to a Blueprint
156156 Project ! . save_path = ''
157+ Project ! . last_used_export_namespace = ''
157158
158159 for ( const group of Group . all ) {
159160 group . createUniqueName ( Group . all . filter ( g => g !== group ) )
@@ -169,7 +170,17 @@ export function convertToBlueprint() {
169170}
170171
171172export 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+ }
173184}
174185
175186export function updateBoundingBox ( ) {
@@ -258,11 +269,14 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
258269 }
259270
260271 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+ }
262276 }
263277
264278 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
266280
267281 if ( model . textures ) {
268282 for ( const texture of model . textures ) {
@@ -408,7 +422,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
408422 save_location : Project . save_path ,
409423 last_used_export_namespace : Project . last_used_export_namespace ,
410424 } ,
411- blueprint_settings : Project . animated_java ,
425+ blueprint_settings : { ... Project . animated_java } ,
412426 resolution : {
413427 width : Project . texture_width || 16 ,
414428 height : Project . texture_height || 16 ,
@@ -552,25 +566,19 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
552566 onSetup ( project , newModel ) {
553567 if ( ! Project ) return
554568 console . log ( 'Animated Java Blueprint format setup' )
569+
555570 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 }
564576 }
565577
566578 const thisProject = Project
567579 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 ( )
574582
575583 Project . loadingPromises ??= [ ]
576584 Project . loadingPromises . push (
@@ -607,9 +615,13 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
607615 )
608616 } ,
609617
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+ // },
613625
614626 codec : BLUEPRINT_CODEC ,
615627
0 commit comments