using Godot; using System.Collections.Generic; namespace Rokojori { public class SceneFile { public static SceneFileEntry Create( string type, string line ) { var entry = new SceneFileEntry(); entry.type = type; entry.line = line; entry.Parse(); return entry; } public static SceneFileEntry Seperator() { return Create( GodotTextSceneLexer.SeperatorMatcher.type, "" ); } public List entries = new List(); public List objects = new List(); public GDSceneSFO gdScene; public NodeSFO rootNode; public List nodes = new List(); public Dictionary nodeMap = new Dictionary(); public List extResources = new List(); public List subResourceSFOs = new List(); public SceneFile GetSerializableJSONVersion() { var file = new SceneFile(); file.entries = entries; return file; } public void CreateObjects() { entries.ForEach( ( e )=> { if ( ! e.hasHeader ) { return; } var sfo = SceneFileObjectFactory.Create( e ); if ( sfo == null ) { return; } if ( sfo is GDSceneSFO ) { gdScene = (GDSceneSFO) sfo; } else if ( sfo is NodeSFO ) { var node = (NodeSFO) sfo; nodes.Add( node ); if ( node.elementPath == "." ) { rootNode = node; } nodeMap[ node.elementPath ] = node; // RJLog.Log( "'" + node.elementPath + "'", node.name.value ); } else if ( sfo is ExtResourceSFO ) { extResources.Add( (ExtResourceSFO) sfo ); } else if ( sfo is SubResourceSFO ) { subResourceSFOs.Add( (SubResourceSFO) sfo ); } objects.Add( sfo ); } ); nodes.ForEach( ( n )=> { n.ResolveParent( nodeMap, rootNode ); } ); } } }