diff --git a/Deltinteger/Deltinteger/Decompiler/ElementToCode/FunctionConvert.cs b/Deltinteger/Deltinteger/Decompiler/ElementToCode/FunctionConvert.cs index a35e13fb5..d526cffbc 100644 --- a/Deltinteger/Deltinteger/Decompiler/ElementToCode/FunctionConvert.cs +++ b/Deltinteger/Deltinteger/Decompiler/ElementToCode/FunctionConvert.cs @@ -284,17 +284,13 @@ public static class WorkshopFunctionDecompileHook }).OnInterupt(() => Cap(decompiler, withBlock)).Get(); }}, {"Wait", (decompiler, function) => { - // Convert the Wait to a MinWait if the wait duration is less than or equal to the minimum. - if ((function.Values[0] is NumberExpression number && number.Value <= Constants.MINIMUM_WAIT) || (function.Values[0] is FunctionExpression durationFunc && durationFunc.Function.Name == "False")) + // Convert the Wait to a MinWait if the wait duration is less than or equal to the minimum and the behavior is set to Ignore Condition. + if (function.Values[1] is ConstantEnumeratorExpression enumerator && + enumerator.Member == ElementRoot.Instance.GetEnumValueFromWorkshop("WaitBehavior", "Ignore Condition") && + ((function.Values[0] is NumberExpression number && number.Value <= Constants.MINIMUM_WAIT) || + (function.Values[0] is FunctionExpression durationFunc && durationFunc.Function.Name == "False"))) { - decompiler.Append("MinWait("); - - // Add wait behavior if it is not the default. - if (function.Values[1] is ConstantEnumeratorExpression enumerator && enumerator.Member != ElementRoot.Instance.GetEnumValueFromWorkshop("WaitBehavior", "Ignore Condition")) - enumerator.Decompile(decompiler); - - // End function - decompiler.Append(")"); + decompiler.Append("MinWait()"); // Finished decompiler.EndAction(); diff --git a/Deltinteger/Deltinteger/Elements/Rule.cs b/Deltinteger/Deltinteger/Elements/Rule.cs index 6f6fc1dac..8bd0998b5 100644 --- a/Deltinteger/Deltinteger/Elements/Rule.cs +++ b/Deltinteger/Deltinteger/Elements/Rule.cs @@ -1,3 +1,6 @@ +using System; +using System.Linq; + namespace Deltin.Deltinteger.Elements { public class Rule @@ -43,6 +46,11 @@ public Rule(string name, string subroutine) public void ToWorkshop(WorkshopBuilder builder) { + + // Element count comment. + if (builder.IncludeComments) + builder.AppendLine("// Rule Element Count: " + ElementCount()); + if (Disabled) { builder.AppendKeyword("disabled") @@ -51,7 +59,6 @@ public void ToWorkshop(WorkshopBuilder builder) builder.AppendKeyword("rule") .AppendLine("(\"" + Name + "\")") .AppendLine("{") - .AppendLine() .Indent() .AppendKeywordLine("event") .AppendLine("{") @@ -78,10 +85,13 @@ public void ToWorkshop(WorkshopBuilder builder) builder.Outdent() .AppendLine("}"); - if (Conditions?.Length > 0) - { - builder.AppendLine() - .AppendKeywordLine("conditions") + if (Conditions?.Length > 0) { + builder.AppendLine(); + + if (builder.IncludeComments) + builder.AppendLine("// Element Count: " + Conditions.Sum(x => x.ElementCount()) + ", Condition Count: " + Conditions.Length); + + builder.AppendKeywordLine("conditions") .AppendLine("{") .Indent(); @@ -96,10 +106,20 @@ public void ToWorkshop(WorkshopBuilder builder) { builder.AppendLine(); - // Action count comment. + // Action and element count comment. if (builder.IncludeComments) - builder.AppendLine("// Action count: " + Actions.Length); - + { + int largestCount = Actions.Max(x => x.ElementCount()); + Element largestAction = Array.FindIndex(Actions, x => x.ElementCount() == largestCount); + int totalElementCount = Actions.Sum(x => x.ElementCount()); + + builder.AppendLine($"// Element Count: {totalElementCount}, Action Count: {Actions.Length}"); + if (Actions.Length > 1) { + builder.AppendLine($"// Largest Action Index: {largestAction} using {largestCount} Elements"); + } + + } + builder.AppendKeywordLine("actions").AppendLine("{").Indent(); int resetIndentInCaseOfUnbalance = builder.GetCurrentIndent();