mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Provide scripts with a context
Nodes - Inform nodes about the script they're being initialized for Nodes - Added float nodes matching the existing other number types Core - Add API for retrieving data binding values via the interface
This commit is contained in:
parent
3ed3cd1b1e
commit
836e979991
@ -19,7 +19,7 @@ namespace Artemis.Core
|
|||||||
Entity = new DataBindingEntity();
|
Entity = new DataBindingEntity();
|
||||||
|
|
||||||
ApplyRegistration(dataBindingRegistration);
|
ApplyRegistration(dataBindingRegistration);
|
||||||
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
|
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile);
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
LayerProperty = layerProperty;
|
LayerProperty = layerProperty;
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
|
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile);
|
||||||
|
|
||||||
// Load will add children so be initialized before that
|
// Load will add children so be initialized before that
|
||||||
Load();
|
Load();
|
||||||
@ -245,8 +245,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Script.Dispose();
|
Script.Dispose();
|
||||||
Script = Entity.NodeScript != null
|
Script = Entity.NodeScript != null
|
||||||
? new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", Entity.NodeScript)
|
? new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", Entity.NodeScript, LayerProperty.ProfileElement.Profile)
|
||||||
: new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
|
: new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -40,6 +40,9 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string DisplayName { get; }
|
public string DisplayName { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Type ValueType => typeof(TProperty);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the data binding created using this registration
|
/// Gets the data binding created using this registration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -74,5 +77,11 @@ namespace Artemis.Core
|
|||||||
// The related entity is left behind, just in case the data binding is added back later
|
// The related entity is left behind, just in case the data binding is added back later
|
||||||
LayerProperty.DisableDataBinding(DataBinding);
|
LayerProperty.DisableDataBinding(DataBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public object? GetValue()
|
||||||
|
{
|
||||||
|
return Getter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
namespace Artemis.Core
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a data binding registration
|
/// Represents a data binding registration
|
||||||
@ -10,6 +12,11 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string DisplayName { get; }
|
string DisplayName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type of the value this data binding registration points to
|
||||||
|
/// </summary>
|
||||||
|
Type ValueType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the data binding applied using this registration
|
/// Returns the data binding applied using this registration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -25,5 +32,11 @@
|
|||||||
/// If present, removes the current data binding
|
/// If present, removes the current data binding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void ClearDataBinding();
|
void ClearDataBinding();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value of the data binding
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A value matching the type of <see cref="ValueType" /></returns>
|
||||||
|
object? GetValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ namespace Artemis.Core
|
|||||||
internal RenderProfileElement(Profile profile) : base(profile)
|
internal RenderProfileElement(Profile profile) : base(profile)
|
||||||
{
|
{
|
||||||
_typeDisplayName = this is Layer ? "layer" : "folder";
|
_typeDisplayName = this is Layer ? "layer" : "folder";
|
||||||
_displayCondition = new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active");
|
_displayCondition = new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", Profile);
|
||||||
|
|
||||||
Timeline = new Timeline();
|
Timeline = new Timeline();
|
||||||
ExpandedPropertyGroups = new List<string>();
|
ExpandedPropertyGroups = new List<string>();
|
||||||
@ -71,8 +71,8 @@ namespace Artemis.Core
|
|||||||
internal void LoadRenderElement()
|
internal void LoadRenderElement()
|
||||||
{
|
{
|
||||||
DisplayCondition = RenderElementEntity.NodeScript != null
|
DisplayCondition = RenderElementEntity.NodeScript != null
|
||||||
? new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", RenderElementEntity.NodeScript)
|
? new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", RenderElementEntity.NodeScript, Profile)
|
||||||
: new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active");
|
: new NodeScript<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", Profile);
|
||||||
|
|
||||||
Timeline = RenderElementEntity.Timeline != null
|
Timeline = RenderElementEntity.Timeline != null
|
||||||
? new Timeline(RenderElementEntity.Timeline)
|
? new Timeline(RenderElementEntity.Timeline)
|
||||||
|
|||||||
@ -28,7 +28,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Entity = new ProfileConfigurationEntity();
|
Entity = new ProfileConfigurationEntity();
|
||||||
Icon = new ProfileConfigurationIcon(Entity) {MaterialIcon = icon};
|
Icon = new ProfileConfigurationIcon(Entity) {MaterialIcon = icon};
|
||||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active");
|
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
|
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
|
||||||
@ -39,7 +39,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
Icon = new ProfileConfigurationIcon(Entity);
|
Icon = new ProfileConfigurationIcon(Entity);
|
||||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active");
|
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
@ -242,8 +242,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
ActivationCondition.Dispose();
|
ActivationCondition.Dispose();
|
||||||
ActivationCondition = Entity.ActivationCondition != null
|
ActivationCondition = Entity.ActivationCondition != null
|
||||||
? new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", Entity.ActivationCondition)
|
? new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", Entity.ActivationCondition, this)
|
||||||
: new NodeScript<bool>("Activate profile", "Whether or not the profile should be active");
|
: new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||||
|
|
||||||
EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null;
|
EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null;
|
||||||
DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null;
|
DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null;
|
||||||
|
|||||||
@ -53,7 +53,7 @@ namespace Artemis.Core.Services
|
|||||||
string description = nodeAttribute?.Description ?? string.Empty;
|
string description = nodeAttribute?.Description ?? string.Empty;
|
||||||
string category = nodeAttribute?.Category ?? string.Empty;
|
string category = nodeAttribute?.Category ?? string.Empty;
|
||||||
|
|
||||||
NodeData nodeData = new(plugin, nodeType, name, description, category, e => CreateNode(e, nodeType));
|
NodeData nodeData = new(plugin, nodeType, name, description, category, (s, e) => CreateNode(s, e, nodeType));
|
||||||
return NodeTypeStore.Add(nodeData);
|
return NodeTypeStore.Add(nodeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ namespace Artemis.Core.Services
|
|||||||
return NodeTypeStore.AddColor(type, color, plugin);
|
return NodeTypeStore.AddColor(type, color, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private INode CreateNode(NodeEntity? entity, Type nodeType)
|
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");
|
INode node = _kernel.Get(nodeType) as INode ?? throw new InvalidOperationException($"Node {nodeType} is not an INode");
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ namespace Artemis.Core.Services
|
|||||||
if (node is CustomViewModelNode customViewModelNode)
|
if (node is CustomViewModelNode customViewModelNode)
|
||||||
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType, new ConstructorArgument("node", node));
|
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType, new ConstructorArgument("node", node));
|
||||||
|
|
||||||
node.Initialize();
|
node.Initialize(script);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,14 +2,8 @@
|
|||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
public class CustomNodeViewModel : CorePropertyChanged
|
public interface ICustomNodeViewModel
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
|
||||||
public INode Node { get; }
|
public INode Node { get; }
|
||||||
|
|
||||||
public CustomNodeViewModel(INode node)
|
|
||||||
{
|
|
||||||
Node = node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
event EventHandler Resetting;
|
event EventHandler Resetting;
|
||||||
|
|
||||||
void Initialize();
|
void Initialize(INodeScript script);
|
||||||
void Evaluate();
|
void Evaluate();
|
||||||
void Reset();
|
void Reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Type ResultType { get; }
|
Type ResultType { get; }
|
||||||
|
|
||||||
|
object? Context { get; set; }
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
void AddNode(INode node);
|
void AddNode(INode node);
|
||||||
void RemoveNode(INode node);
|
void RemoveNode(INode node);
|
||||||
|
|||||||
@ -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 System.Linq;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -136,7 +137,9 @@ namespace Artemis.Core
|
|||||||
return pin;
|
return pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Initialize() { }
|
public virtual void Initialize(INodeScript script)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void Evaluate();
|
public abstract void Evaluate();
|
||||||
|
|
||||||
@ -148,7 +151,7 @@ namespace Artemis.Core
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class Node<T> : CustomViewModelNode where T : CustomNodeViewModel
|
public abstract class Node<T> : CustomViewModelNode where T : ICustomNodeViewModel
|
||||||
{
|
{
|
||||||
protected Node()
|
protected Node()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -14,13 +14,13 @@ namespace Artemis.Core
|
|||||||
public string Description { get; }
|
public string Description { get; }
|
||||||
public string Category { get; }
|
public string Category { get; }
|
||||||
|
|
||||||
private Func<NodeEntity?, INode> _create;
|
private Func<INodeScript, NodeEntity?, INode> _create;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
internal NodeData(Plugin plugin, Type type, string name, string description, string category, Func<NodeEntity?, INode>? create)
|
internal NodeData(Plugin plugin, Type type, string name, string description, string category, Func<INodeScript, NodeEntity?, INode>? create)
|
||||||
{
|
{
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
@ -34,7 +34,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public INode CreateNode(NodeEntity? entity) => _create(entity);
|
public INode CreateNode(INodeScript script, NodeEntity? entity) => _create(script, entity);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,25 +24,29 @@ namespace Artemis.Core
|
|||||||
protected INode ExitNode { get; set; }
|
protected INode ExitNode { get; set; }
|
||||||
public abstract Type ResultType { get; }
|
public abstract Type ResultType { get; }
|
||||||
|
|
||||||
|
public object? Context { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public NodeScript(string name, string description)
|
public NodeScript(string name, string description, object? context = null)
|
||||||
{
|
{
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
|
this.Context = context;
|
||||||
this.Entity = new NodeScriptEntity();
|
this.Entity = new NodeScriptEntity();
|
||||||
|
|
||||||
NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged;
|
NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged;
|
||||||
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
|
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal NodeScript(string name, string description, NodeScriptEntity entity)
|
internal NodeScript(string name, string description, NodeScriptEntity entity, object? context = null)
|
||||||
{
|
{
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.Entity = entity;
|
this.Entity = entity;
|
||||||
|
this.Context = context;
|
||||||
|
|
||||||
NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged;
|
NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged;
|
||||||
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
|
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
|
||||||
@ -108,7 +112,7 @@ namespace Artemis.Core
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Create the node
|
// Create the node
|
||||||
node = nodeTypeRegistration.NodeData.CreateNode(nodeEntity);
|
node = nodeTypeRegistration.NodeData.CreateNode(this, nodeEntity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -272,8 +276,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
internal NodeScript(string name, string description, NodeScriptEntity entity)
|
internal NodeScript(string name, string description, NodeScriptEntity entity, object? context = null)
|
||||||
: base(name, description, entity)
|
: base(name, description, entity, context)
|
||||||
{
|
{
|
||||||
ExitNode = new ExitNode<T>(name, description);
|
ExitNode = new ExitNode<T>(name, description);
|
||||||
AddNode(ExitNode);
|
AddNode(ExitNode);
|
||||||
@ -281,8 +285,8 @@ namespace Artemis.Core
|
|||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeScript(string name, string description)
|
public NodeScript(string name, string description, object? context = null)
|
||||||
: base(name, description)
|
: base(name, description, context)
|
||||||
{
|
{
|
||||||
ExitNode = new ExitNode<T>(name, description);
|
ExitNode = new ExitNode<T>(name, description);
|
||||||
AddNode(ExitNode);
|
AddNode(ExitNode);
|
||||||
|
|||||||
@ -116,8 +116,6 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
|||||||
if (RenderProfileElement == null)
|
if (RenderProfileElement == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RenderProfileElement.DisplayCondition ??= new NodeScript<bool>("End Result", "");
|
|
||||||
|
|
||||||
_windowManager.ShowDialog(_nodeVmFactory.NodeScriptWindowViewModel(RenderProfileElement.DisplayCondition));
|
_windowManager.ShowDialog(_nodeVmFactory.NodeScriptWindowViewModel(RenderProfileElement.DisplayCondition));
|
||||||
_profileEditorService.SaveSelectedProfileElement();
|
_profileEditorService.SaveSelectedProfileElement();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,9 @@
|
|||||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Update="Nodes\CustomViews\StaticFloatValueNodeCustomView.xaml">
|
||||||
|
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||||
|
</Page>
|
||||||
<Page Update="ResourceDictionaries\DataModelConditions.xaml">
|
<Page Update="ResourceDictionaries\DataModelConditions.xaml">
|
||||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@ -383,7 +383,8 @@ namespace Artemis.VisualScripting.Editor.Controls
|
|||||||
if (_creationBoxParent.ContextMenu != null)
|
if (_creationBoxParent.ContextMenu != null)
|
||||||
_creationBoxParent.ContextMenu.IsOpen = false;
|
_creationBoxParent.ContextMenu.IsOpen = false;
|
||||||
|
|
||||||
INode node = nodeData.CreateNode(null);
|
INode node = nodeData.CreateNode(Script, null);
|
||||||
|
node.Initialize(Script);
|
||||||
Script.AddNode(node);
|
Script.AddNode(node);
|
||||||
|
|
||||||
InitializeNode(node, _lastRightClickLocation);
|
InitializeNode(node, _lastRightClickLocation);
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Stylet;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||||
|
{
|
||||||
|
public abstract class CustomNodeViewModel : PropertyChangedBase, IViewAware, ICustomNodeViewModel
|
||||||
|
{
|
||||||
|
protected CustomNodeViewModel(INode node)
|
||||||
|
{
|
||||||
|
Node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public INode Node { get; }
|
||||||
|
|
||||||
|
#region Implementation of IViewAware
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void AttachView(UIElement view)
|
||||||
|
{
|
||||||
|
View = view;
|
||||||
|
OnDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnDisplay()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public UIElement View { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,16 +1,25 @@
|
|||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
using Artemis.Core.Modules;
|
||||||
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||||
{
|
{
|
||||||
public class DataModelNodeCustomViewModel : CustomNodeViewModel
|
public class DataModelNodeCustomViewModel : CustomNodeViewModel
|
||||||
{
|
{
|
||||||
private readonly DataModelNode _node;
|
private readonly DataModelNode _node;
|
||||||
|
private BindableCollection<Module> _modules;
|
||||||
|
|
||||||
public DataModelNodeCustomViewModel(DataModelNode node) : base(node)
|
public DataModelNodeCustomViewModel(DataModelNode node) : base(node)
|
||||||
{
|
{
|
||||||
_node = node;
|
_node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BindableCollection<Module> Modules
|
||||||
|
{
|
||||||
|
get => _modules;
|
||||||
|
set => SetAndNotify(ref _modules, value);
|
||||||
|
}
|
||||||
|
|
||||||
public DataModelPath DataModelPath
|
public DataModelPath DataModelPath
|
||||||
{
|
{
|
||||||
get => _node.DataModelPath;
|
get => _node.DataModelPath;
|
||||||
@ -32,5 +41,28 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
|||||||
_node.UpdateOutputPin();
|
_node.UpdateOutputPin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
if (Modules != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Modules = new BindableCollection<Module>();
|
||||||
|
if (_node.Script.Context is Profile scriptProfile && scriptProfile.Configuration.Module != null)
|
||||||
|
Modules.Add(scriptProfile.Configuration.Module);
|
||||||
|
else if (_node.Script.Context is ProfileConfiguration profileConfiguration && profileConfiguration.Module != null)
|
||||||
|
Modules.Add(profileConfiguration.Module);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Overrides of CustomNodeViewModel
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void OnDisplay()
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
base.OnDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,24 +0,0 @@
|
|||||||
using Artemis.Core;
|
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
|
||||||
{
|
|
||||||
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
|
|
||||||
{
|
|
||||||
private readonly StaticDoubleValueNode _node;
|
|
||||||
|
|
||||||
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
|
|
||||||
{
|
|
||||||
_node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double Input
|
|
||||||
{
|
|
||||||
get => (double) _node.Storage;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_node.Storage = value;
|
|
||||||
OnPropertyChanged(nameof(Input));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
using Artemis.Core;
|
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
|
||||||
{
|
|
||||||
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
|
|
||||||
{
|
|
||||||
private readonly StaticIntegerValueNode _node;
|
|
||||||
|
|
||||||
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
|
|
||||||
{
|
|
||||||
_node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Input
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_node.Storage is long longInput)
|
|
||||||
return (int) longInput;
|
|
||||||
return (int) _node.Storage;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_node.Storage = value;
|
|
||||||
OnPropertyChanged(nameof(Input));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
using Artemis.Core;
|
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
|
||||||
{
|
|
||||||
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
|
|
||||||
{
|
|
||||||
private readonly StaticStringValueNode _node;
|
|
||||||
|
|
||||||
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
|
|
||||||
{
|
|
||||||
_node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Input
|
|
||||||
{
|
|
||||||
get => (string) _node.Storage;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_node.Storage = value;
|
|
||||||
OnPropertyChanged(nameof(Input));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
using Artemis.Core;
|
||||||
|
|
||||||
|
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||||
|
{
|
||||||
|
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
|
||||||
|
{
|
||||||
|
private readonly StaticDoubleValueNode _node;
|
||||||
|
|
||||||
|
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
|
||||||
|
{
|
||||||
|
_node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Input
|
||||||
|
{
|
||||||
|
get => (double) _node.Storage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_node.Storage = value;
|
||||||
|
OnPropertyChanged(nameof(Input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StaticFloatValueNodeCustomViewModel : CustomNodeViewModel
|
||||||
|
{
|
||||||
|
private readonly StaticFloatValueNode _node;
|
||||||
|
|
||||||
|
public StaticFloatValueNodeCustomViewModel(StaticFloatValueNode node) : base(node)
|
||||||
|
{
|
||||||
|
_node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Input
|
||||||
|
{
|
||||||
|
get => (float)_node.Storage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_node.Storage = value;
|
||||||
|
OnPropertyChanged(nameof(Input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
|
||||||
|
{
|
||||||
|
private readonly StaticIntegerValueNode _node;
|
||||||
|
|
||||||
|
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
|
||||||
|
{
|
||||||
|
_node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Input
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_node.Storage is long longInput)
|
||||||
|
return (int)longInput;
|
||||||
|
return (int)_node.Storage;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_node.Storage = value;
|
||||||
|
OnPropertyChanged(nameof(Input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
|
||||||
|
{
|
||||||
|
private readonly StaticStringValueNode _node;
|
||||||
|
|
||||||
|
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
|
||||||
|
{
|
||||||
|
_node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Input
|
||||||
|
{
|
||||||
|
get => (string)_node.Storage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_node.Storage = value;
|
||||||
|
OnPropertyChanged(nameof(Input));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,5 +8,5 @@
|
|||||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<controls:DataModelPicker DataModelPath="{Binding DataModelPath}" ButtonBrush="#434343"/>
|
<controls:DataModelPicker DataModelPath="{Binding DataModelPath}" Modules="{Binding Modules}" ButtonBrush="#434343"/>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.StaticFloatValueNodeCustomView"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:Artemis.VisualScripting.Nodes.CustomViewModels"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
<TextBox VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
Text="{Binding Input}" />
|
||||||
|
</UserControl>
|
||||||
@ -13,11 +13,14 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public INodeScript Script { get; private set; }
|
||||||
public OutputPin Output { get; private set; }
|
public OutputPin Output { get; private set; }
|
||||||
public DataModelPath DataModelPath { get; set; }
|
public DataModelPath DataModelPath { get; set; }
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize(INodeScript script)
|
||||||
{
|
{
|
||||||
|
Script = script;
|
||||||
|
|
||||||
if (Storage is not DataModelPathEntity pathEntity)
|
if (Storage is not DataModelPathEntity pathEntity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
Output.Value = Storage as int? ?? 0;
|
Output.Value = Storage as int? ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize() => Storage ??= 0;
|
public override void Initialize(INodeScript script) => Storage ??= 0;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -60,7 +60,38 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
Output.Value = Storage as double? ?? 0.0;
|
Output.Value = Storage as double? ?? 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize() => Storage ??= 0.0;
|
public override void Initialize(INodeScript script) => Storage ??= 0.0;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
[Node("Float-Value", "Outputs a configurable float value.")]
|
||||||
|
public class StaticFloatValueNode : Node<StaticFloatValueNodeCustomViewModel>
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public OutputPin<float> Output { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public StaticFloatValueNode()
|
||||||
|
: base("Float", "Outputs a configurable float value.")
|
||||||
|
{
|
||||||
|
Output = CreateOutputPin<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public override void Evaluate()
|
||||||
|
{
|
||||||
|
Output.Value = Storage as float? ?? 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize(INodeScript script) => Storage ??= 0.0f;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,38 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Node("Sum (Float)", "Sums the connected float values.")]
|
||||||
|
public class SumFloatsNode : Node
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public InputPinCollection<float> Values { get; }
|
||||||
|
|
||||||
|
public OutputPin<float> Sum { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SumFloatsNode()
|
||||||
|
: base("Sum", "Sums the connected float values.")
|
||||||
|
{
|
||||||
|
Values = CreateInputPinCollection<float>("Values", 2);
|
||||||
|
Sum = CreateOutputPin<float>("Sum");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public override void Evaluate()
|
||||||
|
{
|
||||||
|
Sum.Value = Values.Values.Sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
[Node("Sum (Double)", "Sums the connected double values.")]
|
[Node("Sum (Double)", "Sums the connected double values.")]
|
||||||
public class SumDoublesNode : Node
|
public class SumDoublesNode : Node
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user