Add tile entity occlusion (#14626)
This commit is contained in:
55
Content.Client/Movement/Systems/FloorOcclusionSystem.cs
Normal file
55
Content.Client/Movement/Systems/FloorOcclusionSystem.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Movement.Systems;
|
||||
|
||||
public sealed class FloorOcclusionSystem : SharedFloorOcclusionSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
|
||||
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
|
||||
}
|
||||
|
||||
private void OnOcclusionAuto(EntityUid uid, FloorOcclusionComponent component, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
SetEnabled(uid, component, component.Enabled);
|
||||
}
|
||||
|
||||
private void OnOcclusionStartup(EntityUid uid, FloorOcclusionComponent component, ComponentStartup args)
|
||||
{
|
||||
if (component.Enabled && TryComp<SpriteComponent>(uid, out var sprite))
|
||||
SetShader(sprite, true);
|
||||
}
|
||||
|
||||
protected override void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
||||
{
|
||||
if (component.Enabled == enabled)
|
||||
return;
|
||||
|
||||
base.SetEnabled(uid, component, enabled);
|
||||
|
||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
||||
return;
|
||||
|
||||
SetShader(sprite, enabled);
|
||||
}
|
||||
|
||||
private void SetShader(SpriteComponent sprite, bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
sprite.PostShader = _proto.Index<ShaderPrototype>("HorizontalCut").Instance();
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.PostShader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user