diff --git a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs index 62fcaea73..c95480bae 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs @@ -17,9 +17,10 @@ namespace Artemis.Core { LayerProperty = dataBindingRegistration.LayerProperty; Entity = new DataBindingEntity(); - Script = new NodeScript(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, ""); ApplyRegistration(dataBindingRegistration); + Script = new NodeScript(GetScriptName(), "The value to put into the data binding"); + Save(); } @@ -27,7 +28,7 @@ namespace Artemis.Core { LayerProperty = layerProperty; Entity = entity; - Script = new NodeScript(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, ""); + Script = new NodeScript(GetScriptName(), "The value to put into the data binding"); // Load will add children so be initialized before that Load(); @@ -116,8 +117,7 @@ namespace Artemis.Core if (Registration != null) Registration.DataBinding = null; - Script?.Dispose(); - Script = null; + Script.Dispose(); } } @@ -213,6 +213,13 @@ namespace Artemis.Core _reapplyValue = true; } + private string GetScriptName() + { + if (LayerProperty.GetAllDataBindingRegistrations().Count == 1) + return LayerProperty.PropertyDescription.Name ?? LayerProperty.Path; + return $"{LayerProperty.PropertyDescription.Name ?? LayerProperty.Path} - {Registration?.DisplayName}"; + } + /// public void Dispose() { @@ -238,8 +245,8 @@ namespace Artemis.Core Script.Dispose(); Script = Entity.NodeScript != null - ? new NodeScript(Entity.NodeScript) - : new NodeScript(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, ""); + ? new NodeScript(GetScriptName(), "The value to put into the data binding", Entity.NodeScript) + : new NodeScript(GetScriptName(), "The value to put into the data binding"); } /// diff --git a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs index 8d69a0980..7e841350b 100644 --- a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs @@ -18,13 +18,17 @@ namespace Artemis.Core { private SKRectI _bounds; private SKPath? _path; + private readonly string _typeDisplayName; 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"); + Timeline = new Timeline(); ExpandedPropertyGroups = new List(); LayerEffectsList = new List(); - + LayerEffectStore.LayerEffectAdded += LayerEffectStoreOnLayerEffectAdded; LayerEffectStore.LayerEffectRemoved += LayerEffectStoreOnLayerEffectRemoved; } @@ -59,15 +63,17 @@ namespace Artemis.Core foreach (BaseLayerEffect baseLayerEffect in LayerEffects) baseLayerEffect.Dispose(); - DisplayCondition?.Dispose(); + DisplayCondition.Dispose(); base.Dispose(disposing); } internal void LoadRenderElement() { - DisplayCondition = RenderElementEntity.NodeScript != null ? new NodeScript(RenderElementEntity.NodeScript) : null; - + 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"); + Timeline = RenderElementEntity.Timeline != null ? new Timeline(RenderElementEntity.Timeline) : new Timeline(); @@ -354,14 +360,15 @@ namespace Artemis.Core protected set => SetAndNotify(ref _displayConditionMet, value); } - private NodeScript? _displayCondition; + private NodeScript _displayCondition; private bool _displayConditionMet; private bool _toggledOnByEvent = false; + /// /// Gets or sets the root display condition group /// - public NodeScript? DisplayCondition + public NodeScript DisplayCondition { get => _displayCondition; set => SetAndNotify(ref _displayCondition, value); @@ -378,7 +385,7 @@ namespace Artemis.Core return; } - if (DisplayCondition == null) + if (!DisplayCondition.HasNodes) { DisplayConditionMet = true; return; diff --git a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs index 162567ab7..2f29cdd2a 100644 --- a/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs +++ b/src/Artemis.Core/Models/ProfileConfiguration/ProfileConfiguration.cs @@ -28,6 +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"); } internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity) @@ -38,6 +39,8 @@ namespace Artemis.Core Entity = entity; Icon = new ProfileConfigurationIcon(Entity); + ActivationCondition = new NodeScript("Activate profile", "Whether or not the profile should be active"); + Load(); } @@ -130,7 +133,7 @@ namespace Artemis.Core /// Gets the data model condition that must evaluate to for this profile to be activated /// alongside any activation requirements of the , if set /// - public NodeScript? ActivationCondition { get; set; } + public NodeScript ActivationCondition { get; set; } /// /// Gets or sets the module this profile uses @@ -168,7 +171,7 @@ namespace Artemis.Core if (_disposed) throw new ObjectDisposedException("ProfileConfiguration"); - if (ActivationCondition == null) + if (!ActivationCondition.HasNodes) ActivationConditionMet = true; else { @@ -216,7 +219,7 @@ namespace Artemis.Core public void Dispose() { _disposed = true; - ActivationCondition?.Dispose(); + ActivationCondition.Dispose(); } #endregion @@ -237,8 +240,10 @@ namespace Artemis.Core Icon.Load(); - ActivationCondition?.Dispose(); - ActivationCondition = Entity.ActivationCondition != null ? new NodeScript(Entity.ActivationCondition) : null; + 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"); EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null; DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null; diff --git a/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs b/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs index abfa87b75..c05ba214d 100644 --- a/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs +++ b/src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs @@ -8,6 +8,7 @@ namespace Artemis.Core { string Name { get; } string Description { get; } + bool HasNodes { get; } IEnumerable Nodes { get; } diff --git a/src/Artemis.Core/VisualScripting/NodeScript.cs b/src/Artemis.Core/VisualScripting/NodeScript.cs index 8d30b5fbd..ecb992895 100644 --- a/src/Artemis.Core/VisualScripting/NodeScript.cs +++ b/src/Artemis.Core/VisualScripting/NodeScript.cs @@ -16,13 +16,13 @@ namespace Artemis.Core public string Name { get; } public string Description { get; } + public bool HasNodes => _nodes.Count > 1; private readonly List _nodes = new(); public IEnumerable Nodes => new ReadOnlyCollection(_nodes); protected INode ExitNode { get; set; } public abstract Type ResultType { get; } - public abstract void CreateExitNode(string name, string description = ""); #endregion @@ -38,14 +38,12 @@ namespace Artemis.Core NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged; } - internal NodeScript(NodeScriptEntity entity) + internal NodeScript(string name, string description, NodeScriptEntity entity) { - this.Name = entity.Name; - this.Description = entity.Description; + this.Name = name; + this.Description = description; this.Entity = entity; - Load(); - NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged; NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged; } @@ -85,40 +83,25 @@ namespace Artemis.Core /// public void Load() { - bool gotExitNode = false; - // Create nodes Dictionary nodes = new(); foreach (NodeEntity entityNode in Entity.Nodes) { - INode? node = LoadNode(entityNode); + INode? node = LoadNode(entityNode, entityNode.IsExitNode ? ExitNode : null); if (node == null) continue; - - if (node.IsExitNode) - gotExitNode = true; - nodes.Add(entityNode.Id, node); } - - if (!gotExitNode) - CreateExitNode("Exit node"); - + LoadConnections(nodes); _nodes.Clear(); _nodes.AddRange(nodes.Values); } - private INode? LoadNode(NodeEntity nodeEntity) + private INode? LoadNode(NodeEntity nodeEntity, INode? node) { - INode node; - if (nodeEntity.IsExitNode) - { - CreateExitNode(nodeEntity.Name, nodeEntity.Description); - node = ExitNode; - } - else + if (node == null) { NodeTypeRegistration? nodeTypeRegistration = NodeTypeStore.Get(nodeEntity.PluginId, nodeEntity.Type); if (nodeTypeRegistration == null) @@ -127,7 +110,12 @@ namespace Artemis.Core // Create the node node = nodeTypeRegistration.NodeData.CreateNode(nodeEntity); } - + else + { + node.X = nodeEntity.X; + node.Y = nodeEntity.Y; + } + // Restore pin collections foreach (NodePinCollectionEntity entityNodePinCollection in nodeEntity.PinCollections) { @@ -280,18 +268,17 @@ namespace Artemis.Core public override Type ResultType => typeof(T); - public override void CreateExitNode(string name, string description = "") - { - ExitNode = new ExitNode(name, description); - } - #endregion #region Constructors - internal NodeScript(NodeScriptEntity entity) - : base(entity) + internal NodeScript(string name, string description, NodeScriptEntity entity) + : base(name, description, entity) { + ExitNode = new ExitNode(name, description); + AddNode(ExitNode); + + Load(); } public NodeScript(string name, string description) diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml index a9f8b3867..16a6b7000 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml @@ -45,7 +45,10 @@ - + + + + - Click to edit script + + + + + + + Click to edit script + + + diff --git a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs index dc18ea51d..14e63812c 100644 --- a/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs +++ b/src/Artemis.VisualScripting/Nodes/CustomViewModels/StaticIntegerValueNodeCustomViewModel.cs @@ -13,7 +13,12 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels public int Input { - get => (int) _node.Storage; + get + { + if (_node.Storage is long longInput) + return (int) longInput; + return (int) _node.Storage; + } set { _node.Storage = value;