Nodes - Show errors in node editor when a node fails to evaluate

This commit is contained in:
Robert committed 2022-09-01 20:33:55 +02:00
1 parent cd537051ca
commit eca8985fc4
9 files changed
+89 -48

No files matched your search

+8 -3
View File
@@ -69,11 +69,16 @@ public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
/// <inheritdoc />
public void ClearBrokenState(string state)
{
if (state == null) throw new ArgumentNullException(nameof(state));
if (state == null)
throw new ArgumentNullException(nameof(state));
// If there was no broken state to begin with, done!
if (BrokenState == null)
return;
if (BrokenState != state) return;
// Only clear similar broken states
if (BrokenState != state)
return;
BrokenState = null;
BrokenStateException = null;
OnBrokenStateChanged();
+1 -1
View File
@@ -115,7 +115,7 @@ internal class NodeService : INodeService
}
}
node.Initialize(script);
node.TryInitialize(script);
return node;
}
@@ -8,7 +8,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a kind of node inside a <see cref="INodeScript" />
/// </summary>
public interface INode : INotifyPropertyChanged
public interface INode : INotifyPropertyChanged, IBreakableModel
{
/// <summary>
/// Gets or sets the ID of the node.
@@ -81,15 +81,15 @@ public interface INode : INotifyPropertyChanged
event EventHandler<SingleValueEventArgs<IPinCollection>> PinCollectionRemoved;
/// <summary>
/// Called when the node was loaded from storage or newly created
/// Attempts to initialize the node.
/// </summary>
/// <param name="script">The script the node is contained in</param>
void Initialize(INodeScript script);
void TryInitialize(INodeScript script);
/// <summary>
/// Evaluates the value of the output pins of this node
/// Attempts to evaluate the value of the output pins of this node
/// </summary>
void Evaluate();
void TryEvaluate();
/// <summary>
/// Resets the node causing all pins to re-evaluate the next time <see cref="Evaluate" /> is called
+23 -3
View File
@@ -12,7 +12,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a kind of node inside a <see cref="NodeScript" />
/// </summary>
public abstract class Node : CorePropertyChanged, INode
public abstract class Node : BreakableModel, INode
{
/// <inheritdoc />
public event EventHandler? Resetting;
@@ -95,6 +95,9 @@ public abstract class Node : CorePropertyChanged, INode
/// <inheritdoc />
public IReadOnlyCollection<IPinCollection> PinCollections => new ReadOnlyCollection<IPinCollection>(_pinCollections);
/// <inheritdoc />
public override string BrokenDisplayName => Name;
#endregion
#region Construtors
@@ -335,12 +338,17 @@ public abstract class Node : CorePropertyChanged, INode
return isRemoved;
}
/// <inheritdoc />
/// <summary>
/// Called when the node was loaded from storage or newly created
/// </summary>
/// <param name="script">The script the node is contained in</param>
public virtual void Initialize(INodeScript script)
{
}
/// <inheritdoc />
/// <summary>
/// Evaluates the value of the output pins of this node
/// </summary>
public abstract void Evaluate();
/// <inheritdoc />
@@ -354,6 +362,18 @@ public abstract class Node : CorePropertyChanged, INode
Resetting?.Invoke(this, EventArgs.Empty);
}
/// <inheritdoc />
public void TryInitialize(INodeScript script)
{
TryOrBreak(() => Initialize(script), "Failed to initialize");
}
/// <inheritdoc />
public void TryEvaluate()
{
TryOrBreak(Evaluate, "Failed to evaluate");
}
/// <summary>
/// Called whenever the node must show it's custom view model, if <see langword="null" />, no custom view model is used
/// </summary>
@@ -101,7 +101,7 @@ public abstract class NodeScript : CorePropertyChanged, INodeScript
node.Reset();
}
ExitNode.Evaluate();
ExitNode.TryEvaluate();
}
/// <inheritdoc />
@@ -43,7 +43,7 @@ public sealed class OutputPin<T> : Pin
get
{
if (!IsEvaluated)
Node?.Evaluate();
Node?.TryEvaluate();
return _value;
}
@@ -115,7 +115,7 @@ public sealed class OutputPin : Pin
get
{
if (!IsEvaluated)
Node?.Evaluate();
Node?.TryEvaluate();
return _value;
}