Added DnaListAttribute generation
This commit is contained in:
@@ -184,15 +184,27 @@ namespace CodeGenerator {
|
||||
ctd.Members.Add(cmf);
|
||||
}
|
||||
|
||||
//Add the list fields to the class
|
||||
foreach (var field in listFields) {
|
||||
var listPointer = field.Item1;
|
||||
var listLength = field.Item2;
|
||||
//Add the lists to the class
|
||||
for (var index = 0; index < type.Fields.Count; index++) {
|
||||
var field = type.Fields[index];
|
||||
//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}");
|
||||
var cmf = CreateListMemberField(listPointer, listLength);
|
||||
|
||||
CodeMemberField cmf = CreateListMemberField(listPointer, listLength);
|
||||
//TODO: add DNAListAttribute
|
||||
var attribute = GenerateDnaListAttribute(index, listPointer, listPointer.M_Parent.M_Parent, sizeIndex,
|
||||
listLength, totalSize, out int size);
|
||||
|
||||
totalSize += size;
|
||||
cmf.CustomAttributes.Add(attribute);
|
||||
ctd.Members.Add(cmf);
|
||||
}
|
||||
|
||||
@@ -381,6 +393,23 @@ namespace CodeGenerator {
|
||||
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) {
|
||||
Type t = Type.GetType(field.Type.ParseFType());
|
||||
CodeMemberField cmf;
|
||||
|
||||
Reference in New Issue
Block a user