Skip to content

Commit

Permalink
fix ternary comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Jun 3, 2024
1 parent 127d2ff commit b84148c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions OpenDreamClient/Interface/DMF/IDMFProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OpenDreamClient.Interface.DMF;

public interface IDMFProperty {
public bool Equals(string comparison);
public string AsArg();
public string AsEscaped();
public string AsString();
Expand Down Expand Up @@ -82,6 +83,10 @@ public string AsRaw() {
public override string ToString() {
return AsRaw();
}

public bool Equals(string comparison) {
return comparison.Equals(Value, StringComparison.InvariantCulture);
}
}

public struct DMFPropertyNum(float value) : IDMFProperty {
Expand Down Expand Up @@ -128,6 +133,11 @@ public string AsRaw() {
public override string ToString() {
return AsRaw();
}

public bool Equals(string comparison) {
DMFPropertyNum comparisonNum = new(comparison);
return comparisonNum.Value == Value;

Check warning

Code scanning / InspectCode

Equality comparison of floating point numbers. Possible loss of precision while rounding values Warning

Equality comparison of floating point numbers. Possible loss of precision while rounding values
}
}

public struct DMFPropertyVec2 : IDMFProperty {
Expand Down Expand Up @@ -193,6 +203,11 @@ public string AsRaw() {
public override string ToString() {
return AsRaw();
}

public bool Equals(string comparison) {
DMFPropertyVec2 comparisonVec = new(comparison);
return comparisonVec.X == X && comparisonVec.Y == Y;
}
}

public struct DMFPropertyColor : IDMFProperty {
Expand Down Expand Up @@ -254,6 +269,11 @@ public string AsRaw() {
public override string ToString() {
return AsRaw();
}

public bool Equals(string comparison) {
DMFPropertyColor comparisonColor = new(comparison);
return comparisonColor.Value == Value;
}
}

public struct DMFPropertyBool(bool value) : IDMFProperty {
Expand Down Expand Up @@ -293,6 +313,11 @@ public string AsRaw() {
public override string ToString() {
return AsRaw();
}

public bool Equals(string comparison) {
DMFPropertyBool comparisonBool = new(comparison);
return comparisonBool.Value == Value;
}
}

#region Serializers
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ bool CheckParserErrors() {
if(conditionalElement is null)
_sawmill.Error($"Invalid element on ternary condition \"{elementId}\"");
else
if(conditionalElement.TryGetProperty(winSet.Attribute, out var conditionalCheckValue) && conditionalCheckValue.AsRaw().Equals(winSet.Value, StringComparison.InvariantCultureIgnoreCase)) {
if(conditionalElement.TryGetProperty(winSet.Attribute, out var conditionalCheckValue) && conditionalCheckValue.Equals(winSet.Value)) {
foreach(DMFWinSet statement in winSet.TrueStatements) {
string? statementElementId = statement.Element ?? elementId;
InterfaceElement? statementElement = FindElementWithId(statementElementId);
Expand Down

0 comments on commit b84148c

Please sign in to comment.