mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Added IList support
Nodes - Added simple List operator node
This commit is contained in:
parent
da0d3abbdd
commit
4ed6d10f38
@ -130,10 +130,10 @@ public abstract class Pin : CorePropertyChanged, IPin
|
||||
public bool IsTypeCompatible(Type type, bool forgivingEnumMatching = true)
|
||||
{
|
||||
return Type == type
|
||||
|| (Direction == PinDirection.Input && type.IsAssignableTo(Type))
|
||||
|| (Direction == PinDirection.Output && type.IsAssignableFrom(Type))
|
||||
|| (Direction == PinDirection.Input && Type == typeof(Enum) && type.IsEnum && forgivingEnumMatching)
|
||||
|| (Direction == PinDirection.Output && type == typeof(Enum) && Type.IsEnum && forgivingEnumMatching)
|
||||
|| (Direction == PinDirection.Input && Type == typeof(object))
|
||||
|| (Direction == PinDirection.Output && type == typeof(object));
|
||||
|| (Direction == PinDirection.Output && type == typeof(Enum) && Type.IsEnum && forgivingEnumMatching);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -168,6 +168,6 @@ public abstract class Pin : CorePropertyChanged, IPin
|
||||
IsNumeric = type == typeof(Numeric);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
xmlns:skiaSharp="clr-namespace:SkiaSharp;assembly=SkiaSharp"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:collections="clr-namespace:System.Collections;assembly=System.Runtime"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.VisualScripting.CableView"
|
||||
x:DataType="visualScripting:CableViewModel"
|
||||
@ -79,6 +80,9 @@
|
||||
<DataTemplate DataType="core:Numeric">
|
||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="collections:IList">
|
||||
<TextBlock Text="{Binding Count, StringFormat='List - {0} item(s)'}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
|
||||
46
src/Artemis.VisualScripting/Nodes/List/ListOperatorNode.cs
Normal file
46
src/Artemis.VisualScripting/Nodes/List/ListOperatorNode.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using Artemis.Core;
|
||||
using Artemis.VisualScripting.Nodes.List.Screens;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.List;
|
||||
|
||||
[Node("List Operator", "Checks if any/all/no value in the input list matches the input value", "List", InputType = typeof(IEnumerable), OutputType = typeof(bool))]
|
||||
public class ListOperatorNode : Node<ListOperator, ListOperatorNodeCustomViewModel>
|
||||
{
|
||||
public ListOperatorNode() : base("List Operator", "Checks if any/all/no value in the input list matches the input value")
|
||||
{
|
||||
InputList = CreateInputPin<IList>();
|
||||
InputValue = CreateInputPin<object>();
|
||||
|
||||
Ouput = CreateOutputPin<bool>();
|
||||
}
|
||||
|
||||
public InputPin<IList> InputList { get; }
|
||||
public InputPin<object> InputValue { get; }
|
||||
public OutputPin<bool> Ouput { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Evaluate()
|
||||
{
|
||||
if (InputList.Value == null)
|
||||
{
|
||||
Ouput.Value = Storage == ListOperator.None;
|
||||
return;
|
||||
}
|
||||
|
||||
object? input = InputValue.Value;
|
||||
if (Storage == ListOperator.Any)
|
||||
Ouput.Value = InputList.Value.Cast<object>().Any(v => v.Equals(input));
|
||||
else if (Storage == ListOperator.All)
|
||||
Ouput.Value = InputList.Value.Cast<object>().All(v => v.Equals(input));
|
||||
else if (Storage == ListOperator.All)
|
||||
Ouput.Value = InputList.Value.Cast<object>().All(v => !v.Equals(input));
|
||||
}
|
||||
}
|
||||
|
||||
public enum ListOperator
|
||||
{
|
||||
Any,
|
||||
All,
|
||||
None
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:screens="clr-namespace:Artemis.VisualScripting.Nodes.List.Screens"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.VisualScripting.Nodes.List.Screens.ListOperatorNodeCustomView"
|
||||
x:DataType="screens:ListOperatorNodeCustomViewModel">
|
||||
<shared:EnumComboBox Value="{CompiledBinding CurrentValue}" Classes="condensed"/>
|
||||
</UserControl>
|
||||
@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.List.Screens;
|
||||
|
||||
public partial class ListOperatorNodeCustomView : ReactiveUserControl<ListOperatorNodeCustomViewModel>
|
||||
{
|
||||
public ListOperatorNodeCustomView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Services.NodeEditor;
|
||||
using Artemis.UI.Shared.Services.NodeEditor.Commands;
|
||||
using Artemis.UI.Shared.VisualScripting;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.List.Screens;
|
||||
|
||||
public class ListOperatorNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly ListOperatorNode _node;
|
||||
private readonly INodeEditorService _nodeEditorService;
|
||||
|
||||
public ListOperatorNodeCustomViewModel(ListOperatorNode node, INodeScript script, INodeEditorService nodeEditorService) : base(node, script)
|
||||
{
|
||||
_node = node;
|
||||
_nodeEditorService = nodeEditorService;
|
||||
|
||||
NodeModified += (_, _) => this.RaisePropertyChanged(nameof(CurrentValue));
|
||||
}
|
||||
|
||||
public ListOperator CurrentValue
|
||||
{
|
||||
get => _node.Storage;
|
||||
set => _nodeEditorService.ExecuteCommand(Script, new UpdateStorage<ListOperator>(_node, value));
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@
|
||||
xmlns:skiaSharp="clr-namespace:SkiaSharp;assembly=SkiaSharp"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:converters1="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||
xmlns:collections="clr-namespace:System.Collections;assembly=System.Runtime"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.VisualScripting.Nodes.Static.Screens.DisplayValueNodeCustomView"
|
||||
x:DataType="screens:DisplayValueNodeCustomViewModel">
|
||||
@ -43,6 +44,9 @@
|
||||
<DataTemplate DataType="core:Numeric">
|
||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="collections:IList">
|
||||
<TextBlock Text="{Binding Count, StringFormat='List - {0} item(s)'}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||
</DataTemplate>
|
||||
|
||||
@ -3,13 +3,13 @@ using Artemis.VisualScripting.Nodes.Static.Screens;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Static;
|
||||
|
||||
[Node("String-Value", "Outputs a configurable static string value.", "Static", OutputType = typeof(string))]
|
||||
[Node("Text-Value", "Outputs a configurable static text value.", "Static", OutputType = typeof(string))]
|
||||
public class StaticStringValueNode : Node<string, StaticStringValueNodeCustomViewModel>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public StaticStringValueNode()
|
||||
: base("String", "Outputs a configurable string value.")
|
||||
: base("Text", "Outputs a configurable text value.")
|
||||
{
|
||||
Output = CreateOutputPin<string>();
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Text;
|
||||
|
||||
[Node("Format", "Formats the input string.", "Text", InputType = typeof(object), OutputType = typeof(string))]
|
||||
[Node("Format", "Formats the input text.", "Text", InputType = typeof(object), OutputType = typeof(string))]
|
||||
public class StringFormatNode : Node
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user