]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix rotation visuals desync & appearance state spam (#23016)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Tue, 26 Dec 2023 23:32:25 +0000 (18:32 -0500)
committerGitHub <noreply@github.com>
Tue, 26 Dec 2023 23:32:25 +0000 (16:32 -0700)
* Fix rotation visuals desync

* :bucklemeup:

* A

13 files changed:
Content.Client/Buckle/BuckleSystem.cs
Content.Client/Chemistry/Visualizers/SolutionContainerVisualsSystem.cs
Content.Client/Rotation/RotationVisualizerSystem.cs
Content.Client/Rotation/RotationVisualsComponent.cs [deleted file]
Content.Server/Rotation/RotationVisualsSystem.cs [new file with mode: 0644]
Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs
Content.Shared/Buckle/SharedBuckleSystem.Strap.cs
Content.Shared/Chemistry/Components/SolutionContainerVisualsComponent.cs [moved from Content.Client/Chemistry/Visualizers/SolutionContainerVisualsComponent.cs with 94% similarity]
Content.Shared/Chemistry/EntitySystems/SolutionContainerSystem.cs
Content.Shared/Rotation/RotationVisualsComponent.cs [new file with mode: 0644]
Content.Shared/Rotation/SharedRotationComponent.cs [deleted file]
Content.Shared/Rotation/SharedRotationVisualsSystem.cs [new file with mode: 0644]
Content.Shared/Vehicle/SharedVehicleSystem.cs

index db5fa2bd99126776ae5097849e6cbf5f0619a9e7..8536c3c4293098cf390434ce6bb0550beb87327b 100644 (file)
@@ -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<RotationVisualsComponent>(uid, out var rotVisuals))
             return;
 
-        if (!Appearance.TryGetData<int>(uid, StrapVisuals.RotationAngle, out var angle, args.Component) ||
-            !Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component) ||
+        if (!Appearance.TryGetData<bool>(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);
     }
index 44a24595bacc5c528106c4ec1cc21542ffb9bb9e..20693408ae626329478a0a5a8230e38afd5ee14b 100644 (file)
@@ -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;
index 177c149faa173462cdfc33327f4b210a809136b8..6105c10c8033fe1ffb40df73754e228f625cc0dc 100644 (file)
@@ -5,29 +5,26 @@ using Robust.Shared.Animations;
 
 namespace Content.Client.Rotation;
 
-public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsComponent>
+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<RotationVisualsComponent, AppearanceChangeEvent>(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<RotationState>(uid, RotationVisuals.RotationState, out var state, args.Component);
+        _appearance.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, args.Component);
 
         switch (state)
         {
@@ -53,9 +50,9 @@ public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsC
         var animationComp = EnsureComp<AnimationPlayerComponent>(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<RotationVisualsC
             }
         };
 
-        AnimationSystem.Play((uid, animationComp), animation, animationKey);
+        _animation.Play((uid, animationComp), animation, animationKey);
     }
 }
diff --git a/Content.Client/Rotation/RotationVisualsComponent.cs b/Content.Client/Rotation/RotationVisualsComponent.cs
deleted file mode 100644 (file)
index 1cb1118..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-namespace Content.Client.Rotation;
-
-[RegisterComponent]
-public sealed partial class RotationVisualsComponent : Component
-{
-    [DataField("defaultRotation")]
-    [ViewVariables(VVAccess.ReadOnly)]
-    public Angle DefaultRotation = Angle.FromDegrees(90);
-
-    [ViewVariables(VVAccess.ReadWrite)]
-    public Angle VerticalRotation = 0;
-
-    [DataField("horizontalRotation")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public Angle HorizontalRotation = Angle.FromDegrees(90);
-
-    [ViewVariables(VVAccess.ReadWrite)]
-    public float AnimationTime = 0.125f;
-}
diff --git a/Content.Server/Rotation/RotationVisualsSystem.cs b/Content.Server/Rotation/RotationVisualsSystem.cs
new file mode 100644 (file)
index 0000000..8922318
--- /dev/null
@@ -0,0 +1,7 @@
+using Content.Shared.Rotation;
+
+namespace Content.Server.Rotation;
+
+public sealed class RotationVisualsSystem : SharedRotationVisualsSystem
+{
+}
index 9b31d0899cc100138c18f0dbb495b4399a56fecb..63b7fc17a3ec4e54dcc722bbf77c4179824c4fce 100644 (file)
@@ -357,6 +357,8 @@ public abstract partial class SharedBuckleSystem
         if (TryComp<AppearanceComponent>(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<MobStateComponent>(buckleUid, out var mobState)
             && _mobState.IsIncapacitated(buckleUid, mobState)
index 7c449a5d8bf754644f25e2fd5ed8d6e98a8e4945..7be54360741acb697ed07b898b0f14864d3f7359 100644 (file)
@@ -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<StrapComponent, ComponentStartup>(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);
similarity index 94%
rename from Content.Client/Chemistry/Visualizers/SolutionContainerVisualsComponent.cs
rename to Content.Shared/Chemistry/Components/SolutionContainerVisualsComponent.cs
index 5b8ae937665f032f378c63eaf0432dc4ee582405..8ada8e28f4361e6fe384fdd4ebb474f785203ff4 100644 (file)
@@ -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
index 04ad17869f299e60ba614650693abef45f909bc5..f8fcbf996eb62f697880bfd79e531386bf601d7d 100644 (file)
@@ -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<SolutionContainerVisualsComponent>(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 (file)
index 0000000..3c1c4f1
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// Default value of <see cref="HorizontalRotation"/>
+    /// </summary>
+    [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
+{
+    /// <summary>
+    ///     Standing up. This is the default value.
+    /// </summary>
+    Vertical = 0,
+
+    /// <summary>
+    ///     Laying down
+    /// </summary>
+    Horizontal,
+}
diff --git a/Content.Shared/Rotation/SharedRotationComponent.cs b/Content.Shared/Rotation/SharedRotationComponent.cs
deleted file mode 100644 (file)
index ce1fd37..0000000
+++ /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
-    {
-        /// <summary>
-        ///     Standing up. This is the default value.
-        /// </summary>
-        Vertical = 0,
-
-        /// <summary>
-        ///     Laying down
-        /// </summary>
-        Horizontal,
-    }
-}
diff --git a/Content.Shared/Rotation/SharedRotationVisualsSystem.cs b/Content.Shared/Rotation/SharedRotationVisualsSystem.cs
new file mode 100644 (file)
index 0000000..dbf3bca
--- /dev/null
@@ -0,0 +1,29 @@
+namespace Content.Shared.Rotation;
+
+public abstract class SharedRotationVisualsSystem : EntitySystem
+{
+    /// <summary>
+    /// Sets the rotation an entity will have when it is "horizontal"
+    /// </summary>
+    public void SetHorizontalAngle(Entity<RotationVisualsComponent?> ent, Angle angle)
+    {
+        if (!Resolve(ent, ref ent.Comp, false))
+            return;
+
+        if (ent.Comp.HorizontalRotation.Equals(angle))
+            return;
+
+        ent.Comp.HorizontalRotation = angle;
+        Dirty(ent);
+    }
+
+
+    /// <summary>
+    /// Resets the rotation an entity will have when it is "horizontal" back to it's default value.
+    /// </summary>
+    public void ResetHorizontalAngle(Entity<RotationVisualsComponent?> ent)
+    {
+        if (Resolve(ent, ref ent.Comp, false))
+            SetHorizontalAngle(ent, ent.Comp.DefaultRotation);
+    }
+}
index 475675f22e3fa4c53acd4447dd4491ca0d0e9182..3ac70c31ade995054174f3a905050e45964edd65 100644 (file)
@@ -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);