Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entities getting stuck red #28981

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions Content.Client/Effects/ColorFlashEffectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.Collections;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.Effects;

public sealed class ColorFlashEffectSystem : SharedColorFlashEffectSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly IComponentFactory _factory = default!;

/// <summary>
/// It's a little on the long side but given we use multiple colours denoting what happened it makes it easier to register.
/// </summary>
private const float AnimationLength = 0.30f;
private const string AnimationKey = "color-flash-effect";
private ValueList<EntityUid> _toRemove = new();

public override void Initialize()
{
Expand All @@ -44,8 +46,28 @@
{
sprite.Color = component.Color;
}
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = AllEntityQuery<ColorFlashEffectComponent>();
_toRemove.Clear();

// Can't use deferred removal on animation completion or it will cause issues.
while (query.MoveNext(out var uid, out _))
{
if (_animation.HasRunningAnimation(uid, AnimationKey))
continue;

RemCompDeferred<ColorFlashEffectComponent>(uid);
_toRemove.Add(uid);
}

foreach (var ent in _toRemove)
{
RemComp<ColorFlashEffectComponent>(ent);
}
}

private Animation? GetDamageAnimation(EntityUid uid, Color color, SpriteComponent? sprite = null)
Expand Down Expand Up @@ -82,51 +104,31 @@
{
var ent = GetEntity(nent);

if (Deleted(ent))
if (Deleted(ent) || !TryComp(ent, out SpriteComponent? sprite))
{
continue;
}

if (!TryComp(ent, out AnimationPlayerComponent? player))
{
player = (AnimationPlayerComponent) _factory.GetComponent(typeof(AnimationPlayerComponent));
player.Owner = ent;
player.NetSyncEnabled = false;
AddComp(ent, player);
}

// Need to stop the existing animation first to ensure the sprite color is fixed.
// Otherwise we might lerp to a red colour instead.
if (_animation.HasRunningAnimation(ent, player, AnimationKey))
{
_animation.Stop(ent, player, AnimationKey);
}

if (!TryComp<SpriteComponent>(ent, out var sprite))
{
continue;
}

if (TryComp<ColorFlashEffectComponent>(ent, out var effect))
#if DEBUG
if (!TryComp(ent, out ColorFlashEffectComponent? comp))
{
sprite.Color = effect.Color;
DebugTools.Assert(!_animation.HasRunningAnimation(ent, AnimationKey));
}
#endif

_animation.Stop(ent, AnimationKey);
var animation = GetDamageAnimation(ent, color, sprite);

if (animation == null)
continue;

if (!TryComp(ent, out ColorFlashEffectComponent? comp))
{
comp = (ColorFlashEffectComponent) _factory.GetComponent(typeof(ColorFlashEffectComponent));
comp.Owner = ent;
comp.NetSyncEnabled = false;
AddComp(ent, comp);
continue;
}

comp = EnsureComp<ColorFlashEffectComponent>(ent);

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context

Check failure on line 127 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context
comp.NetSyncEnabled = false;

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context

Check failure on line 128 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context
comp.Color = sprite.Color;

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'comp' does not exist in the current context

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The name 'comp' does not exist in the current context

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context

Check failure on line 129 in Content.Client/Effects/ColorFlashEffectSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The name 'comp' does not exist in the current context
_animation.Play((ent, player), animation, AnimationKey);

_animation.Play(ent, animation, AnimationKey);
}
}
}
2 changes: 1 addition & 1 deletion Content.Client/Gravity/FloatingVisualizerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ private void OnAnimationCompleted(EntityUid uid, FloatingVisualsComponent compon
if (args.Key != component.AnimationKey)
return;

FloatAnimation(uid, component.Offset, component.AnimationKey, component.AnimationTime, !component.CanFloat);
FloatAnimation(uid, component.Offset, component.AnimationKey, component.AnimationTime, stop: !component.CanFloat);
}
}
Loading