mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge remote-tracking branch 'origin/VisualScripting' into VisualScripting
This commit is contained in:
commit
ecdca26cd3
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Events
|
||||||
|
{
|
||||||
|
public class SingleValueEventArgs<T> : EventArgs
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public T Value { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SingleValueEventArgs(T value)
|
||||||
|
{
|
||||||
|
this.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,10 +42,12 @@ namespace Artemis.Core
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
private void Evaluate()
|
private void Evaluate()
|
||||||
{
|
{
|
||||||
Value = ConnectedTo.Count > 0 ? (T)ConnectedTo[0].PinValue : default;
|
if (ConnectedTo.Count > 0)
|
||||||
|
if (ConnectedTo[0].PinValue is T value)
|
||||||
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -16,8 +17,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
object? Context { get; set; }
|
object? Context { get; set; }
|
||||||
|
|
||||||
event EventHandler<INode>? NodeAdded;
|
event EventHandler<SingleValueEventArgs<INode>>? NodeAdded;
|
||||||
event EventHandler<INode>? NodeRemoved;
|
event EventHandler<SingleValueEventArgs<INode>>? NodeRemoved;
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
void AddNode(INode node);
|
void AddNode(INode node);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -16,8 +17,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
bool IsEvaluated { get; set; }
|
bool IsEvaluated { get; set; }
|
||||||
|
|
||||||
event EventHandler<IPin> PinConnected;
|
event EventHandler<SingleValueEventArgs<IPin>> PinConnected;
|
||||||
event EventHandler<IPin> PinDisconnected;
|
event EventHandler<SingleValueEventArgs<IPin>> PinDisconnected;
|
||||||
|
|
||||||
void ConnectTo(IPin pin);
|
void ConnectTo(IPin pin);
|
||||||
void DisconnectFrom(IPin pin);
|
void DisconnectFrom(IPin pin);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -9,8 +10,8 @@ namespace Artemis.Core
|
|||||||
PinDirection Direction { get; }
|
PinDirection Direction { get; }
|
||||||
Type Type { get; }
|
Type Type { get; }
|
||||||
|
|
||||||
event EventHandler<IPin> PinAdded;
|
event EventHandler<SingleValueEventArgs<IPin>> PinAdded;
|
||||||
event EventHandler<IPin> PinRemoved;
|
event EventHandler<SingleValueEventArgs<IPin>> PinRemoved;
|
||||||
|
|
||||||
IPin AddPin();
|
IPin AddPin();
|
||||||
bool Remove(IPin pin);
|
bool Remove(IPin pin);
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Internal;
|
using Artemis.Core.Internal;
|
||||||
using Artemis.Core.Properties;
|
using Artemis.Core.Properties;
|
||||||
using Artemis.Storage.Entities.Profile.Nodes;
|
using Artemis.Storage.Entities.Profile.Nodes;
|
||||||
@ -15,8 +16,8 @@ namespace Artemis.Core
|
|||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler<INode>? NodeAdded;
|
public event EventHandler<SingleValueEventArgs<INode>>? NodeAdded;
|
||||||
public event EventHandler<INode>? NodeRemoved;
|
public event EventHandler<SingleValueEventArgs<INode>>? NodeRemoved;
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
_nodes.Add(node);
|
_nodes.Add(node);
|
||||||
|
|
||||||
NodeAdded?.Invoke(this, node);
|
NodeAdded?.Invoke(this, new SingleValueEventArgs<INode>(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveNode(INode node)
|
public void RemoveNode(INode node)
|
||||||
@ -86,7 +87,7 @@ namespace Artemis.Core
|
|||||||
if (node is IDisposable disposable)
|
if (node is IDisposable disposable)
|
||||||
disposable.Dispose();
|
disposable.Dispose();
|
||||||
|
|
||||||
NodeRemoved?.Invoke(this, node);
|
NodeRemoved?.Invoke(this, new SingleValueEventArgs<INode>(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@ -109,7 +110,7 @@ namespace Artemis.Core
|
|||||||
public void Load()
|
public void Load()
|
||||||
{
|
{
|
||||||
List<INode> removeNodes = _nodes.Where(n => !n.IsExitNode).ToList();
|
List<INode> removeNodes = _nodes.Where(n => !n.IsExitNode).ToList();
|
||||||
foreach (INode removeNode in removeNodes)
|
foreach (INode removeNode in removeNodes)
|
||||||
RemoveNode(removeNode);
|
RemoveNode(removeNode);
|
||||||
|
|
||||||
// Create nodes
|
// Create nodes
|
||||||
@ -148,7 +149,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
IPinCollection? collection = node.PinCollections.FirstOrDefault(c => c.Name == entityNodePinCollection.Name &&
|
IPinCollection? collection = node.PinCollections.FirstOrDefault(c => c.Name == entityNodePinCollection.Name &&
|
||||||
c.Type.Name == entityNodePinCollection.Type &&
|
c.Type.Name == entityNodePinCollection.Type &&
|
||||||
(int) c.Direction == entityNodePinCollection.Direction);
|
(int)c.Direction == entityNodePinCollection.Direction);
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
Name = nodePinCollection.Name,
|
Name = nodePinCollection.Name,
|
||||||
Type = nodePinCollection.Type.Name,
|
Type = nodePinCollection.Type.Name,
|
||||||
Direction = (int) nodePinCollection.Direction,
|
Direction = (int)nodePinCollection.Direction,
|
||||||
Amount = nodePinCollection.Count()
|
Amount = nodePinCollection.Count()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -300,7 +301,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public T Result => ((ExitNode<T>) ExitNode).Value;
|
public T Result => ((ExitNode<T>)ExitNode).Value;
|
||||||
|
|
||||||
public override Type ResultType => typeof(T);
|
public override Type ResultType => typeof(T);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -29,8 +30,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
public event EventHandler<IPin> PinConnected;
|
public event EventHandler<SingleValueEventArgs<IPin>> PinConnected;
|
||||||
public event EventHandler<IPin> PinDisconnected;
|
public event EventHandler<SingleValueEventArgs<IPin>> PinDisconnected;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ namespace Artemis.Core
|
|||||||
_connectedTo.Add(pin);
|
_connectedTo.Add(pin);
|
||||||
OnPropertyChanged(nameof(ConnectedTo));
|
OnPropertyChanged(nameof(ConnectedTo));
|
||||||
|
|
||||||
PinConnected?.Invoke(this, pin);
|
PinConnected?.Invoke(this, new SingleValueEventArgs<IPin>(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectFrom(IPin pin)
|
public void DisconnectFrom(IPin pin)
|
||||||
@ -62,7 +63,7 @@ namespace Artemis.Core
|
|||||||
_connectedTo.Remove(pin);
|
_connectedTo.Remove(pin);
|
||||||
OnPropertyChanged(nameof(ConnectedTo));
|
OnPropertyChanged(nameof(ConnectedTo));
|
||||||
|
|
||||||
PinDisconnected?.Invoke(this, pin);
|
PinDisconnected?.Invoke(this, new SingleValueEventArgs<IPin>(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectAll()
|
public void DisconnectAll()
|
||||||
@ -73,7 +74,7 @@ namespace Artemis.Core
|
|||||||
OnPropertyChanged(nameof(ConnectedTo));
|
OnPropertyChanged(nameof(ConnectedTo));
|
||||||
|
|
||||||
foreach (IPin pin in connectedPins)
|
foreach (IPin pin in connectedPins)
|
||||||
PinDisconnected?.Invoke(this, pin);
|
PinDisconnected?.Invoke(this, new SingleValueEventArgs<IPin>(pin));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNodeResetting(object sender, EventArgs e)
|
private void OnNodeResetting(object sender, EventArgs e)
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -22,8 +23,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
public event EventHandler<IPin> PinAdded;
|
public event EventHandler<SingleValueEventArgs<IPin>> PinAdded;
|
||||||
public event EventHandler<IPin> PinRemoved;
|
public event EventHandler<SingleValueEventArgs<IPin>> PinRemoved;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ namespace Artemis.Core
|
|||||||
IPin pin = CreatePin();
|
IPin pin = CreatePin();
|
||||||
_pins.Add(pin);
|
_pins.Add(pin);
|
||||||
|
|
||||||
PinAdded?.Invoke(this, pin);
|
PinAdded?.Invoke(this, new SingleValueEventArgs<IPin>(pin));
|
||||||
|
|
||||||
return pin;
|
return pin;
|
||||||
}
|
}
|
||||||
@ -58,7 +59,7 @@ namespace Artemis.Core
|
|||||||
bool removed = _pins.Remove(pin);
|
bool removed = _pins.Remove(pin);
|
||||||
|
|
||||||
if (removed)
|
if (removed)
|
||||||
PinRemoved?.Invoke(this, pin);
|
PinRemoved?.Invoke(this, new SingleValueEventArgs<IPin>(pin));
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
using Artemis.VisualScripting.Events;
|
using Artemis.VisualScripting.Events;
|
||||||
using Artemis.VisualScripting.ViewModel;
|
using Artemis.VisualScripting.ViewModel;
|
||||||
|
|
||||||
@ -78,10 +79,9 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
|
|
||||||
LocationOffset = SurfaceSize / 2.0;
|
LocationOffset = SurfaceSize / 2.0;
|
||||||
|
|
||||||
Nodes.CollectionChanged += OnNodeCollectionChanged;
|
CollectionChangedEventManager.AddHandler(Nodes, OnNodeCollectionChanged);
|
||||||
|
NodeAddedEventManager.AddHandler(script, OnScriptNodeAdded);
|
||||||
script.NodeAdded += OnScriptNodeAdded;
|
NodeRemovedEventManager.AddHandler(script, OnScriptNodeRemoved);
|
||||||
script.NodeRemoved += OnScriptRemovedAdded;
|
|
||||||
|
|
||||||
foreach (INode node in Script.Nodes)
|
foreach (INode node in Script.Nodes)
|
||||||
InitializeNode(node);
|
InitializeNode(node);
|
||||||
@ -107,16 +107,16 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
RegisterNodes(args.NewItems.Cast<VisualScriptNode>());
|
RegisterNodes(args.NewItems.Cast<VisualScriptNode>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnScriptNodeAdded(object sender, INode node)
|
private void OnScriptNodeAdded(object sender, SingleValueEventArgs<INode> args)
|
||||||
{
|
{
|
||||||
if (_nodeMapping.ContainsKey(node)) return;
|
if (_nodeMapping.ContainsKey(args.Value)) return;
|
||||||
|
|
||||||
InitializeNode(node);
|
InitializeNode(args.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnScriptRemovedAdded(object sender, INode node)
|
private void OnScriptNodeRemoved(object sender, SingleValueEventArgs<INode> args)
|
||||||
{
|
{
|
||||||
if (!_nodeMapping.TryGetValue(node, out VisualScriptNode visualScriptNode)) return;
|
if (!_nodeMapping.TryGetValue(args.Value, out VisualScriptNode visualScriptNode)) return;
|
||||||
|
|
||||||
Nodes.Remove(visualScriptNode);
|
Nodes.Remove(visualScriptNode);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,7 +98,10 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
this.Script = script;
|
this.Script = script;
|
||||||
this.Node = node;
|
this.Node = node;
|
||||||
|
|
||||||
Node.PropertyChanged += OnNodePropertyChanged;
|
PropertyChangedEventManager.AddHandler(Node, OnNodePropertyChanged, nameof(Node.Pins));
|
||||||
|
PropertyChangedEventManager.AddHandler(Node, OnNodePropertyChanged, nameof(Node.PinCollections));
|
||||||
|
PropertyChangedEventManager.AddHandler(Node, OnNodePropertyChanged, nameof(Node.X));
|
||||||
|
PropertyChangedEventManager.AddHandler(Node, OnNodePropertyChanged, nameof(Node.Y));
|
||||||
|
|
||||||
ValidatePins();
|
ValidatePins();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
using Artemis.VisualScripting.Events;
|
using Artemis.VisualScripting.Events;
|
||||||
using Artemis.VisualScripting.Internal;
|
using Artemis.VisualScripting.Internal;
|
||||||
using Artemis.VisualScripting.ViewModel;
|
using Artemis.VisualScripting.ViewModel;
|
||||||
@ -52,15 +53,15 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
this.Node = node;
|
this.Node = node;
|
||||||
this.Pin = pin;
|
this.Pin = pin;
|
||||||
|
|
||||||
pin.PinConnected += PinConnectionChanged;
|
PinConnectedEventManager.AddHandler(pin, PinConnectionChanged);
|
||||||
pin.PinDisconnected += PinConnectionChanged;
|
PinDisconnectedEventManager.AddHandler(pin, PinConnectionChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
private void PinConnectionChanged(object sender, IPin pin)
|
private void PinConnectionChanged(object sender, SingleValueEventArgs<IPin> pin)
|
||||||
{
|
{
|
||||||
if (_isConnectionUpdated) return;
|
if (_isConnectionUpdated) return;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
using Artemis.VisualScripting.Events;
|
||||||
using Artemis.VisualScripting.ViewModel;
|
using Artemis.VisualScripting.ViewModel;
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
||||||
@ -34,8 +36,8 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
this.Node = node;
|
this.Node = node;
|
||||||
this.PinCollection = pinCollection;
|
this.PinCollection = pinCollection;
|
||||||
|
|
||||||
pinCollection.PinAdded += OnPinCollectionPinAdded;
|
PinAddedEventManager.AddHandler(pinCollection, OnPinCollectionPinAdded);
|
||||||
pinCollection.PinRemoved += OnPinCollectionPinRemoved;
|
PinRemovedEventManager.AddHandler(pinCollection, OnPinCollectionPinRemoved);
|
||||||
|
|
||||||
foreach (IPin pin in PinCollection)
|
foreach (IPin pin in PinCollection)
|
||||||
{
|
{
|
||||||
@ -49,32 +51,27 @@ namespace Artemis.VisualScripting.Editor.Controls.Wrapper
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
private void OnPinCollectionPinRemoved(object sender, IPin pin)
|
private void OnPinCollectionPinRemoved(object sender, SingleValueEventArgs<IPin> args)
|
||||||
{
|
{
|
||||||
if (!_pinMapping.TryGetValue(pin, out VisualScriptPin visualScriptPin)) return;
|
if (!_pinMapping.TryGetValue(args.Value, out VisualScriptPin visualScriptPin)) return;
|
||||||
|
|
||||||
visualScriptPin.DisconnectAll();
|
visualScriptPin.DisconnectAll();
|
||||||
Pins.Remove(visualScriptPin);
|
Pins.Remove(visualScriptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPinCollectionPinAdded(object sender, IPin pin)
|
private void OnPinCollectionPinAdded(object sender, SingleValueEventArgs<IPin> args)
|
||||||
{
|
{
|
||||||
if (_pinMapping.ContainsKey(pin)) return;
|
if (_pinMapping.ContainsKey(args.Value)) return;
|
||||||
|
|
||||||
VisualScriptPin visualScriptPin = new(Node, pin);
|
VisualScriptPin visualScriptPin = new(Node, args.Value);
|
||||||
_pinMapping.Add(pin, visualScriptPin);
|
_pinMapping.Add(args.Value, visualScriptPin);
|
||||||
Pins.Add(visualScriptPin);
|
Pins.Add(visualScriptPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddPin()
|
public void AddPin() => PinCollection.AddPin();
|
||||||
{
|
|
||||||
PinCollection.AddPin();
|
public void RemovePin(VisualScriptPin pin) => PinCollection.Remove(pin.Pin);
|
||||||
}
|
|
||||||
|
|
||||||
public void RemovePin(VisualScriptPin pin)
|
|
||||||
{
|
|
||||||
PinCollection.Remove(pin.Pin);
|
|
||||||
}
|
|
||||||
public void RemoveAll()
|
public void RemoveAll()
|
||||||
{
|
{
|
||||||
List<VisualScriptPin> pins = new(Pins);
|
List<VisualScriptPin> pins = new(Pins);
|
||||||
|
|||||||
77
src/Artemis.VisualScripting/Events/NodeAddedEventManager.cs
Normal file
77
src/Artemis.VisualScripting/Events/NodeAddedEventManager.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class NodeAddedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static NodeAddedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(NodeAddedEventManager);
|
||||||
|
NodeAddedEventManager changedEventManager = (NodeAddedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new NodeAddedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private NodeAddedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(INodeScript source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(INodeScript source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(INodeScript source, EventHandler<SingleValueEventArgs<INode>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(INodeScript source, EventHandler<SingleValueEventArgs<INode>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<INode>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((INodeScript)source).NodeAdded += OnNodeAdded;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((INodeScript)source).NodeAdded -= OnNodeAdded;
|
||||||
|
|
||||||
|
private void OnNodeAdded(object sender, SingleValueEventArgs<INode> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class NodeRemovedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static NodeRemovedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(NodeRemovedEventManager);
|
||||||
|
NodeRemovedEventManager changedEventManager = (NodeRemovedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new NodeRemovedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private NodeRemovedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(INodeScript source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(INodeScript source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(INodeScript source, EventHandler<SingleValueEventArgs<INode>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(INodeScript source, EventHandler<SingleValueEventArgs<INode>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<INode>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((INodeScript)source).NodeRemoved += OnNodeRemoved;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((INodeScript)source).NodeRemoved -= OnNodeRemoved;
|
||||||
|
|
||||||
|
private void OnNodeRemoved(object sender, SingleValueEventArgs<INode> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/Artemis.VisualScripting/Events/PinAddedEventManager.cs
Normal file
77
src/Artemis.VisualScripting/Events/PinAddedEventManager.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class PinAddedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static PinAddedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(PinAddedEventManager);
|
||||||
|
PinAddedEventManager changedEventManager = (PinAddedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new PinAddedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private PinAddedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(IPinCollection source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(IPinCollection source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(IPinCollection source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(IPinCollection source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<IPin>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((IPinCollection)source).PinAdded += OnPinAdded;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((IPinCollection)source).PinAdded -= OnPinAdded;
|
||||||
|
|
||||||
|
private void OnPinAdded(object sender, SingleValueEventArgs<IPin> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class PinConnectedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static PinConnectedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(PinConnectedEventManager);
|
||||||
|
PinConnectedEventManager changedEventManager = (PinConnectedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new PinConnectedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private PinConnectedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(IPin source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(IPin source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(IPin source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(IPin source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<IPin>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((IPin)source).PinConnected += OnPinConnected;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((IPin)source).PinConnected -= OnPinConnected;
|
||||||
|
|
||||||
|
private void OnPinConnected(object sender, SingleValueEventArgs<IPin> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class PinDisconnectedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static PinDisconnectedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(PinDisconnectedEventManager);
|
||||||
|
PinDisconnectedEventManager changedEventManager = (PinDisconnectedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new PinDisconnectedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private PinDisconnectedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(IPin source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(IPin source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(IPin source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(IPin source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<IPin>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((IPin)source).PinDisconnected += OnPinDisconnected;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((IPin)source).PinDisconnected -= OnPinDisconnected;
|
||||||
|
|
||||||
|
private void OnPinDisconnected(object sender, SingleValueEventArgs<IPin> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/Artemis.VisualScripting/Events/PinRemovedEventManager.cs
Normal file
77
src/Artemis.VisualScripting/Events/PinRemovedEventManager.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Events;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Events
|
||||||
|
{
|
||||||
|
public class PinRemovedEventManager : WeakEventManager
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private static PinRemovedEventManager CurrentManager
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Type type = typeof(PinRemovedEventManager);
|
||||||
|
PinRemovedEventManager changedEventManager = (PinRemovedEventManager)GetCurrentManager(type);
|
||||||
|
if (changedEventManager == null)
|
||||||
|
{
|
||||||
|
changedEventManager = new PinRemovedEventManager();
|
||||||
|
SetCurrentManager(type, changedEventManager);
|
||||||
|
}
|
||||||
|
return changedEventManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
private PinRemovedEventManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public static void AddListener(IPinCollection source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveListener(IPinCollection source, IWeakEventListener listener)
|
||||||
|
{
|
||||||
|
if (listener == null) throw new ArgumentNullException(nameof(listener));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveListener(source, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddHandler(IPinCollection source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedAddHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveHandler(IPinCollection source, EventHandler<SingleValueEventArgs<IPin>> handler)
|
||||||
|
{
|
||||||
|
if (handler == null) throw new ArgumentNullException(nameof(handler));
|
||||||
|
|
||||||
|
CurrentManager.ProtectedRemoveHandler(source, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ListenerList NewListenerList() => new ListenerList<SingleValueEventArgs<IPin>>();
|
||||||
|
|
||||||
|
protected override void StartListening(object source) => ((IPinCollection)source).PinRemoved += OnPinRemoved;
|
||||||
|
|
||||||
|
protected override void StopListening(object source) => ((IPinCollection)source).PinRemoved -= OnPinRemoved;
|
||||||
|
|
||||||
|
private void OnPinRemoved(object sender, SingleValueEventArgs<IPin> args) => DeliverEvent(sender, args);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user