Generated new code and added initial data handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>disable</Nullable>
|
||||
<RootNamespace>CodeGenerator</RootNamespace>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CodeGenerator {
|
||||
public static class Program {
|
||||
private static BlendFile blendfile;
|
||||
private static readonly StringBuilder sb = new();
|
||||
private const string OutPath = @"GeneratedOutput\";
|
||||
private const string OutPath = @"GeneratedOutput";
|
||||
private const string Namespace = "BlendFile";
|
||||
private static HashSet<string> customTypes;
|
||||
|
||||
@@ -116,7 +116,10 @@ namespace CodeGenerator {
|
||||
ctd.Members.Add(cmf);
|
||||
}
|
||||
|
||||
Log("Generating constructor");
|
||||
Log("Generating Parameterless constructor");
|
||||
ctd.Members.Add(GenerateParameterlessConstructor(type, ctd));
|
||||
|
||||
Log("Generating Default Constructor");
|
||||
ctd.Members.Add(GenerateConstructor(type, ctd));
|
||||
|
||||
Log("Finished generating struct");
|
||||
@@ -423,6 +426,25 @@ namespace CodeGenerator {
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
private static CodeConstructor GenerateParameterlessConstructor(BlendFile.DnaStruct type, CodeTypeDeclaration ctd) {
|
||||
//Create a normal constructor
|
||||
CodeConstructor cc = new CodeConstructor {
|
||||
Name = type.Type,
|
||||
Attributes = MemberAttributes.Public,
|
||||
ReturnType = new(type.Type)
|
||||
};
|
||||
|
||||
//Assign the parameters to the respective fields
|
||||
cc.Statements.AddRange(ctd.Members
|
||||
.OfType<CodeMemberField>()
|
||||
.Select(f => new CodeAssignStatement(
|
||||
new CFieldRefExp(new CThisRefExp(), f.Name),
|
||||
new CodeSnippetExpression("default"))
|
||||
).ToArray<CodeStatement>());
|
||||
|
||||
return cc;
|
||||
}
|
||||
|
||||
private static void SetupCCU(out CodeGeneratorOptions genOpts, out CSharpCodeProvider provider,
|
||||
out CodeCompileUnit ccu) {
|
||||
@@ -476,7 +498,7 @@ namespace CodeGenerator {
|
||||
}
|
||||
|
||||
private static string GetOutputPath(CodeNamespace ns, string typeName) {
|
||||
return $"{OutPath}\\{string.Concat(ns.Name.Split('.').Skip(1))}\\{typeName}.cs";
|
||||
return Path.Combine(OutPath, ns.Name, typeName + ".cs");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user