]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
parrotMemory is onGetVerbs now in shared (#39341)
authorToken <56667933+TokenStyle@users.noreply.github.com>
Sun, 3 Aug 2025 00:27:49 +0000 (05:27 +0500)
committerGitHub <noreply@github.com>
Sun, 3 Aug 2025 00:27:49 +0000 (02:27 +0200)
* parrotMemory is onGetVerbs now in shared

* code review

* code review popup on client rename parrotMemoryComponent

* code rev create client system

* forgot usings

* is server now

Content.Client/Animals/Systems/ParrotMemorySystem.cs [new file with mode: 0644]
Content.Server/Animals/Systems/ParrotMemorySystem.cs
Content.Shared/Animals/Components/ParrotMemoryComponent.cs [moved from Content.Server/Animals/Components/ParrotMemoryComponent.cs with 67% similarity]
Content.Shared/Animals/Systems/SharedParrotMemorySystem.cs [new file with mode: 0644]

diff --git a/Content.Client/Animals/Systems/ParrotMemorySystem.cs b/Content.Client/Animals/Systems/ParrotMemorySystem.cs
new file mode 100644 (file)
index 0000000..cdf62a4
--- /dev/null
@@ -0,0 +1,5 @@
+using Content.Shared.Animals.Systems;
+
+namespace Content.Client.Animals.Systems;
+
+public sealed class ParrotMemorySystem : SharedParrotMemorySystem;
index eb3429821c2857e3fc3a5109f8d9a673fa6c2f1c..56843094a1af3706959674220b32d70506e2dec1 100644 (file)
@@ -8,10 +8,10 @@ using Content.Server.Radio;
 using Content.Server.Speech;
 using Content.Server.Speech.Components;
 using Content.Server.Vocalization.Systems;
+using Content.Shared.Animals.Components;
+using Content.Shared.Animals.Systems;
 using Content.Shared.Database;
 using Content.Shared.Mobs.Systems;
-using Content.Shared.Popups;
-using Content.Shared.Verbs;
 using Content.Shared.Whitelist;
 using Robust.Shared.Network;
 using Robust.Shared.Random;
@@ -25,7 +25,7 @@ namespace Content.Server.Animals.Systems;
 /// (radiovocalizer) and stores them in a list. When an entity with a VocalizerComponent attempts to vocalize, this will
 /// try to set the message from memory.
 /// </summary>
-public sealed partial class ParrotMemorySystem : EntitySystem
+public sealed partial class ParrotMemorySystem : SharedParrotMemorySystem
 {
     [Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
     [Dependency] private readonly IAdminLogManager _adminLogger = default!;
@@ -42,8 +42,6 @@ public sealed partial class ParrotMemorySystem : EntitySystem
 
         SubscribeLocalEvent<EraseEvent>(OnErase);
 
-        SubscribeLocalEvent<ParrotMemoryComponent, GetVerbsEvent<Verb>>(OnGetVerbs);
-
         SubscribeLocalEvent<ParrotListenerComponent, MapInitEvent>(ListenerOnMapInit);
 
         SubscribeLocalEvent<ParrotListenerComponent, ListenEvent>(OnListen);
@@ -57,30 +55,6 @@ public sealed partial class ParrotMemorySystem : EntitySystem
         DeletePlayerMessages(args.PlayerNetUserId);
     }
 
-    private void OnGetVerbs(Entity<ParrotMemoryComponent> entity, ref GetVerbsEvent<Verb> args)
-    {
-        var user = args.User;
-
-        // limit this to admins
-        if (!_admin.IsAdmin(user))
-            return;
-
-        // simple verb that just clears the memory list
-        var clearMemoryVerb = new Verb()
-        {
-            Text = Loc.GetString("parrot-verb-clear-memory"),
-            Category = VerbCategory.Admin,
-            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/AdminActions/clear-parrot.png")),
-            Act = () =>
-            {
-                entity.Comp.SpeechMemories.Clear();
-                _popup.PopupEntity(Loc.GetString("parrot-popup-memory-cleared"), entity, user, PopupType.Medium);
-            },
-        };
-
-        args.Verbs.Add(clearMemoryVerb);
-    }
-
     private void ListenerOnMapInit(Entity<ParrotListenerComponent> entity, ref MapInitEvent args)
     {
         // If an entity has a ParrotListenerComponent it really ought to have an ActiveListenerComponent
similarity index 67%
rename from Content.Server/Animals/Components/ParrotMemoryComponent.cs
rename to Content.Shared/Animals/Components/ParrotMemoryComponent.cs
index 69908a0a9ecd7e6626d970bb97be2055622aab46..e1c5ba8ed912242dd45a543d86cc306be2e79bee 100644 (file)
@@ -1,57 +1,61 @@
+using Content.Shared.Animals.Systems;
+using Robust.Shared.GameStates;
 using Robust.Shared.Network;
+using Robust.Shared.Serialization;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
 
-namespace Content.Server.Animals.Components;
+namespace Content.Shared.Animals.Components;
 
 /// <summary>
-/// Makes an entity able to memorize chat/radio messages
+/// Makes an entity able to memorize chat/radio messages.
 /// </summary>
-[RegisterComponent]
+[RegisterComponent, NetworkedComponent]
 [AutoGenerateComponentPause]
 public sealed partial class ParrotMemoryComponent : Component
 {
     /// <summary>
-    /// List of SpeechMemory records this entity has learned
+    /// List of SpeechMemory records this entity has learned.
     /// </summary>
     [DataField]
-    public List<SpeechMemory> SpeechMemories = [];
+    public List<SpeechMemory> SpeechMemories = new();
 
     /// <summary>
-    /// The % chance an entity with this component learns a phrase when learning is off cooldown
+    /// The % chance an entity with this component learns a phrase when learning is off cooldown.
     /// </summary>
     [DataField]
     public float LearnChance = 0.6f;
 
     /// <summary>
-    /// Time after which another attempt can be made at learning a phrase
+    /// Time after which another attempt can be made at learning a phrase.
     /// </summary>
     [DataField]
     public TimeSpan LearnCooldown = TimeSpan.FromMinutes(1);
 
     /// <summary>
-    /// Next time at which the parrot can attempt to learn something
+    /// Next time at which the parrot can attempt to learn something.
     /// </summary>
     [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
     [AutoPausedField]
     public TimeSpan NextLearnInterval = TimeSpan.Zero;
 
     /// <summary>
-    /// The number of speech entries that are remembered
+    /// The number of speech entries that are remembered.
     /// </summary>
     [DataField]
     public int MaxSpeechMemory = 50;
 
     /// <summary>
-    /// Minimum length of a speech entry
+    /// Minimum length of a speech entry.
     /// </summary>
     [DataField]
     public int MinEntryLength = 4;
 
     /// <summary>
-    /// Maximum length of a speech entry
+    /// Maximum length of a speech entry.
     /// </summary>
     [DataField]
     public int MaxEntryLength = 50;
 }
 
+[Serializable, NetSerializable]
 public record struct SpeechMemory(NetUserId? NetUserId, string Message);
diff --git a/Content.Shared/Animals/Systems/SharedParrotMemorySystem.cs b/Content.Shared/Animals/Systems/SharedParrotMemorySystem.cs
new file mode 100644 (file)
index 0000000..fb8e330
--- /dev/null
@@ -0,0 +1,48 @@
+using Content.Shared.Administration.Managers;
+using Content.Shared.Animals.Components;
+using Content.Shared.Popups;
+using Content.Shared.Verbs;
+using Robust.Shared.Network;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Animals.Systems;
+
+public abstract class SharedParrotMemorySystem : EntitySystem
+{
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly ISharedAdminManager _admin = default!;
+    [Dependency] private readonly INetManager _net = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<ParrotMemoryComponent, GetVerbsEvent<Verb>>(OnGetVerbs);
+    }
+
+    private void OnGetVerbs(Entity<ParrotMemoryComponent> entity, ref GetVerbsEvent<Verb> args)
+    {
+        var user = args.User;
+
+        // limit this to admins
+        if (!_admin.IsAdmin(user))
+            return;
+
+        // simple verb that just clears the memory list
+        var clearMemoryVerb = new Verb()
+        {
+            Text = Loc.GetString("parrot-verb-clear-memory"),
+            Category = VerbCategory.Admin,
+            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/AdminActions/clear-parrot.png")),
+            Act = () =>
+            {
+                _popup.PopupClient(Loc.GetString("parrot-popup-memory-cleared"), entity.Owner, user);
+
+                if (_net.IsServer)
+                    entity.Comp.SpeechMemories.Clear();
+            },
+        };
+
+        args.Verbs.Add(clearMemoryVerb);
+    }
+}