完善节点图的代码生成

This commit is contained in:
fengjiayi
2025-07-07 20:40:24 +08:00
parent b25fd9c83c
commit 678b01f2fe
33 changed files with 1219 additions and 214 deletions

View File

@@ -29,6 +29,24 @@ namespace Serein.NodeFlow
return false;
}
/// <summary>
/// 是否为根节点
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public static bool IsRoot(this IFlowNode node)
{
var cts = NodeStaticConfig.ConnectionTypes;
foreach (var ct in cts)
{
if (node.PreviousNodes[ct].Count > 0)
{
return false;
}
}
return true;
}
/// <summary>
/// 创建节点
@@ -89,6 +107,8 @@ namespace Serein.NodeFlow
};
}
/// <summary>
/// 触发器运行后状态转为对应的后继分支类别
/// </summary>
@@ -107,6 +127,8 @@ namespace Serein.NodeFlow
};
}
/// <summary>
/// 判断 触发器节点 是否存在上游分支
/// </summary>
@@ -136,19 +158,27 @@ namespace Serein.NodeFlow
/// <param name="retractCount">缩进次数4个空格</param>
/// <param name="code">要添加的代码</param>
/// <returns>字符串构建器本身</returns>
public static StringBuilder AddCode(this StringBuilder sb,
public static StringBuilder AppendCode(this StringBuilder sb,
int retractCount = 0,
string code = null)
string code = null,
bool isWrapping = true)
{
if (!string.IsNullOrWhiteSpace(code))
{
var retract = new string(' ', retractCount * 4);
sb.AppendLine(retract + code);
string retract = new string(' ', retractCount * 4);
sb.Append(retract);
if (isWrapping)
{
sb.AppendLine(code);
}
else
{
sb.Append(code);
}
}
return sb;
}