mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 15:22:27 +02:00
* Fix map deletion not working because of deleted entity referencing map * Change fix * Update Robust.Shared/GameObjects/Components/CollisionWakeComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Players;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.GameObjects
|
|
{
|
|
/// <summary>
|
|
/// An optimisation component for stuff that should be set as collidable when it's awake and non-collidable when asleep.
|
|
/// </summary>
|
|
[NetworkedComponent()]
|
|
public sealed class CollisionWakeComponent : Component
|
|
{
|
|
public override string Name => "CollisionWake";
|
|
|
|
[DataField("enabled")]
|
|
private bool _enabled = true;
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool Enabled
|
|
{
|
|
get => _enabled;
|
|
set
|
|
{
|
|
if (value == _enabled) return;
|
|
|
|
_enabled = value;
|
|
Dirty();
|
|
RaiseStateChange();
|
|
}
|
|
}
|
|
|
|
internal void RaiseStateChange()
|
|
{
|
|
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new CollisionWakeStateMessage(), false);
|
|
}
|
|
|
|
protected override void OnRemove()
|
|
{
|
|
base.OnRemove();
|
|
if (Owner.TryGetComponent(out IPhysBody? body) && Owner.LifeStage < EntityLifeStage.Terminating)
|
|
{
|
|
body.CanCollide = true;
|
|
}
|
|
}
|
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
|
{
|
|
return new CollisionWakeState(Enabled);
|
|
}
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
{
|
|
if (curState is not CollisionWakeState state) return;
|
|
|
|
Enabled = state.Enabled;
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public class CollisionWakeState : ComponentState
|
|
{
|
|
public bool Enabled { get; }
|
|
|
|
public CollisionWakeState(bool enabled)
|
|
{
|
|
Enabled = enabled;
|
|
}
|
|
}
|
|
}
|
|
}
|