mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Nodes - Avoid overriding paths pointing to unloaded plugins with empty values
Nodes - Store the type of paths so that node connections can be restored even if the path their types are based on are unavailable
This commit is contained in:
parent
279761abd3
commit
919199a8d0
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
|
||||
@ -4,4 +4,5 @@ public class DataModelPathEntity
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public string DataModelId { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
@ -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<DataModelPathEntity>(_cycleNode, path?.Entity, "event"));
|
||||
}
|
||||
finally
|
||||
|
||||
@ -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<DataModelPathEntity>(_node, path?.Entity, "event"));
|
||||
}
|
||||
finally
|
||||
|
||||
@ -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<DataModelPathEntity>(_node, path?.Entity, "path"));
|
||||
}
|
||||
finally
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user