Add IEntity.IsWeightless extension method (#2255)
Checking manually every time wasn't that cool
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
#nullable enable
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Physics;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.Components.Movement
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
@@ -7,4 +11,15 @@ namespace Content.Shared.GameObjects.Components.Movement
|
|||||||
{
|
{
|
||||||
public override string Name => "MovementIgnoreGravity";
|
public override string Name => "MovementIgnoreGravity";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GravityExtensions
|
||||||
|
{
|
||||||
|
public static bool IsWeightless(this IEntity entity, IPhysicsManager? physicsManager = null)
|
||||||
|
{
|
||||||
|
physicsManager ??= IoCManager.Resolve<IPhysicsManager>();
|
||||||
|
|
||||||
|
return !entity.HasComponent<MovementIgnoreGravityComponent>() &&
|
||||||
|
physicsManager.IsWeightless(entity.Transform.Coordinates);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
|||||||
{
|
{
|
||||||
physics.EnsureController<MoverController>();
|
physics.EnsureController<MoverController>();
|
||||||
|
|
||||||
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
|
var weightless = !transform.Owner.IsWeightless();
|
||||||
_physicsManager.IsWeightless(transform.Coordinates);
|
|
||||||
|
|
||||||
if (weightless)
|
if (weightless)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ namespace Content.Shared.Physics
|
|||||||
|
|
||||||
public void Move(Vector2 velocityDirection, float speed)
|
public void Move(Vector2 velocityDirection, float speed)
|
||||||
{
|
{
|
||||||
if (ControlledComponent?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false &&
|
if (ControlledComponent?.Owner.IsWeightless() ?? false)
|
||||||
IoCManager.Resolve<IPhysicsManager>().IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using Content.Shared.GameObjects.Components.Movement;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
|
|
||||||
@@ -10,14 +8,11 @@ namespace Content.Shared.Physics
|
|||||||
{
|
{
|
||||||
public class MoverController : VirtualController
|
public class MoverController : VirtualController
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
|
||||||
|
|
||||||
public override IPhysicsComponent? ControlledComponent { protected get; set; }
|
public override IPhysicsComponent? ControlledComponent { protected get; set; }
|
||||||
|
|
||||||
public void Move(Vector2 velocityDirection, float speed)
|
public void Move(Vector2 velocityDirection, float speed)
|
||||||
{
|
{
|
||||||
if (ControlledComponent?.Owner.HasComponent<MovementIgnoreGravityComponent>() == false
|
if (ControlledComponent?.Owner.IsWeightless() ?? false)
|
||||||
&& _physicsManager.IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user