Files
RobustToolbox/Robust.Shared/Toolshed/Commands/Math/ComparisonCommands.cs
Moony 0e1328675c Toolshed (#4197)
* Saving work

* Move shit to engine

* lord

* merg

* awa

* bql is kill

* forgot the fucking bike rack

* bql is kill for real

* pjb will kill me

* aughfhbdj

* yo ho here we go on my way to the MINES

* a

* adgddf

* gdsgvfvxshngfgh

* b

* hfsjhghj

* hbfdjjh

* tf you mean i have to document it

* follow C# standards

* Assorted cleanup and documentation pass, minor bugfix in ValueRefParser.

* Start porting old commands, remove that pesky prefix in favor of integrating with the shell.

* Fix valueref up a bit, improve autocomplete for it.

* e

* Toolshed type system adventure.

* a log

* a

* a e i o u

* awa

* fix tests

* Arithmetic commands.

* a

* parse improvements

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-08-02 16:06:16 -05:00

114 lines
2.9 KiB
C#

using System;
using System.Numerics;
using Robust.Shared.Toolshed.Syntax;
namespace Robust.Shared.Toolshed.Commands.Math;
[ToolshedCommand(Name = ">")]
public sealed class GreaterThanCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : INumber<T>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return x > yVal;
}
}
[ToolshedCommand(Name = "<")]
public sealed class LessThanCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : IComparisonOperators<T, T, bool>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return x > yVal;
}
}
[ToolshedCommand(Name = ">=")]
public sealed class GreaterThanOrEqualCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : INumber<T>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return x >= yVal;
}
}
[ToolshedCommand(Name = "<=")]
public sealed class LessThanOrEqualCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : IComparisonOperators<T, T, bool>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return x <= yVal;
}
}
[ToolshedCommand(Name = "==")]
public sealed class EqualCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : IEquatable<T>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return x.Equals(yVal);
}
}
[ToolshedCommand(Name = "!=")]
public sealed class NotEqualCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public bool Comparison<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] T x,
[CommandArgument] ValueRef<T> y
)
where T : IEquatable<T>
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return false;
return !x.Equals(yVal);
}
}