Changed Slot in RelayNode to ProxySlot;

Changed PullData and PushData from SlotExtension to ISlot;

Added BackTraceExecutableNode;

Removed IExecutable from RelayNode;
This commit is contained in:
Misaki
2024-11-10 12:28:12 +09:00
parent 994297a3f2
commit d3c5968a80
21 changed files with 398 additions and 281 deletions

View File

@@ -34,87 +34,6 @@ namespace Misaki.GraphView
return Type.GetType(slotData.valueType);
}
/// <summary>
/// Pull data from the slot to property and execute the provided action.
/// </summary>
/// <param name="slot">The slot to pull data from.</param>
/// <param name="OnPullData">The action to execute when pulling data.</param>
public static void PullData(this ISlot slot, Action<ISlot> OnPullData)
{
if (slot.SlotData.direction == SlotDirection.Output)
{
return;
}
foreach (var slotData in slot.LinkedSlotDatas)
{
var node = slot.Owner.GraphObject.GetNode(slotData.nodeID);
if (node is not IExecutable executable)
{
continue;
}
if (!executable.IsExecuted)
{
executable.Execute();
}
}
OnPullData?.Invoke(slot);
var property = slot.Owner.GetType().GetField(slot.SlotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
if (slot.IsLinked && property != null)
{
property?.SetValue(slot.Owner, slot.Data);
}
}
/// <summary>
/// Push data to the slot and execute the provided action.
/// </summary>
/// <param name="slot">The slot to push data to.</param>
/// <param name="OnPushData">The action to execute when pushing data.</param>
public static void PushData(this ISlot slot, Action<ISlot> OnPushData)
{
if (slot.SlotData.direction == SlotDirection.Input)
{
return;
}
var property = slot.Owner.GetType().GetField(slot.SlotData.slotName, ConstResource.NODE_FIELD_BINDING_FLAGS);
if (property != null)
{
slot.ReceiveData(property.GetValue(slot.Owner));
}
OnPushData?.Invoke(slot);
foreach (var connectedSlotData in slot.LinkedSlotDatas)
{
var node = slot.Owner.GraphObject.GetNode(connectedSlotData.nodeID);
if (node is not ISlotContainer slotContainer)
{
continue;
}
var connectedSlot = slotContainer.GetSlot(connectedSlotData.slotIndex, connectedSlotData.direction);
if (connectedSlotData.GetValueType() == slot.SlotData.GetValueType() || slot.SlotData.GetValueType() == typeof(object) || connectedSlotData.GetValueType() == typeof(object))
{
connectedSlot.ReceiveData(slot.Data);
}
else if (slot.Owner.GraphObject.ValueConverterManager != null && slot.Owner.GraphObject.ValueConverterManager.TryConvert(slot.SlotData.GetValueType(),
connectedSlotData.GetValueType(), slot.Data, out var data))
{
connectedSlot.ReceiveData(data);
}
else
{
slot.Owner.GraphObject.Logger?.LogError(slot.Owner, $"Failed to convert value from {slot.SlotData.valueType} to {connectedSlotData.valueType}");
}
}
}
/// <summary>
/// Pull data from a collection of slots and execute the provided action.
/// </summary>