1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Robert d9d237e0eb Node editor - Added node collection pin add/remove
Node editor - Added first static value node
2022-03-20 15:54:36 +01:00

53 lines
1.4 KiB
C#

using System.Collections.Generic;
using Artemis.Core;
namespace Artemis.UI.Shared.Services.NodeEditor.Commands;
/// <summary>
/// Represents a node editor command that can be used to connect two pins.
/// </summary>
public class ConnectPins : INodeEditorCommand
{
private readonly IPin _source;
private readonly IPin _target;
private readonly List<IPin>? _originalConnections;
/// <summary>
/// Creates a new instance of the <see cref="ConnectPins" /> class.
/// </summary>
/// <param name="source">The source of the connection.</param>
/// <param name="target">The target of the connection.</param>
public ConnectPins(IPin source, IPin target)
{
_source = source;
_target = target;
_originalConnections = _target.Direction == PinDirection.Input ? new List<IPin>(_target.ConnectedTo) : null;
}
#region Implementation of INodeEditorCommand
/// <inheritdoc />
public string DisplayName => "Connect pins";
/// <inheritdoc />
public void Execute()
{
if (_target.Direction == PinDirection.Input)
_target.DisconnectAll();
_source.ConnectTo(_target);
}
/// <inheritdoc />
public void Undo()
{
_target.DisconnectFrom(_source);
if (_originalConnections == null)
return;
foreach (IPin pin in _originalConnections)
_target.ConnectTo(pin);
}
#endregion
}