]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Cleanup SharedRoleCodewordSystem (#38310)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Fri, 27 Jun 2025 00:27:25 +0000 (02:27 +0200)
committerGitHub <noreply@github.com>
Fri, 27 Jun 2025 00:27:25 +0000 (02:27 +0200)
* cleanup

* Update Content.Shared/Roles/RoleCodeword/SharedRoleCodewordSystem.cs

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
* Apply suggestions from code review

---------

Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Content.Shared/Roles/RoleCodeword/RoleCodewordComponent.cs
Content.Shared/Roles/RoleCodeword/SharedRoleCodewordSystem.cs

index bfe98de8621474dc27ffb71431b0b7b6df4f7fc7..2d96cae861fa6927aae824b6300c9f3b31dd98bd 100644 (file)
@@ -133,11 +133,11 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
             Log.Debug($"MakeTraitor {ToPrettyString(traitor)} - did not get traitor briefing");
         }
 
-        // Send codewords to only the traitor client
         var color = TraitorCodewordColor; // Fall back to a dark red Syndicate color if a prototype is not found
 
-        RoleCodewordComponent codewordComp = EnsureComp<RoleCodewordComponent>(mindId);
-        _roleCodewordSystem.SetRoleCodewords(codewordComp, "traitor", factionCodewords.ToList(), color);
+        // The mind entity is stored in nullspace with a PVS override for the owner, so only they can see the codewords.
+        var codewordComp = EnsureComp<RoleCodewordComponent>(mindId);
+        _roleCodewordSystem.SetRoleCodewords((mindId, codewordComp), "traitor", factionCodewords.ToList(), color);
 
         // Change the faction
         Log.Debug($"MakeTraitor {ToPrettyString(traitor)} - Change faction");
index a1723dbc7ec2c05e33acf52a4be6f198af9675ac..222aec9bf7b3c651090ee9b646c9356c877f8a1d 100644 (file)
@@ -1,5 +1,4 @@
 using Robust.Shared.GameStates;
-using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization;
 
 namespace Content.Shared.Roles.RoleCodeword;
@@ -16,8 +15,6 @@ public sealed partial class RoleCodewordComponent : Component
     /// </summary>
     [DataField, AutoNetworkedField]
     public Dictionary<string, CodewordsData> RoleCodewords = new();
-
-    public override bool SessionSpecific => true;
 }
 
 [DataDefinition, Serializable, NetSerializable]
index 9f860715fbd711886e076065146051ea66fb8ead..345cfd4e212d5a8db28110b792a324b35f754c85 100644 (file)
@@ -1,49 +1,11 @@
-using Content.Shared.Mind;
-using Robust.Shared.GameStates;
-using Robust.Shared.Player;
-
 namespace Content.Shared.Roles.RoleCodeword;
 
 public abstract class SharedRoleCodewordSystem : EntitySystem
 {
-    [Dependency] private readonly SharedMindSystem _mindSystem = default!;
-
-    public override void Initialize()
-    {
-        base.Initialize();
-
-        SubscribeLocalEvent<RoleCodewordComponent, ComponentGetStateAttemptEvent>(OnCodewordCompGetStateAttempt);
-    }
-
-    /// <summary>
-    /// Determines if a codeword component should be sent to the client.
-    /// </summary>
-    private void OnCodewordCompGetStateAttempt(EntityUid uid, RoleCodewordComponent comp, ref ComponentGetStateAttemptEvent args)
-    {
-        args.Cancelled = !CanGetState(args.Player, comp);
-    }
-
-    /// <summary>
-    /// The criteria that determine whether a codeword component should be sent to a client.
-    /// Sends the component if its owner is the player mind.
-    /// </summary>
-    /// <param name="player"> The Player the component will be sent to.</param>
-    /// <param name="comp"> The component being checked against</param>
-    /// <returns></returns>
-    private bool CanGetState(ICommonSession? player, RoleCodewordComponent comp)
-    {
-        if (!_mindSystem.TryGetMind(player, out EntityUid mindId, out var _))
-            return false;
-
-        if (!TryComp(mindId, out RoleCodewordComponent? playerComp) && comp != playerComp)
-            return false;
-
-        return true;
-    }
-
-    public void SetRoleCodewords(RoleCodewordComponent comp, string key, List<string> codewords, Color color)
+    public void SetRoleCodewords(Entity<RoleCodewordComponent> ent, string key, List<string> codewords, Color color)
     {
         var data = new CodewordsData(color, codewords);
-        comp.RoleCodewords[key] = data;
+        ent.Comp.RoleCodewords[key] = data;
+        Dirty(ent);
     }
 }