Skip to content

Commit ebf7ac0

Browse files
committed
Added the ostw.optimizeOutput setting.
1 parent 73245d2 commit ebf7ac0

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

Deltinteger/Deltinteger/Elements/Condition.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ public Condition(Element value1, Elements.Operators compareOperator, Element val
3131
public Condition(V_Compare condition) : this((Element)condition.ParameterValues[0], (EnumMember)condition.ParameterValues[1], (Element)condition.ParameterValues[2]) {}
3232
public Condition(Element condition) : this(condition, Operators.Equal, new V_True()) {}
3333

34-
public string ToWorkshop(OutputLanguage language)
34+
public string ToWorkshop(OutputLanguage language, bool optimize)
3535
{
36-
return Value1.Optimize().ToWorkshop(language) + " " + CompareOperator.ToWorkshop(language) + " " + Value2.Optimize().ToWorkshop(language);
36+
Element a = Value1;
37+
Element b = Value2;
38+
if (optimize)
39+
{
40+
a = a.Optimize();
41+
b = b.Optimize();
42+
}
43+
44+
return a.ToWorkshop(language) + " " + CompareOperator.ToWorkshop(language) + " " + b.ToWorkshop(language);
3745
}
3846

3947
public static implicit operator Condition(Element element) => new Condition(element);

Deltinteger/Deltinteger/Elements/Rule.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override string ToString()
3939
return Name;
4040
}
4141

42-
public string ToWorkshop(OutputLanguage language)
42+
public string ToWorkshop(OutputLanguage language, bool optimize)
4343
{
4444
var builder = new TabStringBuilder(true);
4545

@@ -73,7 +73,7 @@ public string ToWorkshop(OutputLanguage language)
7373
builder.AppendLine("{"); // | {
7474
builder.Indent = 2; // | (indent)
7575
foreach (var condition in Conditions) // |
76-
builder.AppendLine(condition.ToWorkshop(language) + ";"); // | Number Of Players >= 3;
76+
builder.AppendLine(condition.ToWorkshop(language, optimize) + ";"); // | Number Of Players >= 3;
7777
builder.Indent = 1; // | (outdent)
7878
builder.AppendLine("}"); // | }
7979
} //
@@ -86,7 +86,10 @@ public string ToWorkshop(OutputLanguage language)
8686
builder.AppendLine("{"); // | {
8787
builder.Indent = 2; // | (indent)
8888
foreach (var action in Actions) // |
89-
builder.AppendLine(action.Optimize().ToWorkshop(language)); // | Set Global Variable(A, true);
89+
if (optimize) // |
90+
builder.AppendLine(action.Optimize().ToWorkshop(language)); // | Set Global Variable(A, true);
91+
else // |
92+
builder.AppendLine(action.ToWorkshop(language)); // |
9093
builder.Indent = 1; // | (outdent)
9194
builder.AppendLine("}"); // | }
9295
} //

Deltinteger/Deltinteger/Elements/Values.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public override Element Optimize()
448448
double y = -Math.Sin(v * (Math.PI / 180));
449449
double z = Math.Cos(h * (Math.PI / 180));
450450

451-
if (y.ToString() == "-0")
451+
if (y == -0)
452452
y = 0;
453453

454454
return new V_Vector(x, y, z);
@@ -678,7 +678,7 @@ public override Element Optimize()
678678
if (double.IsNaN(gradient))
679679
gradient = 0;
680680
double result = Math.Atan(gradient) * (180 / Math.PI);
681-
if (result.ToString() == "-0") //thank you c# for -0 being a thing
681+
if (result == -0) //thank you c# for -0 being a thing
682682
result = 180;
683683
return result;
684684
}

Deltinteger/Deltinteger/Language Server/ConfigurationHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace Deltin.Deltinteger.LanguageServer
1616
{
1717
public class ConfigurationHandler : IDidChangeConfigurationHandler
1818
{
19+
public static bool OptimizeOutput = true;
20+
1921
private DeltintegerLanguageServer _languageServer { get; }
2022

2123
public ConfigurationHandler(DeltintegerLanguageServer languageServer)
@@ -31,6 +33,7 @@ public Task<Unit> Handle(DidChangeConfigurationParams configChangeParams, Cancel
3133
{
3234
var config = json.ToObject<RawConfiguration>();
3335
I18n.I18n.LoadLanguage(config.GetOutputLanguage());
36+
OptimizeOutput = config.optimizeOutput;
3437
}
3538

3639
return Unit.Task;
@@ -50,8 +53,11 @@ public void SetCapability(DidChangeConfigurationCapability capability)
5053

5154
class RawConfiguration
5255
{
56+
#pragma warning disable CS0649
5357
public string outputLanguage;
5458
public string deltintegerPath;
59+
public bool optimizeOutput;
60+
#pragma warning restore CS0649
5561

5662
public OutputLanguage GetOutputLanguage()
5763
{

Deltinteger/Deltinteger/Parse/Translate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void ToWorkshop(Func<VarCollection, Rule[]> addRules)
255255

256256
// Get the rules.
257257
foreach (var rule in WorkshopRules)
258-
result.AppendLine(rule.ToWorkshop(I18n.I18n.CurrentLanguage));
258+
result.AppendLine(rule.ToWorkshop(I18n.I18n.CurrentLanguage, ConfigurationHandler.OptimizeOutput));
259259

260260
WorkshopCode = result.ToString();
261261
}

overwatch-script-to-workshop/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
"default": "English",
6363
"description": "The output language of the OSTW output."
6464
},
65+
"ostw.optimizeOutput": {
66+
"scope": "window",
67+
"type": "boolean",
68+
"default": true,
69+
"description": "Determines if the workshop output will be optimized."
70+
},
6571
"ostw.deltintegerPath": {
6672
"scope": "machine",
6773
"type": "string",
@@ -81,11 +87,6 @@
8187
}
8288
},
8389
"commands": [
84-
{
85-
"command": "ostw.webviewOutput",
86-
"title": "Create webview panel for workshop code output.",
87-
"category": "Overwatch Script To Workshop"
88-
}
8990
]
9091
},
9192
"scripts": {

0 commit comments

Comments
 (0)