mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Prevent map/emplace command errors from locking up the server * Fix EmplaceCommand * Fix sort commands * Fix JoinCommand * changelog --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Robust.Shared.Toolshed.Syntax;
|
|
|
|
namespace Robust.Shared.Toolshed.Commands.Math;
|
|
|
|
[ToolshedCommand]
|
|
public sealed class JoinCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation]
|
|
public string Join(
|
|
[CommandInvocationContext] IInvocationContext ctx,
|
|
[PipedArgument] string x,
|
|
[CommandArgument] ValueRef<string> y
|
|
)
|
|
{
|
|
var yVal = y.Evaluate(ctx);
|
|
if (yVal is null)
|
|
return x;
|
|
|
|
return x + yVal;
|
|
}
|
|
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<T> Join<T>(
|
|
[CommandInvocationContext] IInvocationContext ctx,
|
|
[PipedArgument] IEnumerable<T> x,
|
|
[CommandArgument] ValueRef<IEnumerable<T>> y
|
|
)
|
|
{
|
|
var yVal = y.Evaluate(ctx);
|
|
if (yVal is null)
|
|
return x;
|
|
|
|
return x.Concat(yVal);
|
|
}
|
|
}
|
|
|
|
[ToolshedCommand]
|
|
public sealed class AppendCommand : ToolshedCommand
|
|
{
|
|
[CommandImplementation, TakesPipedTypeAsGeneric]
|
|
public IEnumerable<T> Append<T>(
|
|
[CommandInvocationContext] IInvocationContext ctx,
|
|
[PipedArgument] IEnumerable<T> x,
|
|
[CommandArgument] ValueRef<T> y
|
|
)
|
|
{
|
|
var yVal = y.Evaluate(ctx);
|
|
if (yVal is null)
|
|
return x;
|
|
|
|
return x.Append(yVal);
|
|
}
|
|
}
|