mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Add new EnsureEntity variants (#4586)
This commit is contained in:
@@ -167,7 +167,7 @@ namespace Robust.Shared.CompNetworkGenerator
|
||||
getStateInit.Append($@"
|
||||
{name} = GetNetEntitySet(component.{name}),");
|
||||
handleStateSetters.Append($@"
|
||||
component.{name} = EnsureEntitySet<{componentName}>(state.{name}, uid);");
|
||||
EnsureEntitySet<{componentName}>(state.{name}, uid, component.{name});");
|
||||
|
||||
break;
|
||||
case GlobalEntityUidListName:
|
||||
@@ -177,7 +177,7 @@ namespace Robust.Shared.CompNetworkGenerator
|
||||
getStateInit.Append($@"
|
||||
{name} = GetNetEntityList(component.{name}),");
|
||||
handleStateSetters.Append($@"
|
||||
component.{name} = EnsureEntityList<{componentName}>(state.{name}, uid);");
|
||||
EnsureEntityList<{componentName}>(state.{name}, uid, component.{name});");
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -256,8 +256,7 @@ public partial class EntityManager
|
||||
/// <inheritdoc />
|
||||
public HashSet<EntityUid> GetEntitySet(HashSet<NetEntity> netEntities)
|
||||
{
|
||||
var entities = new HashSet<EntityUid>();
|
||||
entities.EnsureCapacity(netEntities.Count);
|
||||
var entities = new HashSet<EntityUid>(netEntities.Count);
|
||||
|
||||
foreach (var netEntity in netEntities)
|
||||
{
|
||||
@@ -292,6 +291,16 @@ public partial class EntityManager
|
||||
return entities;
|
||||
}
|
||||
|
||||
public void EnsureEntitySet<T>(HashSet<NetEntity> netEntities, EntityUid callerEntity, HashSet<EntityUid> entities)
|
||||
{
|
||||
entities.Clear();
|
||||
entities.EnsureCapacity(netEntities.Count);
|
||||
foreach (var netEntity in netEntities)
|
||||
{
|
||||
entities.Add(EnsureEntity<T>(netEntity, callerEntity));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<EntityUid> EnsureEntityList<T>(List<NetEntity> netEntities, EntityUid callerEntity)
|
||||
{
|
||||
@@ -305,6 +314,16 @@ public partial class EntityManager
|
||||
return entities;
|
||||
}
|
||||
|
||||
public void EnsureEntityList<T>(List<NetEntity> netEntities, EntityUid callerEntity, List<EntityUid> entities)
|
||||
{
|
||||
entities.Clear();
|
||||
entities.EnsureCapacity(netEntities.Count);
|
||||
foreach (var netEntity in netEntities)
|
||||
{
|
||||
entities.Add(EnsureEntity<T>(netEntity, callerEntity));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<EntityUid> GetEntityList(ICollection<NetEntity> netEntities)
|
||||
{
|
||||
|
||||
@@ -1024,12 +1024,24 @@ public partial class EntitySystem
|
||||
return EntityManager.EnsureEntitySet<T>(netEntities, callerEntity);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void EnsureEntitySet<T>(HashSet<NetEntity> netEntities, EntityUid callerEntity, HashSet<EntityUid> entities)
|
||||
{
|
||||
EntityManager.EnsureEntitySet<T>(netEntities, callerEntity, entities);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected List<EntityUid> EnsureEntityList<T>(List<NetEntity> netEntities, EntityUid callerEntity)
|
||||
{
|
||||
return EntityManager.EnsureEntityList<T>(netEntities, callerEntity);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected void EnsureEntityList<T>(List<NetEntity> netEntities, EntityUid callerEntity, List<EntityUid> entities)
|
||||
{
|
||||
EntityManager.EnsureEntityList<T>(netEntities, callerEntity, entities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="EntityUid"/> of a <see cref="NetEntity"/>. Returns <see cref="EntityUid.Invalid"/> if it doesn't exist.
|
||||
/// </summary>
|
||||
|
||||
@@ -43,8 +43,7 @@ public abstract partial class SharedJointSystem
|
||||
if (args.Current is not JointRelayComponentState state)
|
||||
return;
|
||||
|
||||
component.Relayed.Clear();
|
||||
component.Relayed.UnionWith(EnsureEntitySet<JointRelayTargetComponent>(state.Entities, uid));
|
||||
EnsureEntitySet<JointRelayTargetComponent>(state.Entities, uid, component.Relayed);
|
||||
}
|
||||
|
||||
private void OnRelayShutdown(EntityUid uid, JointRelayTargetComponent component, ComponentShutdown args)
|
||||
|
||||
Reference in New Issue
Block a user