Event conditions - Fix start-node disconnecting

Input - Performance optimizations
This commit is contained in:
Robert authored and RobertBeekman committed 2022-09-16 19:46:43 +02:00
1 parent b19854ee47
commit b779a86d13
15 files changed
+298 -251

No files matched your search

@@ -9,10 +9,11 @@ namespace Artemis.VisualScripting.Nodes.List;
public class ListOperatorPredicateNode : Node<ListOperatorEntity, ListOperatorPredicateNodeCustomViewModel>, IDisposable
{
private readonly object _scriptLock = new();
private ListOperatorPredicateStartNode? _startNode;
private ListOperatorPredicateStartNode _startNode;
public ListOperatorPredicateNode() : base("List Operator (Advanced)", "Checks if any/all/no values in the input list match a condition")
{
_startNode = new ListOperatorPredicateStartNode {X = -200};
InputList = CreateInputPin<IList>();
Output = CreateOutputPin<bool>();
@@ -31,21 +32,8 @@ public class ListOperatorPredicateNode : Node<ListOperatorEntity, ListOperatorPr
lock (_scriptLock)
{
Script = Storage?.Script != null
? new NodeScript<bool>("Is match", "Determines whether the current list item is a match", Storage.Script, script.Context)
: new NodeScript<bool>("Is match", "Determines whether the current list item is a match", script.Context);
// The load action may have created an event node, use that one over the one we have here
INode? existingEventNode = Script.Nodes.FirstOrDefault(n => n.Id == ListOperatorPredicateStartNode.NodeId);
if (existingEventNode != null)
_startNode = (ListOperatorPredicateStartNode) existingEventNode;
else
{
_startNode = new ListOperatorPredicateStartNode {X = -200};
Script.AddNode(_startNode);
}
UpdateStartNode();
Script.LoadConnections();
? new NodeScript<bool>("Is match", "Determines whether the current list item is a match", Storage.Script, script.Context, new List<DefaultNode> {_startNode})
: new NodeScript<bool>("Is match", "Determines whether the current list item is a match", script.Context, new List<DefaultNode> {_startNode});
}
}
@@ -101,6 +89,7 @@ public class ListOperatorPredicateNode : Node<ListOperatorEntity, ListOperatorPr
lock (_scriptLock)
{
UpdateStartNode();
Script?.LoadConnections();
}
}
@@ -1,5 +1,7 @@
using System.Reactive;
using System.Reactive.Disposables;
using Artemis.Core;
using Artemis.Core.Events;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.VisualScripting;
@@ -12,17 +14,37 @@ public class ListOperatorPredicateNodeCustomViewModel : CustomNodeViewModel
private readonly ListOperatorPredicateNode _node;
private readonly IWindowService _windowService;
private ListOperator _operator;
private bool _canOpenEditor;
public ListOperatorPredicateNodeCustomViewModel(ListOperatorPredicateNode node, INodeScript script, IWindowService windowService) : base(node, script)
{
_node = node;
_windowService = windowService;
OpenEditor = ReactiveCommand.CreateFromTask(ExecuteOpenEditor);
OpenEditor = ReactiveCommand.CreateFromTask(ExecuteOpenEditor, this.WhenAnyValue(vm => vm.CanOpenEditor));
CanOpenEditor = node.InputList.ConnectedTo.Any();
this.WhenActivated(d =>
{
node.InputList.PinConnected += InputListOnPinConnected;
node.InputList.PinDisconnected += InputListOnPinDisconnected;
Disposable.Create(() =>
{
node.InputList.PinConnected -= InputListOnPinConnected;
node.InputList.PinDisconnected -= InputListOnPinDisconnected;
}).DisposeWith(d);
});
}
public ReactiveCommand<Unit, Unit> OpenEditor { get; }
private bool CanOpenEditor
{
get => _canOpenEditor;
set => this.RaiseAndSetIfChanged(ref _canOpenEditor, value);
}
public ListOperator Operator
{
get => _operator;
@@ -40,4 +62,14 @@ public class ListOperatorPredicateNodeCustomViewModel : CustomNodeViewModel
_node.Storage ??= new ListOperatorEntity();
_node.Storage.Script = _node.Script.Entity;
}
private void InputListOnPinDisconnected(object? sender, SingleValueEventArgs<IPin> e)
{
CanOpenEditor = false;
}
private void InputListOnPinConnected(object? sender, SingleValueEventArgs<IPin> e)
{
CanOpenEditor = true;
}
}