Added DnaListAttribute generation

This commit is contained in:
Samuele Lorefice
2025-03-04 18:27:53 +01:00
parent b100dc8020
commit a8bf5e6e82

View File

@@ -184,15 +184,27 @@ namespace CodeGenerator {
ctd.Members.Add(cmf); ctd.Members.Add(cmf);
} }
//Add the list fields to the class //Add the lists to the class
foreach (var field in listFields) { for (var index = 0; index < type.Fields.Count; index++) {
var listPointer = field.Item1; var field = type.Fields[index];
var listLength = field.Item2; //Skip fields that are not part of a list
if (!listFields.Select(f => f.Item1).Contains(field)) {
Log($"Field {field.Name} is not part of a list, skipping");
continue;
}
//Retrieve the list pointer and the list length fields
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
//Retrieve the index of the list length field
int sizeIndex = type.Fields.IndexOf(listLength);
Log($"Generating list field {listPointer.Name}"); Log($"Generating list field {listPointer.Name}");
var cmf = CreateListMemberField(listPointer, listLength);
CodeMemberField cmf = CreateListMemberField(listPointer, listLength); var attribute = GenerateDnaListAttribute(index, listPointer, listPointer.M_Parent.M_Parent, sizeIndex,
//TODO: add DNAListAttribute listLength, totalSize, out int size);
totalSize += size;
cmf.CustomAttributes.Add(attribute);
ctd.Members.Add(cmf); ctd.Members.Add(cmf);
} }
@@ -380,7 +392,24 @@ namespace CodeGenerator {
}); });
return cad; return cad;
} }
private static CodeAttributeDeclaration GenerateDnaListAttribute(int listIndex, BlendFile.DnaField listField,
BlendFile.Dna1Body body, int lenghtIndex, BlendFile.DnaField lenghtField, int offset, out int size) {
size = 0;
var cad = new CodeAttributeDeclaration("DNAListAttribute");
cad.Arguments.AddRange(new CodeAttributeArgumentCollection() {
new(new CodeSnippetExpression("8")),//pointer size
new(new CodePrimitiveExpression(listField.Type)),
new(new CodePrimitiveExpression(listField.Name)),
new(new CodePrimitiveExpression(listIndex)),
new(new CodePrimitiveExpression(listField.Type)),//TODO: double check this
new(new CodePrimitiveExpression(lenghtField.Name)),
new(new CodePrimitiveExpression(lenghtIndex)),
new(new CodePrimitiveExpression(offset))
});
return cad;
}
private static CodeMemberField CreateMemberField(BlendFile.DnaField field) { private static CodeMemberField CreateMemberField(BlendFile.DnaField field) {
Type t = Type.GetType(field.Type.ParseFType()); Type t = Type.GetType(field.Type.ParseFType());
CodeMemberField cmf; CodeMemberField cmf;