11import { Serialized } from "@/types/node" ;
22import { toast } from "sonner" ;
33import { v4 as uuidv4 } from "uuid" ;
4- import { ConnectableEntity } from "./stageObject/abstract/ConnectableEntity" ;
54
65export 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