]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Convert `NameIdentifier` to use `NameModifierSystem` (#36736)
authorTayrtahn <tayrtahn@gmail.com>
Sun, 20 Apr 2025 04:16:59 +0000 (00:16 -0400)
committerGitHub <noreply@github.com>
Sun, 20 Apr 2025 04:16:59 +0000 (14:16 +1000)
Convert NameIdentifier to use NameModifierSystem

Content.Client/Silicons/Borgs/BorgMenu.xaml.cs
Content.Server/NameIdentifier/NameIdentifierSystem.cs
Content.Server/Silicons/Borgs/BorgSystem.Ui.cs
Resources/Locale/en-US/name-identifier/name-identifier.ftl [new file with mode: 0644]

index b8f0e69c022f868a4e3c53b9a53618682f13f6ba..007a0cc5cbe9f90b0ef1aca39c33e05ec97caea7 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Client.Stylesheets;
 using Content.Client.UserInterface.Controls;
 using Content.Shared.NameIdentifier;
+using Content.Shared.NameModifier.EntitySystems;
 using Content.Shared.Preferences;
 using Content.Shared.Silicons.Borgs;
 using Content.Shared.Silicons.Borgs.Components;
@@ -15,6 +16,7 @@ namespace Content.Client.Silicons.Borgs;
 public sealed partial class BorgMenu : FancyWindow
 {
     [Dependency] private readonly IEntityManager _entity = default!;
+    private readonly NameModifierSystem _nameModifier;
 
     public Action? BrainButtonPressed;
     public Action? EjectBatteryButtonPressed;
@@ -32,6 +34,8 @@ public sealed partial class BorgMenu : FancyWindow
         RobustXamlLoader.Load(this);
         IoCManager.InjectDependencies(this);
 
+        _nameModifier = _entity.System<NameModifierSystem>();
+
         _lastValidName = NameLineEdit.Text;
 
         EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
@@ -54,9 +58,7 @@ public sealed partial class BorgMenu : FancyWindow
             NameIdentifierLabel.Visible = true;
             NameIdentifierLabel.Text = nameIdentifierComponent.FullIdentifier;
 
-            var fullName = _entity.GetComponent<MetaDataComponent>(Entity).EntityName;
-            var name = fullName.Substring(0, fullName.Length - nameIdentifierComponent.FullIdentifier.Length - 1);
-            NameLineEdit.Text = name;
+            NameLineEdit.Text = _nameModifier.GetBaseName(entity);
         }
         else
         {
index 273e9407fd5f65de6d4643417627a8028d05b19e..0a9f87557a0260cc80edb9bebb079df63b4bce29 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Shared.GameTicking;
 using Content.Shared.NameIdentifier;
+using Content.Shared.NameModifier.EntitySystems;
 using Robust.Shared.Collections;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
@@ -13,7 +14,7 @@ public sealed class NameIdentifierSystem : EntitySystem
 {
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IRobustRandom _robustRandom = default!;
-    [Dependency] private readonly MetaDataSystem _metaData = default!;
+    [Dependency] private readonly NameModifierSystem _nameModifier = default!;
 
     /// <summary>
     /// Free IDs available per <see cref="NameIdentifierGroupPrototype"/>.
@@ -27,6 +28,7 @@ public sealed class NameIdentifierSystem : EntitySystem
 
         SubscribeLocalEvent<NameIdentifierComponent, MapInitEvent>(OnMapInit);
         SubscribeLocalEvent<NameIdentifierComponent, ComponentShutdown>(OnComponentShutdown);
+        SubscribeLocalEvent<NameIdentifierComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
         SubscribeLocalEvent<RoundRestartCleanupEvent>(CleanupIds);
         SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnReloadPrototypes);
 
@@ -44,6 +46,7 @@ public sealed class NameIdentifierSystem : EntitySystem
             ids[randomIndex] = component.Identifier;
             ids.Add(random);
         }
+        _nameModifier.RefreshNameModifiers(uid);
     }
 
     /// <summary>
@@ -108,12 +111,22 @@ public sealed class NameIdentifierSystem : EntitySystem
             ? uniqueName
             : $"({uniqueName})";
 
-        var meta = MetaData(uid);
-        // "DR-1234" as opposed to "drone (DR-1234)"
-        _metaData.SetEntityName(uid, group.FullName
-            ? uniqueName
-            : $"{meta.EntityName} ({uniqueName})", meta);
         Dirty(uid, component);
+        _nameModifier.RefreshNameModifiers(uid);
+    }
+
+    private void OnRefreshNameModifiers(Entity<NameIdentifierComponent> ent, ref RefreshNameModifiersEvent args)
+    {
+        // Don't apply the modifier if the component is being removed
+        if (ent.Comp.LifeStage > ComponentLifeStage.Running)
+            return;
+
+        if (!_prototypeManager.TryIndex<NameIdentifierGroupPrototype>(ent.Comp.Group, out var group))
+            return;
+        var format = group.FullName ? "name-identifier-format-full" : "name-identifier-format-append";
+        // We apply the modifier with a low priority to keep it near the base name
+        // "Beep (Si-4562) the zombie" instead of "Beep the zombie (Si-4562)"
+        args.AddModifier(format, -10, ("identifier", ent.Comp.FullIdentifier));
     }
 
     private void InitialSetupPrototypes()
index 40c2c3bf3324dc12983dfb4fa2e0be1ea1cf0aa3..9f9977cddc29abd1666803470241cabf26dc1b65 100644 (file)
@@ -62,8 +62,6 @@ public sealed partial class BorgSystem
         }
 
         var name = args.Name.Trim();
-        if (TryComp<NameIdentifierComponent>(uid, out var identifier))
-            name = $"{name} {identifier.FullIdentifier}";
 
         var metaData = MetaData(uid);
 
diff --git a/Resources/Locale/en-US/name-identifier/name-identifier.ftl b/Resources/Locale/en-US/name-identifier/name-identifier.ftl
new file mode 100644 (file)
index 0000000..e0c05e5
--- /dev/null
@@ -0,0 +1,2 @@
+name-identifier-format-append = {$baseName} {$identifier}
+name-identifier-format-full = {$identifier}