using Godot; using Rokojori; using System.Collections.Generic; using System; namespace Rokojori.DocGenerator { public class ClassTypeEntry { public Type type; public string path; } public class DocGenerator { string path = ""; string outputPath = ""; List icons = new List(); public List classFiles = new List(); public List classTypes = new List(); public void Generate( string path, string outputPath, List icons ) { this.path = path; this.outputPath = outputPath; this.icons = icons; GetFiles(); CreateTypesFromFiles(); IncludeDefaultTypes(); GenerateDocsFromTypes(); } void GetFiles() { classFiles = FilesSync.GetFiles( path, f => f.fileExtension == ".cs", true ); } void IncludeDefaultTypes() { var defaultTypes = new List() { typeof( RJNetworkNode ), typeof( RJAction ), typeof( RJSensor ), typeof( RJSelector ), typeof( RJSensor ) }; defaultTypes.ForEach( ( dt )=> { var entry = new ClassTypeEntry(); entry.type = dt; entry.path = null; classTypes.Add( entry); } ); } void CreateTypesFromFiles() { var genericType = new EventSlot().GetType(); var namespaceLabel = "Rokojori"; var assembly = genericType.Assembly; classFiles.ForEach( ( cf )=> { var name = cf.fileName; var type = ReflectionHelper.GetTypeByName( namespaceLabel + "." + name ); if ( type == null ) { type = ReflectionHelper.GetTypeByNameFromAssembly( name, assembly ); } if ( type != null ) { var entry = new ClassTypeEntry(); entry.type = type; entry.path = cf.fullPath; classTypes.Add( entry); } } ); } void GenerateDocsFromTypes() { classTypes.ForEach( ( c )=> { var cdg = new ClassDocGenerator(); var cinfo = cdg.Create( c.path, c.type, icons ); var outputPath = FilePath.Join( this.outputPath, cinfo.name + ".json" ); FilesSync.SaveJSON( outputPath, cinfo ); } ); } } }