diff --git a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs index ea1a85825..681ddb923 100644 --- a/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs +++ b/src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs @@ -158,7 +158,16 @@ public class DataModelPath : IStorageModel, IDisposable if (_disposed) throw new ObjectDisposedException("DataModelPath"); - return Segments.LastOrDefault()?.GetPropertyType(); + // Prefer the actual type from the segments + Type? segmentType = Segments.LastOrDefault()?.GetPropertyType(); + if (segmentType != null) + return segmentType; + + // Fall back to stored type + if (!string.IsNullOrWhiteSpace(Entity.Type)) + return Type.GetType(Entity.Type); + + return null; } /// @@ -358,9 +367,14 @@ public class DataModelPath : IStorageModel, IDisposable // Do not save an invalid state if (!IsValid) return; - + Entity.Path = Path; Entity.DataModelId = DataModelId; + + // Store the type name but only if available + Type? pathType = Segments.LastOrDefault()?.GetPropertyType(); + if (pathType != null) + Entity.Type = pathType.FullName; } #region Equality members diff --git a/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs b/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs index 780c4800c..ef585ce45 100644 --- a/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs @@ -4,4 +4,5 @@ public class DataModelPathEntity { public string Path { get; set; } public string DataModelId { get; set; } + public string Type { get; set; } } \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventCycleNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventCycleNodeCustomViewModel.cs index 6e129a434..20247322b 100644 --- a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventCycleNodeCustomViewModel.cs +++ b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventCycleNodeCustomViewModel.cs @@ -38,7 +38,7 @@ public class DataModelEventCycleNodeCustomViewModel : CustomNodeViewModel // Subscribe to node changes _cycleNode.WhenAnyValue(n => n.Storage).Subscribe(UpdateDataModelPath).DisposeWith(d); - this.WhenAnyValue(vm => vm.DataModelPath).Subscribe(ApplyDataModelPath).DisposeWith(d); + this.WhenAnyValue(vm => vm.DataModelPath).WhereNotNull().Subscribe(ApplyDataModelPath).DisposeWith(d); Disposable.Create(() => { @@ -82,18 +82,18 @@ public class DataModelEventCycleNodeCustomViewModel : CustomNodeViewModel } } - private void ApplyDataModelPath(DataModelPath? path) + private void ApplyDataModelPath(DataModelPath path) { try { if (_updating) return; - if (path?.Path == _cycleNode.Storage?.Path) + if (path.Path == _cycleNode.Storage?.Path) return; _updating = true; - path?.Save(); + path.Save(); _nodeEditorService.ExecuteCommand(Script, new UpdateStorage(_cycleNode, path?.Entity, "event")); } finally diff --git a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventNodeCustomViewModel.cs index 9fe7d1058..3238ba287 100644 --- a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventNodeCustomViewModel.cs +++ b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelEventNodeCustomViewModel.cs @@ -44,7 +44,7 @@ public class DataModelEventNodeCustomViewModel : CustomNodeViewModel // Subscribe to node changes _node.WhenAnyValue(n => n.Storage).Subscribe(UpdateDataModelPath).DisposeWith(d); - this.WhenAnyValue(vm => vm.DataModelPath).Subscribe(ApplyDataModelPath).DisposeWith(d); + this.WhenAnyValue(vm => vm.DataModelPath).WhereNotNull().Subscribe(ApplyDataModelPath).DisposeWith(d); Disposable.Create(() => { @@ -89,18 +89,18 @@ public class DataModelEventNodeCustomViewModel : CustomNodeViewModel } } - private void ApplyDataModelPath(DataModelPath? path) + private void ApplyDataModelPath(DataModelPath path) { try { if (_updating) return; - if (path?.Path == _node.Storage?.Path) + if (path.Path == _node.Storage?.Path) return; _updating = true; - path?.Save(); + path.Save(); _nodeEditorService.ExecuteCommand(Script, new UpdateStorage(_node, path?.Entity, "event")); } finally diff --git a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelNodeCustomViewModel.cs b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelNodeCustomViewModel.cs index 55b4d6dd2..91d502e98 100644 --- a/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelNodeCustomViewModel.cs +++ b/src/Artemis.VisualScripting/Nodes/DataModel/Screens/DataModelNodeCustomViewModel.cs @@ -41,7 +41,7 @@ public class DataModelNodeCustomViewModel : CustomNodeViewModel // Subscribe to node changes _node.WhenAnyValue(n => n.Storage).Subscribe(UpdateDataModelPath).DisposeWith(d); - this.WhenAnyValue(vm => vm.DataModelPath).Subscribe(ApplyDataModelPath).DisposeWith(d); + this.WhenAnyValue(vm => vm.DataModelPath).WhereNotNull().Subscribe(ApplyDataModelPath).DisposeWith(d); Disposable.Create(() => { @@ -86,18 +86,18 @@ public class DataModelNodeCustomViewModel : CustomNodeViewModel } } - private void ApplyDataModelPath(DataModelPath? path) + private void ApplyDataModelPath(DataModelPath path) { try { if (_updating) return; - if (path?.Path == _node.Storage?.Path) + if (path.Path == _node.Storage?.Path) return; _updating = true; - path?.Save(); + path.Save(); _nodeEditorService.ExecuteCommand(Script, new UpdateStorage(_node, path?.Entity, "path")); } finally