Added nodes related to the list and array operations
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
251
Examples/Nodify.Calculator/NodeHandlers/ListNodeHandlers.cs
Normal file
251
Examples/Nodify.Calculator/NodeHandlers/ListNodeHandlers.cs
Normal file
@@ -0,0 +1,251 @@
|
||||
using Nodify.Calculator.Models;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace Nodify.Calculator.NodeHandlers
|
||||
{
|
||||
// ─── LIST ADD ───
|
||||
public class ListAddHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_ADD;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_ADD);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Add",
|
||||
SystemOperationType = SystemOperations.LIST_ADD
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle, IsInput = false });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Item", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Universal, IsCopyConnector = true });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "List", IsInput = false, Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_ADD });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_ADD);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST REMOVE ───
|
||||
public class ListRemoveHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_REMOVE;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_REMOVE);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Remove",
|
||||
SystemOperationType = SystemOperations.LIST_REMOVE
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle, IsInput = false });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Index", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Integer, DataType = "int" });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "List", IsInput = false, Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_REMOVE });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_REMOVE);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST UPDATE ───
|
||||
public class ListUpdateHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_UPDATE;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_UPDATE);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Update",
|
||||
SystemOperationType = SystemOperations.LIST_UPDATE
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle, IsInput = false });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Index", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Integer, DataType = "int" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Item", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Universal, IsCopyConnector = true });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "List", IsInput = false, Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_UPDATE });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST GET (non-flow, value node) ───
|
||||
public class ListGetHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_GET;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_GET);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Get",
|
||||
SystemOperationType = SystemOperations.LIST_GET
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Index", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Integer, DataType = "int" });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "Item", IsInput = false, Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Object, DataType = "object" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_GET });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_GET);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST COUNT (non-flow, value node) ───
|
||||
public class ListCountHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_COUNT;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_COUNT);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Count",
|
||||
SystemOperationType = SystemOperations.LIST_COUNT
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "Count", IsInput = false, Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Integer, DataType = "int" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_COUNT });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST CONTAINS (non-flow, value node) ───
|
||||
public class ListContainsHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_CONTAINS;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_CONTAINS);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Contains",
|
||||
SystemOperationType = SystemOperations.LIST_CONTAINS
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "Item", Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Universal, IsCopyConnector = true });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "Result", IsInput = false, Shape = ConnectorShape.Circle, ConnectorColor = NodeColors.Boolean, DataType = "bool" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_CONTAINS });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_CONTAINS);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── LIST CLEAR ───
|
||||
public class ListClearHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.LIST_CLEAR;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.LIST_CLEAR);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new SystemOperationViewModel
|
||||
{
|
||||
Title = info.Title ?? "List Clear",
|
||||
SystemOperationType = SystemOperations.LIST_CLEAR
|
||||
};
|
||||
op.Input.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "", Shape = ConnectorShape.Triangle, IsInput = false });
|
||||
op.Input.Add(new ConnectorViewModel { Title = "List", Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
op.Output.Add(new ConnectorViewModel { Title = "List", IsInput = false, Shape = ConnectorShape.Grid, ConnectorColor = NodeColors.List, DataType = "list" });
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
=> Create(new OperationInfoViewModel { Title = data.Title, Type = OperationType.System, sysOp = SystemOperations.LIST_CLEAR });
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.LIST_CLEAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,13 @@ namespace Nodify.Calculator.NodeHandlers
|
||||
_handlers.Add(new CopyHandler());
|
||||
_handlers.Add(new SplitHandler());
|
||||
_handlers.Add(new ParseJsonHandler());
|
||||
_handlers.Add(new ListAddHandler());
|
||||
_handlers.Add(new ListRemoveHandler());
|
||||
_handlers.Add(new ListUpdateHandler());
|
||||
_handlers.Add(new ListGetHandler());
|
||||
_handlers.Add(new ListCountHandler());
|
||||
_handlers.Add(new ListContainsHandler());
|
||||
_handlers.Add(new ListClearHandler());
|
||||
_handlers.Add(new GetSetVariableHandler());
|
||||
_handlers.Add(new GetSetModelHandler());
|
||||
_handlers.Add(new BeginEndHandler());
|
||||
@@ -108,6 +115,13 @@ namespace Nodify.Calculator.NodeHandlers
|
||||
SystemOperations.END => _handlers.OfType<BeginEndHandler>().FirstOrDefault(),
|
||||
SystemOperations.GET_SET when sys.IsSimpleVariable => _handlers.OfType<GetSetVariableHandler>().FirstOrDefault(),
|
||||
SystemOperations.GET_SET => _handlers.OfType<GetSetModelHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_ADD => _handlers.OfType<ListAddHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_REMOVE => _handlers.OfType<ListRemoveHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_UPDATE => _handlers.OfType<ListUpdateHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_GET => _handlers.OfType<ListGetHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_COUNT => _handlers.OfType<ListCountHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_CONTAINS => _handlers.OfType<ListContainsHandler>().FirstOrDefault(),
|
||||
SystemOperations.LIST_CLEAR => _handlers.OfType<ListClearHandler>().FirstOrDefault(),
|
||||
_ => _handlers.OfType<GenericSystemHandler>().FirstOrDefault()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user