diff --git a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs index c95480bae..0cf5fc9fb 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs @@ -19,7 +19,7 @@ namespace Artemis.Core Entity = new DataBindingEntity(); ApplyRegistration(dataBindingRegistration); - Script = new NodeScript(GetScriptName(), "The value to put into the data binding"); + Script = new NodeScript(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile); Save(); } @@ -28,7 +28,7 @@ namespace Artemis.Core { LayerProperty = layerProperty; Entity = entity; - Script = new NodeScript(GetScriptName(), "The value to put into the data binding"); + Script = new NodeScript(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile); // Load will add children so be initialized before that Load(); @@ -245,8 +245,8 @@ namespace Artemis.Core Script.Dispose(); Script = Entity.NodeScript != null - ? new NodeScript(GetScriptName(), "The value to put into the data binding", Entity.NodeScript) - : new NodeScript(GetScriptName(), "The value to put into the data binding"); + ? new NodeScript(GetScriptName(), "The value to put into the data binding", Entity.NodeScript, LayerProperty.ProfileElement.Profile) + : new NodeScript(GetScriptName(), "The value to put into the data binding", LayerProperty.ProfileElement.Profile); } /// diff --git a/src/Artemis.Core/Models/Profile/DataBindings/DataBindingRegistration.cs b/src/Artemis.Core/Models/Profile/DataBindings/DataBindingRegistration.cs index ab50c44c9..cab335a43 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/DataBindingRegistration.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/DataBindingRegistration.cs @@ -40,6 +40,9 @@ namespace Artemis.Core /// public string DisplayName { get; } + /// + public Type ValueType => typeof(TProperty); + /// /// Gets the data binding created using this registration /// @@ -74,5 +77,11 @@ namespace Artemis.Core // The related entity is left behind, just in case the data binding is added back later LayerProperty.DisableDataBinding(DataBinding); } + + /// + public object? GetValue() + { + return Getter(); + } } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/DataBindings/IDataBindingRegistration.cs b/src/Artemis.Core/Models/Profile/DataBindings/IDataBindingRegistration.cs index c1321d4c3..4b9ceeb94 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/IDataBindingRegistration.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/IDataBindingRegistration.cs @@ -1,4 +1,6 @@ -namespace Artemis.Core +using System; + +namespace Artemis.Core { /// /// Represents a data binding registration @@ -10,6 +12,11 @@ /// string DisplayName { get; } + /// + /// Gets the type of the value this data binding registration points to + /// + Type ValueType { get; } + /// /// Returns the data binding applied using this registration /// @@ -25,5 +32,11 @@ /// If present, removes the current data binding /// void ClearDataBinding(); + + /// + /// Gets the value of the data binding + /// + /// A value matching the type of + object? GetValue(); } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs index 7e841350b..7003dd985 100644 --- a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs @@ -23,7 +23,7 @@ namespace Artemis.Core internal RenderProfileElement(Profile profile) : base(profile) { _typeDisplayName = this is Layer ? "layer" : "folder"; - _displayCondition = new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active"); + _displayCondition = new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", Profile); Timeline = new Timeline(); ExpandedPropertyGroups = new List(); @@ -71,8 +71,8 @@ namespace Artemis.Core internal void LoadRenderElement() { DisplayCondition = RenderElementEntity.NodeScript != null - ? new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", RenderElementEntity.NodeScript) - : new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active"); + ? new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", RenderElementEntity.NodeScript, Profile) + : new NodeScript($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active", Profile); Timeline = RenderElementEntity.Timeline != null ? new Timeline(RenderElementEntity.Timeline) diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs index 2f29cdd2a..b2ce08edb 100644 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs +++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs @@ -28,7 +28,7 @@ namespace Artemis.Core Entity = new ProfileConfigurationEntity(); Icon = new ProfileConfigurationIcon(Entity) {MaterialIcon = icon}; - ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active"); + ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active", this); } internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity) @@ -39,7 +39,7 @@ namespace Artemis.Core Entity = entity; Icon = new ProfileConfigurationIcon(Entity); - ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active"); + ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active", this); Load(); } @@ -242,8 +242,8 @@ namespace Artemis.Core ActivationCondition.Dispose(); ActivationCondition = Entity.ActivationCondition != null - ? new NodeScript("Activate profile", "Whether or not the profile should be active", Entity.ActivationCondition) - : new NodeScript("Activate profile", "Whether or not the profile should be active"); + ? new NodeScript("Activate profile", "Whether or not the profile should be active", Entity.ActivationCondition, this) + : new NodeScript("Activate profile", "Whether or not the profile should be active", this); EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null; DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null; diff --git a/src/Artemis.Core/Services/NodeService.cs b/src/Artemis.Core/Services/NodeService.cs index 66ffd7804..fd09d8de5 100644 --- a/src/Artemis.Core/Services/NodeService.cs +++ b/src/Artemis.Core/Services/NodeService.cs @@ -53,7 +53,7 @@ namespace Artemis.Core.Services string description = nodeAttribute?.Description ?? 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); } @@ -65,7 +65,7 @@ namespace Artemis.Core.Services 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"); @@ -79,7 +79,7 @@ namespace Artemis.Core.Services if (node is CustomViewModelNode customViewModelNode) customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType, new ConstructorArgument("node", node)); - node.Initialize(); + node.Initialize(script); return node; } diff --git a/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs b/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs index c53cf951e..5975ed806 100644 --- a/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs +++ b/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs @@ -2,14 +2,8 @@ namespace Artemis.Core { - public class CustomNodeViewModel : CorePropertyChanged + public interface ICustomNodeViewModel { - [JsonIgnore] public INode Node { get; } - - public CustomNodeViewModel(INode node) - { - Node = node; - } } } \ No newline at end of file diff --git a/src/Artemis.Core/VisualScripting/Interfaces/INode.cs b/src/Artemis.Core/VisualScripting/Interfaces/INode.cs index 5a548a4b9..f17fd3352 100644 --- a/src/Artemis.Core/VisualScripting/Interfaces/INode.cs +++ b/src/Artemis.Core/VisualScripting/Interfaces/INode.cs @@ -19,7 +19,7 @@ namespace Artemis.Core event EventHandler Resetting; - void Initialize(); + void Initialize(INodeScript script); void Evaluate(); void Reset(); } diff --git a/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs b/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs index c05ba214d..76a6df648 100644 --- a/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs +++ b/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs @@ -14,6 +14,8 @@ namespace Artemis.Core Type ResultType { get; } + object? Context { get; set; } + void Run(); void AddNode(INode node); void RemoveNode(INode node); diff --git a/src/Artemis.Core/VisualScripting/Node.cs b/src/Artemis.Core/VisualScripting/Node.cs index 90a5f404e..5b504a8ec 100644 --- a/src/Artemis.Core/VisualScripting/Node.cs +++ b/src/Artemis.Core/VisualScripting/Node.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; namespace Artemis.Core { @@ -107,7 +108,7 @@ namespace Artemis.Core OnPropertyChanged(nameof(Pins)); return pin; } - + protected bool RemovePin(Pin pin) { bool isRemoved = _pins.Remove(pin); @@ -136,7 +137,9 @@ namespace Artemis.Core return pin; } - public virtual void Initialize() { } + public virtual void Initialize(INodeScript script) + { + } public abstract void Evaluate(); @@ -148,7 +151,7 @@ namespace Artemis.Core #endregion } - public abstract class Node : CustomViewModelNode where T : CustomNodeViewModel + public abstract class Node : CustomViewModelNode where T : ICustomNodeViewModel { protected Node() { diff --git a/src/Artemis.Core/VisualScripting/NodeData.cs b/src/Artemis.Core/VisualScripting/NodeData.cs index 7d21a0438..8a13d4580 100644 --- a/src/Artemis.Core/VisualScripting/NodeData.cs +++ b/src/Artemis.Core/VisualScripting/NodeData.cs @@ -14,13 +14,13 @@ namespace Artemis.Core public string Description { get; } public string Category { get; } - private Func _create; + private Func _create; #endregion #region Constructors - internal NodeData(Plugin plugin, Type type, string name, string description, string category, Func? create) + internal NodeData(Plugin plugin, Type type, string name, string description, string category, Func? create) { this.Plugin = plugin; this.Type = type; @@ -34,7 +34,7 @@ namespace Artemis.Core #region Methods - public INode CreateNode(NodeEntity? entity) => _create(entity); + public INode CreateNode(INodeScript script, NodeEntity? entity) => _create(script, entity); #endregion } diff --git a/src/Artemis.Core/VisualScripting/NodeScript.cs b/src/Artemis.Core/VisualScripting/NodeScript.cs index ecb992895..8f675a56e 100644 --- a/src/Artemis.Core/VisualScripting/NodeScript.cs +++ b/src/Artemis.Core/VisualScripting/NodeScript.cs @@ -24,25 +24,29 @@ namespace Artemis.Core protected INode ExitNode { get; set; } public abstract Type ResultType { get; } + public object? Context { get; set; } + #endregion #region Constructors - public NodeScript(string name, string description) + public NodeScript(string name, string description, object? context = null) { this.Name = name; this.Description = description; + this.Context = context; this.Entity = new NodeScriptEntity(); NodeTypeStore.NodeTypeAdded += 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.Description = description; this.Entity = entity; + this.Context = context; NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged; NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged; @@ -108,7 +112,7 @@ namespace Artemis.Core return null; // Create the node - node = nodeTypeRegistration.NodeData.CreateNode(nodeEntity); + node = nodeTypeRegistration.NodeData.CreateNode(this, nodeEntity); } else { @@ -272,8 +276,8 @@ namespace Artemis.Core #region Constructors - internal NodeScript(string name, string description, NodeScriptEntity entity) - : base(name, description, entity) + internal NodeScript(string name, string description, NodeScriptEntity entity, object? context = null) + : base(name, description, entity, context) { ExitNode = new ExitNode(name, description); AddNode(ExitNode); @@ -281,8 +285,8 @@ namespace Artemis.Core Load(); } - public NodeScript(string name, string description) - : base(name, description) + public NodeScript(string name, string description, object? context = null) + : base(name, description, context) { ExitNode = new ExitNode(name, description); AddNode(ExitNode); diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs index 08f3659e9..72f4bfb91 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs @@ -116,8 +116,6 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions if (RenderProfileElement == null) return; - RenderProfileElement.DisplayCondition ??= new NodeScript("End Result", ""); - _windowManager.ShowDialog(_nodeVmFactory.NodeScriptWindowViewModel(RenderProfileElement.DisplayCondition)); _profileEditorService.SaveSelectedProfileElement(); } diff --git a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj index 93f3b3450..85b4c6b8e 100644 --- a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj +++ b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj @@ -50,6 +50,9 @@ $(DefaultXamlRuntime) Designer + + $(DefaultXamlRuntime) + $(DefaultXamlRuntime) diff --git a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPresenter.cs b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPresenter.cs index d7c4016c9..bc92fa645 100644 --- a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPresenter.cs +++ b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptPresenter.cs @@ -383,7 +383,8 @@ namespace Artemis.VisualScripting.Editor.Controls if (_creationBoxParent.ContextMenu != null) _creationBoxParent.ContextMenu.IsOpen = false; - INode node = nodeData.CreateNode(null); + INode node = nodeData.CreateNode(Script, null); + node.Initialize(Script); Script.AddNode(node); InitializeNode(node, _lastRightClickLocation); diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/CustomNodeViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/CustomNodeViewModel.cs new file mode 100644 index 000000000..fca28dbbb --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/CustomViewModels/CustomNodeViewModel.cs @@ -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 + + /// + public void AttachView(UIElement view) + { + View = view; + OnDisplay(); + } + + protected virtual void OnDisplay() + { + } + + /// + public UIElement View { get; private set; } + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/DataModelNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/DataModelNodeCustomViewModel.cs index 4e18dd0b1..126a1815d 100644 --- a/src/Artemis.VisualScripting/Nodes/CustomViewModels/DataModelNodeCustomViewModel.cs +++ b/src/Artemis.VisualScripting/Nodes/CustomViewModels/DataModelNodeCustomViewModel.cs @@ -1,16 +1,25 @@ using Artemis.Core; +using Artemis.Core.Modules; +using Stylet; namespace Artemis.VisualScripting.Nodes.CustomViewModels { public class DataModelNodeCustomViewModel : CustomNodeViewModel { private readonly DataModelNode _node; + private BindableCollection _modules; public DataModelNodeCustomViewModel(DataModelNode node) : base(node) { _node = node; } + public BindableCollection Modules + { + get => _modules; + set => SetAndNotify(ref _modules, value); + } + public DataModelPath DataModelPath { get => _node.DataModelPath; @@ -32,5 +41,28 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels _node.UpdateOutputPin(); } } + + public void Initialize() + { + if (Modules != null) + return; + + Modules = new BindableCollection(); + 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 + + /// + protected override void OnDisplay() + { + Initialize(); + base.OnDisplay(); + } + + #endregion } } \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticDoubleValueNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticDoubleValueNodeCustomViewModel.cs deleted file mode 100644 index 1a0db0a2e..000000000 --- a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticDoubleValueNodeCustomViewModel.cs +++ /dev/null @@ -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)); - } - } - } -} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs deleted file mode 100644 index 14e63812c..000000000 --- a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs +++ /dev/null @@ -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)); - } - } - } -} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticStringValueNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticStringValueNodeCustomViewModel.cs deleted file mode 100644 index 1b6f3eae4..000000000 --- a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticStringValueNodeCustomViewModel.cs +++ /dev/null @@ -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)); - } - } - } -} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticValueNodeViewModels.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticValueNodeViewModels.cs new file mode 100644 index 000000000..17b09f66e --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticValueNodeViewModels.cs @@ -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)); + } + } + } +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/CustomViews/DataModelNodeCustomView.xaml b/src/Artemis.VisualScripting/Nodes/CustomViews/DataModelNodeCustomView.xaml index 4ced4397a..e1a1c9d39 100644 --- a/src/Artemis.VisualScripting/Nodes/CustomViews/DataModelNodeCustomView.xaml +++ b/src/Artemis.VisualScripting/Nodes/CustomViews/DataModelNodeCustomView.xaml @@ -8,5 +8,5 @@ xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - + diff --git a/src/Artemis.VisualScripting/Nodes/CustomViews/StaticFloatValueNodeCustomView.xaml b/src/Artemis.VisualScripting/Nodes/CustomViews/StaticFloatValueNodeCustomView.xaml new file mode 100644 index 000000000..7cd2b5ad7 --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/CustomViews/StaticFloatValueNodeCustomView.xaml @@ -0,0 +1,12 @@ + + + diff --git a/src/Artemis.VisualScripting/Nodes/DataModelNode.cs b/src/Artemis.VisualScripting/Nodes/DataModelNode.cs index 53b172eb1..64b28a169 100644 --- a/src/Artemis.VisualScripting/Nodes/DataModelNode.cs +++ b/src/Artemis.VisualScripting/Nodes/DataModelNode.cs @@ -13,18 +13,21 @@ namespace Artemis.VisualScripting.Nodes { } + public INodeScript Script { get; private set; } public OutputPin Output { get; private set; } public DataModelPath DataModelPath { get; set; } - public override void Initialize() + public override void Initialize(INodeScript script) { - if (Storage is not DataModelPathEntity pathEntity) + Script = script; + + if (Storage is not DataModelPathEntity pathEntity) return; DataModelPath = new DataModelPath(null, pathEntity); UpdateOutputPin(); } - + public override void Evaluate() { if (DataModelPath.IsValid && Output != null) diff --git a/src/Artemis.VisualScripting/Nodes/StaticValueNodes.cs b/src/Artemis.VisualScripting/Nodes/StaticValueNodes.cs index eadf03c79..4d37fb320 100644 --- a/src/Artemis.VisualScripting/Nodes/StaticValueNodes.cs +++ b/src/Artemis.VisualScripting/Nodes/StaticValueNodes.cs @@ -29,7 +29,7 @@ namespace Artemis.VisualScripting.Nodes Output.Value = Storage as int? ?? 0; } - public override void Initialize() => Storage ??= 0; + public override void Initialize(INodeScript script) => Storage ??= 0; #endregion } @@ -60,7 +60,38 @@ namespace Artemis.VisualScripting.Nodes 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 + { + #region Properties & Fields + + public OutputPin Output { get; } + + #endregion + + #region Constructors + + public StaticFloatValueNode() + : base("Float", "Outputs a configurable float value.") + { + Output = CreateOutputPin(); + } + + #endregion + + #region Methods + + public override void Evaluate() + { + Output.Value = Storage as float? ?? 0.0f; + } + + public override void Initialize(INodeScript script) => Storage ??= 0.0f; #endregion } diff --git a/src/Artemis.VisualScripting/Nodes/SumNode.cs b/src/Artemis.VisualScripting/Nodes/SumNode.cs index 555f6a7f1..27cf67955 100644 --- a/src/Artemis.VisualScripting/Nodes/SumNode.cs +++ b/src/Artemis.VisualScripting/Nodes/SumNode.cs @@ -35,6 +35,38 @@ namespace Artemis.VisualScripting.Nodes #endregion } + [Node("Sum (Float)", "Sums the connected float values.")] + public class SumFloatsNode : Node + { + #region Properties & Fields + + public InputPinCollection Values { get; } + + public OutputPin Sum { get; } + + #endregion + + #region Constructors + + public SumFloatsNode() + : base("Sum", "Sums the connected float values.") + { + Values = CreateInputPinCollection("Values", 2); + Sum = CreateOutputPin("Sum"); + } + + #endregion + + #region Methods + + public override void Evaluate() + { + Sum.Value = Values.Values.Sum(); + } + + #endregion + } + [Node("Sum (Double)", "Sums the connected double values.")] public class SumDoublesNode : Node {