Files
crystall-punk-14/Content.Shared/Movement/Systems/SharedFloorOcclusionSystem.cs

54 lines
1.5 KiB
C#
Raw Permalink Normal View History

2023-08-30 12:32:35 +10:00
using Content.Shared.Movement.Components;
using Robust.Shared.Physics.Events;
namespace Content.Shared.Movement.Systems;
/// <summary>
/// Applies an occlusion shader for any relevant entities.
/// </summary>
public abstract partial class SharedFloorOcclusionSystem : EntitySystem //CP14 partial
2023-08-30 12:32:35 +10:00
{
public override void Initialize()
{
base.Initialize();
CP14InitializeMapOccluder(); //CP14
2023-08-30 12:32:35 +10:00
SubscribeLocalEvent<FloorOccluderComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<FloorOccluderComponent, EndCollideEvent>(OnEndCollide);
}
2024-05-26 06:23:34 +10:00
private void OnStartCollide(Entity<FloorOccluderComponent> entity, ref StartCollideEvent args)
2023-08-30 12:32:35 +10:00
{
var other = args.OtherEntity;
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion) ||
2024-05-26 06:23:34 +10:00
occlusion.Colliding.Contains(entity.Owner))
2023-08-30 12:32:35 +10:00
{
return;
}
2024-05-26 06:23:34 +10:00
occlusion.Colliding.Add(entity.Owner);
Dirty(other, occlusion);
SetEnabled((other, occlusion));
2023-08-30 12:32:35 +10:00
}
2024-05-26 06:23:34 +10:00
private void OnEndCollide(Entity<FloorOccluderComponent> entity, ref EndCollideEvent args)
2023-08-30 12:32:35 +10:00
{
var other = args.OtherEntity;
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion))
return;
2024-05-26 06:23:34 +10:00
if (!occlusion.Colliding.Remove(entity.Owner))
return;
2023-08-30 12:32:35 +10:00
2024-05-26 06:23:34 +10:00
Dirty(other, occlusion);
SetEnabled((other, occlusion));
2023-08-30 12:32:35 +10:00
}
2024-05-26 06:23:34 +10:00
protected virtual void SetEnabled(Entity<FloorOcclusionComponent> entity)
2023-08-30 12:32:35 +10:00
{
}
}