Skip to content

Commit 36cf943

Browse files
committed
[StateMachine] Added transitions conditions
1 parent bf1a42a commit 36cf943

21 files changed

+330
-198
lines changed

Examples/Nodify.Shared/Themes/Generic.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
Value="0" />
1717
<Setter Property="Foreground"
1818
Value="White" />
19+
<Setter Property="VerticalContentAlignment"
20+
Value="Center" />
1921
<Setter Property="Template">
2022
<Setter.Value>
2123
<ControlTemplate TargetType="{x:Type local:EditableTextBlock}">
22-
<Grid>
24+
<Grid VerticalAlignment="{TemplateBinding VerticalAlignment}"
25+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
2326
<TextBlock Text="{Binding Text, ElementName=PART_TextBox}"
2427
Background="{TemplateBinding Background}"
2528
Foreground="{TemplateBinding Foreground}"
2629
TextWrapping="{TemplateBinding TextWrapping}"
2730
Padding="{TemplateBinding Padding}"
2831
TextTrimming="{TemplateBinding TextTrimming}"
32+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
33+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2934
x:Name="PART_Text" />
3035

3136
<TextBox Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
@@ -44,7 +49,8 @@
4449
MaxLines="{TemplateBinding MinLines}"
4550
AcceptsTab="True"
4651
Visibility="Collapsed"
47-
VerticalContentAlignment="Center"
52+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
53+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
4854
Margin="-1"
4955
x:Name="PART_TextBox" />
5056
</Grid>

Examples/Nodify.Shared/Themes/Icons.xaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="clr-namespace:Nodify">
44

5+
<Rectangle x:Key="PlusIcon"
6+
x:Shared="False"
7+
Width="16"
8+
Height="16">
9+
<Rectangle.Fill>
10+
<DrawingBrush>
11+
<DrawingBrush.Drawing>
12+
<DrawingGroup>
13+
<DrawingGroup.Children>
14+
<GeometryDrawing Brush="#00FFFFFF"
15+
Geometry="F1M16,16L0,16 0,0 16,0z" />
16+
<GeometryDrawing Brush="#FFF6F6F6"
17+
Geometry="F1M6.0003,-0.000199999999999534L6.0003,5.9998 0.000300000000000189,5.9998 0.000300000000000189,9.9998 6.0003,9.9998 6.0003,15.9998 10.0003,15.9998 10.0003,9.9998 16.0003,9.9998 16.0003,5.9998 10.0003,5.9998 10.0003,-0.000199999999999534z" />
18+
<GeometryDrawing Brush="#FF424242"
19+
Geometry="F1M15,9L9,9 9,15 7,15 7,9 1,9 1,7 7,7 7,1 9,1 9,7 15,7z" />
20+
</DrawingGroup.Children>
21+
</DrawingGroup>
22+
</DrawingBrush.Drawing>
23+
</DrawingBrush>
24+
</Rectangle.Fill>
25+
</Rectangle>
26+
527
<Rectangle x:Key="RemoveKeyIcon"
628
x:Shared="False"
729
Width="16"

Examples/Nodify.StateMachine/ActionReferenceViewModel.cs renamed to Examples/Nodify.StateMachine/BlackboardItemReferenceViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Nodify.StateMachine
44
{
5-
public class ActionReferenceViewModel
5+
// Condition or Action reference
6+
public class BlackboardItemReferenceViewModel
67
{
78
public string? Name { get; set; }
89
public Type? Type { get; set; }

Examples/Nodify.StateMachine/ActionViewModel.cs renamed to Examples/Nodify.StateMachine/BlackboardItemViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Nodify.StateMachine
44
{
5-
public class ActionViewModel : ObservableObject
5+
public class BlackboardItemViewModel : ObservableObject
66
{
77
private string? _name;
88
public string? Name

Examples/Nodify.StateMachine/BlackboardViewModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ public NodifyObservableCollection<BlackboardKeyViewModel> Keys
1111
set => SetProperty(ref _keys, value);
1212
}
1313

14-
private NodifyObservableCollection<ActionReferenceViewModel> _actions = new NodifyObservableCollection<ActionReferenceViewModel>();
15-
public NodifyObservableCollection<ActionReferenceViewModel> Actions
14+
private NodifyObservableCollection<BlackboardItemReferenceViewModel> _actions = new NodifyObservableCollection<BlackboardItemReferenceViewModel>();
15+
public NodifyObservableCollection<BlackboardItemReferenceViewModel> Actions
1616
{
1717
get => _actions;
1818
set => SetProperty(ref _actions, value);
1919
}
2020

21+
private NodifyObservableCollection<BlackboardItemReferenceViewModel> _conditions = new NodifyObservableCollection<BlackboardItemReferenceViewModel>();
22+
public NodifyObservableCollection<BlackboardItemReferenceViewModel> Conditions
23+
{
24+
get => _conditions;
25+
set => SetProperty(ref _conditions, value);
26+
}
27+
2128
public INodifyCommand AddKeyCommand { get; }
2229
public INodifyCommand RemoveKeyCommand { get; }
2330

Examples/Nodify.StateMachine/ConditionViewModel.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Examples/Nodify.StateMachine/Helpers/ActionDescriptor.cs renamed to Examples/Nodify.StateMachine/Helpers/BlackboardDescriptor.cs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Nodify.StateMachine
77
{
8-
public class ActionDescriptor
8+
public static class BlackboardDescriptor
99
{
1010
private class KeyDescription
1111
{
@@ -21,16 +21,16 @@ public KeyDescription(string displayName, string propertyName, BlackboardKeyType
2121
public BlackboardKeyType Type { get; }
2222
}
2323

24-
private class ActionDescription
24+
private class ItemDescription
2525
{
2626
public string? Name { get; set; }
2727
public List<KeyDescription> Input { get; } = new List<KeyDescription>();
2828
public List<KeyDescription> Output { get; } = new List<KeyDescription>();
2929
}
3030

31-
public static ActionViewModel? GetAction(ActionReferenceViewModel? actionRef)
31+
public static BlackboardItemViewModel? GetItem(BlackboardItemReferenceViewModel? actionRef)
3232
{
33-
if (actionRef?.Type != null && typeof(IBlackboardAction).IsAssignableFrom(actionRef.Type))
33+
if (actionRef?.Type != null)
3434
{
3535
var description = GetDescription(actionRef.Type);
3636

@@ -48,7 +48,7 @@ private class ActionDescription
4848
PropertyName = d.PropertyName
4949
});
5050

51-
return new ActionViewModel
51+
return new BlackboardItemViewModel
5252
{
5353
Name = actionRef.Name,
5454
Type = actionRef.Type,
@@ -60,30 +60,25 @@ private class ActionDescription
6060
return default;
6161
}
6262

63-
public static ActionReferenceViewModel GetReference(Type type)
63+
public static BlackboardItemReferenceViewModel GetReference(Type type)
6464
{
65-
if (typeof(IBlackboardAction).IsAssignableFrom(type))
66-
{
67-
var desc = GetDescription(type);
68-
69-
return new ActionReferenceViewModel
70-
{
71-
Name = desc.Name,
72-
Type = type
73-
};
74-
}
65+
var desc = GetDescription(type);
7566

76-
throw new NotSupportedException(type.Name);
67+
return new BlackboardItemReferenceViewModel
68+
{
69+
Name = desc.Name,
70+
Type = type
71+
};
7772
}
7873

79-
private static readonly Dictionary<Type, ActionDescription> _descriptions = new Dictionary<Type, ActionDescription>();
80-
private static ActionDescription GetDescription(Type type)
74+
private static readonly Dictionary<Type, ItemDescription> _descriptions = new Dictionary<Type, ItemDescription>();
75+
private static ItemDescription GetDescription(Type type)
8176
{
8277
if (!_descriptions.TryGetValue(type, out var description))
8378
{
84-
var actionAttr = type.GetCustomAttribute<BlackboardActionAttribute>();
79+
var actionAttr = type.GetCustomAttribute<BlackboardItemAttribute>();
8580

86-
var desc = new ActionDescription
81+
var desc = new ItemDescription
8782
{
8883
Name = actionAttr?.DisplayName ?? type.Name
8984
};
@@ -98,19 +93,40 @@ private static ActionDescription GetDescription(Type type)
9893
{
9994
if (keyAttr.Usage == BlackboardKeyUsage.Input)
10095
{
101-
desc.Input.Add(new KeyDescription(keyAttr.Name, prop.Name, keyAttr.Type));
96+
desc.Input.Add(new KeyDescription(keyAttr.Name ?? prop.Name, prop.Name, keyAttr.Type));
10297
}
10398
else
10499
{
105-
desc.Output.Add(new KeyDescription(keyAttr.Name, prop.Name, keyAttr.Type));
100+
desc.Output.Add(new KeyDescription(keyAttr.Name ?? prop.Name, prop.Name, keyAttr.Type));
106101
}
107102
}
108103
}
109104

105+
_descriptions.Add(type, desc);
106+
110107
return desc;
111108
}
112109

113110
return description;
114111
}
112+
113+
public static List<BlackboardItemReferenceViewModel> GetAvailableItems<T>()
114+
{
115+
var result = new List<BlackboardItemReferenceViewModel>();
116+
var ourType = typeof(T);
117+
118+
var types = ourType.Assembly.GetTypes();
119+
120+
for (int i = 0; i < types.Length; i++)
121+
{
122+
var type = types[i];
123+
if (type.IsClass && !type.IsAbstract && ourType.IsAssignableFrom(type))
124+
{
125+
result.Add(GetReference(type));
126+
}
127+
}
128+
129+
return result;
130+
}
115131
}
116132
}

0 commit comments

Comments
 (0)