mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Use metadata query in ToPrettyString() (#4478)
This commit is contained in:
@@ -93,14 +93,10 @@ namespace Robust.Client.GameObjects
|
||||
base.Dirty(uid, component, meta);
|
||||
}
|
||||
|
||||
[return: NotNullIfNotNull("uid")]
|
||||
public override EntityStringRepresentation? ToPrettyString(EntityUid? uid)
|
||||
public override EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metaDataComponent = null)
|
||||
{
|
||||
if (uid == null)
|
||||
return null;
|
||||
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity == uid)
|
||||
return base.ToPrettyString(uid).Value with { Session = _playerManager.LocalPlayer.Session };
|
||||
return base.ToPrettyString(uid) with { Session = _playerManager.LocalPlayer.Session };
|
||||
|
||||
return base.ToPrettyString(uid);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace Robust.Server.GameObjects
|
||||
#endif
|
||||
|
||||
private ISawmill _netEntSawmill = default!;
|
||||
private EntityQuery<ActorComponent> _actorQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -53,6 +54,12 @@ namespace Robust.Server.GameObjects
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
_actorQuery = GetEntityQuery<ActorComponent>();
|
||||
}
|
||||
|
||||
EntityUid IServerEntityManagerInternal.AllocEntity(EntityPrototype? prototype)
|
||||
{
|
||||
return AllocEntity(prototype, out _);
|
||||
@@ -109,15 +116,10 @@ namespace Robust.Server.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
[return: NotNullIfNotNull("uid")]
|
||||
public override EntityStringRepresentation? ToPrettyString(EntityUid? uid)
|
||||
public override EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata = null)
|
||||
{
|
||||
if (uid == null)
|
||||
return null;
|
||||
|
||||
TryGetComponent(uid, out ActorComponent? actor);
|
||||
|
||||
return base.ToPrettyString(uid).Value with { Session = actor?.PlayerSession };
|
||||
_actorQuery.TryGetComponent(uid, out ActorComponent? actor);
|
||||
return base.ToPrettyString(uid) with { Session = actor?.PlayerSession };
|
||||
}
|
||||
|
||||
#region IEntityNetworkManager impl
|
||||
|
||||
@@ -751,36 +751,34 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
/// <inheritdoc />
|
||||
[return: NotNullIfNotNull("uid")]
|
||||
public virtual EntityStringRepresentation? ToPrettyString(EntityUid? uid)
|
||||
public EntityStringRepresentation? ToPrettyString(EntityUid? uid, MetaDataComponent? metadata = null)
|
||||
{
|
||||
// We want to retrieve the MetaData component even if it is deleted.
|
||||
if (uid == null)
|
||||
return null;
|
||||
return uid == null ? null : ToPrettyString(uid.Value, metadata);
|
||||
}
|
||||
|
||||
if (!_entTraitArray[CompIdx.ArrayIndex<MetaDataComponent>()].TryGetValue(uid.Value, out var component))
|
||||
return new EntityStringRepresentation(uid.Value, true);
|
||||
/// <inheritdoc />
|
||||
public virtual EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata = null)
|
||||
{
|
||||
if (!MetaQuery.Resolve(uid, ref metadata, false))
|
||||
return new EntityStringRepresentation(uid, true);
|
||||
|
||||
var metadata = (MetaDataComponent) component;
|
||||
|
||||
return ToPrettyString(uid.Value, metadata);
|
||||
return new EntityStringRepresentation(uid, metadata.EntityDeleted, metadata.EntityName, metadata.EntityPrototype?.ID);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[return: NotNullIfNotNull("netEntity")]
|
||||
public EntityStringRepresentation? ToPrettyString(NetEntity? netEntity)
|
||||
{
|
||||
return ToPrettyString(GetEntity(netEntity));
|
||||
return netEntity == null ? null : ToPrettyString(netEntity.Value);
|
||||
}
|
||||
|
||||
public EntityStringRepresentation ToPrettyString(EntityUid uid)
|
||||
=> ToPrettyString((EntityUid?) uid).Value;
|
||||
|
||||
/// <inheritdoc />
|
||||
public EntityStringRepresentation ToPrettyString(NetEntity netEntity)
|
||||
=> ToPrettyString((NetEntity?) netEntity).Value;
|
||||
|
||||
private EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent metadata)
|
||||
{
|
||||
return new EntityStringRepresentation(uid, metadata.EntityDeleted, metadata.EntityName, metadata.EntityPrototype?.ID);
|
||||
if (!TryGetEntityData(netEntity, out var uid, out var meta))
|
||||
return new EntityStringRepresentation(EntityUid.Invalid, true);
|
||||
|
||||
return ToPrettyString(uid.Value, meta);
|
||||
}
|
||||
|
||||
#endregion Entity Management
|
||||
|
||||
@@ -399,9 +399,9 @@ public partial class EntitySystem
|
||||
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[return: NotNullIfNotNull("uid")]
|
||||
protected EntityStringRepresentation? ToPrettyString(EntityUid? uid)
|
||||
protected EntityStringRepresentation? ToPrettyString(EntityUid? uid, MetaDataComponent? metadata = null)
|
||||
{
|
||||
return EntityManager.ToPrettyString(uid);
|
||||
return EntityManager.ToPrettyString(uid, metadata);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
|
||||
@@ -412,15 +412,20 @@ public partial class EntitySystem
|
||||
return EntityManager.ToPrettyString(netEntity);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata)
|
||||
=> EntityManager.ToPrettyString(uid, metadata);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityStringRepresentation ToPrettyString(EntityUid uid)
|
||||
=> ToPrettyString((EntityUid?) uid).Value;
|
||||
=> EntityManager.ToPrettyString(uid);
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.ToPrettyString"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected EntityStringRepresentation ToPrettyString(NetEntity netEntity)
|
||||
=> ToPrettyString((NetEntity?) netEntity).Value;
|
||||
=> EntityManager.ToPrettyString(netEntity);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <param name="uid">Entity to modify.</param>
|
||||
/// <param name="component">The output component after being ensured.</param>
|
||||
/// <typeparam name="T">Component to add.</typeparam>
|
||||
/// <returns>The component in question</returns>
|
||||
/// <returns>True if the component already existed</returns>
|
||||
bool EnsureComponent<T>(EntityUid uid, out T component) where T : Component, new();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <summary>
|
||||
/// Returns a string representation of an entity with various information regarding it.
|
||||
/// </summary>
|
||||
EntityStringRepresentation ToPrettyString(EntityUid uid);
|
||||
EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of an entity with various information regarding it.
|
||||
@@ -138,7 +138,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Returns a string representation of an entity with various information regarding it.
|
||||
/// </summary>
|
||||
[return: NotNullIfNotNull("uid")]
|
||||
EntityStringRepresentation? ToPrettyString(EntityUid? uid);
|
||||
EntityStringRepresentation? ToPrettyString(EntityUid? uid, MetaDataComponent? metadata = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of an entity with various information regarding it.
|
||||
|
||||
@@ -128,6 +128,7 @@ namespace Robust.UnitTesting
|
||||
|
||||
// Required components for the engine to work
|
||||
// Why are we still here? Just to suffer? Why can't we just use [RegisterComponent] magic?
|
||||
// TODO End Suffering.
|
||||
var compFactory = deps.Resolve<IComponentFactory>();
|
||||
|
||||
if (!compFactory.AllRegisteredTypes.Contains(typeof(EyeComponent)))
|
||||
@@ -225,6 +226,11 @@ namespace Robust.UnitTesting
|
||||
compFactory.RegisterClass<Gravity2DComponent>();
|
||||
}
|
||||
|
||||
if (!compFactory.AllRegisteredTypes.Contains(typeof(ActorComponent)))
|
||||
{
|
||||
compFactory.RegisterClass<ActorComponent>();
|
||||
}
|
||||
|
||||
// So by default EntityManager does its own EntitySystemManager initialize during Startup.
|
||||
// We want to bypass this and load our own systems hence we will manually initialize it here.
|
||||
entMan.Initialize();
|
||||
|
||||
@@ -61,7 +61,6 @@ entities:
|
||||
var compFactory = IoCManager.Resolve<IComponentFactory>();
|
||||
compFactory.RegisterClass<MapDeserializeTestComponent>();
|
||||
compFactory.RegisterClass<VisibilityComponent>();
|
||||
compFactory.RegisterClass<ActorComponent>();
|
||||
compFactory.RegisterClass<IgnoreUIRangeComponent>();
|
||||
compFactory.GenerateNetIds();
|
||||
IoCManager.Resolve<ISerializationManager>().Initialize();
|
||||
|
||||
Reference in New Issue
Block a user