]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add Silicon Law cues to Every method a Silicon can have their laws change (#32887)
authorZachary Higgs <compgeek223@gmail.com>
Mon, 4 Nov 2024 11:23:12 +0000 (07:23 -0400)
committerGitHub <noreply@github.com>
Mon, 4 Nov 2024 11:23:12 +0000 (12:23 +0100)
* Silicon Law Sound cue refactor

- Added CueEntityMind to Silicon Law system to more uniformally
send sounds to minds

- Switch all previous MindPlaySound to instead call to the new method

* Change SiliconLawEui to cue the mind

* CR: TryGetComponent and Change the Documentation

- Remove GetComponentOrNull for  _entityManager.TryGetComponent

- Change SiliconLawProviderComponent.LawUploadSound to be more general
rather than just referencing lawboards

* Update Content.Server/Silicons/Laws/SiliconLawEui.cs

* Update Content.Shared/Silicons/Laws/Components/SiliconLawProviderComponent.cs

* Silicon-law-cue-refactor - CR:

- Roll the cuing into NotifyLawsChanged via an optional variable for the
cue

- Modify "SetLaws" to take in an optional soundProvider for the cue

- modify Emagged, Ion, Eui and SetLaws to instead send the sound cue via
NotifyLawsChanged

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/Silicons/Laws/SiliconLawEui.cs
Content.Server/Silicons/Laws/SiliconLawSystem.cs
Content.Shared/Silicons/Laws/Components/SiliconLawProviderComponent.cs

index d5a5c4f40917fc049b690544470b68325776f5b6..9fd639e9b3d313b9f36e3867be10769cce5b74c4 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Server.Administration.Managers;
+using Content.Server.Administration.Managers;
 using Content.Server.EUI;
 using Content.Shared.Administration;
 using Content.Shared.Eui;
@@ -52,8 +52,8 @@ public sealed class SiliconLawEui : BaseEui
             return;
 
         var player = _entityManager.GetEntity(message.Target);
-
-        _siliconLawSystem.SetLaws(message.Laws, player);
+        if (_entityManager.TryGetComponent<SiliconLawProviderComponent>(player, out var playerProviderComp))
+            _siliconLawSystem.SetLaws(message.Laws, player, playerProviderComp.LawUploadSound);
     }
 
     private bool IsAllowed()
index 0070beb6ef9f5c4ee371983c6d343b811235d444..9a361132a5ca7f02eaff669325d6bb6c64f2a368 100644 (file)
@@ -21,6 +21,8 @@ using Robust.Shared.Containers;
 using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Toolshed;
+using Robust.Shared.Audio;
+using Robust.Shared.GameObjects;
 
 namespace Content.Server.Silicons.Laws;
 
@@ -113,7 +115,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
             component.Lawset = args.Lawset;
 
             // gotta tell player to check their laws
-            NotifyLawsChanged(uid);
+            NotifyLawsChanged(uid, component.LawUploadSound);
 
             // new laws may allow antagonist behaviour so make it clear for admins
             if (TryComp<EmagSiliconLawComponent>(uid, out var emag))
@@ -149,14 +151,11 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
             return;
 
         base.OnGotEmagged(uid, component, ref args);
-        NotifyLawsChanged(uid);
+        NotifyLawsChanged(uid, component.EmaggedSound);
         EnsureEmaggedRole(uid, component);
 
         _stunSystem.TryParalyze(uid, component.StunTime, true);
 
-        if (!_mind.TryGetMind(uid, out var mindId, out _))
-            return;
-        _roles.MindPlaySound(mindId, component.EmaggedSound);
     }
 
     private void OnEmagMindAdded(EntityUid uid, EmagSiliconLawComponent component, MindAddedMessage args)
@@ -237,7 +236,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
         return ev.Laws;
     }
 
-    public void NotifyLawsChanged(EntityUid uid)
+    public void NotifyLawsChanged(EntityUid uid, SoundSpecifier? cue = null)
     {
         if (!TryComp<ActorComponent>(uid, out var actor))
             return;
@@ -245,6 +244,9 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
         var msg = Loc.GetString("laws-update-notify");
         var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", msg));
         _chatManager.ChatMessageToOne(ChatChannel.Server, msg, wrappedMessage, default, false, actor.PlayerSession.Channel, colorOverride: Color.Red);
+
+        if (cue != null && _mind.TryGetMind(uid, out var mindId, out _))
+            _roles.MindPlaySound(mindId, cue);
     }
 
     /// <summary>
@@ -269,7 +271,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
     /// <summary>
     /// Set the laws of a silicon entity while notifying the player.
     /// </summary>
-    public void SetLaws(List<SiliconLaw> newLaws, EntityUid target)
+    public void SetLaws(List<SiliconLaw> newLaws, EntityUid target, SoundSpecifier? cue = null)
     {
         if (!TryComp<SiliconLawProviderComponent>(target, out var component))
             return;
@@ -278,7 +280,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
             component.Lawset = new SiliconLawset();
 
         component.Lawset.Laws = newLaws;
-        NotifyLawsChanged(target);
+        NotifyLawsChanged(target, cue);
     }
 
     protected override void OnUpdaterInsert(Entity<SiliconLawUpdaterComponent> ent, ref EntInsertedIntoContainerMessage args)
@@ -292,9 +294,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
 
         while (query.MoveNext(out var update))
         {
-            SetLaws(lawset, update);
-            if (provider.LawUploadSound != null && _mind.TryGetMind(update, out var mindId, out _))
-                _roles.MindPlaySound(mindId, provider.LawUploadSound);
+            SetLaws(lawset, update, provider.LawUploadSound);
         }
     }
 }
index 1c54938b8a40cef8a0d63ca8fa676e657302a78a..4885bd0265c489635394eaf7173305f2901b5557 100644 (file)
@@ -24,7 +24,7 @@ public sealed partial class SiliconLawProviderComponent : Component
 
     /// <summary>
     /// The sound that plays for the Silicon player
-    /// when the particular lawboard has been inserted.
+    /// when the law change is processed for the provider.
     /// </summary>
     [DataField]
     public SoundSpecifier? LawUploadSound = new SoundPathSpecifier("/Audio/Misc/cryo_warning.ogg");