Skip to content

Commit e540a32

Browse files
committed
🐛 修复导入部分旧版文件时报错
1 parent 093805b commit e540a32

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

app/src/core/service/GlobalMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ export async function onOpenFile(uri?: URI, source: string = "unknown") {
583583
}
584584
const project = new Project(uri);
585585
if (stage) {
586-
project.stage = deserialize(stage);
586+
project.stage = deserialize(stage, project);
587+
console.log(project.stage);
587588
}
588589
const t = performance.now();
589590
loadAllServices(project);

app/src/core/stage/ProjectUpgrader.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Serialized } from "@/types/node";
22
import { toast } from "sonner";
33
import { v4 as uuidv4 } from "uuid";
4-
import { ConnectableEntity } from "./stageObject/abstract/ConnectableEntity";
54

65
export namespace ProjectUpgrader {
76
export function upgrade(data: Record<string, any>): Record<string, any> {
@@ -323,16 +322,14 @@ export namespace ProjectUpgrader {
323322
// 升级json数据到最新版本
324323
json = ProjectUpgrader.upgrade(json);
325324

326-
const uuidMap = new Map<string, ConnectableEntity>();
325+
const uuidMap = new Map<string, Record<string, any>>();
327326
const stage: Record<string, any>[] = [];
328327

329328
// 遍历每一个实体
330329
for (const entity of json.entities) {
331-
uuidMap.set(entity.uuid, entity);
332-
330+
let data;
333331
if (entity.type === "core:text_node") {
334-
uuidMap.set(entity.uuid, entity.uuid);
335-
stage.push({
332+
data = {
336333
_: "TextNode",
337334
uuid: entity.uuid,
338335
text: entity.text,
@@ -355,9 +352,15 @@ export namespace ProjectUpgrader {
355352
},
356353
],
357354
},
358-
color: entity.color,
355+
color: {
356+
_: "Color",
357+
r: entity.color[0],
358+
g: entity.color[1],
359+
b: entity.color[2],
360+
a: entity.color[3],
361+
},
359362
sizeAdjust: entity.sizeAdjust,
360-
});
363+
};
361364
} else if (entity.type === "core:pen_stroke") {
362365
// 涂鸦
363366
} else if (entity.type === "core:image_node") {
@@ -375,6 +378,10 @@ export namespace ProjectUpgrader {
375378
} else {
376379
console.warn(`未知的实体类型${entity.type}`);
377380
}
381+
if (data) {
382+
stage.push(data);
383+
uuidMap.set(entity.uuid, data);
384+
}
378385
}
379386

380387
for (const association of json.associations) {
@@ -395,7 +402,13 @@ export namespace ProjectUpgrader {
395402
uuid: association.uuid,
396403
associationList: [fromNode, toNode],
397404
text: association.text,
398-
color: association.color,
405+
color: {
406+
_: "Color",
407+
r: association.color[0],
408+
g: association.color[1],
409+
b: association.color[2],
410+
a: association.color[3],
411+
},
399412
sourceRectangleRate: {
400413
_: "Vector",
401414
x: association.sourceRectRate[0],

0 commit comments

Comments
 (0)