Gravity Generators cannot be unanchored while active (#41256)

* 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
This commit is contained in:
Justin Pfeifler
2025-11-06 18:53:27 -06:00
committed by GitHub
parent 2eab3ce2bb
commit 4f0b1f377e
10 changed files with 63 additions and 43 deletions

View 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

View File

@@ -0,0 +1,8 @@
using Content.Shared.Gravity;
namespace Content.Client.Gravity;
public sealed class GravityGeneratorSystem : SharedGravityGeneratorSystem
{
}

View 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;

View File

@@ -1,4 +1,3 @@
using Content.Server.Gravity;
using Content.Server.Power.Components;
using Content.Shared.Gravity;
using Robust.Shared.GameObjects;

View File

@@ -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;
}
}

View 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);

View 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;
}

View File

@@ -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();
}
}

View 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

View 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.