* Convert all shader prototype string literals to protoids in overlays * Convert more shader prototype literal strings to protoids * Convert ValidatePrototypeId to ProtoId * Later
68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
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
|
|
{
|
|
private static readonly ProtoId<ShaderPrototype> HorizontalCut = "HorizontalCut";
|
|
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
|
|
private EntityQuery<SpriteComponent> _spriteQuery;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_spriteQuery = GetEntityQuery<SpriteComponent>();
|
|
|
|
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
|
|
SubscribeLocalEvent<FloorOcclusionComponent, ComponentShutdown>(OnOcclusionShutdown);
|
|
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
|
|
}
|
|
|
|
private void OnOcclusionAuto(Entity<FloorOcclusionComponent> ent, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
SetShader(ent.Owner, ent.Comp.Enabled);
|
|
}
|
|
|
|
private void OnOcclusionStartup(Entity<FloorOcclusionComponent> ent, ref ComponentStartup args)
|
|
{
|
|
SetShader(ent.Owner, ent.Comp.Enabled);
|
|
}
|
|
|
|
private void OnOcclusionShutdown(Entity<FloorOcclusionComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
SetShader(ent.Owner, false);
|
|
}
|
|
|
|
protected override void SetEnabled(Entity<FloorOcclusionComponent> entity)
|
|
{
|
|
SetShader(entity.Owner, entity.Comp.Enabled);
|
|
}
|
|
|
|
private void SetShader(Entity<SpriteComponent?> sprite, bool enabled)
|
|
{
|
|
if (!_spriteQuery.Resolve(sprite.Owner, ref sprite.Comp, false))
|
|
return;
|
|
|
|
var shader = _proto.Index(HorizontalCut).Instance();
|
|
|
|
if (sprite.Comp.PostShader is not null && sprite.Comp.PostShader != shader)
|
|
return;
|
|
|
|
if (enabled)
|
|
{
|
|
sprite.Comp.PostShader = shader;
|
|
}
|
|
else
|
|
{
|
|
sprite.Comp.PostShader = null;
|
|
}
|
|
}
|
|
}
|