Skip to content

Commit 8eaf4c9

Browse files
committed
🐛 Blueprint settings from previously opened models leak into new, and converted models
This either fixes, or greatly improves the leaking issue.
1 parent 28f61be commit 8eaf4c9

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

src/blueprintFormat.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
154154
export 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

171172
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+
}
173184
}
174185

175186
export 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

src/interface/dialog/blueprintSettings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { PACKAGE } from '../../constants'
2-
import { SvelteDialog } from '../../util/svelteDialog'
3-
import { Valuable } from '../../util/stores'
1+
import { updateBoundingBox } from '../../blueprintFormat'
2+
import { defaultValues, ExportMode } from '../../blueprintSettings'
43
import BlueprintSettingsDialogSvelteComponent from '../../components/blueprintSettingsDialog.svelte'
4+
import { PACKAGE } from '../../constants'
5+
import { MinecraftVersion } from '../../systems/datapackCompiler/mcbFiles'
56
import { toSafeFuntionName } from '../../util/minecraftUtil'
6-
import { defaultValues, ExportMode } from '../../blueprintSettings'
7+
import { Valuable } from '../../util/stores'
8+
import { SvelteDialog } from '../../util/svelteDialog'
79
import { translate } from '../../util/translation'
8-
import { updateBoundingBox } from '../../blueprintFormat'
9-
import { MinecraftVersion } from '../../systems/datapackCompiler/mcbFiles'
1010

1111
function getSettings() {
1212
return {

0 commit comments

Comments
 (0)