fix: Fixes code genning armor, clothing, and BODs (#810)
* Fixes code genning clothing * Fixes code genning armor * Fixes code genning BODs
This commit is contained in:
parent
990d151ef3
commit
8eaa859332
28 changed files with 122 additions and 111 deletions
|
|
@ -190,7 +190,7 @@ namespace SerializationGenerator
|
|||
) != null
|
||||
) : null;
|
||||
|
||||
var serializablePropertySet = new SortedSet<SerializableProperty>(new SerializablePropertyComparer());
|
||||
var serializablePropertySet = new SortedDictionary<SerializableProperty, ISymbol>(new SerializablePropertyComparer());
|
||||
|
||||
foreach (var fieldOrPropertySymbol in fieldsAndProperties)
|
||||
{
|
||||
|
|
@ -267,10 +267,16 @@ namespace SerializationGenerator
|
|||
serializableFieldSaveFlagMethods
|
||||
);
|
||||
|
||||
serializablePropertySet.Add(serializableProperty);
|
||||
serializablePropertySet.Add(serializableProperty, fieldOrPropertySymbol);
|
||||
}
|
||||
|
||||
var serializableProperties = serializablePropertySet.ToImmutableArray();
|
||||
var serializableFields = serializablePropertySet.Keys.ToImmutableArray();
|
||||
var serializableProperties = serializablePropertySet.Select(
|
||||
kvp => kvp.Key with
|
||||
{
|
||||
Name = (kvp.Value as IFieldSymbol)?.GetPropertyName() ?? ((IPropertySymbol)kvp.Value).Name
|
||||
}
|
||||
).ToImmutableArray();
|
||||
|
||||
// If we are not inheriting ISerializable, then we need to define some stuff
|
||||
if (!(isOverride || embedded))
|
||||
|
|
@ -323,6 +329,7 @@ namespace SerializationGenerator
|
|||
indent,
|
||||
isOverride,
|
||||
encodedVersion,
|
||||
serializableFields,
|
||||
serializableProperties,
|
||||
serializableFieldSaveFlags
|
||||
);
|
||||
|
|
@ -337,6 +344,7 @@ namespace SerializationGenerator
|
|||
version,
|
||||
encodedVersion,
|
||||
migrations,
|
||||
serializableFields,
|
||||
serializableProperties,
|
||||
parentFieldOrProperty,
|
||||
serializableFieldSaveFlags
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace SerializationGenerator
|
|||
int version,
|
||||
bool encodedVersion,
|
||||
ImmutableArray<SerializableMetadata> migrations,
|
||||
ImmutableArray<SerializableProperty> fields,
|
||||
ImmutableArray<SerializableProperty> properties,
|
||||
ISymbol parentFieldOrProperty,
|
||||
SortedDictionary<int, SerializableFieldSaveFlagMethods> serializableFieldSaveFlagMethodsDictionary
|
||||
|
|
@ -124,11 +125,12 @@ namespace SerializationGenerator
|
|||
source.AppendLine($"{bodyIndent}var saveFlags = reader.ReadEnum<SaveFlag>();");
|
||||
}
|
||||
|
||||
foreach (var property in properties)
|
||||
for (var i = 0; i < properties.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
var property = properties[i];
|
||||
var rule = SerializableMigrationRulesEngine.Rules[property.Rule];
|
||||
|
||||
|
||||
if (serializableFieldSaveFlagMethodsDictionary.TryGetValue(
|
||||
property.Order,
|
||||
out var serializableFieldSaveFlagMethods
|
||||
|
|
@ -138,7 +140,7 @@ namespace SerializationGenerator
|
|||
// Special case
|
||||
if (property.Type == "bool")
|
||||
{
|
||||
source.AppendLine($"{bodyIndent}{property.Name} = (saveFlags & SaveFlag.{property.Name}) != 0;");
|
||||
source.AppendLine($"{bodyIndent}{field.Name} = (saveFlags & SaveFlag.{property.Name}) != 0;");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -146,16 +148,22 @@ namespace SerializationGenerator
|
|||
rule.GenerateDeserializationMethod(
|
||||
source,
|
||||
innerIndent,
|
||||
property,
|
||||
field,
|
||||
parentFieldOrProperty?.Name ?? "this"
|
||||
);
|
||||
(rule as IPostDeserializeMethod)?.PostDeserializeMethod(source, innerIndent, property, compilation, classSymbol);
|
||||
(rule as IPostDeserializeMethod)?.PostDeserializeMethod(
|
||||
source,
|
||||
innerIndent,
|
||||
field,
|
||||
compilation,
|
||||
classSymbol
|
||||
);
|
||||
|
||||
if (serializableFieldSaveFlagMethods.GetFieldDefaultValue != null)
|
||||
{
|
||||
source.AppendLine($"{bodyIndent}}}\n{bodyIndent}else\n{bodyIndent}{{");
|
||||
source.AppendLine(
|
||||
$"{bodyIndent} {property.Name} = {serializableFieldSaveFlagMethods.GetFieldDefaultValue.Name}();"
|
||||
$"{bodyIndent} {field.Name} = {serializableFieldSaveFlagMethods.GetFieldDefaultValue.Name}();"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -168,10 +176,16 @@ namespace SerializationGenerator
|
|||
rule.GenerateDeserializationMethod(
|
||||
source,
|
||||
bodyIndent,
|
||||
property,
|
||||
field,
|
||||
parentFieldOrProperty?.Name ?? "this"
|
||||
);
|
||||
(rule as IPostDeserializeMethod)?.PostDeserializeMethod(source, bodyIndent, property, compilation, classSymbol);
|
||||
(rule as IPostDeserializeMethod)?.PostDeserializeMethod(
|
||||
source,
|
||||
bodyIndent,
|
||||
field,
|
||||
compilation,
|
||||
classSymbol
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace SerializationGenerator
|
|||
string indent,
|
||||
bool isOverride,
|
||||
bool encodedVersion,
|
||||
ImmutableArray<SerializableProperty> fields,
|
||||
ImmutableArray<SerializableProperty> properties,
|
||||
SortedDictionary<int, SerializableFieldSaveFlagMethods> serializableFieldSaveFlagMethodsDictionary
|
||||
)
|
||||
|
|
@ -74,30 +75,34 @@ namespace SerializationGenerator
|
|||
source.AppendLine($"{bodyIndent}writer.WriteEnum(saveFlags);");
|
||||
}
|
||||
|
||||
foreach (var property in properties)
|
||||
for (var i = 0; i < properties.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
var property = properties[i];
|
||||
if (serializableFieldSaveFlagMethodsDictionary.ContainsKey(property.Order))
|
||||
{
|
||||
// Special case
|
||||
if (property.Type != "bool")
|
||||
{
|
||||
source.AppendLine($"\n{bodyIndent}if ((saveFlags & SaveFlag.{property.Name}) != 0)\n{bodyIndent}{{");
|
||||
SerializableMigrationRulesEngine.Rules[property.Rule].GenerateSerializationMethod(
|
||||
source,
|
||||
innerIndent,
|
||||
property
|
||||
);
|
||||
SerializableMigrationRulesEngine.Rules[property.Rule]
|
||||
.GenerateSerializationMethod(
|
||||
source,
|
||||
innerIndent,
|
||||
field
|
||||
);
|
||||
source.AppendLine($"{bodyIndent}}}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
source.AppendLine();
|
||||
SerializableMigrationRulesEngine.Rules[property.Rule].GenerateSerializationMethod(
|
||||
source,
|
||||
bodyIndent,
|
||||
property
|
||||
);
|
||||
SerializableMigrationRulesEngine.Rules[property.Rule]
|
||||
.GenerateSerializationMethod(
|
||||
source,
|
||||
bodyIndent,
|
||||
field
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue