1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.VisualScripting/Nodes/External/Commands/UpdateLayerPropertyNodeSelectedProfileElement.cs
2022-03-30 20:10:43 +02:00

54 lines
1.5 KiB
C#

using Artemis.Core;
using Artemis.UI.Shared.Services.NodeEditor;
namespace Artemis.VisualScripting.Nodes.External.Commands;
public class UpdateLayerPropertyNodeSelectedProfileElement : INodeEditorCommand
{
private readonly LayerPropertyNode _node;
private readonly NodeConnectionStore _connections;
private readonly RenderProfileElement? _value;
private readonly RenderProfileElement? _oldValue;
private readonly ILayerProperty? _oldLayerProperty;
public UpdateLayerPropertyNodeSelectedProfileElement(LayerPropertyNode node, RenderProfileElement? value)
{
_node = node;
_connections = new NodeConnectionStore(_node);
_value = value;
_oldValue = node.ProfileElement;
_oldLayerProperty = node.LayerProperty;
}
/// <inheritdoc />
public string DisplayName => "Update node profile element";
/// <inheritdoc />
public void Execute()
{
// Store connections as they currently are
_connections.Store();
// Update the selected profile element
_node.ChangeProfileElement(_value);
}
/// <inheritdoc />
public void Undo()
{
// Can't undo it if that profile element is now gone :\
if (_oldValue != null && _oldValue.Disposed)
return;
// Restore the previous profile element
_node.ChangeProfileElement(_oldValue);
// Restore the previous layer property
_node.ChangeLayerProperty(_oldLayerProperty);
// Restore connections
_connections.Restore();
}
}