using System.Collections.Generic; using System.Linq; using Artemis.Core; namespace Artemis.UI.Shared.Services.NodeEditor.Commands; /// /// Represents a node editor command that can be used to organize a script /// public class OrganizeScript : INodeEditorCommand { private readonly NodeScript _script; private readonly List<(INode node, double x, double y)> _originalPositions; /// /// Creates a new instance of the class. /// /// The script to organize. public OrganizeScript(NodeScript script) { _script = script; _originalPositions = script.Nodes.Select(n => (n, n.X, n.Y)).ToList(); } /// public string DisplayName => "Organize script"; /// public void Execute() { _script.Organize(); } /// public void Undo() { foreach ((INode? node, double x, double y) in _originalPositions) { node.X = x; node.Y = y; } } }