Skip to content

Commit

Permalink
[WzLib] Fix InvalidCastException when calling WzFloatProperty.SetValu…
Browse files Browse the repository at this point in the history
…e() & WzDoubleProperty.SetValue()
  • Loading branch information
lastbattle committed Nov 28, 2020
1 parent 113d7cc commit 440101f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
51 changes: 19 additions & 32 deletions HaCreator/GUI/MapPhysicsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,25 @@ private bool Save()
WzImage image = (WzImage)wzMapFile[WZ_FILE_IMAGE];
if (image != null)
{
SetWzImageValue(image["walkForce"], numericUpDown_walkForce.Value);
SetWzImageValue(image["walkSpeed"], numericUpDown_walkSpeed.Value);
SetWzImageValue(image["walkDrag"], numericUpDown_walkDrag.Value);
SetWzImageValue(image["slipForce"], numericUpDown_slipForce.Value);
SetWzImageValue(image["slipSpeed"], numericUpDown_slipSpeed.Value);
SetWzImageValue(image["floatDrag1"], numericUpDown_floatDrag1.Value);
SetWzImageValue(image["floatDrag2"], numericUpDown_floatDrag2.Value);
SetWzImageValue(image["floatCoefficient"], numericUpDown_floatCoefficient.Value);
SetWzImageValue(image["swimForce"], numericUpDown_swimForce.Value);
SetWzImageValue(image["swimSpeed"], numericUpDown_swimSpeed.Value);
SetWzImageValue(image["flyForce"], numericUpDown_flyForce.Value);
SetWzImageValue(image["flySpeed"], numericUpDown_flySpeed.Value);
SetWzImageValue(image["gravityAcc"], numericUpDown_gravityAcc.Value);
SetWzImageValue(image["fallSpeed"], numericUpDown_fallSpeed.Value);
SetWzImageValue(image["jumpSpeed"], numericUpDown_jumpSpeed.Value);
SetWzImageValue(image["maxFriction"], numericUpDown_maxFriction.Value);
SetWzImageValue(image["minFriction"], numericUpDown_minFriction.Value);
SetWzImageValue(image["swimSpeedDec"], numericUpDown_swimSpeedDec.Value);
SetWzImageValue(image["flyJumpDec"], numericUpDown_flyJumpDec.Value);

image["walkForce"].SetValue(numericUpDown_walkForce.Value);
image["walkSpeed"].SetValue(numericUpDown_walkSpeed.Value);
image["walkDrag"].SetValue(numericUpDown_walkDrag.Value);
image["slipForce"].SetValue(numericUpDown_slipForce.Value);
image["slipSpeed"].SetValue(numericUpDown_slipSpeed.Value);
image["floatDrag1"].SetValue(numericUpDown_floatDrag1.Value);
image["floatDrag2"].SetValue(numericUpDown_floatDrag2.Value);
image["floatCoefficient"].SetValue(numericUpDown_floatCoefficient.Value);
image["swimForce"].SetValue(numericUpDown_swimForce.Value);
image["swimSpeed"].SetValue(numericUpDown_swimSpeed.Value);
image["flyForce"].SetValue(numericUpDown_flyForce.Value);
image["flySpeed"].SetValue(numericUpDown_flySpeed.Value);
image["gravityAcc"].SetValue(numericUpDown_gravityAcc.Value);
image["fallSpeed"].SetValue(numericUpDown_fallSpeed.Value);
image["jumpSpeed"].SetValue(numericUpDown_jumpSpeed.Value);
image["maxFriction"].SetValue(numericUpDown_maxFriction.Value);
image["minFriction"].SetValue(numericUpDown_minFriction.Value);
image["swimSpeedDec"].SetValue(numericUpDown_swimSpeedDec.Value);
image["flyJumpDec"].SetValue(numericUpDown_flyJumpDec.Value);

Program.WzManager.SetWzFileUpdated(WZ_FILE_NAME, image); // flag as changed
}
Expand Down Expand Up @@ -199,18 +198,6 @@ private void button_save_Click(object sender, EventArgs e)
Save();
}

private void SetWzImageValue(WzImageProperty image, decimal value)
{
if (image is WzDoubleProperty doubleProperty)
{
doubleProperty.Value = (double)value;
}
else if (image is WzFloatProperty floatProperty)
{
floatProperty.Value = (float)value;
}
}

/// <summary>
/// Reset to pre-bb map physics values
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions MapleLib/WzLib/WzProperties/WzDoubleProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WzDoubleProperty : WzImageProperty
#region Inherited Members
public override void SetValue(object value)
{
val = (double)value;
val = System.Convert.ToDouble(value);
}

public override WzImageProperty DeepClone()
Expand Down Expand Up @@ -79,7 +79,7 @@ public override void Dispose()
/// <summary>
/// The value of this property
/// </summary>
public double Value { get { return val; } set { val = value; } }
public double Value { get { return val; } set { val = (double) value; } }
/// <summary>
/// Creates a blank WzDoubleProperty
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions MapleLib/WzLib/WzProperties/WzFloatProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WzFloatProperty : WzImageProperty
#region Inherited Members
public override void SetValue(object value)
{
val = (float)value;
val = System.Convert.ToSingle(value);
}

public override WzImageProperty DeepClone()
Expand Down Expand Up @@ -91,7 +91,7 @@ public override void Dispose()
/// <summary>
/// The value of the property
/// </summary>
public float Value { get { return val; } set { val = value; } }
public float Value { get { return val; } set { val = (float) value; } }
/// <summary>
/// Creates a blank WzByteFloatProperty
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MapleLib/WzLib/WzProperties/WzIntProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void Dispose()
/// <summary>
/// The value of the property
/// </summary>
public int Value { get { return val; } set { val = value; } }
public int Value { get { return val; } set { val = (int) value; } }
/// <summary>
/// Creates a blank WzCompressedIntProperty
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MapleLib/WzLib/WzProperties/WzLongProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override void Dispose()
/// <summary>
/// The value of the property
/// </summary>
public long Value { get { return val; } set { val = value; } }
public long Value { get { return val; } set { val = (long) value; } }
/// <summary>
/// Creates a blank WzCompressedIntProperty
/// </summary>
Expand Down

0 comments on commit 440101f

Please sign in to comment.