]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Gravity Generators cannot be unanchored while active (#41256)
authorJustin Pfeifler <jrpl101998@gmail.com>
Fri, 7 Nov 2025 00:53:27 +0000 (18:53 -0600)
committerGitHub <noreply@github.com>
Fri, 7 Nov 2025 00:53:27 +0000 (00:53 +0000)
* Add unanchor attempt check

* Combine shared component and server component

- Combines SharedGravityGeneratorComponent and GravityGeneratorComponent
- AutoNetworked the GravityActiveBool

* Remove SharedGravityGeneratorComponent

* Update to SharedGravityGeneratorComponent

* Fix to be a complete sentence

* Dirty GravityActive whenever changed

* Rename component and remove view variables

* Update referenced component name

* Move unanchor attempt to shared system

* Add client system

* Revert popup to PopupEntity

* Fix popup to be PopupClient

* Set access restriction on GravityActive

Content.Client/Entry/EntryPoint.cs
Content.Client/Gravity/GravityGeneratorSystem.cs [new file with mode: 0644]
Content.Client/Gravity/GravitySystem.cs
Content.IntegrationTests/Tests/GravityGridTest.cs
Content.Server/Gravity/GravityGeneratorComponent.cs [deleted file]
Content.Server/Gravity/GravityGeneratorSystem.cs
Content.Shared/Gravity/GravityGeneratorComponent.cs [moved from Content.Shared/Gravity/SharedGravityGeneratorComponent.cs with 59% similarity]
Content.Shared/Gravity/SharedGravityGeneratorSystem.cs [new file with mode: 0644]
Resources/Locale/en-US/components/station-anchor-component.ftl
Resources/Locale/en-US/gravity/gravity-generator-component.ftl

index ac08547859b42653c70eff40bc9a7fcbf59f19f7..b9f0e0e8e6e6f5e4a189d0e5170619dc42fe8c2f 100644 (file)
@@ -98,7 +98,6 @@ namespace Content.Client.Entry
             _componentFactory.IgnoreMissingComponents();
 
             // Do not add to these, they are legacy.
-            _componentFactory.RegisterClass<SharedGravityGeneratorComponent>();
             _componentFactory.RegisterClass<SharedAmeControllerComponent>();
             // Do not add to the above, they are legacy
 
diff --git a/Content.Client/Gravity/GravityGeneratorSystem.cs b/Content.Client/Gravity/GravityGeneratorSystem.cs
new file mode 100644 (file)
index 0000000..b74ea35
--- /dev/null
@@ -0,0 +1,8 @@
+using Content.Shared.Gravity;
+
+namespace Content.Client.Gravity;
+
+public sealed class GravityGeneratorSystem : SharedGravityGeneratorSystem
+{
+
+}
index 60e043cc993779d18892e56f8856ae1f89c1c902..f1e09fdb44dd2567840305a94d3c8d35bdabc7a0 100644 (file)
@@ -12,14 +12,14 @@ public sealed partial class GravitySystem : SharedGravitySystem
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<SharedGravityGeneratorComponent, AppearanceChangeEvent>(OnAppearanceChange);
+        SubscribeLocalEvent<GravityGeneratorComponent, AppearanceChangeEvent>(OnAppearanceChange);
         InitializeShake();
     }
 
     /// <summary>
     /// Ensures that the visible state of gravity generators are synced with their sprites.
     /// </summary>
-    private void OnAppearanceChange(EntityUid uid, SharedGravityGeneratorComponent comp, ref AppearanceChangeEvent args)
+    private void OnAppearanceChange(EntityUid uid, GravityGeneratorComponent comp, ref AppearanceChangeEvent args)
     {
         if (args.Sprite == null)
             return;
index 8257035de66c00480835ab4c34d6934a66f4a42e..047ec0259a52762d28584f5bed316cccc37a1cf6 100644 (file)
@@ -1,4 +1,3 @@
-using Content.Server.Gravity;
 using Content.Server.Power.Components;
 using Content.Shared.Gravity;
 using Robust.Shared.GameObjects;
diff --git a/Content.Server/Gravity/GravityGeneratorComponent.cs b/Content.Server/Gravity/GravityGeneratorComponent.cs
deleted file mode 100644 (file)
index c715a5e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-using Content.Shared.Gravity;
-using Content.Shared.Construction.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-
-namespace Content.Server.Gravity
-{
-    [RegisterComponent]
-    [Access(typeof(GravityGeneratorSystem))]
-    public sealed partial class GravityGeneratorComponent : SharedGravityGeneratorComponent
-    {
-        [DataField("lightRadiusMin")] public float LightRadiusMin { get; set; }
-        [DataField("lightRadiusMax")] public float LightRadiusMax { get; set; }
-
-        /// <summary>
-        /// Is the gravity generator currently "producing" gravity?
-        /// </summary>
-        [ViewVariables]
-        public bool GravityActive { get; set; } = false;
-    }
-}
index 9d58b82d690c7bb83c98e158756aa92079a10ac0..8e714cf88428d10d57ed7e26578c23ddc68d1e3b 100644 (file)
@@ -4,7 +4,7 @@ using Content.Shared.Gravity;
 
 namespace Content.Server.Gravity;
 
-public sealed class GravityGeneratorSystem : EntitySystem
+public sealed class GravityGeneratorSystem : SharedGravityGeneratorSystem
 {
     [Dependency] private readonly GravitySystem _gravitySystem = default!;
     [Dependency] private readonly SharedPointLightSystem _lights = default!;
@@ -36,6 +36,7 @@ public sealed class GravityGeneratorSystem : EntitySystem
     private void OnActivated(Entity<GravityGeneratorComponent> ent, ref ChargedMachineActivatedEvent args)
     {
         ent.Comp.GravityActive = true;
+        Dirty(ent, ent.Comp);
 
         var xform = Transform(ent);
 
@@ -48,6 +49,7 @@ public sealed class GravityGeneratorSystem : EntitySystem
     private void OnDeactivated(Entity<GravityGeneratorComponent> ent, ref ChargedMachineDeactivatedEvent args)
     {
         ent.Comp.GravityActive = false;
+        Dirty(ent, ent.Comp);
 
         var xform = Transform(ent);
 
similarity index 59%
rename from Content.Shared/Gravity/SharedGravityGeneratorComponent.cs
rename to Content.Shared/Gravity/GravityGeneratorComponent.cs
index 75b636b2fa89ac0c3e4a282a7aaee6ff11ce30c2..f7b1240f1a6801f33486480919de96942414a0b9 100644 (file)
@@ -3,42 +3,45 @@ using Robust.Shared.GameStates;
 
 namespace Content.Shared.Gravity;
 
-[NetworkedComponent()]
-[Virtual]
-public partial class SharedGravityGeneratorComponent : Component
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class GravityGeneratorComponent : Component
 {
+    [DataField] public float LightRadiusMin { get; set; }
+    [DataField] public float LightRadiusMax { get; set; }
+
     /// <summary>
     /// A map of the sprites used by the gravity generator given its status.
     /// </summary>
-    [DataField("spriteMap")]
-    [Access(typeof(SharedGravitySystem))]
-    public Dictionary<PowerChargeStatus, string> SpriteMap = new();
+    [DataField, Access(typeof(SharedGravitySystem))]
+    public Dictionary<PowerChargeStatus, string> SpriteMap = [];
 
     /// <summary>
     /// The sprite used by the core of the gravity generator when the gravity generator is starting up.
     /// </summary>
-    [DataField("coreStartupState")]
-    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField]
     public string CoreStartupState = "startup";
 
     /// <summary>
     /// The sprite used by the core of the gravity generator when the gravity generator is idle.
     /// </summary>
-    [DataField("coreIdleState")]
-    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField]
     public string CoreIdleState = "idle";
 
     /// <summary>
     /// The sprite used by the core of the gravity generator when the gravity generator is activating.
     /// </summary>
-    [DataField("coreActivatingState")]
-    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField]
     public string CoreActivatingState = "activating";
 
     /// <summary>
     /// The sprite used by the core of the gravity generator when the gravity generator is active.
     /// </summary>
-    [DataField("coreActivatedState")]
-    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField]
     public string CoreActivatedState = "activated";
+
+    /// <summary>
+    /// Is the gravity generator currently "producing" gravity?
+    /// </summary>
+    [DataField, AutoNetworkedField, Access(typeof(SharedGravityGeneratorSystem))]
+    public bool GravityActive = false;
 }
diff --git a/Content.Shared/Gravity/SharedGravityGeneratorSystem.cs b/Content.Shared/Gravity/SharedGravityGeneratorSystem.cs
new file mode 100644 (file)
index 0000000..b2b2e72
--- /dev/null
@@ -0,0 +1,29 @@
+using Content.Shared.Popups;
+using Content.Shared.Construction.Components;
+
+namespace Content.Shared.Gravity;
+
+public abstract class SharedGravityGeneratorSystem : EntitySystem
+{
+    [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<GravityGeneratorComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
+    }
+
+    /// <summary>
+    /// Prevent unanchoring when gravity is active
+    /// </summary>
+    private void OnUnanchorAttempt(Entity<GravityGeneratorComponent> ent, ref UnanchorAttemptEvent args)
+    {
+        if (!ent.Comp.GravityActive)
+            return;
+
+        _popupSystem.PopupClient(Loc.GetString("gravity-generator-unanchoring-failed"), ent.Owner, args.User, PopupType.Medium);
+
+        args.Cancel();
+    }
+}
index fd9d5ea4aec464dd7726a3d10c453a803ede1728..18221e945a0c72d04b1c24c9b4a92767639dadfa 100644 (file)
@@ -1,2 +1,2 @@
-station-anchor-unanchoring-failed = Can't unanchor an active station anchor
+station-anchor-unanchoring-failed = Can't unanchor an active station anchor.
 station-anchor-window-title = Station Anchor
index b4e6cddcd5c2c907d718dd1a713bcff067878ac3..fa3783fc34853f735d340d1630f0a8c6fc7d7644 100644 (file)
@@ -1,11 +1,9 @@
 ### Gravity Generator
 
 ## UI
-
 gravity-generator-window-title = Gravity Generator
 
 ## UI field names
-
 gravity-generator-window-status = Status:
 gravity-generator-window-power = Power:
 gravity-generator-window-eta = ETA:
@@ -23,6 +21,8 @@ gravity-generator-window-power-off = Off
 gravity-generator-window-power-label = { $draw } / { $max } W
 
 ## UI ETA label
-
 gravity-generator-window-eta-none = N/A
 gravity-generator-window-eta-value = { TOSTRING($left, "m\\:ss") }
+
+## Popup
+gravity-generator-unanchoring-failed = Can't unanchor an active gravity generator.