mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Properly implemented custom VMs
This commit is contained in:
parent
7eadc58bee
commit
61d7f1e1fb
@ -51,8 +51,8 @@ namespace Artemis.Core.Services
|
|||||||
private INode CreateNode(Type nodeType)
|
private INode CreateNode(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");
|
||||||
if (node.CustomViewModelType != null)
|
if (node is CustomViewModelNode customViewModelNode)
|
||||||
node.CustomViewModel = _kernel.Get(node.CustomViewModelType);
|
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,9 +16,6 @@ namespace Artemis.Core
|
|||||||
public IReadOnlyCollection<IPin> Pins { get; }
|
public IReadOnlyCollection<IPin> Pins { get; }
|
||||||
public IReadOnlyCollection<IPinCollection> PinCollections { get; }
|
public IReadOnlyCollection<IPinCollection> PinCollections { get; }
|
||||||
|
|
||||||
public Type? CustomViewModelType { get; }
|
|
||||||
public object? CustomViewModel { get; set; }
|
|
||||||
|
|
||||||
event EventHandler Resetting;
|
event EventHandler Resetting;
|
||||||
|
|
||||||
void Evaluate();
|
void Evaluate();
|
||||||
|
|||||||
@ -6,6 +6,8 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
public abstract class Node : CorePropertyChanged, INode
|
public abstract class Node : CorePropertyChanged, INode
|
||||||
{
|
{
|
||||||
|
public event EventHandler Resetting;
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private string _name;
|
private string _name;
|
||||||
@ -48,15 +50,6 @@ namespace Artemis.Core
|
|||||||
private readonly List<IPinCollection> _pinCollections = new();
|
private readonly List<IPinCollection> _pinCollections = new();
|
||||||
public IReadOnlyCollection<IPinCollection> PinCollections => new ReadOnlyCollection<IPinCollection>(_pinCollections);
|
public IReadOnlyCollection<IPinCollection> PinCollections => new ReadOnlyCollection<IPinCollection>(_pinCollections);
|
||||||
|
|
||||||
public Type? CustomViewModelType { get; private set; }
|
|
||||||
public object? CustomViewModel { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Events
|
|
||||||
|
|
||||||
public event EventHandler Resetting;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Construtors
|
#region Construtors
|
||||||
@ -67,8 +60,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
protected Node(string name, string description)
|
protected Node(string name, string description)
|
||||||
{
|
{
|
||||||
this.Name = name;
|
Name = name;
|
||||||
this.Description = description;
|
Description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -135,11 +128,6 @@ namespace Artemis.Core
|
|||||||
return pin;
|
return pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RegisterCustomViewModel<T>()
|
|
||||||
{
|
|
||||||
CustomViewModelType = typeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Evaluate();
|
public abstract void Evaluate();
|
||||||
|
|
||||||
public virtual void Reset()
|
public virtual void Reset()
|
||||||
@ -149,4 +137,34 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract class Node<T> : CustomViewModelNode
|
||||||
|
{
|
||||||
|
protected Node()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node(string name, string description) : base(name, description)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Type CustomViewModelType => typeof(T);
|
||||||
|
public T? CustomViewModel => (T?) BaseCustomViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class CustomViewModelNode : Node
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected CustomViewModelNode()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected CustomViewModelNode(string name, string description) : base(name, description)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Type CustomViewModelType { get; }
|
||||||
|
public object? BaseCustomViewModel { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@
|
|||||||
<Separator Grid.Row="1" Grid.Column="0" Style="{StaticResource MaterialDesignDarkSeparator}" Margin="-2 0" />
|
<Separator Grid.Row="1" Grid.Column="0" Style="{StaticResource MaterialDesignDarkSeparator}" Margin="-2 0" />
|
||||||
|
|
||||||
<Grid Grid.Row="2" Grid.Column="0">
|
<Grid Grid.Row="2" Grid.Column="0">
|
||||||
<controls:VisualScriptEditor Script="{Binding Script}" AvailableNodes="{Binding AvailableNodes}" />
|
<controls:VisualScriptEditor Script="{Binding RenderProfileElement.DisplayCondition}" AvailableNodes="{Binding AvailableNodes}" />
|
||||||
|
|
||||||
<!--<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="{StaticResource MaterialDesignCardBackground}">
|
<!--<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="{StaticResource MaterialDesignCardBackground}">
|
||||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||||
|
|||||||
@ -27,15 +27,6 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
|||||||
_dataModelConditionsVmFactory = dataModelConditionsVmFactory;
|
_dataModelConditionsVmFactory = dataModelConditionsVmFactory;
|
||||||
|
|
||||||
AvailableNodes = _nodeService.AvailableNodes;
|
AvailableNodes = _nodeService.AvailableNodes;
|
||||||
Script = new NodeScript<bool>("Display Condition (TODO)", "TODO");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private NodeScript<bool> _script;
|
|
||||||
public NodeScript<bool> Script
|
|
||||||
{
|
|
||||||
get => _script;
|
|
||||||
private set => SetAndNotify(ref _script, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<NodeData> _availableNodes;
|
private IEnumerable<NodeData> _availableNodes;
|
||||||
|
|||||||
@ -207,6 +207,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
|
<!-- TODO: Figure out how to only use this for CustomViewModelNode -->
|
||||||
<Border x:Name="BrdCustomView" Grid.Column="1">
|
<Border x:Name="BrdCustomView" Grid.Column="1">
|
||||||
<ContentControl s:View.Model="{Binding Node.CustomViewModel}"/>
|
<ContentControl s:View.Model="{Binding Node.CustomViewModel}"/>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@ -4,12 +4,10 @@ using Artemis.VisualScripting.Nodes.CustomViewModels;
|
|||||||
namespace Artemis.VisualScripting.Nodes
|
namespace Artemis.VisualScripting.Nodes
|
||||||
{
|
{
|
||||||
[Node("Integer-Value", "Outputs an configurable integer value.")]
|
[Node("Integer-Value", "Outputs an configurable integer value.")]
|
||||||
public class StaticIntegerValueNode : Node
|
public class StaticIntegerValueNode : Node<StaticIntegerValueNodeCustomViewModel>
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private StaticIntegerValueNodeCustomViewModel _customViewModel = new();
|
|
||||||
|
|
||||||
public OutputPin<int> Output { get; }
|
public OutputPin<int> Output { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -20,7 +18,6 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
: base("Integer", "Outputs an configurable integer value.")
|
: base("Integer", "Outputs an configurable integer value.")
|
||||||
{
|
{
|
||||||
Output = CreateOutputPin<int>();
|
Output = CreateOutputPin<int>();
|
||||||
RegisterCustomViewModel<StaticIntegerValueNodeCustomViewModel>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -29,19 +26,17 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
|
|
||||||
public override void Evaluate()
|
public override void Evaluate()
|
||||||
{
|
{
|
||||||
Output.Value = _customViewModel.Input;
|
Output.Value = CustomViewModel.Input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
[Node("Double-Value", "Outputs a configurable double value.")]
|
[Node("Double-Value", "Outputs a configurable double value.")]
|
||||||
public class StaticDoubleValueNode : Node
|
public class StaticDoubleValueNode : Node<StaticDoubleValueNodeCustomViewModel>
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private StaticDoubleValueNodeCustomViewModel _customViewModel = new();
|
|
||||||
|
|
||||||
public OutputPin<double> Output { get; }
|
public OutputPin<double> Output { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -52,7 +47,6 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
: base("Double", "Outputs a configurable double value.")
|
: base("Double", "Outputs a configurable double value.")
|
||||||
{
|
{
|
||||||
Output = CreateOutputPin<double>();
|
Output = CreateOutputPin<double>();
|
||||||
RegisterCustomViewModel<StaticDoubleValueNodeCustomViewModel>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -61,19 +55,17 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
|
|
||||||
public override void Evaluate()
|
public override void Evaluate()
|
||||||
{
|
{
|
||||||
Output.Value = _customViewModel.Input;
|
Output.Value = CustomViewModel.Input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
[Node("String-Value", "Outputs a configurable string value.")]
|
[Node("String-Value", "Outputs a configurable string value.")]
|
||||||
public class StaticStringValueNode : Node
|
public class StaticStringValueNode : Node<StaticStringValueNodeCustomViewModel>
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private StaticStringValueNodeCustomViewModel _customViewModel = new();
|
|
||||||
|
|
||||||
public OutputPin<string> Output { get; }
|
public OutputPin<string> Output { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -84,7 +76,6 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
: base("String", "Outputs a configurable string value.")
|
: base("String", "Outputs a configurable string value.")
|
||||||
{
|
{
|
||||||
Output = CreateOutputPin<string>();
|
Output = CreateOutputPin<string>();
|
||||||
RegisterCustomViewModel<StaticStringValueNodeCustomViewModel>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -93,7 +84,7 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
|
|
||||||
public override void Evaluate()
|
public override void Evaluate()
|
||||||
{
|
{
|
||||||
Output.Value = _customViewModel.Input;
|
Output.Value = CustomViewModel.Input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -101,7 +92,5 @@ namespace Artemis.VisualScripting.Nodes
|
|||||||
|
|
||||||
#region CustomViewModels
|
#region CustomViewModels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user