Add FixedPoint2TypeParser (#38169)
This commit is contained in:
@@ -303,15 +303,7 @@ namespace Content.Shared.FixedPoint
|
|||||||
|
|
||||||
public readonly int CompareTo(FixedPoint2 other)
|
public readonly int CompareTo(FixedPoint2 other)
|
||||||
{
|
{
|
||||||
if (other.Value > Value)
|
return Value.CompareTo(other.Value);
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (other.Value < Value)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
36
Content.Shared/Toolshed/TypeParsers/FixedPoint2TypeParser.cs
Normal file
36
Content.Shared/Toolshed/TypeParsers/FixedPoint2TypeParser.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user