diff --git a/DeedyDesigner/Deedy.Testing/App.xaml.cs b/DeedyDesigner/Deedy.Testing/App.xaml.cs index f2ccd89..72bfa28 100644 --- a/DeedyDesigner/Deedy.Testing/App.xaml.cs +++ b/DeedyDesigner/Deedy.Testing/App.xaml.cs @@ -21,9 +21,14 @@ Func Add var1x var2x math AddResult @var1x 777 + @var2 - @var2x - retu AddResult EndF - +//调用自定义方法 Call Add @var1 99 PopV result +ifth true 4 3 < + letp result 248 +else + letp result 80 +endi "; Todo todo = new Todo(); todo.Init(script); diff --git a/DeedyDesigner/Deedy.Testing/Dodo.cs b/DeedyDesigner/Deedy.Testing/Dodo.cs index 42684ab..4655341 100644 --- a/DeedyDesigner/Deedy.Testing/Dodo.cs +++ b/DeedyDesigner/Deedy.Testing/Dodo.cs @@ -158,7 +158,7 @@ namespace Deedy.Testing for (int lineNum = 0; lineNum < cmdLines.Length; lineNum++) { string command = cmdLines[lineNum].Trim(); - if (!string.IsNullOrEmpty(command)) this.Script.Add(command); + if (!string.IsNullOrEmpty(command) && !command.StartsWith('/')) this.Script.Add(command); } } /// @@ -231,6 +231,7 @@ namespace Deedy.Testing case "endi": this.CmdC_EndI(); break; case "endw": this.CmdC_EndW(); break; case "reen": this.CmdC_Reen(); break; + case "else": this.CmdC_Else(); break; case "func": this.CmdI_Func(cmdArgs); break; case "call": this.CmdI_Call(cmdArgs); break; @@ -246,7 +247,7 @@ namespace Deedy.Testing case "push": this.CmdS_Push(cmdArgs); break; case "popv": this.CmdS_PopV(cmdArgs); break; - default: break; + default: this.Control_CurrentLine++; break; } break; case Mode.Reentry: // 重启脚本逻辑 @@ -410,6 +411,19 @@ namespace Deedy.Testing //HACK:如果需要支持代码块级局部变量则需要在此处闭合代码块 } /// + /// 条件执行的「Else」逻辑 + /// + protected void CmdC_Else() + { + this.Control_CurrentLine++; + while (this.Control_CurrentLine < this.Script.Count) + { + string cmd = Pre_Hand(this.Script[this.Control_CurrentLine]); + if (cmd == "endI") break; + else this.Control_CurrentLine++; + } + } + /// /// $>> 跳转到指定的指令序列位置 /// 注意:跳转指令不会超出「Funcation」范围;如果超出,引擎会自动修正 /// @@ -475,7 +489,11 @@ namespace Deedy.Testing if (!funcHandle.LocalParams.TryAdd(paramDefine[0].TrimStart('@'), paramValue)) funcHandle.LocalParams[paramDefine[0].TrimStart('@')] = paramValue; } - else this.CmdI_VarP(cmdArgs ?? ""); + else + { + this.CmdI_VarP(cmdArgs ?? ""); + return; // 由于「CmdI_VarP」方法已经变更脚本指令“游标”,所以此处直接返回 + } } this.Control_CurrentLine++; } @@ -881,16 +899,17 @@ namespace Deedy.Testing /// 表达式的真值,如果表达式有误则返回指定的值 private bool CmdP_Cond(string condition) { - bool result = true; + bool result = false; Stack stack = []; string[] conParts = condition.Split(' ', options: StringSplitOptions.RemoveEmptyEntries); if (conParts.Length > 0) { - result = bool.Parse(conParts[0].ToLower()); - int index = 0; + _ = bool.TryParse(conParts[0], out result); + if (conParts.Length == 1) return result; + + int index = 1; while (index < conParts.Length) - { - index++; + { switch (conParts[index]) { case "!": this.Cond_Nega(stack); break; @@ -908,6 +927,7 @@ namespace Deedy.Testing default: stack.Push(conParts[index]); break; } + index++; } } if (stack.Count > 0) result = this.Val_Boolean(stack.Pop()); @@ -1056,8 +1076,8 @@ namespace Deedy.Testing /// 设置参数表中的一个参数 /// 备注:先去局部变量中查找,再去全局变量中查找,最后去外部引用变量中查找 /// - /// - /// + /// 变量名称 + /// 变量的值,支持引用 private void ParamSetter(string paramName, object paramValue) { //HACK:暂时不支持代码块级的局部变量 @@ -1093,9 +1113,9 @@ namespace Deedy.Testing /// 从参数表中获取参数 /// 备注:先去局部变量中查找,再去全局变量中查找,最后去外部引用变量中查找 /// - /// - /// - /// + /// 变量名称 + /// 默认值 + /// 如果找不到变量则返回默认值 private object ParamGetter(string paramName, object @default) { //HACK:暂时不支持代码块级的局部变量