Add tile entity occlusion (#14626)
This commit is contained in:
12
Content.Shared/Movement/Components/FloorOccluderComponent.cs
Normal file
12
Content.Shared/Movement/Components/FloorOccluderComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Applies floor occlusion to any <see cref="FloorOcclusionComponent"/> that intersect us.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed partial class FloorOccluderComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Movement.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Applies an occlusion shader to this entity if it's colliding with a <see cref="FloorOccluderComponent"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class FloorOcclusionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the shader currently enabled.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("enabled"), AutoNetworkedField]
|
||||
public bool Enabled;
|
||||
|
||||
[DataField("colliding")]
|
||||
public List<EntityUid> Colliding = new();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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 class SharedFloorOcclusionSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FloorOccluderComponent, StartCollideEvent>(OnStartCollide);
|
||||
SubscribeLocalEvent<FloorOccluderComponent, EndCollideEvent>(OnEndCollide);
|
||||
}
|
||||
|
||||
private void OnStartCollide(EntityUid uid, FloorOccluderComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
var other = args.OtherEntity;
|
||||
|
||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion) ||
|
||||
occlusion.Colliding.Contains(uid))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetEnabled(other, occlusion, true);
|
||||
occlusion.Colliding.Add(uid);
|
||||
}
|
||||
|
||||
private void OnEndCollide(EntityUid uid, FloorOccluderComponent component, ref EndCollideEvent args)
|
||||
{
|
||||
var other = args.OtherEntity;
|
||||
|
||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion))
|
||||
return;
|
||||
|
||||
occlusion.Colliding.Remove(uid);
|
||||
|
||||
if (occlusion.Colliding.Count == 0)
|
||||
SetEnabled(other, occlusion, false);
|
||||
}
|
||||
|
||||
protected virtual void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
||||
{
|
||||
if (component.Enabled == enabled)
|
||||
return;
|
||||
|
||||
component.Enabled = enabled;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user