]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict EmitterSystem ExamineEvent and GetVerbsEvent (#39318)
authorKyle Tyo <36606155+VerinSenpai@users.noreply.github.com>
Fri, 1 Aug 2025 17:40:15 +0000 (13:40 -0400)
committerGitHub <noreply@github.com>
Fri, 1 Aug 2025 17:40:15 +0000 (19:40 +0200)
* ididathing.exe

* commit

* cleanup

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Client/Singularity/Systems/EmitterSystem.cs
Content.Server/Singularity/EntitySystems/EmitterSystem.cs
Content.Shared/Singularity/Components/SharedEmitterComponent.cs
Content.Shared/Singularity/EntitySystems/SharedEmitterSystem.cs

index e9e0846340499c0dc4675e175b1be8005e4c86d0..b35c3297a17d601f900db4e2e6ed552a9f776229 100644 (file)
@@ -12,6 +12,8 @@ public sealed class EmitterSystem : SharedEmitterSystem
     /// <inheritdoc/>
     public override void Initialize()
     {
+        base.Initialize();
+
         SubscribeLocalEvent<EmitterComponent, AppearanceChangeEvent>(OnAppearanceChange);
     }
 
index 662df43e1229eface8ecc3ce521ce81f4ffa2930..28d3eedd3287ce203b922fda4557134ba7ae3485 100644 (file)
@@ -7,7 +7,6 @@ using Content.Server.Projectiles;
 using Content.Server.Weapons.Ranged.Systems;
 using Content.Shared.Database;
 using Content.Shared.DeviceLinking.Events;
-using Content.Shared.Examine;
 using Content.Shared.Interaction;
 using Content.Shared.Lock;
 using Content.Shared.Popups;
@@ -15,9 +14,7 @@ using Content.Shared.Power;
 using Content.Shared.Projectiles;
 using Content.Shared.Singularity.Components;
 using Content.Shared.Singularity.EntitySystems;
-using Content.Shared.Verbs;
 using Content.Shared.Weapons.Ranged.Components;
-using JetBrains.Annotations;
 using Robust.Shared.Map;
 using Robust.Shared.Physics;
 using Robust.Shared.Physics.Components;
@@ -28,7 +25,6 @@ using Timer = Robust.Shared.Timing.Timer;
 
 namespace Content.Server.Singularity.EntitySystems
 {
-    [UsedImplicitly]
     public sealed class EmitterSystem : SharedEmitterSystem
     {
         [Dependency] private readonly IRobustRandom _random = default!;
@@ -46,8 +42,6 @@ namespace Content.Server.Singularity.EntitySystems
             SubscribeLocalEvent<EmitterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
             SubscribeLocalEvent<EmitterComponent, PowerChangedEvent>(OnApcChanged);
             SubscribeLocalEvent<EmitterComponent, ActivateInWorldEvent>(OnActivate);
-            SubscribeLocalEvent<EmitterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
-            SubscribeLocalEvent<EmitterComponent, ExaminedEvent>(OnExamined);
             SubscribeLocalEvent<EmitterComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
             SubscribeLocalEvent<EmitterComponent, SignalReceivedEvent>(OnSignalReceived);
         }
@@ -99,47 +93,6 @@ namespace Content.Server.Singularity.EntitySystems
             }
         }
 
-        private void OnGetVerb(EntityUid uid, EmitterComponent component, GetVerbsEvent<Verb> args)
-        {
-            if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract || args.Hands == null)
-                return;
-
-            if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked)
-                return;
-
-            if (component.SelectableTypes.Count < 2)
-                return;
-
-            foreach (var type in component.SelectableTypes)
-            {
-                var proto = _prototype.Index<EntityPrototype>(type);
-
-                var v = new Verb
-                {
-                    Priority = 1,
-                    Category = VerbCategory.SelectType,
-                    Text = proto.Name,
-                    Disabled = type == component.BoltType,
-                    Impact = LogImpact.Medium,
-                    DoContactInteraction = true,
-                    Act = () =>
-                    {
-                        component.BoltType = type;
-                        _popup.PopupEntity(Loc.GetString("emitter-component-type-set", ("type", proto.Name)), uid);
-                    }
-                };
-                args.Verbs.Add(v);
-            }
-        }
-
-        private void OnExamined(EntityUid uid, EmitterComponent component, ExaminedEvent args)
-        {
-            if (component.SelectableTypes.Count < 2)
-                return;
-            var proto = _prototype.Index<EntityPrototype>(component.BoltType);
-            args.PushMarkup(Loc.GetString("emitter-component-current-type", ("type", proto.Name)));
-        }
-
         private void ReceivedChanged(
             EntityUid uid,
             EmitterComponent component,
index dce2f92d0c7d892810182d87be583831ce4ba187..d181757968912bb17a4b44a9a99a96cbffe586ac 100644 (file)
@@ -3,12 +3,10 @@ using Content.Shared.DeviceLinking;
 using Robust.Shared.GameStates;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
 
 namespace Content.Shared.Singularity.Components;
 
-[RegisterComponent, NetworkedComponent]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
 public sealed partial class EmitterComponent : Component
 {
     public CancellationTokenSource? TimerCancel;
@@ -27,8 +25,8 @@ public sealed partial class EmitterComponent : Component
     /// <summary>
     /// The entity that is spawned when the emitter fires.
     /// </summary>
-    [DataField("boltType", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
-    public string BoltType = "EmitterBolt";
+    [DataField, AutoNetworkedField]
+    public EntProtoId BoltType = "EmitterBolt";
 
     [DataField]
     public List<EntProtoId> SelectableTypes = new();
@@ -36,68 +34,68 @@ public sealed partial class EmitterComponent : Component
     /// <summary>
     /// The current amount of power being used.
     /// </summary>
-    [DataField("powerUseActive")]
+    [DataField]
     public int PowerUseActive = 600;
 
     /// <summary>
     /// The amount of shots that are fired in a single "burst"
     /// </summary>
-    [DataField("fireBurstSize")]
+    [DataField]
     public int FireBurstSize = 3;
 
     /// <summary>
     /// The time between each shot during a burst.
     /// </summary>
-    [DataField("fireInterval")]
+    [DataField]
     public TimeSpan FireInterval = TimeSpan.FromSeconds(2);
 
     /// <summary>
     /// The current minimum delay between bursts.
     /// </summary>
-    [DataField("fireBurstDelayMin")]
+    [DataField]
     public TimeSpan FireBurstDelayMin = TimeSpan.FromSeconds(4);
 
     /// <summary>
     /// The current maximum delay between bursts.
     /// </summary>
-    [DataField("fireBurstDelayMax")]
+    [DataField]
     public TimeSpan FireBurstDelayMax = TimeSpan.FromSeconds(10);
 
     /// <summary>
     /// The visual state that is set when the emitter is turned on
     /// </summary>
-    [DataField("onState")]
+    [DataField]
     public string? OnState = "beam";
 
     /// <summary>
     /// The visual state that is set when the emitter doesn't have enough power.
     /// </summary>
-    [DataField("underpoweredState")]
+    [DataField]
     public string? UnderpoweredState = "underpowered";
 
     /// <summary>
     /// Signal port that turns on the emitter.
     /// </summary>
-    [DataField("onPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
-    public string OnPort = "On";
+    [DataField]
+    public ProtoId<SinkPortPrototype> OnPort = "On";
 
     /// <summary>
     /// Signal port that turns off the emitter.
     /// </summary>
-    [DataField("offPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
-    public string OffPort = "Off";
+    [DataField]
+    public ProtoId<SinkPortPrototype> OffPort = "Off";
 
     /// <summary>
     /// Signal port that toggles the emitter on or off.
     /// </summary>
-    [DataField("togglePort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
-    public string TogglePort = "Toggle";
+    [DataField]
+    public ProtoId<SinkPortPrototype> TogglePort = "Toggle";
 
     /// <summary>
     /// Map of signal ports to entity prototype IDs of the entity that will be fired.
     /// </summary>
-    [DataField("setTypePorts", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<string, SinkPortPrototype>))]
-    public Dictionary<string, string> SetTypePorts = new();
+    [DataField]
+    public Dictionary<ProtoId<SinkPortPrototype>, EntProtoId> SetTypePorts = new();
 }
 
 [NetSerializable, Serializable]
index bba662998867b3d957e36a400984ccf6680019d6..9ef7dcfbdb24215b08075d9b40b97b78b042bb1e 100644 (file)
@@ -1,6 +1,66 @@
-namespace Content.Shared.Singularity.EntitySystems;
+using Content.Shared.Database;
+using Content.Shared.Examine;
+using Content.Shared.Lock;
+using Content.Shared.Popups;
+using Content.Shared.Singularity.Components;
+using Content.Shared.Verbs;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Singularity.EntitySystems;
 
 public abstract class SharedEmitterSystem : EntitySystem
 {
+    [Dependency] private readonly IPrototypeManager _prototype = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<EmitterComponent, ExaminedEvent>(OnExamined);
+        SubscribeLocalEvent<EmitterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
+    }
+
+    private void OnGetVerb(Entity<EmitterComponent> ent, ref GetVerbsEvent<Verb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract || args.Hands == null)
+            return;
+
+        if (TryComp<LockComponent>(ent.Owner, out var lockComp) && lockComp.Locked)
+            return;
+
+        if (ent.Comp.SelectableTypes.Count < 2)
+            return;
+
+        foreach (var type in ent.Comp.SelectableTypes)
+        {
+            var proto = _prototype.Index(type);
+
+            var v = new Verb
+            {
+                Priority = 1,
+                Category = VerbCategory.SelectType,
+                Text = proto.Name,
+                Disabled = type == ent.Comp.BoltType,
+                Impact = LogImpact.Medium,
+                DoContactInteraction = true,
+                Act = () =>
+                {
+                    ent.Comp.BoltType = type;
+                    Dirty(ent);
+                    _popup.PopupClient(Loc.GetString("emitter-component-type-set", ("type", proto.Name)), ent.Owner);
+                },
+            };
+            args.Verbs.Add(v);
+        }
+    }
+
+    private void OnExamined(Entity<EmitterComponent> ent, ref ExaminedEvent args)
+    {
+        if (ent.Comp.SelectableTypes.Count < 2)
+            return;
 
+        var proto = _prototype.Index(ent.Comp.BoltType);
+        args.PushMarkup(Loc.GetString("emitter-component-current-type", ("type", proto.Name)));
+    }
 }