NetSyncEnabled fixes (#23553)

NetSyncEnabled  fixes
This commit is contained in:
Leon Friedrich
2024-01-04 23:11:26 -05:00
committed by GitHub
parent 78f4bec3e1
commit 663983bfc3
2 changed files with 25 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ 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.
@@ -86,8 +87,13 @@ public sealed class ColorFlashEffectSystem : SharedColorFlashEffectSystem
continue;
}
var player = EnsureComp<AnimationPlayerComponent>(ent);
player.NetSyncEnabled = false;
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.
@@ -111,8 +117,14 @@ public sealed class ColorFlashEffectSystem : SharedColorFlashEffectSystem
if (animation == null)
continue;
var comp = EnsureComp<ColorFlashEffectComponent>(ent);
comp.NetSyncEnabled = false;
if (!TryComp(ent, out ColorFlashEffectComponent? comp))
{
comp = (ColorFlashEffectComponent) _factory.GetComponent(typeof(ColorFlashEffectComponent));
comp.Owner = ent;
comp.NetSyncEnabled = false;
AddComp(ent, comp);
}
comp.Color = sprite.Color;
_animation.Play((ent, player), animation, AnimationKey);
}