]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Move job info changing methods for id cards to shared (#27337)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Fri, 26 Apr 2024 08:00:16 +0000 (01:00 -0700)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 08:00:16 +0000 (18:00 +1000)
* Move job info changing methods for id cards to shared

* Revert "Move job info changing methods for id cards to shared"

This reverts commit 95cbc46b2d1934fa7bf5c72d7d3de9f9168992a1.

* Reapply changes

Content.Client/Access/IdCardSystem.cs
Content.Server/Access/Systems/IdCardSystem.cs
Content.Shared/Access/Systems/SharedIdCardSystem.cs

index fcf2bf57de386f049c4b732530d8029cd5137aa2..e0c02976f7b331da2c22b75d36a786efe162d4db 100644 (file)
@@ -2,6 +2,4 @@
 
 namespace Content.Client.Access;
 
-public sealed class IdCardSystem : SharedIdCardSystem
-{
-}
+public sealed class IdCardSystem : SharedIdCardSystem;
index 6b3d8db595fcaacffb2813b49a070605eb08fa28..9cd9976cea900c59eff98f01bdc6c4356cc413b0 100644 (file)
@@ -7,8 +7,6 @@ using Content.Shared.Access.Components;
 using Content.Shared.Access.Systems;
 using Content.Shared.Database;
 using Content.Shared.Popups;
-using Content.Shared.Roles;
-using Content.Shared.StatusIcon;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 
@@ -20,20 +18,13 @@ public sealed class IdCardSystem : SharedIdCardSystem
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IAdminLogManager _adminLogger = default!;
-    [Dependency] private readonly MetaDataSystem _metaSystem = default!;
 
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<IdCardComponent, MapInitEvent>(OnMapInit);
         SubscribeLocalEvent<IdCardComponent, BeingMicrowavedEvent>(OnMicrowaved);
     }
 
-    private void OnMapInit(EntityUid uid, IdCardComponent id, MapInitEvent args)
-    {
-        UpdateEntityName(uid, id);
-    }
-
     private void OnMicrowaved(EntityUid uid, IdCardComponent component, BeingMicrowavedEvent args)
     {
         if (TryComp<AccessComponent>(uid, out var access))
@@ -81,143 +72,4 @@ public sealed class IdCardSystem : SharedIdCardSystem
                     $"{ToPrettyString(args.Microwave)} added {random.ID} access to {ToPrettyString(uid):entity}");
         }
     }
-
-    /// <summary>
-    /// Attempts to change the job title of a card.
-    /// Returns true/false.
-    /// </summary>
-    /// <remarks>
-    /// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
-    /// </remarks>
-    public bool TryChangeJobTitle(EntityUid uid, string? jobTitle, IdCardComponent? id = null, EntityUid? player = null)
-    {
-        if (!Resolve(uid, ref id))
-            return false;
-
-        if (!string.IsNullOrWhiteSpace(jobTitle))
-        {
-            jobTitle = jobTitle.Trim();
-
-            if (jobTitle.Length > IdCardConsoleComponent.MaxJobTitleLength)
-                jobTitle = jobTitle[..IdCardConsoleComponent.MaxJobTitleLength];
-        }
-        else
-        {
-            jobTitle = null;
-        }
-
-        if (id.JobTitle == jobTitle)
-            return true;
-        id.JobTitle = jobTitle;
-        Dirty(uid, id);
-        UpdateEntityName(uid, id);
-
-        if (player != null)
-        {
-            _adminLogger.Add(LogType.Identity, LogImpact.Low,
-                $"{ToPrettyString(player.Value):player} has changed the job title of {ToPrettyString(uid):entity} to {jobTitle} ");
-        }
-        return true;
-    }
-
-    public bool TryChangeJobIcon(EntityUid uid, StatusIconPrototype jobIcon, IdCardComponent? id = null, EntityUid? player = null)
-    {
-        if (!Resolve(uid, ref id))
-        {
-            return false;
-        }
-
-        if (id.JobIcon == jobIcon.ID)
-        {
-            return true;
-        }
-
-        id.JobIcon = jobIcon.ID;
-        Dirty(uid, id);
-
-        if (player != null)
-        {
-            _adminLogger.Add(LogType.Identity, LogImpact.Low,
-                $"{ToPrettyString(player.Value):player} has changed the job icon of {ToPrettyString(uid):entity} to {jobIcon} ");
-        }
-
-        return true;
-    }
-
-    public bool TryChangeJobDepartment(EntityUid uid, JobPrototype job, IdCardComponent? id = null)
-    {
-        if (!Resolve(uid, ref id))
-            return false;
-
-        id.JobDepartments.Clear();
-        foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
-        {
-            if (department.Roles.Contains(job.ID))
-                id.JobDepartments.Add("department-" + department.ID);
-        }
-
-        Dirty(uid, id);
-
-        return true;
-    }
-
-    /// <summary>
-    /// Attempts to change the full name of a card.
-    /// Returns true/false.
-    /// </summary>
-    /// <remarks>
-    /// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
-    /// </remarks>
-    public bool TryChangeFullName(EntityUid uid, string? fullName, IdCardComponent? id = null, EntityUid? player = null)
-    {
-        if (!Resolve(uid, ref id))
-            return false;
-
-        if (!string.IsNullOrWhiteSpace(fullName))
-        {
-            fullName = fullName.Trim();
-            if (fullName.Length > IdCardConsoleComponent.MaxFullNameLength)
-                fullName = fullName[..IdCardConsoleComponent.MaxFullNameLength];
-        }
-        else
-        {
-            fullName = null;
-        }
-
-        if (id.FullName == fullName)
-            return true;
-        id.FullName = fullName;
-        Dirty(uid, id);
-        UpdateEntityName(uid, id);
-
-        if (player != null)
-        {
-            _adminLogger.Add(LogType.Identity, LogImpact.Low,
-                $"{ToPrettyString(player.Value):player} has changed the name of {ToPrettyString(uid):entity} to {fullName} ");
-        }
-        return true;
-    }
-
-    /// <summary>
-    /// Changes the name of the id's owner.
-    /// </summary>
-    /// <remarks>
-    /// If either <see cref="FullName"/> or <see cref="JobTitle"/> is empty, it's replaced by placeholders.
-    /// If both are empty, the original entity's name is restored.
-    /// </remarks>
-    private void UpdateEntityName(EntityUid uid, IdCardComponent? id = null)
-    {
-        if (!Resolve(uid, ref id))
-            return;
-
-        var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? string.Empty : $" ({id.JobTitle})";
-
-        var val = string.IsNullOrWhiteSpace(id.FullName)
-            ? Loc.GetString("access-id-card-component-owner-name-job-title-text",
-                ("jobSuffix", jobSuffix))
-            : Loc.GetString("access-id-card-component-owner-full-name-job-title-text",
-                ("fullName", id.FullName),
-                ("jobSuffix", jobSuffix));
-        _metaSystem.SetEntityName(uid, val);
-    }
 }
index 842e7e7e6ac9eec11669c7ec3f6af2f6fc4bcfd9..11a61c7bf30cf7daacc73d283f5c8c6449057065 100644 (file)
@@ -1,13 +1,32 @@
 using Content.Shared.Access.Components;
+using Content.Shared.Administration.Logs;
+using Content.Shared.Database;
 using Content.Shared.Hands.Components;
 using Content.Shared.Inventory;
 using Content.Shared.PDA;
+using Content.Shared.Roles;
+using Content.Shared.StatusIcon;
+using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Access.Systems;
 
 public abstract class SharedIdCardSystem : EntitySystem
 {
+    [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
     [Dependency] private readonly InventorySystem _inventorySystem = default!;
+    [Dependency] private readonly MetaDataSystem _metaSystem = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<IdCardComponent, MapInitEvent>(OnMapInit);
+    }
+
+    private void OnMapInit(EntityUid uid, IdCardComponent id, MapInitEvent args)
+    {
+        UpdateEntityName(uid, id);
+    }
 
     /// <summary>
     ///     Attempt to find an ID card on an entity. This will look in the entity itself, in the entity's hands, and
@@ -56,4 +75,143 @@ public abstract class SharedIdCardSystem : EntitySystem
         idCard = default;
         return false;
     }
+
+    /// <summary>
+    /// Attempts to change the job title of a card.
+    /// Returns true/false.
+    /// </summary>
+    /// <remarks>
+    /// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
+    /// </remarks>
+    public bool TryChangeJobTitle(EntityUid uid, string? jobTitle, IdCardComponent? id = null, EntityUid? player = null)
+    {
+        if (!Resolve(uid, ref id))
+            return false;
+
+        if (!string.IsNullOrWhiteSpace(jobTitle))
+        {
+            jobTitle = jobTitle.Trim();
+
+            if (jobTitle.Length > IdCardConsoleComponent.MaxJobTitleLength)
+                jobTitle = jobTitle[..IdCardConsoleComponent.MaxJobTitleLength];
+        }
+        else
+        {
+            jobTitle = null;
+        }
+
+        if (id.JobTitle == jobTitle)
+            return true;
+        id.JobTitle = jobTitle;
+        Dirty(uid, id);
+        UpdateEntityName(uid, id);
+
+        if (player != null)
+        {
+            _adminLogger.Add(LogType.Identity, LogImpact.Low,
+                $"{ToPrettyString(player.Value):player} has changed the job title of {ToPrettyString(uid):entity} to {jobTitle} ");
+        }
+        return true;
+    }
+
+    public bool TryChangeJobIcon(EntityUid uid, StatusIconPrototype jobIcon, IdCardComponent? id = null, EntityUid? player = null)
+    {
+        if (!Resolve(uid, ref id))
+        {
+            return false;
+        }
+
+        if (id.JobIcon == jobIcon.ID)
+        {
+            return true;
+        }
+
+        id.JobIcon = jobIcon.ID;
+        Dirty(uid, id);
+
+        if (player != null)
+        {
+            _adminLogger.Add(LogType.Identity, LogImpact.Low,
+                $"{ToPrettyString(player.Value):player} has changed the job icon of {ToPrettyString(uid):entity} to {jobIcon} ");
+        }
+
+        return true;
+    }
+
+    public bool TryChangeJobDepartment(EntityUid uid, JobPrototype job, IdCardComponent? id = null)
+    {
+        if (!Resolve(uid, ref id))
+            return false;
+
+        id.JobDepartments.Clear();
+        foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
+        {
+            if (department.Roles.Contains(job.ID))
+                id.JobDepartments.Add("department-" + department.ID);
+        }
+
+        Dirty(uid, id);
+
+        return true;
+    }
+
+    /// <summary>
+    /// Attempts to change the full name of a card.
+    /// Returns true/false.
+    /// </summary>
+    /// <remarks>
+    /// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
+    /// </remarks>
+    public bool TryChangeFullName(EntityUid uid, string? fullName, IdCardComponent? id = null, EntityUid? player = null)
+    {
+        if (!Resolve(uid, ref id))
+            return false;
+
+        if (!string.IsNullOrWhiteSpace(fullName))
+        {
+            fullName = fullName.Trim();
+            if (fullName.Length > IdCardConsoleComponent.MaxFullNameLength)
+                fullName = fullName[..IdCardConsoleComponent.MaxFullNameLength];
+        }
+        else
+        {
+            fullName = null;
+        }
+
+        if (id.FullName == fullName)
+            return true;
+        id.FullName = fullName;
+        Dirty(uid, id);
+        UpdateEntityName(uid, id);
+
+        if (player != null)
+        {
+            _adminLogger.Add(LogType.Identity, LogImpact.Low,
+                $"{ToPrettyString(player.Value):player} has changed the name of {ToPrettyString(uid):entity} to {fullName} ");
+        }
+        return true;
+    }
+
+    /// <summary>
+    /// Changes the name of the id's owner.
+    /// </summary>
+    /// <remarks>
+    /// If either <see cref="FullName"/> or <see cref="JobTitle"/> is empty, it's replaced by placeholders.
+    /// If both are empty, the original entity's name is restored.
+    /// </remarks>
+    private void UpdateEntityName(EntityUid uid, IdCardComponent? id = null)
+    {
+        if (!Resolve(uid, ref id))
+            return;
+
+        var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? string.Empty : $" ({id.JobTitle})";
+
+        var val = string.IsNullOrWhiteSpace(id.FullName)
+            ? Loc.GetString("access-id-card-component-owner-name-job-title-text",
+                ("jobSuffix", jobSuffix))
+            : Loc.GetString("access-id-card-component-owner-full-name-job-title-text",
+                ("fullName", id.FullName),
+                ("jobSuffix", jobSuffix));
+        _metaSystem.SetEntityName(uid, val);
+    }
 }