diff --git a/Content.Client/Orbit/OrbitVisualsSystem.cs b/Content.Client/Orbit/OrbitVisualsSystem.cs index ce3dee8094..cae65a609f 100644 --- a/Content.Client/Orbit/OrbitVisualsSystem.cs +++ b/Content.Client/Orbit/OrbitVisualsSystem.cs @@ -4,6 +4,7 @@ using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Animations; using Robust.Shared.Random; +using Robust.Shared.Timing; namespace Content.Client.Orbit; @@ -11,8 +12,8 @@ public sealed class OrbitVisualsSystem : EntitySystem { [Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly AnimationPlayerSystem _animations = default!; + [Dependency] private readonly IGameTiming _timing = default!; - private readonly string _orbitAnimationKey = "orbiting"; private readonly string _orbitStopKey = "orbiting_stop"; public override void Initialize() @@ -21,11 +22,11 @@ public sealed class OrbitVisualsSystem : EntitySystem SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentRemove); - SubscribeLocalEvent(OnAnimationCompleted); } private void OnComponentInit(EntityUid uid, OrbitVisualsComponent component, ComponentInit args) { + _robustRandom.SetSeed((int)_timing.CurTime.TotalMilliseconds); component.OrbitDistance = _robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * component.OrbitDistance); @@ -38,15 +39,10 @@ public sealed class OrbitVisualsSystem : EntitySystem } var animationPlayer = EnsureComp(uid); - if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey)) - return; - if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey)) { - _animations.Stop(uid, animationPlayer, _orbitStopKey); + _animations.Stop((uid, animationPlayer), _orbitStopKey); } - - _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey); } private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args) @@ -57,14 +53,9 @@ public sealed class OrbitVisualsSystem : EntitySystem sprite.EnableDirectionOverride = false; var animationPlayer = EnsureComp(uid); - if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey)) - { - _animations.Stop(uid, animationPlayer, _orbitAnimationKey); - } - if (!_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey)) { - _animations.Play(uid, animationPlayer, GetStopAnimation(component, sprite), _orbitStopKey); + _animations.Play((uid, animationPlayer), GetStopAnimation(component, sprite), _orbitStopKey); } } @@ -74,7 +65,8 @@ public sealed class OrbitVisualsSystem : EntitySystem foreach (var (orbit, sprite) in EntityManager.EntityQuery()) { - var angle = new Angle(Math.PI * 2 * orbit.Orbit); + var progress = (float)(_timing.CurTime.TotalSeconds / orbit.OrbitLength) % 1; + var angle = new Angle(Math.PI * 2 * progress); var vec = angle.RotateVec(new Vector2(orbit.OrbitDistance, 0)); sprite.Rotation = orbit.KeepUpright ? Angle.Zero : angle; // WWDP EDIT @@ -82,38 +74,6 @@ public sealed class OrbitVisualsSystem : EntitySystem } } - private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args) - { - if (args.Key == _orbitAnimationKey && TryComp(uid, out AnimationPlayerComponent? animationPlayer)) - { - _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey); - } - } - - private Animation GetOrbitAnimation(OrbitVisualsComponent component) - { - var length = component.OrbitLength; - - return new Animation() - { - Length = TimeSpan.FromSeconds(length), - AnimationTracks = - { - new AnimationTrackComponentProperty() - { - ComponentType = typeof(OrbitVisualsComponent), - Property = nameof(OrbitVisualsComponent.Orbit), - KeyFrames = - { - new AnimationTrackProperty.KeyFrame(0.0f, 0f), - new AnimationTrackProperty.KeyFrame(1.0f, length), - }, - InterpolationMode = AnimationInterpolationMode.Linear - } - } - }; - } - private Animation GetStopAnimation(OrbitVisualsComponent component, SpriteComponent sprite) { var length = component.OrbitStopLength; diff --git a/Content.Shared/Follower/Components/OrbitVisualsComponent.cs b/Content.Shared/Follower/Components/OrbitVisualsComponent.cs index a80288345f..73db737535 100644 --- a/Content.Shared/Follower/Components/OrbitVisualsComponent.cs +++ b/Content.Shared/Follower/Components/OrbitVisualsComponent.cs @@ -22,12 +22,6 @@ public sealed partial class OrbitVisualsComponent : Component /// public float OrbitStopLength = 1.0f; - /// - /// How far along in the orbit, from 0 to 1, is this entity? - /// - [Animatable] - public float Orbit { get; set; } = 0.0f; - // WWDP EDIT START /// /// Whether the orbiting entity's sprite will rotate along the orbit, or stay vertical.