98 lines
2.2 KiB
C#
98 lines
2.2 KiB
C#
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<SceneFileEntry> entries = new List<SceneFileEntry>();
|
|
public List<SceneFileObject> objects = new List<SceneFileObject>();
|
|
|
|
public GDSceneSFO gdScene;
|
|
public NodeSFO rootNode;
|
|
public List<NodeSFO> nodes = new List<NodeSFO>();
|
|
public Dictionary<string,NodeSFO> nodeMap = new Dictionary<string, NodeSFO>();
|
|
public List<ExtResourceSFO> extResources = new List<ExtResourceSFO>();
|
|
public List<SubResourceSFO> subResourceSFOs = new List<SubResourceSFO>();
|
|
|
|
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 );
|
|
}
|
|
);
|
|
}
|
|
}
|
|
} |