Files
crystall-punk-14/Content.Client/Movement/Systems/FloorOcclusionSystem.cs

66 lines
2.0 KiB
C#
Raw Permalink Normal View History

2023-08-30 12:32:35 +10:00
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!;
2024-05-26 06:23:34 +10:00
private EntityQuery<SpriteComponent> _spriteQuery;
2023-08-30 12:32:35 +10:00
public override void Initialize()
{
base.Initialize();
2024-05-26 06:23:34 +10:00
_spriteQuery = GetEntityQuery<SpriteComponent>();
2023-08-30 12:32:35 +10:00
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
2024-05-26 06:23:34 +10:00
SubscribeLocalEvent<FloorOcclusionComponent, ComponentShutdown>(OnOcclusionShutdown);
2023-08-30 12:32:35 +10:00
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
}
2024-05-26 06:23:34 +10:00
private void OnOcclusionAuto(Entity<FloorOcclusionComponent> ent, ref AfterAutoHandleStateEvent args)
2023-08-30 12:32:35 +10:00
{
2024-05-26 06:23:34 +10:00
SetShader(ent.Owner, ent.Comp.Enabled);
2023-08-30 12:32:35 +10:00
}
2024-05-26 06:23:34 +10:00
private void OnOcclusionStartup(Entity<FloorOcclusionComponent> ent, ref ComponentStartup args)
2023-08-30 12:32:35 +10:00
{
2024-05-26 06:23:34 +10:00
SetShader(ent.Owner, ent.Comp.Enabled);
2023-08-30 12:32:35 +10:00
}
2024-05-26 06:23:34 +10:00
private void OnOcclusionShutdown(Entity<FloorOcclusionComponent> ent, ref ComponentShutdown args)
2023-08-30 12:32:35 +10:00
{
2024-05-26 06:23:34 +10:00
SetShader(ent.Owner, false);
}
2023-08-30 12:32:35 +10:00
2024-05-26 06:23:34 +10:00
protected override void SetEnabled(Entity<FloorOcclusionComponent> entity)
{
SetShader(entity.Owner, entity.Comp.Enabled);
2023-08-30 12:32:35 +10:00
}
2024-05-26 06:23:34 +10:00
private void SetShader(Entity<SpriteComponent?> sprite, bool enabled)
2023-08-30 12:32:35 +10:00
{
2024-05-26 06:23:34 +10:00
if (!_spriteQuery.Resolve(sprite.Owner, ref sprite.Comp, false))
return;
var shader = _proto.Index<ShaderPrototype>("HorizontalCut").Instance();
2024-05-26 06:23:34 +10:00
if (sprite.Comp.PostShader is not null && sprite.Comp.PostShader != shader)
return;
2023-08-30 12:32:35 +10:00
if (enabled)
{
2024-05-26 06:23:34 +10:00
sprite.Comp.PostShader = shader;
2023-08-30 12:32:35 +10:00
}
else
{
2024-05-26 06:23:34 +10:00
sprite.Comp.PostShader = null;
2023-08-30 12:32:35 +10:00
}
}
}