using System;
using System.Collections.Generic;
namespace Misaki.GraphView
{
public static class SlotExtension
{
///
/// Unlink all slots from this slot.
///
/// The slot to unlink all connections from.
public static void UnlinkAll(this ISlot slot)
{
var slotCount = slot.LinkedSlotDatas.Count;
for (var i = 0; i < slotCount; i++)
{
var other = slot.LinkedSlotDatas[i];
var otherNode = slot.Owner.GraphObject.GetNode(other.nodeID);
if (otherNode is ISlotContainer slotContainer)
{
slotContainer.GetSlot(other.slotIndex, other.direction)?.Unlink(slot);
}
}
}
///
/// Get the value type of the slot data.
///
/// The slot data to get the value type from.
/// The type of the slot value.
public static Type GetValueType(this SlotData slotData)
{
return Type.GetType(slotData.valueType);
}
///
/// Pull data from a collection of slots and execute the provided action.
///
/// The collection of slots to pull data from.
/// The action to execute when pulling data.
public static void PullData(this IEnumerable slots, Action OnPullData)
{
foreach (var slot in slots)
{
slot.PullData(OnPullData);
}
}
///
/// Push data to a collection of slots and execute the provided action.
///
/// The collection of slots to push data to.
/// The action to execute when pushing data.
public static void PushData(this IEnumerable slots, Action OnPushData)
{
foreach (var slot in slots)
{
slot.PushData(OnPushData);
}
}
}
}