Add FixedPoint2TypeParser (#38169)

This commit is contained in:
Leon Friedrich
2025-06-09 18:01:53 +10:00
committed by GitHub
parent 5604607af4
commit 9247621a96
2 changed files with 37 additions and 9 deletions

View 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);
}
}

View File

@@ -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));
}
}