mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Node editor - Added menu
Node scripts - Fixed IDs not being set for regular nodes Enums node - Hardened VM logic against weird connections
This commit is contained in:
1 parent
a0260b53e5
commit
850346ccd2
14 files changed
+352
-56
No files matched your search
@@ -55,7 +55,7 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
|
||||
public NodeScript<bool> Script
|
||||
{
|
||||
get => _script;
|
||||
set => SetAndNotify(ref _script, value);
|
||||
private set => SetAndNotify(ref _script, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Artemis.Core.VisualScripting;
|
||||
using Artemis.Storage.Entities.Profile.Nodes;
|
||||
using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
using SkiaSharp;
|
||||
|
||||
@@ -80,6 +82,21 @@ namespace Artemis.Core.Services
|
||||
return NodeTypeStore.AddColor(type, color, plugin);
|
||||
}
|
||||
|
||||
public string ExportScript(NodeScript nodeScript)
|
||||
{
|
||||
nodeScript.Save();
|
||||
return JsonConvert.SerializeObject(nodeScript.Entity, IProfileService.ExportSettings);
|
||||
}
|
||||
|
||||
public void ImportScript(string json, NodeScript target)
|
||||
{
|
||||
NodeScriptEntity? entity = JsonConvert.DeserializeObject<NodeScriptEntity>(json);
|
||||
if (entity == null)
|
||||
throw new ArtemisCoreException("Failed to load node script");
|
||||
|
||||
target.LoadFromEntity(entity);
|
||||
}
|
||||
|
||||
private INode CreateNode(INodeScript script, NodeEntity? entity, Type nodeType)
|
||||
{
|
||||
INode node = _kernel.Get(nodeType) as INode ?? throw new InvalidOperationException($"Node {nodeType} is not an INode");
|
||||
@@ -135,5 +152,8 @@ namespace Artemis.Core.Services
|
||||
/// <param name="type">The type to associate the color with</param>
|
||||
/// <param name="color">The color to display</param>
|
||||
TypeColorRegistration RegisterTypeColor(Plugin plugin, Type type, SKColor color);
|
||||
|
||||
string ExportScript(NodeScript nodeScript);
|
||||
void ImportScript(string json, NodeScript target);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,8 @@ namespace Artemis.Core.Internal
|
||||
DataBinding = dataBinding;
|
||||
DataBinding.DataBindingPropertiesCleared += DataBindingOnDataBindingPropertiesCleared;
|
||||
DataBinding.DataBindingPropertyRegistered += DataBindingOnDataBindingPropertyRegistered;
|
||||
|
||||
Id = IExitNode.NodeId;
|
||||
|
||||
CreateInputPins();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ public abstract class Node : CorePropertyChanged, INode
|
||||
public event EventHandler? Resetting;
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
|
||||
private Guid _id;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Id
|
||||
{
|
||||
get => _id;
|
||||
set => SetAndNotify(ref _id , value);
|
||||
set => SetAndNotify(ref _id, value);
|
||||
}
|
||||
|
||||
private string _name;
|
||||
@@ -73,7 +73,7 @@ public abstract class Node : CorePropertyChanged, INode
|
||||
public IReadOnlyCollection<IPin> Pins => new ReadOnlyCollection<IPin>(_pins);
|
||||
|
||||
private readonly List<IPinCollection> _pinCollections = new();
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<IPinCollection> PinCollections => new ReadOnlyCollection<IPinCollection>(_pinCollections);
|
||||
|
||||
@@ -88,6 +88,7 @@ public abstract class Node : CorePropertyChanged, INode
|
||||
{
|
||||
_name = string.Empty;
|
||||
_description = string.Empty;
|
||||
_id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,6 +98,7 @@ public abstract class Node : CorePropertyChanged, INode
|
||||
{
|
||||
_name = name;
|
||||
_description = description;
|
||||
_id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Artemis.Core
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
internal NodeScriptEntity Entity { get; }
|
||||
internal NodeScriptEntity Entity { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name { get; }
|
||||
@@ -183,8 +183,15 @@ namespace Artemis.Core
|
||||
LoadConnections();
|
||||
}
|
||||
|
||||
internal void LoadFromEntity(NodeScriptEntity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Load();
|
||||
}
|
||||
|
||||
private void LoadExistingNode(INode node, NodeEntity nodeEntity)
|
||||
{
|
||||
node.Id = nodeEntity.Id;
|
||||
node.X = nodeEntity.X;
|
||||
node.Y = nodeEntity.Y;
|
||||
|
||||
@@ -245,17 +252,21 @@ namespace Artemis.Core
|
||||
|
||||
// Clear existing connections on input pins, we don't want none of that now
|
||||
if (targetPin.Direction == PinDirection.Input)
|
||||
{
|
||||
while (targetPin.ConnectedTo.Any())
|
||||
targetPin.DisconnectFrom(targetPin.ConnectedTo[0]);
|
||||
}
|
||||
|
||||
if (sourcePin.Direction == PinDirection.Input)
|
||||
{
|
||||
while (sourcePin.ConnectedTo.Any())
|
||||
sourcePin.DisconnectFrom(sourcePin.ConnectedTo[0]);
|
||||
}
|
||||
|
||||
// Only connect the nodes if they aren't already connected (LoadConnections may be called twice or more)
|
||||
if (!targetPin.ConnectedTo.Contains(sourcePin))
|
||||
if (!targetPin.ConnectedTo.Contains(sourcePin) && targetPin.IsTypeCompatible(sourcePin.Type))
|
||||
targetPin.ConnectTo(sourcePin);
|
||||
if (!sourcePin.ConnectedTo.Contains(targetPin))
|
||||
if (!sourcePin.ConnectedTo.Contains(targetPin) && sourcePin.IsTypeCompatible(targetPin.Type))
|
||||
sourcePin.ConnectTo(targetPin);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user