diff --git a/Content.Client/Orbit/OrbitVisualsSystem.cs b/Content.Client/Orbit/OrbitVisualsSystem.cs index dad8cf2c96..2ab144fda2 100644 --- a/Content.Client/Orbit/OrbitVisualsSystem.cs +++ b/Content.Client/Orbit/OrbitVisualsSystem.cs @@ -7,7 +7,7 @@ using Robust.Shared.Random; namespace Content.Client.Orbit; -public sealed class OrbitVisualsSystem : VisualizerSystem +public sealed class OrbitVisualsSystem : EntitySystem { [Dependency] private readonly IRobustRandom _robustRandom = default!; @@ -19,6 +19,7 @@ public sealed class OrbitVisualsSystem : VisualizerSystem base.Initialize(); SubscribeLocalEvent(OnComponentInit); + SubscribeLocalEvent(OnComponentRemove); SubscribeLocalEvent(OnAnimationCompleted); } @@ -28,6 +29,34 @@ public sealed class OrbitVisualsSystem : VisualizerSystem _robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * component.OrbitDistance); component.OrbitLength = _robustRandom.NextFloat(0.5f * component.OrbitLength, 1.5f * component.OrbitLength); + + var animationPlayer = EntityManager.EnsureComponent(uid); + if (animationPlayer.HasRunningAnimation(_orbitAnimationKey)) + return; + + if (animationPlayer.HasRunningAnimation(_orbitStopKey)) + { + animationPlayer.Stop(_orbitStopKey); + } + + animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey); + } + + private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args) + { + if (!TryComp(uid, out var sprite)) + return; + + var animationPlayer = EntityManager.EnsureComponent(uid); + if (animationPlayer.HasRunningAnimation(_orbitAnimationKey)) + { + animationPlayer.Stop(_orbitAnimationKey); + } + + if (!animationPlayer.HasRunningAnimation(_orbitStopKey)) + { + animationPlayer.Play(GetStopAnimation(component, sprite), _orbitStopKey); + } } public override void FrameUpdate(float frameTime) @@ -44,43 +73,6 @@ public sealed class OrbitVisualsSystem : VisualizerSystem } } - protected override void OnAppearanceChange(EntityUid uid, OrbitVisualsComponent component, ref AppearanceChangeEvent args) - { - if (!args.Component.TryGetData(OrbitingVisuals.IsOrbiting, out var orbiting)) - return; - - if (!TryComp(uid, out var sprite)) - return; - - var animationPlayer = EntityManager.EnsureComponent(uid); - - if (orbiting) - { - if (animationPlayer.HasRunningAnimation(_orbitAnimationKey)) - return; - - if (animationPlayer.HasRunningAnimation(_orbitStopKey)) - { - animationPlayer.Stop(_orbitStopKey); - } - - animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey); - } - else - { - RemComp(uid); - if (animationPlayer.HasRunningAnimation(_orbitAnimationKey)) - { - animationPlayer.Stop(_orbitAnimationKey); - } - - if (!animationPlayer.HasRunningAnimation(_orbitStopKey)) - { - animationPlayer.Play(GetStopAnimation(component, sprite), _orbitStopKey); - } - } - } - private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args) { if (args.Key == _orbitAnimationKey) diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index 0d358aac00..d83e99e909 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -71,18 +71,13 @@ public sealed class FollowerSystem : EntitySystem followerComp.Following = entity; var followedComp = EnsureComp(entity); - if (!followedComp.Following.Add(follower)) - return; + followedComp.Following.Add(follower); var xform = Transform(follower); xform.AttachParent(entity); xform.LocalPosition = Vector2.Zero; - if (TryComp(follower, out var appearance)) - { - EnsureComp(follower); - appearance.SetData(OrbitingVisuals.IsOrbiting, true); - } + EnsureComp(follower); var followerEv = new StartedFollowingEntityEvent(entity, follower); var entityEv = new EntityStartedFollowingEvent(entity, follower); @@ -110,12 +105,7 @@ public sealed class FollowerSystem : EntitySystem Transform(uid).AttachToGridOrMap(); - if (TryComp(uid, out var appearance)) - { - // We don't remove OrbitVisuals here since the OrbitVisualsSystem will handle that itself - // during the OnChangeData, which is deferred.. - appearance.SetData(OrbitingVisuals.IsOrbiting, false); - } + RemComp(uid); var uidEv = new StoppedFollowingEntityEvent(target, uid); var targetEv = new EntityStoppedFollowingEvent(target, uid); @@ -191,10 +181,3 @@ public sealed class EntityStoppedFollowingEvent : FollowEvent { } } - -[Serializable, NetSerializable] -public enum OrbitingVisuals : byte -{ - IsOrbiting -} -