Generated new code and added initial data handling

This commit is contained in:
mm00
2025-01-27 19:24:50 +01:00
parent ebcc629feb
commit 146a3992ce
940 changed files with 11560 additions and 9 deletions

View File

@@ -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");
}
}
}