From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Tue, 26 Dec 2023 23:32:25 +0000 (-0500) Subject: Fix rotation visuals desync & appearance state spam (#23016) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=cf98300ba223cc9b8bed72d9b6dff273a79119a3;p=space-station-14.git Fix rotation visuals desync & appearance state spam (#23016) * Fix rotation visuals desync * :bucklemeup: * A --- diff --git a/Content.Client/Buckle/BuckleSystem.cs b/Content.Client/Buckle/BuckleSystem.cs index db5fa2bd99..8536c3c429 100644 --- a/Content.Client/Buckle/BuckleSystem.cs +++ b/Content.Client/Buckle/BuckleSystem.cs @@ -1,6 +1,7 @@ using Content.Client.Rotation; using Content.Shared.Buckle; using Content.Shared.Buckle.Components; +using Content.Shared.Rotation; using Content.Shared.Vehicle.Components; using Robust.Client.GameObjects; @@ -56,17 +57,15 @@ internal sealed class BuckleSystem : SharedBuckleSystem if (!TryComp(uid, out var rotVisuals)) return; - if (!Appearance.TryGetData(uid, StrapVisuals.RotationAngle, out var angle, args.Component) || - !Appearance.TryGetData(uid, BuckleVisuals.Buckled, out var buckled, args.Component) || + if (!Appearance.TryGetData(uid, BuckleVisuals.Buckled, out var buckled, args.Component) || !buckled || args.Sprite == null) { - _rotationVisualizerSystem.SetHorizontalAngle(uid, rotVisuals.DefaultRotation, rotVisuals); + _rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation); return; } // Animate strapping yourself to something at a given angle - _rotationVisualizerSystem.SetHorizontalAngle(uid, Angle.FromDegrees(angle), rotVisuals); // TODO: Dump this when buckle is better _rotationVisualizerSystem.AnimateSpriteRotation(uid, args.Sprite, rotVisuals.HorizontalRotation, 0.125f); } diff --git a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs b/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs index 44a24595ba..20693408ae 100644 --- a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs +++ b/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs @@ -1,4 +1,5 @@ using Content.Shared.Chemistry; +using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Rounding; using Robust.Client.GameObjects; diff --git a/Content.Client/Rotation/RotationVisualizerSystem.cs b/Content.Client/Rotation/RotationVisualizerSystem.cs index 177c149faa..6105c10c80 100644 --- a/Content.Client/Rotation/RotationVisualizerSystem.cs +++ b/Content.Client/Rotation/RotationVisualizerSystem.cs @@ -5,29 +5,26 @@ using Robust.Shared.Animations; namespace Content.Client.Rotation; -public sealed class RotationVisualizerSystem : VisualizerSystem +public sealed class RotationVisualizerSystem : SharedRotationVisualsSystem { - public void SetHorizontalAngle(EntityUid uid, Angle angle, RotationVisualsComponent? component = null) - { - if (!Resolve(uid, ref component)) - return; - if (component.HorizontalRotation.Equals(angle)) - return; + [Dependency] private readonly AppearanceSystem _appearance = default!; + [Dependency] private readonly AnimationPlayerSystem _animation = default!; - component.HorizontalRotation = angle; - Dirty(component); + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAppearanceChange); } - protected override void OnAppearanceChange(EntityUid uid, RotationVisualsComponent component, ref AppearanceChangeEvent args) + private void OnAppearanceChange(EntityUid uid, RotationVisualsComponent component, ref AppearanceChangeEvent args) { - base.OnAppearanceChange(uid, component, ref args); - if (args.Sprite == null) return; // If not defined, defaults to standing. - AppearanceSystem.TryGetData(uid, RotationVisuals.RotationState, out var state, args.Component); + _appearance.TryGetData(uid, RotationVisuals.RotationState, out var state, args.Component); switch (state) { @@ -53,9 +50,9 @@ public sealed class RotationVisualizerSystem : VisualizerSystem(uid); const string animationKey = "rotate"; // Stop the current rotate animation and then start a new one - if (AnimationSystem.HasRunningAnimation(animationComp, animationKey)) + if (_animation.HasRunningAnimation(animationComp, animationKey)) { - AnimationSystem.Stop(animationComp, animationKey); + _animation.Stop(animationComp, animationKey); } var animation = new Animation @@ -77,6 +74,6 @@ public sealed class RotationVisualizerSystem : VisualizerSystem(buckleUid, out var appearance)) Appearance.SetData(buckleUid, BuckleVisuals.Buckled, true, appearance); + _rotationVisuals.SetHorizontalAngle(buckleUid, strapComp.Rotation); + ReAttach(buckleUid, strapUid, buckleComp, strapComp); SetBuckledTo(buckleUid, strapUid, strapComp, buckleComp); // TODO user is currently set to null because if it isn't the sound fails to play in some situations, fix that @@ -471,6 +473,7 @@ public abstract partial class SharedBuckleSystem if (TryComp(buckleUid, out AppearanceComponent? appearance)) Appearance.SetData(buckleUid, BuckleVisuals.Buckled, false, appearance); + _rotationVisuals.ResetHorizontalAngle(buckleUid); if (TryComp(buckleUid, out var mobState) && _mobState.IsIncapacitated(buckleUid, mobState) diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs b/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs index 7c449a5d8b..7be5436074 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs @@ -5,6 +5,7 @@ using Content.Shared.Destructible; using Content.Shared.DragDrop; using Content.Shared.Foldable; using Content.Shared.Interaction; +using Content.Shared.Rotation; using Content.Shared.Storage; using Content.Shared.Verbs; using Robust.Shared.Containers; @@ -13,6 +14,8 @@ namespace Content.Shared.Buckle; public abstract partial class SharedBuckleSystem { + [Dependency] private readonly SharedRotationVisualsSystem _rotationVisuals = default!; + private void InitializeStrap() { SubscribeLocalEvent(OnStrapStartup); @@ -292,8 +295,6 @@ public abstract partial class SharedBuckleSystem strapComp.OccupiedSize += buckleComp.Size; - Appearance.SetData(buckleUid, StrapVisuals.RotationAngle, strapComp.Rotation); - Appearance.SetData(strapUid, StrapVisuals.State, true); Dirty(strapUid, strapComp); diff --git a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsComponent.cs b/Content.Shared/Chemistry/Components/SolutionContainerVisualsComponent.cs similarity index 94% rename from Content.Client/Chemistry/Visualizers/SolutionContainerVisualsComponent.cs rename to Content.Shared/Chemistry/Components/SolutionContainerVisualsComponent.cs index 5b8ae93766..8ada8e28f4 100644 --- a/Content.Client/Chemistry/Visualizers/SolutionContainerVisualsComponent.cs +++ b/Content.Shared/Chemistry/Components/SolutionContainerVisualsComponent.cs @@ -1,7 +1,6 @@ -using Content.Shared.Chemistry; using Robust.Shared.Utility; -namespace Content.Client.Chemistry.Visualizers +namespace Content.Shared.Chemistry.Components { [RegisterComponent] public sealed partial class SolutionContainerVisualsComponent : Component diff --git a/Content.Shared/Chemistry/EntitySystems/SolutionContainerSystem.cs b/Content.Shared/Chemistry/EntitySystems/SolutionContainerSystem.cs index 04ad17869f..f8fcbf996e 100644 --- a/Content.Shared/Chemistry/EntitySystems/SolutionContainerSystem.cs +++ b/Content.Shared/Chemistry/EntitySystems/SolutionContainerSystem.cs @@ -228,8 +228,7 @@ public sealed partial class SolutionContainerSystem : EntitySystem public void UpdateAppearance(EntityUid uid, Solution solution, AppearanceComponent? appearanceComponent = null) { - if (!EntityManager.EntityExists(uid) - || !Resolve(uid, ref appearanceComponent, false)) + if (!HasComp(uid) || !Resolve(uid, ref appearanceComponent, false)) return; _appearance.SetData(uid, SolutionContainerVisuals.FillFraction, solution.FillFraction, appearanceComponent); diff --git a/Content.Shared/Rotation/RotationVisualsComponent.cs b/Content.Shared/Rotation/RotationVisualsComponent.cs new file mode 100644 index 0000000000..3c1c4f1843 --- /dev/null +++ b/Content.Shared/Rotation/RotationVisualsComponent.cs @@ -0,0 +1,43 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared.Rotation; + +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class RotationVisualsComponent : Component +{ + /// + /// Default value of + /// + [DataField] + public Angle DefaultRotation = Angle.FromDegrees(90); + + [DataField] + public Angle VerticalRotation = 0; + + [DataField, AutoNetworkedField] + public Angle HorizontalRotation = Angle.FromDegrees(90); + + [DataField] + public float AnimationTime = 0.125f; +} + +[Serializable, NetSerializable] +public enum RotationVisuals +{ + RotationState +} + +[Serializable, NetSerializable] +public enum RotationState +{ + /// + /// Standing up. This is the default value. + /// + Vertical = 0, + + /// + /// Laying down + /// + Horizontal, +} diff --git a/Content.Shared/Rotation/SharedRotationComponent.cs b/Content.Shared/Rotation/SharedRotationComponent.cs deleted file mode 100644 index ce1fd374b3..0000000000 --- a/Content.Shared/Rotation/SharedRotationComponent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Rotation -{ - [Serializable, NetSerializable] - public enum RotationVisuals - { - RotationState - } - - [Serializable, NetSerializable] - public enum RotationState - { - /// - /// Standing up. This is the default value. - /// - Vertical = 0, - - /// - /// Laying down - /// - Horizontal, - } -} diff --git a/Content.Shared/Rotation/SharedRotationVisualsSystem.cs b/Content.Shared/Rotation/SharedRotationVisualsSystem.cs new file mode 100644 index 0000000000..dbf3bca31b --- /dev/null +++ b/Content.Shared/Rotation/SharedRotationVisualsSystem.cs @@ -0,0 +1,29 @@ +namespace Content.Shared.Rotation; + +public abstract class SharedRotationVisualsSystem : EntitySystem +{ + /// + /// Sets the rotation an entity will have when it is "horizontal" + /// + public void SetHorizontalAngle(Entity ent, Angle angle) + { + if (!Resolve(ent, ref ent.Comp, false)) + return; + + if (ent.Comp.HorizontalRotation.Equals(angle)) + return; + + ent.Comp.HorizontalRotation = angle; + Dirty(ent); + } + + + /// + /// Resets the rotation an entity will have when it is "horizontal" back to it's default value. + /// + public void ResetHorizontalAngle(Entity ent) + { + if (Resolve(ent, ref ent.Comp, false)) + SetHorizontalAngle(ent, ent.Comp.DefaultRotation); + } +} diff --git a/Content.Shared/Vehicle/SharedVehicleSystem.cs b/Content.Shared/Vehicle/SharedVehicleSystem.cs index 475675f22e..3ac70c31ad 100644 --- a/Content.Shared/Vehicle/SharedVehicleSystem.cs +++ b/Content.Shared/Vehicle/SharedVehicleSystem.cs @@ -74,6 +74,8 @@ public abstract partial class SharedVehicleSystem : EntitySystem if (!vehicle.AutoAnimate) continue; + // Why is this updating appearance data every tick, instead of when it needs to be updated??? + if (_mover.GetVelocityInput(mover).Sprinting == Vector2.Zero) { UpdateAutoAnimate(uid, false);