Skip to content

Commit 2cb84e3

Browse files
authored
Merge pull request #504 from damagex/master
Extra element info in output + MinWait() decompile bug fixed
2 parents caa84d9 + cc7cb59 commit 2cb84e3

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

Deltinteger/Deltinteger/Decompiler/ElementToCode/FunctionConvert.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,13 @@ public static class WorkshopFunctionDecompileHook
284284
}).OnInterupt(() => Cap(decompiler, withBlock)).Get();
285285
}},
286286
{"Wait", (decompiler, function) => {
287-
// Convert the Wait to a MinWait if the wait duration is less than or equal to the minimum.
288-
if ((function.Values[0] is NumberExpression number && number.Value <= Constants.MINIMUM_WAIT) || (function.Values[0] is FunctionExpression durationFunc && durationFunc.Function.Name == "False"))
287+
// 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.
288+
if (function.Values[1] is ConstantEnumeratorExpression enumerator &&
289+
enumerator.Member == ElementRoot.Instance.GetEnumValueFromWorkshop("WaitBehavior", "Ignore Condition") &&
290+
((function.Values[0] is NumberExpression number && number.Value <= Constants.MINIMUM_WAIT) ||
291+
(function.Values[0] is FunctionExpression durationFunc && durationFunc.Function.Name == "False")))
289292
{
290-
decompiler.Append("MinWait(");
291-
292-
// Add wait behavior if it is not the default.
293-
if (function.Values[1] is ConstantEnumeratorExpression enumerator && enumerator.Member != ElementRoot.Instance.GetEnumValueFromWorkshop("WaitBehavior", "Ignore Condition"))
294-
enumerator.Decompile(decompiler);
295-
296-
// End function
297-
decompiler.Append(")");
293+
decompiler.Append("MinWait()");
298294

299295
// Finished
300296
decompiler.EndAction();

Deltinteger/Deltinteger/Elements/Rule.cs

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.Linq;
3+
14
namespace Deltin.Deltinteger.Elements
25
{
36
public class Rule
@@ -43,6 +46,11 @@ public Rule(string name, string subroutine)
4346

4447
public void ToWorkshop(WorkshopBuilder builder)
4548
{
49+
50+
// Element count comment.
51+
if (builder.IncludeComments)
52+
builder.AppendLine("// Rule Element Count: " + ElementCount());
53+
4654
if (Disabled)
4755
{
4856
builder.AppendKeyword("disabled")
@@ -51,7 +59,6 @@ public void ToWorkshop(WorkshopBuilder builder)
5159
builder.AppendKeyword("rule")
5260
.AppendLine("(\"" + Name + "\")")
5361
.AppendLine("{")
54-
.AppendLine()
5562
.Indent()
5663
.AppendKeywordLine("event")
5764
.AppendLine("{")
@@ -78,10 +85,13 @@ public void ToWorkshop(WorkshopBuilder builder)
7885
builder.Outdent()
7986
.AppendLine("}");
8087

81-
if (Conditions?.Length > 0)
82-
{
83-
builder.AppendLine()
84-
.AppendKeywordLine("conditions")
88+
if (Conditions?.Length > 0) {
89+
builder.AppendLine();
90+
91+
if (builder.IncludeComments)
92+
builder.AppendLine("// Element Count: " + Conditions.Sum(x => x.ElementCount()) + ", Condition Count: " + Conditions.Length);
93+
94+
builder.AppendKeywordLine("conditions")
8595
.AppendLine("{")
8696
.Indent();
8797

@@ -96,10 +106,20 @@ public void ToWorkshop(WorkshopBuilder builder)
96106
{
97107
builder.AppendLine();
98108

99-
// Action count comment.
109+
// Action and element count comment.
100110
if (builder.IncludeComments)
101-
builder.AppendLine("// Action count: " + Actions.Length);
102-
111+
{
112+
int largestCount = Actions.Max(x => x.ElementCount());
113+
Element largestAction = Array.FindIndex(Actions, x => x.ElementCount() == largestCount);
114+
int totalElementCount = Actions.Sum(x => x.ElementCount());
115+
116+
builder.AppendLine($"// Element Count: {totalElementCount}, Action Count: {Actions.Length}");
117+
if (Actions.Length > 1) {
118+
builder.AppendLine($"// Largest Action Index: {largestAction} using {largestCount} Elements");
119+
}
120+
121+
}
122+
103123
builder.AppendKeywordLine("actions").AppendLine("{").Indent();
104124
int resetIndentInCaseOfUnbalance = builder.GetCurrentIndent();
105125

0 commit comments

Comments
 (0)