1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 17:53:32 +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; LayerProperty = dataBindingRegistration.LayerProperty;
Entity = new DataBindingEntity(); Entity = new DataBindingEntity();
Script = new NodeScript<TProperty>(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, "");
ApplyRegistration(dataBindingRegistration); ApplyRegistration(dataBindingRegistration);
Script = new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
Save(); Save();
} }
@ -27,7 +28,7 @@ namespace Artemis.Core
{ {
LayerProperty = layerProperty; LayerProperty = layerProperty;
Entity = entity; 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 will add children so be initialized before that
Load(); Load();
@ -116,8 +117,7 @@ namespace Artemis.Core
if (Registration != null) if (Registration != null)
Registration.DataBinding = null; Registration.DataBinding = null;
Script?.Dispose(); Script.Dispose();
Script = null;
} }
} }
@ -213,6 +213,13 @@ namespace Artemis.Core
_reapplyValue = true; _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 /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ {
@ -238,8 +245,8 @@ namespace Artemis.Core
Script.Dispose(); Script.Dispose();
Script = Entity.NodeScript != null Script = Entity.NodeScript != null
? new NodeScript<TProperty>(Entity.NodeScript) ? new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding", Entity.NodeScript)
: new NodeScript<TProperty>(LayerProperty.PropertyDescription.Name ?? LayerProperty.Path, ""); : new NodeScript<TProperty>(GetScriptName(), "The value to put into the data binding");
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -18,13 +18,17 @@ namespace Artemis.Core
{ {
private SKRectI _bounds; private SKRectI _bounds;
private SKPath? _path; private SKPath? _path;
private readonly string _typeDisplayName;
internal RenderProfileElement(Profile profile) : base(profile) 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(); Timeline = new Timeline();
ExpandedPropertyGroups = new List<string>(); ExpandedPropertyGroups = new List<string>();
LayerEffectsList = new List<BaseLayerEffect>(); LayerEffectsList = new List<BaseLayerEffect>();
LayerEffectStore.LayerEffectAdded += LayerEffectStoreOnLayerEffectAdded; LayerEffectStore.LayerEffectAdded += LayerEffectStoreOnLayerEffectAdded;
LayerEffectStore.LayerEffectRemoved += LayerEffectStoreOnLayerEffectRemoved; LayerEffectStore.LayerEffectRemoved += LayerEffectStoreOnLayerEffectRemoved;
} }
@ -59,15 +63,17 @@ namespace Artemis.Core
foreach (BaseLayerEffect baseLayerEffect in LayerEffects) foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.Dispose(); baseLayerEffect.Dispose();
DisplayCondition?.Dispose(); DisplayCondition.Dispose();
base.Dispose(disposing); base.Dispose(disposing);
} }
internal void LoadRenderElement() 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 Timeline = RenderElementEntity.Timeline != null
? new Timeline(RenderElementEntity.Timeline) ? new Timeline(RenderElementEntity.Timeline)
: new Timeline(); : new Timeline();
@ -354,14 +360,15 @@ namespace Artemis.Core
protected set => SetAndNotify(ref _displayConditionMet, value); protected set => SetAndNotify(ref _displayConditionMet, value);
} }
private NodeScript<bool>? _displayCondition; private NodeScript<bool> _displayCondition;
private bool _displayConditionMet; private bool _displayConditionMet;
private bool _toggledOnByEvent = false; private bool _toggledOnByEvent = false;
/// <summary> /// <summary>
/// Gets or sets the root display condition group /// Gets or sets the root display condition group
/// </summary> /// </summary>
public NodeScript<bool>? DisplayCondition public NodeScript<bool> DisplayCondition
{ {
get => _displayCondition; get => _displayCondition;
set => SetAndNotify(ref _displayCondition, value); set => SetAndNotify(ref _displayCondition, value);
@ -378,7 +385,7 @@ namespace Artemis.Core
return; return;
} }
if (DisplayCondition == null) if (!DisplayCondition.HasNodes)
{ {
DisplayConditionMet = true; DisplayConditionMet = true;
return; return;

View File

@ -28,6 +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");
} }
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity) internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
@ -38,6 +39,8 @@ 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");
Load(); 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 /// 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 /// alongside any activation requirements of the <see cref="Module" />, if set
/// </summary> /// </summary>
public NodeScript<bool>? ActivationCondition { get; set; } public NodeScript<bool> ActivationCondition { get; set; }
/// <summary> /// <summary>
/// Gets or sets the module this profile uses /// Gets or sets the module this profile uses
@ -168,7 +171,7 @@ namespace Artemis.Core
if (_disposed) if (_disposed)
throw new ObjectDisposedException("ProfileConfiguration"); throw new ObjectDisposedException("ProfileConfiguration");
if (ActivationCondition == null) if (!ActivationCondition.HasNodes)
ActivationConditionMet = true; ActivationConditionMet = true;
else else
{ {
@ -216,7 +219,7 @@ namespace Artemis.Core
public void Dispose() public void Dispose()
{ {
_disposed = true; _disposed = true;
ActivationCondition?.Dispose(); ActivationCondition.Dispose();
} }
#endregion #endregion
@ -237,8 +240,10 @@ namespace Artemis.Core
Icon.Load(); Icon.Load();
ActivationCondition?.Dispose(); ActivationCondition.Dispose();
ActivationCondition = Entity.ActivationCondition != null ? new NodeScript<bool>(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");
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;

View File

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

View File

@ -16,13 +16,13 @@ namespace Artemis.Core
public string Name { get; } public string Name { get; }
public string Description { get; } public string Description { get; }
public bool HasNodes => _nodes.Count > 1;
private readonly List<INode> _nodes = new(); private readonly List<INode> _nodes = new();
public IEnumerable<INode> Nodes => new ReadOnlyCollection<INode>(_nodes); public IEnumerable<INode> Nodes => new ReadOnlyCollection<INode>(_nodes);
protected INode ExitNode { get; set; } protected INode ExitNode { get; set; }
public abstract Type ResultType { get; } public abstract Type ResultType { get; }
public abstract void CreateExitNode(string name, string description = "");
#endregion #endregion
@ -38,14 +38,12 @@ namespace Artemis.Core
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged; NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
} }
internal NodeScript(NodeScriptEntity entity) internal NodeScript(string name, string description, NodeScriptEntity entity)
{ {
this.Name = entity.Name; this.Name = name;
this.Description = entity.Description; this.Description = description;
this.Entity = entity; this.Entity = entity;
Load();
NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged; NodeTypeStore.NodeTypeAdded += NodeTypeStoreOnNodeTypeChanged;
NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged; NodeTypeStore.NodeTypeRemoved += NodeTypeStoreOnNodeTypeChanged;
} }
@ -85,40 +83,25 @@ namespace Artemis.Core
/// <inheritdoc /> /// <inheritdoc />
public void Load() public void Load()
{ {
bool gotExitNode = false;
// Create nodes // Create nodes
Dictionary<int, INode> nodes = new(); Dictionary<int, INode> nodes = new();
foreach (NodeEntity entityNode in Entity.Nodes) foreach (NodeEntity entityNode in Entity.Nodes)
{ {
INode? node = LoadNode(entityNode); INode? node = LoadNode(entityNode, entityNode.IsExitNode ? ExitNode : null);
if (node == null) if (node == null)
continue; continue;
if (node.IsExitNode)
gotExitNode = true;
nodes.Add(entityNode.Id, node); nodes.Add(entityNode.Id, node);
} }
if (!gotExitNode)
CreateExitNode("Exit node");
LoadConnections(nodes); LoadConnections(nodes);
_nodes.Clear(); _nodes.Clear();
_nodes.AddRange(nodes.Values); _nodes.AddRange(nodes.Values);
} }
private INode? LoadNode(NodeEntity nodeEntity) private INode? LoadNode(NodeEntity nodeEntity, INode? node)
{ {
INode node; if (node == null)
if (nodeEntity.IsExitNode)
{
CreateExitNode(nodeEntity.Name, nodeEntity.Description);
node = ExitNode;
}
else
{ {
NodeTypeRegistration? nodeTypeRegistration = NodeTypeStore.Get(nodeEntity.PluginId, nodeEntity.Type); NodeTypeRegistration? nodeTypeRegistration = NodeTypeStore.Get(nodeEntity.PluginId, nodeEntity.Type);
if (nodeTypeRegistration == null) if (nodeTypeRegistration == null)
@ -127,7 +110,12 @@ namespace Artemis.Core
// Create the node // Create the node
node = nodeTypeRegistration.NodeData.CreateNode(nodeEntity); node = nodeTypeRegistration.NodeData.CreateNode(nodeEntity);
} }
else
{
node.X = nodeEntity.X;
node.Y = nodeEntity.Y;
}
// Restore pin collections // Restore pin collections
foreach (NodePinCollectionEntity entityNodePinCollection in nodeEntity.PinCollections) foreach (NodePinCollectionEntity entityNodePinCollection in nodeEntity.PinCollections)
{ {
@ -280,18 +268,17 @@ namespace Artemis.Core
public override Type ResultType => typeof(T); public override Type ResultType => typeof(T);
public override void CreateExitNode(string name, string description = "")
{
ExitNode = new ExitNode<T>(name, description);
}
#endregion #endregion
#region Constructors #region Constructors
internal NodeScript(NodeScriptEntity entity) internal NodeScript(string name, string description, NodeScriptEntity entity)
: base(entity) : base(name, description, entity)
{ {
ExitNode = new ExitNode<T>(name, description);
AddNode(ExitNode);
Load();
} }
public NodeScript(string name, string description) 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"> <Grid Grid.Row="2" Grid.Column="0" MouseUp="{s:Action ScriptGridMouseUp}" Cursor="Hand">
<controls:VisualScriptEditor Script="{Binding RenderProfileElement.DisplayCondition}" <controls:VisualScriptEditor Script="{Binding RenderProfileElement.DisplayCondition}"
Visibility="{Binding RenderProfileElement.DisplayCondition, Converter={StaticResource NullToVisibilityConverter}}" /> 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> <Border.Style>
<Style> <Style>
<Style.Triggers> <Style.Triggers>
@ -68,9 +71,16 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</Border.Style> </Border.Style>
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" <Grid HorizontalAlignment="Center">
VerticalAlignment="Center" <Grid.ColumnDefinitions>
HorizontalAlignment="Center">Click to edit script</TextBlock> <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> </Border>
</Grid> </Grid>

View File

@ -13,7 +13,12 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
public int Input public int Input
{ {
get => (int) _node.Storage; get
{
if (_node.Storage is long longInput)
return (int) longInput;
return (int) _node.Storage;
}
set set
{ {
_node.Storage = value; _node.Storage = value;