]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict some power PowerReceiver stuff (#33834)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 10 Mar 2025 02:00:49 +0000 (13:00 +1100)
committerGitHub <noreply@github.com>
Mon, 10 Mar 2025 02:00:49 +0000 (13:00 +1100)
* Predict some power PowerReceiver stuff

Need it for some atmos device prediction.

* Also this

Content.Client/Power/EntitySystems/PowerReceiverSystem.cs
Content.Server/Power/Components/ApcPowerReceiverComponent.cs
Content.Server/Power/EntitySystems/PowerReceiverSystem.cs
Content.Server/Power/Generation/Teg/TegSystem.cs
Content.Server/Power/PowerWireAction.cs
Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs
Content.Shared/Power/Components/ApcPowerReceiverComponentState.cs
Content.Shared/Power/Components/SharedApcPowerReceiverComponent.cs
Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs

index ebf6c18c953ad2704085bd3ef4d8c1ce82fe3572..319ab5c56dc2b254c1ad2e26de8c9657f303a6e8 100644 (file)
@@ -27,6 +27,8 @@ public sealed class PowerReceiverSystem : SharedPowerReceiverSystem
             return;
 
         component.Powered = state.Powered;
+        component.NeedsPower = state.NeedsPower;
+        component.PowerDisabled = state.PowerDisabled;
     }
 
     public override bool ResolveApc(EntityUid entity, [NotNullWhen(true)] ref SharedApcPowerReceiverComponent? component)
index ebb3c6b42f306d18649d5e62322eff6d8eb96c85..aa8feff3e033e47febd9a983141cad32118789b4 100644 (file)
@@ -24,7 +24,7 @@ namespace Content.Server.Power.Components
         ///     When false, causes this to appear powered even if not receiving power from an Apc.
         /// </summary>
         [ViewVariables(VVAccess.ReadWrite)]
-        public bool NeedsPower
+        public override bool NeedsPower
         {
             get => _needsPower;
             set
@@ -41,9 +41,9 @@ namespace Content.Server.Power.Components
         /// <summary>
         ///     When true, causes this to never appear powered.
         /// </summary>
-        [ViewVariables(VVAccess.ReadWrite)]
         [DataField("powerDisabled")]
-        public bool PowerDisabled {
+        public override bool PowerDisabled
+        {
             get => !NetworkLoad.Enabled;
             set => NetworkLoad.Enabled = !value;
         }
index 38d7376e5470e850688778fe10b9cf2204c6ad90..023927345506a9f8424fa91cf66f7abd2ec5c4d3 100644 (file)
@@ -1,18 +1,12 @@
 using System.Diagnostics.CodeAnalysis;
-using Content.Server.Administration.Logs;
 using Content.Server.Administration.Managers;
 using Content.Server.Power.Components;
 using Content.Shared.Administration;
-using Content.Shared.Database;
 using Content.Shared.Examine;
 using Content.Shared.Hands.Components;
-using Content.Shared.Power;
 using Content.Shared.Power.Components;
 using Content.Shared.Power.EntitySystems;
 using Content.Shared.Verbs;
-using Robust.Server.Audio;
-using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
 using Robust.Shared.Utility;
 
@@ -20,9 +14,8 @@ namespace Content.Server.Power.EntitySystems
 {
     public sealed class PowerReceiverSystem : SharedPowerReceiverSystem
     {
-        [Dependency] private readonly IAdminLogManager _adminLogger = default!;
         [Dependency] private readonly IAdminManager _adminManager = default!;
-        [Dependency] private readonly AudioSystem _audio = default!;
+
         private EntityQuery<ApcPowerReceiverComponent> _recQuery;
         private EntityQuery<ApcPowerProviderComponent> _provQuery;
 
@@ -63,7 +56,10 @@ namespace Content.Server.Power.EntitySystems
                 Text = Loc.GetString("verb-debug-toggle-need-power"),
                 Category = VerbCategory.Debug,
                 Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/smite.svg.192dpi.png")), // "smite" is a lightning bolt
-                Act = () => component.NeedsPower = !component.NeedsPower
+                Act = () =>
+                {
+                    SetNeedsPower(uid, !component.NeedsPower, component);
+                }
             });
         }
 
@@ -143,7 +139,9 @@ namespace Content.Server.Power.EntitySystems
         {
             args.State = new ApcPowerReceiverComponentState
             {
-                Powered = component.Powered
+                Powered = component.Powered,
+                NeedsPower = component.NeedsPower,
+                PowerDisabled = component.PowerDisabled,
             };
         }
 
@@ -164,36 +162,6 @@ namespace Content.Server.Power.EntitySystems
             return !_recQuery.Resolve(uid, ref receiver, false) || receiver.Powered;
         }
 
-        /// <summary>
-        /// Turn this machine on or off.
-        /// Returns true if we turned it on, false if we turned it off.
-        /// </summary>
-        public bool TogglePower(EntityUid uid, bool playSwitchSound = true, ApcPowerReceiverComponent? receiver = null, EntityUid? user = null)
-        {
-            if (!_recQuery.Resolve(uid, ref receiver, false))
-                return true;
-
-            // it'll save a lot of confusion if 'always powered' means 'always powered'
-            if (!receiver.NeedsPower)
-            {
-                receiver.PowerDisabled = false;
-                return true;
-            }
-
-            receiver.PowerDisabled = !receiver.PowerDisabled;
-
-            if (user != null)
-                _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(user.Value):player} hit power button on {ToPrettyString(uid)}, it's now {(!receiver.PowerDisabled ? "on" : "off")}");
-
-            if (playSwitchSound)
-            {
-                _audio.PlayPvs(new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"), uid,
-                    AudioParams.Default.WithVolume(-2f));
-            }
-
-            return !receiver.PowerDisabled; // i.e. PowerEnabled
-        }
-
         public void SetLoad(ApcPowerReceiverComponent comp, float load)
         {
             comp.Load = load;
index 027f25704023705c67fa724808d7dd28f5553b61..5c2ac27352e7aa7216bac86df87aaf89ec3b1317 100644 (file)
@@ -11,6 +11,7 @@ using Content.Shared.Atmos;
 using Content.Shared.DeviceNetwork;
 using Content.Shared.Examine;
 using Content.Shared.Power;
+using Content.Shared.Power.EntitySystems;
 using Content.Shared.Power.Generation.Teg;
 using Content.Shared.Rounding;
 using Robust.Server.GameObjects;
@@ -66,11 +67,12 @@ public sealed class TegSystem : EntitySystem
     /// </summary>
     public const string DeviceNetworkCommandSyncData = "teg_sync_data";
 
+    [Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
+    [Dependency] private readonly AppearanceSystem _appearance = default!;
     [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
     [Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
-    [Dependency] private readonly AppearanceSystem _appearance = default!;
     [Dependency] private readonly PointLightSystem _pointLight = default!;
-    [Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
+    [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
 
     private EntityQuery<NodeContainerComponent> _nodeContainerQuery;
 
@@ -241,8 +243,7 @@ public sealed class TegSystem : EntitySystem
 
         var powerReceiver = Comp<ApcPowerReceiverComponent>(uid);
 
-        powerReceiver.PowerDisabled = !group.IsFullyBuilt;
-
+        _receiver.SetPowerDisabled(uid, !group.IsFullyBuilt, powerReceiver);
         UpdateAppearance(uid, component, powerReceiver, group);
     }
 
index 9e4e6a6086d190d37e5897a47770789832654273..82736155469a1a928d05b68b368df270c4702642 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Server.Electrocution;
 using Content.Shared.Electrocution;
 using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
 using Content.Server.Wires;
 using Content.Shared.Power;
 using Content.Shared.Wires;
@@ -61,15 +62,17 @@ public sealed partial class PowerWireAction : BaseWireAction
             return;
         }
 
+        var receiverSys = EntityManager.System<PowerReceiverSystem>();
+
         if (pulsed)
         {
-            power.PowerDisabled = true;
+            receiverSys.SetPowerDisabled(owner, true, power);
             return;
         }
 
         if (AllWiresCut(owner))
         {
-            power.PowerDisabled = true;
+            receiverSys.SetPowerDisabled(owner, true, power);
         }
         else
         {
@@ -79,7 +82,7 @@ public sealed partial class PowerWireAction : BaseWireAction
                 return;
             }
 
-            power.PowerDisabled = false;
+            receiverSys.SetPowerDisabled(owner, false, power);
         }
     }
 
index 67c67de57f3bdc488cd5ab188ba80f526968f2df..a5670ec8ee3ffcdd4d4acc0f22fbfd284d747514 100644 (file)
@@ -12,6 +12,7 @@ using Content.Shared.Paper;
 using Content.Shared.Placeable;
 using Content.Shared.Popups;
 using Content.Shared.Power;
+using Content.Shared.Power.EntitySystems;
 using Content.Shared.Research.Components;
 using Content.Shared.Xenoarchaeology.Equipment;
 using Content.Shared.Xenoarchaeology.XenoArtifacts;
@@ -33,15 +34,16 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
 {
     [Dependency] private readonly IGameTiming _timing = default!;
     [Dependency] private readonly IPrototypeManager _prototype = default!;
-    [Dependency] private readonly SharedAudioSystem _audio = default!;
-    [Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
-    [Dependency] private readonly SharedPopupSystem _popup = default!;
-    [Dependency] private readonly UserInterfaceSystem _ui = default!;
     [Dependency] private readonly ArtifactSystem _artifact = default!;
+    [Dependency] private readonly MetaDataSystem _metaSystem = default!;
     [Dependency] private readonly PaperSystem _paper = default!;
     [Dependency] private readonly ResearchSystem _research = default!;
-    [Dependency] private readonly MetaDataSystem _metaSystem = default!;
+    [Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
     [Dependency] private readonly TraversalDistorterSystem _traversalDistorter = default!;
+    [Dependency] private readonly UserInterfaceSystem _ui = default!;
 
     /// <inheritdoc/>
     public override void Initialize()
@@ -492,17 +494,13 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
 
     private void OnAnalyzeStart(EntityUid uid, ActiveArtifactAnalyzerComponent component, ComponentStartup args)
     {
-        if (TryComp<ApcPowerReceiverComponent>(uid, out var powa))
-            powa.NeedsPower = true;
-
+        _receiver.SetNeedsPower(uid, true);
         _ambientSound.SetAmbience(uid, true);
     }
 
     private void OnAnalyzeEnd(EntityUid uid, ActiveArtifactAnalyzerComponent component, ComponentShutdown args)
     {
-        if (TryComp<ApcPowerReceiverComponent>(uid, out var powa))
-            powa.NeedsPower = false;
-
+        _receiver.SetNeedsPower(uid, false);
         _ambientSound.SetAmbience(uid, false);
     }
 
index 9b18d6ad938facbb0b02455b5eade2c6fe4fbfe9..31456c86f2272a2890437af862aac19caf0710d1 100644 (file)
@@ -6,4 +6,6 @@ namespace Content.Shared.Power.Components;
 public sealed class ApcPowerReceiverComponentState : ComponentState
 {
     public bool Powered;
+    public bool NeedsPower;
+    public bool PowerDisabled;
 }
index d73993357a3c6664abaaabd80771f44e44fd2444..69c3bd790e57db2551df115d0faa7e4dd0229a80 100644 (file)
@@ -7,4 +7,10 @@ public abstract partial class SharedApcPowerReceiverComponent : Component
 {
     [ViewVariables]
     public bool Powered;
+
+    [ViewVariables]
+    public virtual bool NeedsPower { get; set; }
+
+    [ViewVariables]
+    public virtual bool PowerDisabled { get; set; }
 }
index b7ba2a31c5d94efd6c1d2718cea87c4d10d86642..2d152d8b45e235775636e6bff90691776a6c5e33 100644 (file)
@@ -1,12 +1,67 @@
 using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Administration.Logs;
+using Content.Shared.Database;
 using Content.Shared.Power.Components;
+using Robust.Shared.Audio;
+using Robust.Shared.Audio.Systems;
 
 namespace Content.Shared.Power.EntitySystems;
 
 public abstract class SharedPowerReceiverSystem : EntitySystem
 {
+    [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+
     public abstract bool ResolveApc(EntityUid entity, [NotNullWhen(true)] ref SharedApcPowerReceiverComponent? component);
 
+    public void SetNeedsPower(EntityUid uid, bool value, SharedApcPowerReceiverComponent? receiver = null)
+    {
+        if (!ResolveApc(uid, ref receiver) || receiver.NeedsPower == value)
+            return;
+
+        receiver.NeedsPower = value;
+        Dirty(uid, receiver);
+    }
+
+    public void SetPowerDisabled(EntityUid uid, bool value, SharedApcPowerReceiverComponent? receiver = null)
+    {
+        if (!ResolveApc(uid, ref receiver) || receiver.PowerDisabled == value)
+            return;
+
+        receiver.PowerDisabled = value;
+        Dirty(uid, receiver);
+    }
+
+    /// <summary>
+    /// Turn this machine on or off.
+    /// Returns true if we turned it on, false if we turned it off.
+    /// </summary>
+    public bool TogglePower(EntityUid uid, bool playSwitchSound = true, SharedApcPowerReceiverComponent? receiver = null, EntityUid? user = null)
+    {
+        if (!ResolveApc(uid, ref receiver))
+            return true;
+
+        // it'll save a lot of confusion if 'always powered' means 'always powered'
+        if (!receiver.NeedsPower)
+        {
+            SetPowerDisabled(uid, false, receiver);
+            return true;
+        }
+
+        SetPowerDisabled(uid, !receiver.PowerDisabled, receiver);
+
+        if (user != null)
+            _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(user.Value):player} hit power button on {ToPrettyString(uid)}, it's now {(!receiver.PowerDisabled ? "on" : "off")}");
+
+        if (playSwitchSound)
+        {
+            _audio.PlayPredicted(new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"), uid, user: user,
+                AudioParams.Default.WithVolume(-2f));
+        }
+
+        return !receiver.PowerDisabled; // i.e. PowerEnabled
+    }
+
     /// <summary>
     /// Checks if entity is APC-powered device, and if it have power.
     /// </summary>