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>
|
2024-10-29 11:48:52 +03:00
|
|
|
public abstract partial class SharedFloorOcclusionSystem : EntitySystem //CP14 partial
|
2023-08-30 12:32:35 +10:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-10-29 11:48:52 +03:00
|
|
|
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
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|