Skip to content

Commit

Permalink
Fixed property types not being set through PersistAndSave
Browse files Browse the repository at this point in the history
Improved display of types of collision in List collision view.
  • Loading branch information
vchelaru committed Nov 24, 2023
1 parent 1d04cba commit 1f6504a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 21 deletions.
84 changes: 65 additions & 19 deletions FRBDK/Glue/GlueCommon/SaveClasses/PropertySave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,80 @@ public static void SetValue<T>(this List<PropertySave> propertySaveList, string
newPropertySave.Name = nameToSearchFor;
newPropertySave.Value = value;

if(typeof(T) == typeof(int))
{
newPropertySave.Type = "int";
}
else if(typeof(T) == typeof(float))
{
newPropertySave.Type = "float";
}
else if (typeof(T) == typeof(decimal))
{
newPropertySave.Type = "decimal";
}
else
{
newPropertySave.Type = typeof(T).Name;
}

AssignTypeOnProperty<T>(newPropertySave);

propertySaveList.Add(newPropertySave);
}
}
}

public static void SetValuePersistIfDefault(this List<PropertySave> propertySaveList, string nameToSearchFor, object value)
private static void AssignTypeOnProperty<T>(PropertySave newPropertySave)
{
if (typeof(T) == typeof(int))
{
newPropertySave.Type = "int";
}
else if(typeof(T) == typeof(int?))
{
newPropertySave.Type = "int?";
}
else if (typeof(T) == typeof(long))
{
newPropertySave.Type = "long";
}
else if (typeof(T) == typeof(long?))
{
newPropertySave.Type = "long?";
}
else if (typeof(T) == typeof(float))
{
newPropertySave.Type = "float";
}
else if (typeof(T) == typeof(float?))
{
newPropertySave.Type = "float?";
}
else if (typeof(T) == typeof(decimal))
{
newPropertySave.Type = "decimal";
}
else if (typeof(T) == typeof(decimal?))
{
newPropertySave.Type = "decimal?";
}

else if (typeof(T) == typeof(bool))
{
newPropertySave.Type = "bool";
}

else if (typeof(T) == typeof(bool?))
{
newPropertySave.Type = "bool?";
}

else if (typeof(T) == typeof(byte))
{
newPropertySave.Type = "byte";
}

else if (typeof(T) == typeof(byte?))
{
newPropertySave.Type = "byte?";
}

else
{
newPropertySave.Type = typeof(T).Name;
}
}

public static void SetValuePersistIfDefault<T>(this List<PropertySave> propertySaveList, string nameToSearchFor, T value)
{
SetValue(propertySaveList, nameToSearchFor, value, true);
}

public static void SetValue(this List<PropertySave> propertySaveList, string nameToSearchFor, object value, bool persistIfDefault)
public static void SetValue<T>(this List<PropertySave> propertySaveList, string nameToSearchFor, T value, bool persistIfDefault)
{
var handled = false;
if(!persistIfDefault)
Expand All @@ -211,6 +256,7 @@ public static void SetValue(this List<PropertySave> propertySaveList, string nam
PropertySave newPropertySave = new PropertySave();
newPropertySave.Name = nameToSearchFor;
newPropertySave.Value = value;
AssignTypeOnProperty<T>(newPropertySave);
propertySaveList.Add(newPropertySave);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,21 @@ public string RelationshipPhysicsDetails
{
if (CollisionRelationshipNamedObject != null)
{
var collision = CollisionRelationshipNamedObject.Properties.GetValue(
nameof(CollisionRelationshipViewModel.CollisionType)) as int?;
int? collision = null;

var collisionTypeAsObject = CollisionRelationshipNamedObject.Properties.GetValue(
nameof(CollisionRelationshipViewModel.CollisionType));

if(collisionTypeAsObject is int asInt)
{
collision = asInt;
}
else if(collisionTypeAsObject is long asLong)
{
// There's a bug in FRB where the Type would not get saved properly on a collision property. Let's tolerate that here
// for now. This bug has been fixed in FRB in November 2023, but we'll still add this here for Cranky Chibi Cthulhu
collision = (int)asLong;
}

string physicsText = "No Physics";

Expand Down

0 comments on commit 1f6504a

Please sign in to comment.