mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 10:07:15 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using Robust.Shared.Console;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Systems;
|
|
|
|
namespace Robust.Server.Console.Commands;
|
|
|
|
public sealed partial class SpinCommand : LocalizedCommands
|
|
{
|
|
[Dependency] private IEntityManager _entities = default!;
|
|
|
|
public override string Command => "spin";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length < 1)
|
|
{
|
|
shell.WriteError($"Usage: {Help}");
|
|
return;
|
|
}
|
|
|
|
float drag = 0;
|
|
if (!float.TryParse(args[0], out var speed) || (args.Length > 1 && !float.TryParse(args[1], out drag)))
|
|
{
|
|
shell.WriteError($"Unable to parse float");
|
|
return;
|
|
}
|
|
|
|
// get the target
|
|
EntityUid? target;
|
|
|
|
if (args.Length == 3)
|
|
{
|
|
if (!NetEntity.TryParse(args[2], out var targetNet) ||
|
|
!_entities.TryGetEntity(targetNet, out target))
|
|
{
|
|
shell.WriteError($"Unable to find entity {args[1]}");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!_entities.TryGetComponent(shell.Player?.AttachedEntity, out TransformComponent? xform)
|
|
|| xform.ParentUid is not { Valid: true } parent)
|
|
{
|
|
shell.WriteError($"Cannot find default entity (attached player's parent).");
|
|
return;
|
|
}
|
|
|
|
target = parent;
|
|
}
|
|
|
|
// Try get physics
|
|
if (!_entities.TryGetComponent(target, out PhysicsComponent? physics))
|
|
{
|
|
shell.WriteError($"Target entity is incorporeal");
|
|
return;
|
|
}
|
|
|
|
if (physics.BodyType != BodyType.Dynamic)
|
|
{
|
|
shell.WriteError($"Target entity is not dynamic");
|
|
return;
|
|
}
|
|
|
|
var physicsSystem = _entities.System<SharedPhysicsSystem>();
|
|
physicsSystem.SetAngularDamping(target.Value, physics, drag);
|
|
physicsSystem.SetAngularVelocity(target.Value, speed, body: physics);
|
|
}
|
|
}
|