fix: make IdentityComp.IdentityEntitySlot optional (#39357)
* fix: make IdentityComp.IdentityEntitySlot optional * Revert "fix: make IdentityComp.IdentityEntitySlot optional" This reverts commit fa25263be916ed142bf2cff9871fca3e64c6da2b. * fix conflicts --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
@@ -14,8 +14,12 @@ namespace Content.Shared.IdentityManagement.Components;
|
|||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public sealed partial class IdentityComponent : Component
|
public sealed partial class IdentityComponent : Component
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The slot which carries around the entity representing the carrier's
|
||||||
|
/// perceived identity. May be null if the component is not initialized.
|
||||||
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public ContainerSlot IdentityEntitySlot = default!;
|
public ContainerSlot? IdentityEntitySlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,7 +36,7 @@ public sealed class IdentityRepresentation
|
|||||||
public string? PresumedName;
|
public string? PresumedName;
|
||||||
public string? PresumedJob;
|
public string? PresumedJob;
|
||||||
|
|
||||||
public IdentityRepresentation(string trueName, Gender trueGender, string ageString, string? presumedName=null, string? presumedJob=null)
|
public IdentityRepresentation(string trueName, Gender trueGender, string ageString, string? presumedName = null, string? presumedJob = null)
|
||||||
{
|
{
|
||||||
TrueName = trueName;
|
TrueName = trueName;
|
||||||
TrueGender = trueGender;
|
TrueGender = trueGender;
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ public static class Identity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the name that should be used for this entity for identity purposes.
|
/// Returns the name that should be used for this entity for identity purposes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Name(EntityUid uid, IEntityManager ent, EntityUid? viewer=null)
|
/// <remarks>
|
||||||
|
/// This will return the true identity of the entity if called before the
|
||||||
|
/// identity component has been initialized — this may occur for example if
|
||||||
|
/// the client raises an event in response to an entity entering PVS for
|
||||||
|
/// the first time.
|
||||||
|
/// </remarks>
|
||||||
|
public static string Name(EntityUid uid, IEntityManager ent, EntityUid? viewer = null)
|
||||||
{
|
{
|
||||||
if (!uid.IsValid())
|
if (!uid.IsValid())
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
@@ -27,7 +33,7 @@ public static class Identity
|
|||||||
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
||||||
return uidName;
|
return uidName;
|
||||||
|
|
||||||
var ident = identity.IdentityEntitySlot.ContainedEntity;
|
var ident = identity.IdentityEntitySlot?.ContainedEntity;
|
||||||
if (ident is null)
|
if (ident is null)
|
||||||
return uidName;
|
return uidName;
|
||||||
|
|
||||||
@@ -52,6 +58,7 @@ public static class Identity
|
|||||||
/// <param name="viewer">
|
/// <param name="viewer">
|
||||||
/// If this entity can see through identities, this method will always return the actual target entity.
|
/// If this entity can see through identities, this method will always return the actual target entity.
|
||||||
/// </param>
|
/// </param>
|
||||||
|
/// <inheritdoc cref="Name" path="remarks" />
|
||||||
public static EntityUid Entity(EntityUid uid, IEntityManager ent, EntityUid? viewer = null)
|
public static EntityUid Entity(EntityUid uid, IEntityManager ent, EntityUid? viewer = null)
|
||||||
{
|
{
|
||||||
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
if (!ent.TryGetComponent<IdentityComponent>(uid, out var identity))
|
||||||
@@ -60,7 +67,7 @@ public static class Identity
|
|||||||
if (viewer != null && CanSeeThroughIdentity(uid, viewer.Value, ent))
|
if (viewer != null && CanSeeThroughIdentity(uid, viewer.Value, ent))
|
||||||
return uid;
|
return uid;
|
||||||
|
|
||||||
return identity.IdentityEntitySlot.ContainedEntity ?? uid;
|
return identity.IdentityEntitySlot?.ContainedEntity ?? uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CanSeeThroughIdentity(EntityUid uid, EntityUid viewer, IEntityManager ent)
|
public static bool CanSeeThroughIdentity(EntityUid uid, EntityUid viewer, IEntityManager ent)
|
||||||
|
|||||||
@@ -78,11 +78,17 @@ public sealed class IdentitySystem : EntitySystem
|
|||||||
// Creates an identity entity, and store it in the identity container
|
// Creates an identity entity, and store it in the identity container
|
||||||
private void OnMapInit(Entity<IdentityComponent> ent, ref MapInitEvent args)
|
private void OnMapInit(Entity<IdentityComponent> ent, ref MapInitEvent args)
|
||||||
{
|
{
|
||||||
|
if (ent.Comp.IdentityEntitySlot is not { } slot)
|
||||||
|
{
|
||||||
|
Log.Error($"Uninitialized IdentityEntitySlot for {ToPrettyString(ent.Owner)}.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var ident = Spawn(null, Transform(ent).Coordinates);
|
var ident = Spawn(null, Transform(ent).Coordinates);
|
||||||
|
|
||||||
_metaData.SetEntityName(ident, "identity");
|
_metaData.SetEntityName(ident, "identity");
|
||||||
QueueIdentityUpdate(ent);
|
QueueIdentityUpdate(ent);
|
||||||
_container.Insert(ident, ent.Comp.IdentityEntitySlot);
|
_container.Insert(ident, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnComponentInit(Entity<IdentityComponent> ent, ref ComponentInit args)
|
private void OnComponentInit(Entity<IdentityComponent> ent, ref ComponentInit args)
|
||||||
@@ -132,7 +138,7 @@ public sealed class IdentitySystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateIdentityInfo(Entity<IdentityComponent> ent)
|
private void UpdateIdentityInfo(Entity<IdentityComponent> ent)
|
||||||
{
|
{
|
||||||
if (ent.Comp.IdentityEntitySlot.ContainedEntity is not { } ident)
|
if (ent.Comp.IdentityEntitySlot?.ContainedEntity is not { } ident)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var representation = GetIdentityRepresentation(ent.Owner);
|
var representation = GetIdentityRepresentation(ent.Owner);
|
||||||
|
|||||||
Reference in New Issue
Block a user