@@ -186,39 +186,66 @@ private static bool DeserializeFieldGroup(Prototype prototype, Blueprint bluepri
186
186
/// Deserializes a property mixin field group of a Calligraphy prototype.
187
187
/// </summary>
188
188
private static bool DeserializePropertyMixin ( Prototype prototype , Blueprint blueprint , Blueprint groupBlueprint , byte blueprintCopyNum ,
189
- PrototypeId prototypeDataRef , string prototypeName , Type classType , BinaryReader reader )
189
+ PrototypeId prototypeDataRef , string prototypeFilePath , Type classType , BinaryReader reader )
190
190
{
191
- // TODO: do actual deserialization in DeserializeFieldGroupIntoProperty()
191
+ PrototypePropertyCollection collection = null ;
192
+
193
+ // Property mixins are used both for initializing property infos and filling prototype property collections
194
+ // If this isn't a default prototype, it means the field group needs to be deserialized into a property collection
195
+ if ( prototypeDataRef != groupBlueprint . DefaultPrototypeId )
196
+ {
197
+ // Look for a property collection to deserialize into
198
+ // TODO: check mixins for collections
199
+
200
+ // PropertyId fields are currently also being sent here, so they are not going to have a Properties field
201
+ // Also the only PropertyList field (from ModPrototype) is currently being considered just a regular property collection
202
+ var collectionFieldInfo = classType . GetProperty ( "Properties" ) ;
203
+ if ( collectionFieldInfo != null )
204
+ {
205
+ collection = ( PrototypePropertyCollection ) collectionFieldInfo . GetValue ( prototype ) ;
206
+
207
+ // Initialize a new collection in this field if there isn't one already
208
+ if ( collection == null )
209
+ {
210
+ collection = new ( ) ;
211
+ collectionFieldInfo . SetValue ( prototype , collection ) ;
212
+ }
213
+ }
214
+ }
215
+
216
+ // This handles both cases (initialization and filling property collections)
217
+ DeserializeFieldGroupIntoProperty ( collection , groupBlueprint , blueprintCopyNum , prototypeFilePath , reader , "Property Fields" ) ;
218
+
219
+ // Property field groups do not have any list fields, so numListFields should always be 0
220
+ short numListFields = reader . ReadInt16 ( ) ;
221
+ if ( numListFields != 0 ) Logger . Warn ( $ "Property field group numListFields != 0") ;
222
+ return true ;
223
+ }
224
+
225
+ private static bool DeserializeFieldGroupIntoProperty ( PrototypePropertyCollection collection , Blueprint groupBlueprint , byte blueprintCopyNum ,
226
+ string prototypeFilePath , BinaryReader reader , string groupTag )
227
+ {
228
+ // TODO: deserializeFieldGroupIntoPropertyBuilder
192
229
short numSimpleFields = reader . ReadInt16 ( ) ;
193
230
for ( int i = 0 ; i < numSimpleFields ; i ++ )
194
231
{
195
232
var fieldId = ( StringId ) reader . ReadUInt64 ( ) ;
196
233
var type = ( CalligraphyBaseType ) reader . ReadByte ( ) ;
197
234
198
- // Property mixins don't have any RHStructs, so we can always read the value as uint64
235
+ // Property mixin field groups don't have any RHStructs, so we can always read the value as uint64
199
236
// (also no types or localized string refs)
200
237
var value = reader . ReadUInt64 ( ) ;
201
238
202
239
// hack: write data to a temporary PrototypePropertyCollection implementation
203
- if ( classType == typeof ( PropertyPrototype ) ) continue ;
204
- var propertyCollectionFieldInfo = classType . GetProperty ( "Properties" ) ;
205
- var propertyCollection = ( PrototypePropertyCollection ) propertyCollectionFieldInfo . GetValue ( prototype ) ;
206
-
207
- if ( propertyCollection == null )
240
+ if ( collection != null )
208
241
{
209
- propertyCollection = new ( ) ;
210
- propertyCollectionFieldInfo . SetValue ( prototype , propertyCollection ) ;
211
- }
242
+ if ( groupBlueprint . TryGetBlueprintMemberInfo ( fieldId , out var blueprintMemberInfo ) == false )
243
+ return Logger . ErrorReturn ( false , $ "Failed to find member id { fieldId } in blueprint { GameDatabase . GetBlueprintName ( groupBlueprint . Id ) } ") ;
212
244
213
- // Get blueprint member info for this field
214
- if ( blueprint . TryGetBlueprintMemberInfo ( fieldId , out var blueprintMemberInfo ) == false )
215
- return Logger . ErrorReturn ( false , $ "Failed to find member id { fieldId } in blueprint { GameDatabase . GetBlueprintName ( blueprint . Id ) } ") ;
216
-
217
- propertyCollection . AddPropertyFieldValue ( groupBlueprint . Id , blueprintCopyNum , blueprintMemberInfo . Member . FieldName , value ) ;
245
+ collection . AddPropertyFieldValue ( groupBlueprint . Id , blueprintCopyNum , blueprintMemberInfo . Member . FieldName , value ) ;
246
+ }
218
247
}
219
248
220
- // Property field groups do not have any list fields, so numListFields should always be 0
221
- short numListFields = reader . ReadInt16 ( ) ;
222
249
return true ;
223
250
}
224
251
0 commit comments