]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add FixedPoint2TypeParser (#38169)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 9 Jun 2025 08:01:53 +0000 (18:01 +1000)
committerGitHub <noreply@github.com>
Mon, 9 Jun 2025 08:01:53 +0000 (18:01 +1000)
Content.Shared/FixedPoint/FixedPoint2.cs
Content.Shared/Toolshed/TypeParsers/FixedPoint2TypeParser.cs [new file with mode: 0644]

index 7316d22f113a7a27f4c3c2d5e729dd58300f1d9b..a8deae413ff457fb40b0cdf784b6767a0bef9cef 100644 (file)
@@ -303,15 +303,7 @@ namespace Content.Shared.FixedPoint
 
         public readonly int CompareTo(FixedPoint2 other)
         {
-            if (other.Value > Value)
-            {
-                return -1;
-            }
-            if (other.Value < Value)
-            {
-                return 1;
-            }
-            return 0;
+            return Value.CompareTo(other.Value);
         }
 
     }
diff --git a/Content.Shared/Toolshed/TypeParsers/FixedPoint2TypeParser.cs b/Content.Shared/Toolshed/TypeParsers/FixedPoint2TypeParser.cs
new file mode 100644 (file)
index 0000000..331c7eb
--- /dev/null
@@ -0,0 +1,36 @@
+using Content.Shared.FixedPoint;
+using Robust.Shared.Console;
+using Robust.Shared.Toolshed;
+using Robust.Shared.Toolshed.Syntax;
+using Robust.Shared.Toolshed.TypeParsers;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Toolshed.TypeParsers;
+
+public sealed class FixedPoint2TypeParser : TypeParser<FixedPoint2>
+{
+    public override bool TryParse(ParserContext ctx, out FixedPoint2 result)
+    {
+        if (Toolshed.TryParse(ctx, out int? value))
+        {
+            result =  FixedPoint2.New(value.Value);
+            return true;
+        }
+
+        if (Toolshed.TryParse(ctx, out float? fValue))
+        {
+            result = FixedPoint2.New(fValue.Value);
+            return true;
+        }
+
+        // Toolshed's number parser (NumberBaseTypeParser) should have assigned ctx.Error so we don't have to.
+        DebugTools.AssertNotNull(ctx.Error);
+        result = FixedPoint2.Zero;
+        return false;
+    }
+
+    public override CompletionResult? TryAutocomplete(ParserContext parserContext, CommandArgument? arg)
+    {
+        return CompletionResult.FromHint(GetArgHint(arg));
+    }
+}