I am having bit of an issue with saving my custom type in a list. The type in question is below:
Code: Select all
public class ResolvedEntityObject : IResolvedEntityBase
{
public string Id;
public Int2 SavedPosition; // this is also a custom type that I added to the supported types list and it works in other contexts
public List<IResolvedEntityBase> Properties;
public ResolvedEntityObject (string id, List<IResolvedEntityBase> properties)
{
this.Id = id;
this.Properties = properties;
}
public ResolvedEntityObject ()
{
}
public string GetStringPropertyValueWithId (string id)
{
var stringProps = Properties.Where(p => p is ResolvedEntityProperty<string>).Cast<ResolvedEntityProperty<string>>();
var prop = stringProps.FirstOrDefault(p => p.PropertyId == id);
if (prop != null)
{
return prop.PropertyValue;
}
else
{
return null;
}
}
}
Code: Select all
public class ES2UserType_EntityDataStructuresResolvedEntityObject : ES2Type
{
public override void Write(object obj, ES2Writer writer)
{
EntityDataStructures.ResolvedEntityObject data = (EntityDataStructures.ResolvedEntityObject)obj;
// Add your writer.Write calls here.
writer.Write(data.Id);
writer.Write(data.SavedPosition);
var intProps = data.Properties.Where(p => p is ResolvedIntegerProperty).Cast<ResolvedIntegerProperty>().ToList();
writer.Write(intProps);
var floatProps = data.Properties.Where(p => p is ResolvedFloatProperty).Cast<ResolvedFloatProperty>().ToList();
writer.Write(floatProps);
var stringProps = data.Properties.Where(p => p is ResolvedStringProperty).Cast<ResolvedStringProperty>().ToList();
writer.Write(stringProps);
}
public override object Read(ES2Reader reader)
{
EntityDataStructures.ResolvedEntityObject data = new EntityDataStructures.ResolvedEntityObject();
Read(reader, data);
return data;
}
public override void Read(ES2Reader reader, object c)
{
EntityDataStructures.ResolvedEntityObject data = (EntityDataStructures.ResolvedEntityObject)c;
// Add your reader.Read calls here to read the data into the object.
data.Id = reader.Read<string>();
data.SavedPosition = reader.Read<Int2>(); // this is also a custom type that I added to the supported types list and it works in other contexts
data.Properties = new List<IResolvedEntityBase>();
var intProps = reader.Read<List<ResolvedIntegerProperty>>();
var floatProps = reader.Read<List<ResolvedFloatProperty>>();
var stringProps = reader.Read<List<ResolvedStringProperty>>();
data.Properties.AddRange(stringProps);
data.Properties.AddRange(floatProps);
data.Properties.AddRange(intProps);
}
/* ! Don't modify anything below this line ! */
public ES2UserType_EntityDataStructuresResolvedEntityObject():base(typeof(EntityDataStructures.ResolvedEntityObject)){}
}
Code: Select all
public class ES2UserType_EntityDataStructuresResolvedStringProperty : ES2Type
{
public override void Write(object obj, ES2Writer writer)
{
EntityDataStructures.ResolvedStringProperty data = (EntityDataStructures.ResolvedStringProperty)obj;
// Add your writer.Write calls here.
writer.Write(data.PropertyValue);
writer.Write(data.PropertyId);
}
public override object Read(ES2Reader reader)
{
EntityDataStructures.ResolvedStringProperty data = new EntityDataStructures.ResolvedStringProperty();
Read(reader, data);
return data;
}
public override void Read(ES2Reader reader, object c)
{
EntityDataStructures.ResolvedStringProperty data = (EntityDataStructures.ResolvedStringProperty)c;
// Add your reader.Read calls here to read the data into the object.
data.PropertyValue = reader.Read<System.String>();
data.PropertyId = reader.Read<System.String>();
}
/* ! Don't modify anything below this line ! */
public ES2UserType_EntityDataStructuresResolvedStringProperty():base(typeof(EntityDataStructures.ResolvedStringProperty)){}
}
I thought maybe this was due to my ResolvedEntityObject class containing a collection inside, and qualifying as a nested collection, although it really should behave more like a wrapper in this case. But I went ahead and created an EntitySaveWrapper class anyways with a List<ResolvedEntityObject> member, and guess what: I didn't get the same error this time but I got three other errors, one for each Resolved[Type]Property class: "Easy Save does not support saving of type System.Collections.Generic.List`1[EntityDataStructures.ResolvedIntegerProperty]." etc. I suspect those are coming from the custom type code I added manually, and I could try and write a wrapper class for each, but this doesn't really seem right to me. According to the docs on the website ES2 should be able to handle generic collections of a custom type as long as the underlying type has support added for it. Am I wrong? Am I missing something here?
Please help!