mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Clean up all missing EntitySystem proxy method uses * Restore comment * Fix bad change that caused closure allocation * tuple * Revert "tuple" This reverts commit14581a40aa. * Revert "Fix bad change that caused closure allocation" This reverts commit215b2559ed. * Revert "Restore comment" This reverts commit4a47a36557. * Revert "Clean up all missing EntitySystem proxy method uses" This reverts commit3b1fe4ce7f. * Redo with improved code fixer. Let's see how it fares this time
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using Robust.Shared.IoC;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Systems;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
public sealed class CollideOnAnchorSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedPhysicsSystem _physics = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<CollideOnAnchorComponent, ComponentStartup>(OnStartup);
|
|
// Shouldn't need to handle re-anchor.
|
|
SubscribeLocalEvent<CollideOnAnchorComponent, AnchorStateChangedEvent>(OnAnchor);
|
|
}
|
|
|
|
private void OnStartup(EntityUid uid, CollideOnAnchorComponent component, ComponentStartup args)
|
|
{
|
|
if (!TryComp(uid, out TransformComponent? transformComponent)) return;
|
|
|
|
SetCollide(uid, component, transformComponent.Anchored);
|
|
}
|
|
|
|
private void OnAnchor(EntityUid uid, CollideOnAnchorComponent component, ref AnchorStateChangedEvent args)
|
|
{
|
|
if (!args.Detaching)
|
|
SetCollide(uid, component, args.Anchored);
|
|
}
|
|
|
|
private void SetCollide(EntityUid uid, CollideOnAnchorComponent component, bool anchored)
|
|
{
|
|
if (!TryComp(uid, out PhysicsComponent? body)) return;
|
|
|
|
var enabled = component.Enable;
|
|
|
|
if (!anchored)
|
|
{
|
|
enabled ^= true;
|
|
}
|
|
|
|
_physics.SetCanCollide(uid, enabled, body: body);
|
|
}
|
|
}
|
|
}
|