]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict GetVerbsEvent in PowerSwitchableSystem (#39589)
authorWinkarst-cpu <74284083+Winkarst-cpu@users.noreply.github.com>
Wed, 13 Aug 2025 07:54:02 +0000 (10:54 +0300)
committerGitHub <noreply@github.com>
Wed, 13 Aug 2025 07:54:02 +0000 (09:54 +0200)
* Prediction

* Update

Content.Server/Power/Generator/GeneratorSystem.cs
Content.Server/Power/Generator/PortableGeneratorSystem.cs
Content.Server/Power/Generator/PowerSwitchableSystem.cs
Content.Shared/Power/Generator/SharedPortableGeneratorSystem.cs
Content.Shared/Power/Generator/SharedPowerSwitchableSystem.cs

index 72b99d59af8f62d70fcc49718d8fcbe6af2f6175..97491ddbf4174dd42f1a6bfb20e376857e016f1c 100644 (file)
@@ -198,6 +198,7 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
 
         generator.On = on;
         UpdateState(uid, generator);
+        Dirty(uid, generator);
     }
 
     public override void Update(float frameTime)
index a2d506f6c25998954342efdbf5a79d533b8e54c4..d8fca4e48af49379138d128d3766dc21f5a371a9 100644 (file)
@@ -42,8 +42,6 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
         SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorStartMessage>(GeneratorStartMessage);
         SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorStopMessage>(GeneratorStopMessage);
         SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorSwitchOutputMessage>(GeneratorSwitchOutputMessage);
-
-        SubscribeLocalEvent<FuelGeneratorComponent, SwitchPowerCheckEvent>(OnSwitchPowerCheck);
     }
 
     private void GeneratorSwitchOutputMessage(EntityUid uid, PortableGeneratorComponent component, PortableGeneratorSwitchOutputMessage args)
@@ -195,12 +193,6 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
         }
     }
 
-    private void OnSwitchPowerCheck(EntityUid uid, FuelGeneratorComponent comp, ref SwitchPowerCheckEvent args)
-    {
-        if (comp.On)
-            args.DisableMessage = Loc.GetString("fuel-generator-verb-disable-on");
-    }
-
     public override void Update(float frameTime)
     {
         var query = EntityQueryEnumerator<PortableGeneratorComponent, FuelGeneratorComponent, PowerSupplierComponent>();
index 25de3bd293487fc0f78ad46a629f208717a0132f..1a89f20627ce094cf1dcf928f41ea104ab02921c 100644 (file)
@@ -1,5 +1,4 @@
-using Content.Server.NodeContainer;
-using Content.Server.NodeContainer.EntitySystems;
+using Content.Server.NodeContainer.EntitySystems;
 using Content.Server.Popups;
 using Content.Server.Power.Components;
 using Content.Server.Power.Nodes;
@@ -7,9 +6,7 @@ using Content.Shared.NodeContainer;
 using Content.Shared.Power;
 using Content.Shared.Power.Generator;
 using Content.Shared.Timing;
-using Content.Shared.Verbs;
 using Robust.Shared.Audio.Systems;
-using Robust.Shared.Utility;
 
 namespace Content.Server.Power.Generator;
 
@@ -26,47 +23,9 @@ public sealed class PowerSwitchableSystem : SharedPowerSwitchableSystem
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly UseDelaySystem _useDelay = default!;
 
-    public override void Initialize()
-    {
-        base.Initialize();
-
-        SubscribeLocalEvent<PowerSwitchableComponent, GetVerbsEvent<InteractionVerb>>(GetVerbs);
-    }
-
-    private void GetVerbs(EntityUid uid, PowerSwitchableComponent comp, GetVerbsEvent<InteractionVerb> args)
-    {
-        if (!args.CanAccess || !args.CanInteract)
-            return;
-
-        var voltage = VoltageColor(GetNextVoltage(uid, comp));
-        var msg = Loc.GetString("power-switchable-switch-voltage", ("voltage", voltage));
-
-        InteractionVerb verb = new()
-        {
-            Act = () =>
-            {
-                // don't need to check it again since if its disabled server wont let the verb act
-                Cycle(uid, args.User, comp);
-            },
-            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/zap.svg.192dpi.png")),
-            Text = msg
-        };
-
-        var ev = new SwitchPowerCheckEvent();
-        RaiseLocalEvent(uid, ref ev);
-        if (ev.DisableMessage != null)
-        {
-            verb.Message = ev.DisableMessage;
-            verb.Disabled = true;
-        }
-
-        args.Verbs.Add(verb);
-    }
-
-    /// <summary>
-    /// Cycles voltage then updates nodes and optionally power supplier to match it.
-    /// </summary>
-    public void Cycle(EntityUid uid, EntityUid user, PowerSwitchableComponent? comp = null)
+    // TODO: Prediction
+    /// <inheritdoc/>
+    public override void Cycle(EntityUid uid, EntityUid user, PowerSwitchableComponent? comp = null)
     {
         if (!Resolve(uid, ref comp))
             return;
@@ -115,10 +74,3 @@ public sealed class PowerSwitchableSystem : SharedPowerSwitchableSystem
         _useDelay.TryResetDelay((uid, useDelay));
     }
 }
-
-/// <summary>
-/// Raised on a <see cref="PowerSwitchableComponent"/> to see if its verb should work.
-/// If <see cref="DisableMessage"/> is non-null, the verb is disabled with that as the message.
-/// </summary>
-[ByRefEvent]
-public record struct SwitchPowerCheckEvent(string? DisableMessage = null);
index e8ccc8516690c395958b4b084168fc549cb39a83..4ed911c296542eff4b2f61a577e70f87e1332be2 100644 (file)
@@ -9,6 +9,18 @@ namespace Content.Shared.Power.Generator;
 /// <seealso cref="PortableGeneratorComponent"/>
 public abstract class SharedPortableGeneratorSystem : EntitySystem
 {
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<FuelGeneratorComponent, SwitchPowerCheckEvent>(OnSwitchPowerCheck);
+    }
+
+    private void OnSwitchPowerCheck(EntityUid uid, FuelGeneratorComponent comp, ref SwitchPowerCheckEvent args)
+    {
+        if (comp.On)
+            args.DisableMessage = Loc.GetString("fuel-generator-verb-disable-on");
+    }
 }
 
 /// <summary>
index c1787b60784314cf9976ee7a0017ef88f8b41163..00d2b1d7a086aa37c50828e3e1fdb7b010e23d25 100644 (file)
@@ -1,4 +1,6 @@
 using Content.Shared.Examine;
+using Content.Shared.Verbs;
+using Robust.Shared.Utility;
 
 namespace Content.Shared.Power.Generator;
 
@@ -11,6 +13,7 @@ public abstract class SharedPowerSwitchableSystem : EntitySystem
     public override void Initialize()
     {
         SubscribeLocalEvent<PowerSwitchableComponent, ExaminedEvent>(OnExamined);
+        SubscribeLocalEvent<PowerSwitchableComponent, GetVerbsEvent<InteractionVerb>>(GetVerbs);
     }
 
     private void OnExamined(EntityUid uid, PowerSwitchableComponent comp, ExaminedEvent args)
@@ -20,6 +23,41 @@ public abstract class SharedPowerSwitchableSystem : EntitySystem
         args.PushMarkup(Loc.GetString(comp.ExamineText, ("voltage", voltage)));
     }
 
+    private void GetVerbs(EntityUid uid, PowerSwitchableComponent comp, GetVerbsEvent<InteractionVerb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract)
+            return;
+
+        var voltage = VoltageColor(GetNextVoltage(uid, comp));
+        var msg = Loc.GetString("power-switchable-switch-voltage", ("voltage", voltage));
+
+        InteractionVerb verb = new()
+        {
+            Act = () =>
+            {
+                // don't need to check it again since if its disabled server wont let the verb act
+                Cycle(uid, args.User, comp);
+            },
+            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/zap.svg.192dpi.png")),
+            Text = msg
+        };
+
+        var ev = new SwitchPowerCheckEvent();
+        RaiseLocalEvent(uid, ref ev);
+        if (ev.DisableMessage != null)
+        {
+            verb.Message = ev.DisableMessage;
+            verb.Disabled = true;
+        }
+
+        args.Verbs.Add(verb);
+    }
+
+    /// <summary>
+    /// Cycles voltage then updates nodes and optionally power supplier to match it.
+    /// </summary>
+    public virtual void Cycle(EntityUid uid, EntityUid user, PowerSwitchableComponent? comp = null) { }
+
     /// <summary>
     /// Helper to get the colored markup string for a voltage type.
     /// </summary>
@@ -70,3 +108,10 @@ public abstract class SharedPowerSwitchableSystem : EntitySystem
         return comp.Cables[NextIndex(uid, comp)].Voltage;
     }
 }
+
+/// <summary>
+/// Raised on a <see cref="PowerSwitchableComponent"/> to see if its verb should work.
+/// If <see cref="DisableMessage"/> is non-null, the verb is disabled with that as the message.
+/// </summary>
+[ByRefEvent]
+public record struct SwitchPowerCheckEvent(string? DisableMessage = null);