@@ -15,23 +15,61 @@ struct Cli {
1515async fn load_scene_from_file ( file_path : & str ) -> Scene {
1616 let file: String = fs:: read_to_string ( file_path) . expect ( "failed to read file" ) ;
1717 let canvas_file = parse ( & file) . expect ( "failed to parse file" ) ;
18- let nodes = canvas_file. document . nodes ;
19- // entry_scene_id or scenes[0]
20- let scene_id = canvas_file. document . entry_scene_id . unwrap_or (
21- canvas_file
22- . document
23- . scenes
24- . keys ( )
25- . next ( )
26- . unwrap ( )
27- . to_string ( ) ,
28- ) ;
29- let scene = canvas_file. document . scenes . get ( & scene_id) . unwrap ( ) ;
18+
19+ let links = canvas_file. document . links ;
20+
21+ // Determine scene_id
22+ let scene_id = canvas_file
23+ . document
24+ . entry_scene_id
25+ . or_else ( || canvas_file. document . scenes_ref . first ( ) . cloned ( ) )
26+ . expect ( "no scene found" ) ;
27+
28+ // Extract scene metadata from SceneNode
29+ let ( scene_name, _bg_color) = if let Some ( cg:: io:: io_grida:: JSONNode :: Scene ( scene_node) ) =
30+ canvas_file. document . nodes . get ( & scene_id)
31+ {
32+ ( scene_node. name . clone ( ) , scene_node. background_color . clone ( ) )
33+ } else {
34+ ( scene_id. clone ( ) , None )
35+ } ;
36+
37+ // Get scene children from links
38+ let scene_children = links
39+ . get ( & scene_id)
40+ . and_then ( |c| c. clone ( ) )
41+ . unwrap_or_default ( ) ;
42+
43+ // Convert nodes to repository, filtering out scene nodes and populating children from links
44+ let mut node_repo = cg:: node:: repository:: NodeRepository :: new ( ) ;
45+ for ( node_id, json_node) in canvas_file. document . nodes {
46+ // Skip scene nodes - they're handled separately
47+ if matches ! ( json_node, cg:: io:: io_grida:: JSONNode :: Scene ( _) ) {
48+ continue ;
49+ }
50+
51+ let mut node: cg:: node:: schema:: Node = json_node. into ( ) ;
52+
53+ // Populate children from links
54+ if let Some ( children_opt) = links. get ( & node_id) {
55+ if let Some ( children) = children_opt {
56+ match & mut node {
57+ cg:: node:: schema:: Node :: Container ( n) => n. children = children. clone ( ) ,
58+ cg:: node:: schema:: Node :: Group ( n) => n. children = children. clone ( ) ,
59+ cg:: node:: schema:: Node :: BooleanOperation ( n) => n. children = children. clone ( ) ,
60+ _ => { } // Other nodes don't have children
61+ }
62+ }
63+ }
64+
65+ node_repo. insert ( node) ;
66+ }
67+
3068 Scene {
31- nodes : nodes . into_iter ( ) . map ( | ( k , v ) | ( k , v . into ( ) ) ) . collect ( ) ,
69+ nodes : node_repo ,
3270 id : scene_id,
33- name : scene . name . clone ( ) ,
34- children : scene . children . clone ( ) ,
71+ name : scene_name ,
72+ children : scene_children ,
3573 background_color : Some ( CGColor ( 230 , 230 , 230 , 255 ) ) ,
3674 }
3775}
0 commit comments