Fix water postshader (#28130)
This commit is contained in:
@@ -10,51 +10,56 @@ public sealed class FloorOcclusionSystem : SharedFloorOcclusionSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
|
|
||||||
|
private EntityQuery<SpriteComponent> _spriteQuery;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
_spriteQuery = GetEntityQuery<SpriteComponent>();
|
||||||
|
|
||||||
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
|
SubscribeLocalEvent<FloorOcclusionComponent, ComponentStartup>(OnOcclusionStartup);
|
||||||
|
SubscribeLocalEvent<FloorOcclusionComponent, ComponentShutdown>(OnOcclusionShutdown);
|
||||||
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
|
SubscribeLocalEvent<FloorOcclusionComponent, AfterAutoHandleStateEvent>(OnOcclusionAuto);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOcclusionAuto(EntityUid uid, FloorOcclusionComponent component, ref AfterAutoHandleStateEvent args)
|
private void OnOcclusionAuto(Entity<FloorOcclusionComponent> ent, ref AfterAutoHandleStateEvent args)
|
||||||
{
|
{
|
||||||
SetEnabled(uid, component, component.Enabled);
|
SetShader(ent.Owner, ent.Comp.Enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOcclusionStartup(EntityUid uid, FloorOcclusionComponent component, ComponentStartup args)
|
private void OnOcclusionStartup(Entity<FloorOcclusionComponent> ent, ref ComponentStartup args)
|
||||||
{
|
{
|
||||||
if (component.Enabled && TryComp<SpriteComponent>(uid, out var sprite))
|
SetShader(ent.Owner, ent.Comp.Enabled);
|
||||||
SetShader(sprite, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
private void OnOcclusionShutdown(Entity<FloorOcclusionComponent> ent, ref ComponentShutdown args)
|
||||||
{
|
{
|
||||||
if (component.Enabled == enabled)
|
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;
|
return;
|
||||||
|
|
||||||
base.SetEnabled(uid, component, enabled);
|
|
||||||
|
|
||||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SetShader(sprite, enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetShader(SpriteComponent sprite, bool enabled)
|
|
||||||
{
|
|
||||||
var shader = _proto.Index<ShaderPrototype>("HorizontalCut").Instance();
|
var shader = _proto.Index<ShaderPrototype>("HorizontalCut").Instance();
|
||||||
|
|
||||||
if (sprite.PostShader is not null && sprite.PostShader != shader)
|
if (sprite.Comp.PostShader is not null && sprite.Comp.PostShader != shader)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
sprite.PostShader = shader;
|
sprite.Comp.PostShader = shader;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite.PostShader = null;
|
sprite.Comp.PostShader = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,9 @@ namespace Content.Shared.Movement.Components;
|
|||||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||||
public sealed partial class FloorOcclusionComponent : Component
|
public sealed partial class FloorOcclusionComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
[ViewVariables]
|
||||||
/// Is the shader currently enabled.
|
public bool Enabled => Colliding.Count > 0;
|
||||||
/// </summary>
|
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("enabled"), AutoNetworkedField]
|
|
||||||
public bool Enabled;
|
|
||||||
|
|
||||||
[DataField("colliding")]
|
[DataField, AutoNetworkedField]
|
||||||
public List<EntityUid> Colliding = new();
|
public List<EntityUid> Colliding = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,39 +15,37 @@ public abstract class SharedFloorOcclusionSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<FloorOccluderComponent, EndCollideEvent>(OnEndCollide);
|
SubscribeLocalEvent<FloorOccluderComponent, EndCollideEvent>(OnEndCollide);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStartCollide(EntityUid uid, FloorOccluderComponent component, ref StartCollideEvent args)
|
private void OnStartCollide(Entity<FloorOccluderComponent> entity, ref StartCollideEvent args)
|
||||||
{
|
{
|
||||||
var other = args.OtherEntity;
|
var other = args.OtherEntity;
|
||||||
|
|
||||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion) ||
|
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion) ||
|
||||||
occlusion.Colliding.Contains(uid))
|
occlusion.Colliding.Contains(entity.Owner))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetEnabled(other, occlusion, true);
|
occlusion.Colliding.Add(entity.Owner);
|
||||||
occlusion.Colliding.Add(uid);
|
Dirty(other, occlusion);
|
||||||
|
SetEnabled((other, occlusion));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEndCollide(EntityUid uid, FloorOccluderComponent component, ref EndCollideEvent args)
|
private void OnEndCollide(Entity<FloorOccluderComponent> entity, ref EndCollideEvent args)
|
||||||
{
|
{
|
||||||
var other = args.OtherEntity;
|
var other = args.OtherEntity;
|
||||||
|
|
||||||
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion))
|
if (!TryComp<FloorOcclusionComponent>(other, out var occlusion))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
occlusion.Colliding.Remove(uid);
|
if (!occlusion.Colliding.Remove(entity.Owner))
|
||||||
|
|
||||||
if (occlusion.Colliding.Count == 0)
|
|
||||||
SetEnabled(other, occlusion, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void SetEnabled(EntityUid uid, FloorOcclusionComponent component, bool enabled)
|
|
||||||
{
|
|
||||||
if (component.Enabled == enabled)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
component.Enabled = enabled;
|
Dirty(other, occlusion);
|
||||||
Dirty(uid, component);
|
SetEnabled((other, occlusion));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void SetEnabled(Entity<FloorOcclusionComponent> entity)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user