优化了流程的进行

This commit is contained in:
fengjiayi
2024-09-15 22:07:10 +08:00
parent fe2ccaf74c
commit 61d40977ff
21 changed files with 153 additions and 117 deletions

View File

@@ -26,50 +26,38 @@ namespace Serein.NodeFlow.Model
/// <returns></returns>
public override object? Execute(IDynamicContext context)
{
// bool allTrue = ConditionNodes.All(condition => Judge(context,condition.MethodDetails));
// bool IsAllTrue = true; // 初始化为 true
FlowState = FlowStateType.Succeed;
// NextOrientation = ConnectionType.IsSucceed;
// 条件区域中遍历每个条件节点
foreach (SingleConditionNode? node in ConditionNodes)
{
var state = Judge(context, node);
if (state == FlowStateType.Fail || FlowStateType.Fail == FlowStateType.Error)
NextOrientation = state; // 每次判读完成后,设置区域后继方向为判断结果
if (state != ConnectionType.IsSucceed)
{
FlowState = state;
break;// 一旦发现条件为假,立即退出循环
// 如果条件不通过,立刻推出循环
break;
}
}
return PreviousNode?.FlowData;
//if (IsAllTrue)
//{
// foreach (var nextNode in TrueBranchNextNodes)
// {
// nextNode.ExecuteStack(context);
// }
//}
//else
//{
// foreach (var nextNode in FalseBranchNextNodes)
// {
// nextNode.ExecuteStack(context);
// }
//}
}
private FlowStateType Judge(IDynamicContext context, SingleConditionNode node)
private ConnectionType Judge(IDynamicContext context, SingleConditionNode node)
{
try
{
node.Execute(context);
return node.FlowState;
return node.NextOrientation;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return FlowStateType.Error;
NextOrientation = ConnectionType.IsError;
RuningException = ex;
return ConnectionType.IsError;
}
}