IdentityComponent.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Robust.Shared.Containers;
  2. using Robust.Shared.Enums;
  3. namespace Content.Shared.IdentityManagement.Components;
  4. /// <summary>
  5. /// Stores the identity entity (whose name is the users 'identity', etc)
  6. /// for a given entity, and marks that it can have an identity at all.
  7. /// </summary>
  8. /// <remarks>
  9. /// This is a <see cref="ContainerSlot"/> and not just a datum entity because we do sort of care that it gets deleted and sent with the user.
  10. /// </remarks>
  11. [RegisterComponent]
  12. public sealed partial class IdentityComponent : Component
  13. {
  14. [ViewVariables]
  15. public ContainerSlot IdentityEntitySlot = default!;
  16. }
  17. /// <summary>
  18. /// A data structure representing the 'identity' of an entity as presented to
  19. /// other players.
  20. /// </summary>
  21. public sealed class IdentityRepresentation
  22. {
  23. public string TrueName;
  24. public Gender TrueGender;
  25. public string AgeString;
  26. public string? PresumedName;
  27. public string? PresumedJob;
  28. public IdentityRepresentation(string trueName, Gender trueGender, string ageString, string? presumedName=null, string? presumedJob=null)
  29. {
  30. TrueName = trueName;
  31. TrueGender = trueGender;
  32. AgeString = ageString;
  33. PresumedJob = presumedJob;
  34. PresumedName = presumedName;
  35. }
  36. public string ToStringKnown(bool trueName)
  37. {
  38. return trueName
  39. ? TrueName
  40. : PresumedName ?? ToStringUnknown();
  41. }
  42. /// <summary>
  43. /// Returns a string representing their identity where it is 'unknown' by a viewer.
  44. /// Used for cases where the viewer is not necessarily able to accurately assess
  45. /// the identity of the person being viewed.
  46. /// </summary>
  47. public string ToStringUnknown()
  48. {
  49. var genderString = TrueGender switch
  50. {
  51. Gender.Female => Loc.GetString("identity-gender-feminine"),
  52. Gender.Male => Loc.GetString("identity-gender-masculine"),
  53. Gender.Epicene or Gender.Neuter or _ => Loc.GetString("identity-gender-person")
  54. };
  55. // i.e. 'young assistant man' or 'old cargo technician person' or 'middle-aged captain'
  56. return PresumedJob is null
  57. ? $"{AgeString} {genderString}"
  58. : $"{AgeString} {PresumedJob} {genderString}";
  59. }
  60. }