diff --git a/src/Artemis.Core/VisualScripting/InputPin.cs b/src/Artemis.Core/VisualScripting/InputPin.cs
index 108e7c620..9db82c693 100644
--- a/src/Artemis.Core/VisualScripting/InputPin.cs
+++ b/src/Artemis.Core/VisualScripting/InputPin.cs
@@ -94,18 +94,11 @@ public sealed class InputPin : Pin
/// The new type of the pin.
public void ChangeType(Type type)
{
- if (_type == type)
+ if (type == _type)
return;
-
- // Disconnect pins incompatible with the new type
- List toDisconnect = ConnectedTo.Where(p => !p.IsTypeCompatible(type)).ToList();
- foreach (IPin pin in toDisconnect)
- DisconnectFrom(pin);
-
- // Change the type
- SetAndNotify(ref _type, type, nameof(Type));
+
+ base.ChangeType(type, ref _type);
Value = type.GetDefault();
- IsNumeric = type == typeof(Numeric);
}
private void Evaluate()
@@ -117,10 +110,10 @@ public sealed class InputPin : Pin
else
Value = Type.GetDefault()!;
}
- else
- {
+ else if (ConnectedTo.Count > 0)
Value = ConnectedTo[0].PinValue;
- }
+ else
+ Value = null;
}
#endregion
diff --git a/src/Artemis.Core/VisualScripting/Interfaces/IPin.cs b/src/Artemis.Core/VisualScripting/Interfaces/IPin.cs
index 819d57fc1..67a0619c3 100644
--- a/src/Artemis.Core/VisualScripting/Interfaces/IPin.cs
+++ b/src/Artemis.Core/VisualScripting/Interfaces/IPin.cs
@@ -85,6 +85,7 @@ public interface IPin
/// Determines whether this pin is compatible with the given type
///
/// The type to check for compatibility
+ /// A boolean indicating whether or not enums should be exactly equal or just both be enums
/// if the type is compatible, otherwise .
- public bool IsTypeCompatible(Type type);
+ public bool IsTypeCompatible(Type type, bool forgivingEnumMatching = true);
}
\ No newline at end of file
diff --git a/src/Artemis.Core/VisualScripting/OutputPin.cs b/src/Artemis.Core/VisualScripting/OutputPin.cs
index f7d03e042..2e135eb13 100644
--- a/src/Artemis.Core/VisualScripting/OutputPin.cs
+++ b/src/Artemis.Core/VisualScripting/OutputPin.cs
@@ -84,15 +84,11 @@ public sealed class OutputPin : Pin
/// The new type of the pin.
public void ChangeType(Type type)
{
- // Disconnect pins incompatible with the new type
- List toDisconnect = ConnectedTo.Where(p => !p.IsTypeCompatible(type)).ToList();
- foreach (IPin pin in toDisconnect)
- DisconnectFrom(pin);
+ if (type == _type)
+ return;
- // Change the type
- SetAndNotify(ref _type, type, nameof(Type));
+ base.ChangeType(type, ref _type);
Value = type.GetDefault();
- IsNumeric = type == typeof(Numeric);
}
#endregion
diff --git a/src/Artemis.Core/VisualScripting/Pin.cs b/src/Artemis.Core/VisualScripting/Pin.cs
index 21e37c7f3..89fc2ce2a 100644
--- a/src/Artemis.Core/VisualScripting/Pin.cs
+++ b/src/Artemis.Core/VisualScripting/Pin.cs
@@ -127,14 +127,47 @@ public abstract class Pin : CorePropertyChanged, IPin
}
///
- public bool IsTypeCompatible(Type type)
+ public bool IsTypeCompatible(Type type, bool forgivingEnumMatching = true)
{
return Type == type
- || (Type == typeof(Enum) && type.IsEnum)
- || (Type.IsEnum && type == typeof(Enum))
+ || (Direction == PinDirection.Input && Type == typeof(Enum) && type.IsEnum && forgivingEnumMatching)
+ || (Direction == PinDirection.Output && type == typeof(Enum) && Type.IsEnum && forgivingEnumMatching)
|| (Direction == PinDirection.Input && Type == typeof(object))
|| (Direction == PinDirection.Output && type == typeof(object));
}
+ ///
+ /// Changes the type of this pin, disconnecting any pins that are incompatible with the new type.
+ ///
+ /// The new type of the pin.
+ /// The backing field of the current type of the pin.
+ protected void ChangeType(Type type, ref Type currentType)
+ {
+ // Enums are a special case that disconnect and, if still compatible, reconnect
+ if (type.IsEnum && currentType.IsEnum)
+ {
+ List connections = new(ConnectedTo);
+ DisconnectAll();
+
+ // Change the type
+ SetAndNotify(ref currentType, type, nameof(Type));
+ IsNumeric = type == typeof(Numeric);
+
+ foreach (IPin pin in connections.Where(p => p.IsTypeCompatible(type)))
+ ConnectTo(pin);
+ }
+ // Disconnect pins incompatible with the new type
+ else
+ {
+ List toDisconnect = ConnectedTo.Where(p => !p.IsTypeCompatible(type, false)).ToList();
+ foreach (IPin pin in toDisconnect)
+ DisconnectFrom(pin);
+
+ // Change the type
+ SetAndNotify(ref currentType, type, nameof(Type));
+ IsNumeric = type == typeof(Numeric);
+ }
+ }
+
#endregion
}
\ No newline at end of file