mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Functional product * Bugfix * Handle empty case gracefully * Fix inserting bad values * First set of tests * Don't need this * Dont add empty modifers to names Signed-off-by: Connor Huffine <chuffine@gmail.com> * Typo and [SubscribeLocalEvent] Signed-off-by: Connor Huffine <chuffine@gmail.com> * Refactor GenerateUniqueName to GenerateUniqueNameModifier Signed-off-by: Connor Huffine <chuffine@gmail.com> * Fix returning name when empty Signed-off-by: Connor Huffine <chuffine@gmail.com> * Docs Signed-off-by: Connor Huffine <chuffine@gmail.com> * Tests Signed-off-by: Connor Huffine <chuffine@gmail.com> * Fix comment Signed-off-by: Connor Huffine <chuffine@gmail.com> * Fix FTL test Signed-off-by: Connor Huffine <chuffine@gmail.com> * Add adjectives Signed-off-by: Connor Huffine <chuffine@gmail.com> * Amateur hour Signed-off-by: Connor Huffine <chuffine@gmail.com> * Simplify spawning Signed-off-by: Connor Huffine <chuffine@gmail.com> * Even more streamlined Signed-off-by: Connor Huffine <chuffine@gmail.com> * Improve comment Signed-off-by: Connor Huffine <chuffine@gmail.com> * Apply suggestions from code review Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> --------- Signed-off-by: Connor Huffine <chuffine@gmail.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com>
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Content.Shared.NameModifier.EntitySystems;
|
|
|
|
namespace Content.Shared.NameIdentifier;
|
|
|
|
/// <summary>
|
|
/// Handles unique name identifiers for entities e.g. `monkey (MK-912)`
|
|
/// </summary>
|
|
public abstract partial class SharedNameIdentifierSystem : EntitySystem
|
|
{
|
|
[SubscribeLocalEvent]
|
|
private void OnRefreshNameModifiers(Entity<NameIdentifierComponent> ent, ref RefreshNameModifiersEvent args)
|
|
{
|
|
if (ent.Comp.Group is null)
|
|
return;
|
|
|
|
// Don't add whitespace
|
|
if (string.IsNullOrWhiteSpace(ent.Comp.FullIdentifier))
|
|
return;
|
|
|
|
// Don't apply the modifier if the component is being removed
|
|
if (ent.Comp.LifeStage > ComponentLifeStage.Running)
|
|
return;
|
|
|
|
if (!ProtoMan.Resolve(ent.Comp.Group, out var group))
|
|
return;
|
|
|
|
var format = "name-identifier-format-full";
|
|
|
|
if (!group.FullName)
|
|
format = group.Prefix ? "name-identifier-format-prepend" : "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));
|
|
}
|
|
}
|