Remove Unneeded Generators
This commit is contained in:
parent
107614bcb7
commit
1cd28eb707
|
|
@ -1,139 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using Godot;
|
|
||||||
using Rokojori.DocGenerator;
|
|
||||||
|
|
||||||
namespace Rokojori;
|
|
||||||
|
|
||||||
[Tool,GlobalClass]
|
|
||||||
public partial class CSParserTest:Node
|
|
||||||
{
|
|
||||||
[Export]
|
|
||||||
public string defines = "a,b,c";
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public string formula = "";
|
|
||||||
[ExportToolButton( "Parse Formula" )]
|
|
||||||
public Callable parseFormulaButton => Callable.From(
|
|
||||||
()=>
|
|
||||||
{
|
|
||||||
ParseFormula();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
[Export( PropertyHint.File )]
|
|
||||||
public string path;
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public bool createGD = false;
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public bool createDocInfo = false;
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public bool createASTView = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public ASTViewContext.ViewType viewType = ASTViewContext.ViewType.Tree_Structure;
|
|
||||||
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public string docInfoPath = "res://.rokojori/cache/docs";
|
|
||||||
|
|
||||||
[ExportToolButton( "Parse" )]
|
|
||||||
public Callable parseButton => Callable.From(
|
|
||||||
()=>
|
|
||||||
{
|
|
||||||
Parse();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
void Parse()
|
|
||||||
{
|
|
||||||
var defines = new HashSet<string>();
|
|
||||||
defines.Add( GDScriptGenerator.GD_SCRIPT_TRANSPILING );
|
|
||||||
|
|
||||||
var parser = new CSParser( ProjectSettings.GlobalizePath( path ), defines );
|
|
||||||
|
|
||||||
var root = parser.root as CSFileRoot;
|
|
||||||
|
|
||||||
this.LogInfo( "Parsed Nodes:", root.parsedNodes.Count );
|
|
||||||
|
|
||||||
|
|
||||||
for ( int i = 0; i < root.parsedNodes.Count; i++ )
|
|
||||||
{
|
|
||||||
this.LogInfo( i, root.parsedNodes[ i ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( createGD )
|
|
||||||
{
|
|
||||||
CreateGDClass( root );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( createDocInfo )
|
|
||||||
{
|
|
||||||
CreateDocInfo( root );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( createASTView )
|
|
||||||
{
|
|
||||||
CreateASTView( root );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateASTView( CSFileRoot root )
|
|
||||||
{
|
|
||||||
var astView = this.GetOrCreateChild<ASTViewContext>( "AST View");
|
|
||||||
astView.viewType = viewType;
|
|
||||||
astView.Create( root );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateDocInfo( CSFileRoot root )
|
|
||||||
{
|
|
||||||
var objects = root.walker.FilterType<CSObjectDeclaration>( root );
|
|
||||||
|
|
||||||
var originalPath = FilePath.Absolute( root.GetFilePath() );
|
|
||||||
|
|
||||||
var name = originalPath.fullFileName + ".json";
|
|
||||||
|
|
||||||
var outputPath = FilePath.Join( ProjectSettings.GlobalizePath( docInfoPath ), name );
|
|
||||||
|
|
||||||
var doc = ClassDocFromParser.CreateFrom( objects[ 0 ] );
|
|
||||||
|
|
||||||
this.LogInfo( "saving:", outputPath, JSON.StringifyObject( doc ) );
|
|
||||||
FilesSync.SaveJSON( outputPath, doc );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CreateGDClass( CSFileRoot root )
|
|
||||||
{
|
|
||||||
var originalPath = FilePath.Absolute( root.GetFilePath() );
|
|
||||||
|
|
||||||
var converter = new GDScriptFromCSAST();
|
|
||||||
converter.Convert( root );
|
|
||||||
var gdclass = converter.gdClass;
|
|
||||||
|
|
||||||
var gdgenerator = new GDScriptGenerator();
|
|
||||||
gdgenerator.gdClasses = [ gdclass ];
|
|
||||||
gdgenerator.Generate( originalPath.parentAbsolutePath );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ParseFormula()
|
|
||||||
{
|
|
||||||
var defines = this.defines.Split( "," );
|
|
||||||
var evaluator = new CSPreProcessorConditionalEvaluator();
|
|
||||||
defines.ForEach( d => evaluator.defines.Add( d ) );
|
|
||||||
evaluator.Parse( formula );
|
|
||||||
|
|
||||||
var result = evaluator.Evaluate();
|
|
||||||
|
|
||||||
this.LogInfo( "Result:", result );
|
|
||||||
|
|
||||||
this.LogInfo( "Context:", evaluator.context.messages );
|
|
||||||
|
|
||||||
var info = evaluator.root.CreateDebugTreeInfo();
|
|
||||||
this.LogInfo( "\n" + info );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
uid://btbsqwh2k3ocl
|
|
||||||
|
|
@ -1,171 +0,0 @@
|
||||||
|
|
||||||
using Godot;
|
|
||||||
|
|
||||||
using Rokojori;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Linq;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Rokojori.GDLibraryGeneration
|
|
||||||
{
|
|
||||||
[Tool][GlobalClass]
|
|
||||||
public partial class GDLibraryGenerator:Node
|
|
||||||
{
|
|
||||||
[Export]
|
|
||||||
public string path = "rokojori_action_library_gd";
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public bool scanForGDExport = true;
|
|
||||||
|
|
||||||
[Export]
|
|
||||||
public string[] files = [];
|
|
||||||
|
|
||||||
[ExportToolButton( "Generate" )]
|
|
||||||
public Callable generateButton => Callable.From(
|
|
||||||
()=>
|
|
||||||
{
|
|
||||||
GenerateGDLibrary();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
HashSet<string> defines = new HashSet<string>();
|
|
||||||
|
|
||||||
void GenerateGDLibrary()
|
|
||||||
{
|
|
||||||
defines = new HashSet<string>();
|
|
||||||
defines.Add( GDScriptGenerator.GD_SCRIPT_TRANSPILING );
|
|
||||||
|
|
||||||
var codeFilePaths = GetCodeFilePaths();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var rokojoriProPath = FilePath.Absolute( ProjectSettings.GlobalizePath( RokojoriPlugin.path ) );
|
|
||||||
var rokojoriGDPath = FilePath.Absolute( ProjectSettings.GlobalizePath( "res://addons/" + path ) );
|
|
||||||
|
|
||||||
|
|
||||||
codeFilePaths.ForEach(
|
|
||||||
( c )=>
|
|
||||||
{
|
|
||||||
var parser = new CSParser( c.absolutePath, defines );
|
|
||||||
var root = parser.root as CSFileRoot;
|
|
||||||
|
|
||||||
var originalPath = FilePath.Absolute( root.GetFilePath() );
|
|
||||||
var relativePath = rokojoriProPath.MakeAbsolutePathRelative( originalPath.parentAbsolutePath );
|
|
||||||
var gdPath = rokojoriGDPath.MakeRelative( relativePath.path );
|
|
||||||
|
|
||||||
var converter = new GDScriptFromCSAST();
|
|
||||||
converter.Convert( root );
|
|
||||||
var gdclass = converter.gdClass;
|
|
||||||
|
|
||||||
var gdgenerator = new GDScriptGenerator();
|
|
||||||
gdgenerator.gdClasses = [ gdclass ];
|
|
||||||
|
|
||||||
FilesSync.EnsureDirectoryExists( gdPath.absolutePath );
|
|
||||||
gdgenerator.Generate( gdPath.absolutePath );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FilePath> GetCodeFilePaths()
|
|
||||||
{
|
|
||||||
var codeFilePaths = new List<FilePath>();
|
|
||||||
|
|
||||||
var map = new HashSet<string>();
|
|
||||||
|
|
||||||
var combinedFiles = new List<string>();
|
|
||||||
|
|
||||||
combinedFiles.AddRange( files );
|
|
||||||
|
|
||||||
if ( scanForGDExport )
|
|
||||||
{
|
|
||||||
var absPath = ProjectSettings.GlobalizePath( RokojoriPlugin.path );
|
|
||||||
var scannedExportfiles = FilesSync.GetFilesRecursive( absPath, f => f.HasFileExtension( ".cs" ) );
|
|
||||||
scannedExportfiles = scannedExportfiles.Filter(
|
|
||||||
( f, i ) =>
|
|
||||||
{
|
|
||||||
var text = f.LoadUTF8();
|
|
||||||
|
|
||||||
if ( ! text.Contains( "GDExport" ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var parser = new CSParser( f.absolutePath, defines );
|
|
||||||
var csRoot = parser.root as CSFileRoot;
|
|
||||||
var cd = csRoot.GetObjectDeclarations().Find( c => c.objectName.match == f.fileName );
|
|
||||||
|
|
||||||
return cd?.GetMemberAttributes().Contains( "GDExport" ) ?? false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
var scannedPaths = scannedExportfiles.Map( f => f.absolutePath );
|
|
||||||
|
|
||||||
RJLog.Log( "Found paths:", scannedPaths );
|
|
||||||
combinedFiles.AddRange( scannedPaths );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
combinedFiles.ForEach(
|
|
||||||
( fileString )=>
|
|
||||||
{
|
|
||||||
FilePath filePath;
|
|
||||||
|
|
||||||
if ( fileString.StartsWith( "res://" ) )
|
|
||||||
{
|
|
||||||
filePath = FilePath.Absolute( ProjectSettings.GlobalizePath( fileString ) );
|
|
||||||
}
|
|
||||||
else if ( ! fileString.EndsWith( ".cs" ) )
|
|
||||||
{
|
|
||||||
filePath = FindFilePathOf( fileString );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filePath = FilePath.Absolute( fileString );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( filePath == null || ! filePath.Exists() )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var absolutePath = filePath.absolutePath;
|
|
||||||
|
|
||||||
if ( map.Contains( absolutePath ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
codeFilePaths.Add( filePath );
|
|
||||||
map.Add( absolutePath );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return codeFilePaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<FilePath> filePaths;
|
|
||||||
|
|
||||||
FilePath FindFilePathOf( string type )
|
|
||||||
{
|
|
||||||
if ( filePaths == null )
|
|
||||||
{
|
|
||||||
var rokojoriPath = ProjectSettings.GlobalizePath( RokojoriPlugin.path );
|
|
||||||
filePaths = FilesSync.GetFilesRecursive( rokojoriPath, fp => fp.HasFileExtension( ".cs" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return filePaths.Find( fp => fp.fileName == type );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
uid://bosqs73jx5m0m
|
|
||||||
Loading…
Reference in New Issue