Fix objects not showing up when imported multiple times

This commit is contained in:
Skyler Lehmkuhl 2025-01-18 00:25:36 -05:00
parent c76cc75337
commit c7151d6796
1 changed files with 23 additions and 19 deletions

View File

@ -4418,7 +4418,7 @@ async function _save(path) {
// console.log(action.name); // console.log(action.name);
// } // }
const fileData = { const fileData = {
version: "1.7.6", version: "1.7.7",
width: config.fileWidth, width: config.fileWidth,
height: config.fileHeight, height: config.fileHeight,
fps: config.framerate, fps: config.framerate,
@ -4598,13 +4598,12 @@ async function _open(path, returnJson = false) {
obj.parent = parentIdx; // Set the parent property obj.parent = parentIdx; // Set the parent property
} }
if (Array.isArray(obj.children)) { Object.values(obj).forEach(child => {
for (const child of obj.children) { if (typeof child === 'object' && child !== null) setParentReferences(child, obj.type === "GraphicsObject" ? obj.idx : parentIdx);
setParentReferences(child, obj.type === "GraphicsObject" ? obj.idx : parentIdx); })
}
}
} }
setParentReferences(file.json) setParentReferences(file.json)
console.log(file.json)
} }
if (file.version < "1.7.6") { if (file.version < "1.7.6") {
function restoreLineColors(obj) { function restoreLineColors(obj) {
@ -4796,23 +4795,27 @@ async function importFile() {
function assignUUIDs(obj, existing) { function assignUUIDs(obj, existing) {
const uuidCache = {}; // Cache to store UUIDs for existing values const uuidCache = {}; // Cache to store UUIDs for existing values
function deepAssign(obj) { function replaceUuids(obj) {
for (const [key, value] of Object.entries(obj)) { for (const [key, value] of Object.entries(obj)) {
if (typeof value === "object" && value !== null) { if (typeof value === "object" && value !== null) {
// Recurse for nested objects replaceUuids(value);
deepAssign(value);
} else if (value in existing && key != "name") { } else if (value in existing && key != "name") {
// If the value is in the "existing" list, assign a UUID
if (!uuidCache[value]) { if (!uuidCache[value]) {
uuidCache[value] = uuidv4(); // Store the generated UUID for the value uuidCache[value] = uuidv4();
} }
obj[key] = uuidCache[value]; // Assign the UUID to the object property obj[key] = uuidCache[value];
} else if (key in existing) { }
// If the value is in the "existing" list, assign a UUID }
if (!uuidCache[key]) { }
uuidCache[key] = uuidv4(); // Store the generated UUID for the value
} function replaceReferences(obj) {
obj[key] = uuidCache[key]; // Assign the UUID to the object property for (const [key, value] of Object.entries(obj)) {
if (key in existing) {
obj[uuidCache[key]] = obj[key];
delete obj[key]
}
if (typeof value === "object" && value !== null) {
replaceReferences(value);
} else if (value in uuidCache) { } else if (value in uuidCache) {
obj[key] = value obj[key] = value
} }
@ -4820,7 +4823,8 @@ async function importFile() {
} }
// Start the recursion with the provided object // Start the recursion with the provided object
deepAssign(obj); replaceUuids(obj);
replaceReferences(obj)
return obj; // Return the updated object return obj; // Return the updated object
} }