1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Nodes - Ensure models using scripts always have a script

This commit is contained in:
Robert 2021-08-19 16:13:37 +02:00
parent b8077ca589
commit 05d8222991
7 changed files with 78 additions and 56 deletions

View File

@ -17,9 +17,10 @@ namespace Artemis.Core
{
LayerProperty = dataBindingRegistration.LayerProperty;
Entity = new DataBindingEntity();
Script = new NodeScript<TProperty>(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, "");
ApplyRegistration(dataBindingRegistration);
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
Save();
}
@ -27,7 +28,7 @@ namespace Artemis.Core
{
LayerProperty = layerProperty;
Entity = entity;
Script = new NodeScript<TProperty>(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, "");
Script = new NodeScript<TProperty>(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}";
}
/// <inheritdoc />
public void Dispose()
{
@ -238,8 +245,8 @@ namespace Artemis.Core
Script.Dispose();
Script = Entity.NodeScript != null
? new NodeScript<TProperty>(Entity.NodeScript)
: new NodeScript<TProperty>(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, "");
? 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");
}
/// <inheritdoc />

View File

@ -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<bool>($"Activate {_typeDisplayName}", $"Whether or not this {_typeDisplayName} should be active");
Timeline = new Timeline();
ExpandedPropertyGroups = new List<string>();
LayerEffectsList = new List<BaseLayerEffect>();
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<bool>(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");
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<bool>? _displayCondition;
private NodeScript<bool> _displayCondition;
private bool _displayConditionMet;
private bool _toggledOnByEvent = false;
/// <summary>
/// Gets or sets the root display condition group
/// </summary>
public NodeScript<bool>? DisplayCondition
public NodeScript<bool> 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;

View File

@ -28,6 +28,7 @@ namespace Artemis.Core
Entity = new ProfileConfigurationEntity();
Icon = new ProfileConfigurationIcon(Entity) {MaterialIcon = icon};
ActivationCondition = new NodeScript<bool>("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<bool>("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 <see langword="true" /> for this profile to be activated
/// alongside any activation requirements of the <see cref="Module" />, if set
/// </summary>
public NodeScript<bool>? ActivationCondition { get; set; }
public NodeScript<bool> ActivationCondition { get; set; }
/// <summary>
/// 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<bool>(Entity.ActivationCondition) : null;
ActivationCondition.Dispose();
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");
EnableHotkey = Entity.EnableHotkey != null ? new ProfileConfigurationHotkey(Entity.EnableHotkey) : null;
DisableHotkey = Entity.DisableHotkey != null ? new ProfileConfigurationHotkey(Entity.DisableHotkey) : null;

View File

@ -8,6 +8,7 @@ namespace Artemis.Core
{
string Name { get; }
string Description { get; }
bool HasNodes { get; }
IEnumerable<INode> Nodes { get; }

View File

@ -16,13 +16,13 @@ namespace Artemis.Core
public string Name { get; }
public string Description { get; }
public bool HasNodes => _nodes.Count > 1;
private readonly List<INode> _nodes = new();
public IEnumerable<INode> Nodes => new ReadOnlyCollection<INode>(_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
/// <inheritdoc />
public void Load()
{
bool gotExitNode = false;
// Create nodes
Dictionary<int, INode> 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<T>(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<T>(name, description);
AddNode(ExitNode);
Load();
}
public NodeScript(string name, string description)

View File

@ -45,7 +45,10 @@
<Grid Grid.Row="2" Grid.Column="0" MouseUp="{s:Action ScriptGridMouseUp}" Cursor="Hand">
<controls:VisualScriptEditor Script="{Binding RenderProfileElement.DisplayCondition}"
Visibility="{Binding RenderProfileElement.DisplayCondition, Converter={StaticResource NullToVisibilityConverter}}" />
<Border Background="#CD353535" Opacity="0">
<Border Opacity="0">
<Border.Background>
<SolidColorBrush Color="{Binding Color, Source={StaticResource MaterialDesignCardBackground}}" Opacity="0.75" />
</Border.Background>
<Border.Style>
<Style>
<Style.Triggers>
@ -68,9 +71,16 @@
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}"
VerticalAlignment="Center"
HorizontalAlignment="Center">Click to edit script</TextBlock>
<Grid HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" VerticalAlignment="Center" Grid.Column="0">
Click to edit script
</TextBlock>
<materialDesign:PackIcon Kind="OpenInNew" Margin="10 " Width="30" Height="30" Grid.Column="1" VerticalAlignment="Center" />
</Grid>
</Border>
</Grid>

View File

@ -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;