Replace IEntityManager resolves in systems for cached EntityManager
This commit is contained in:
@@ -57,7 +57,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
if (slot.HasItem || string.IsNullOrEmpty(slot.StartingItem))
|
||||
continue;
|
||||
|
||||
var item = EntityManager.SpawnEntity(slot.StartingItem, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(itemSlots.Owner).Coordinates);
|
||||
var item = EntityManager.SpawnEntity(slot.StartingItem, EntityManager.GetComponent<TransformComponent>(itemSlots.Owner).Coordinates);
|
||||
slot.ContainerSlot.Insert(item);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
var itemSlots = EntityManager.EnsureComponent<ItemSlotsComponent>(uid);
|
||||
slot.ContainerSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(itemSlots.Owner, id);
|
||||
if (itemSlots.Slots.ContainsKey(id))
|
||||
Logger.Error($"Duplicate item slot key. Entity: {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(itemSlots.Owner).EntityName} ({uid}), key: {id}");
|
||||
Logger.Error($"Duplicate item slot key. Entity: {EntityManager.GetComponent<MetaDataComponent>(itemSlots.Owner).EntityName} ({uid}), key: {id}");
|
||||
itemSlots.Slots[id] = slot;
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
|
||||
var verbSubject = slot.Name != string.Empty
|
||||
? Loc.GetString(slot.Name)
|
||||
: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
: EntityManager.GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Act = () => TryEjectToHands(uid, slot, args.User);
|
||||
@@ -399,7 +399,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
|
||||
var verbSubject = slot.Name != string.Empty
|
||||
? Loc.GetString(slot.Name)
|
||||
: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
: EntityManager.GetComponent<MetaDataComponent>(slot.Item!.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb takeVerb = new();
|
||||
takeVerb.Act = () => TryEjectToHands(uid, slot, args.User);
|
||||
@@ -425,7 +425,7 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
|
||||
var verbSubject = slot.Name != string.Empty
|
||||
? Loc.GetString(slot.Name)
|
||||
: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(args.Using.Value).EntityName ?? string.Empty;
|
||||
: EntityManager.GetComponent<MetaDataComponent>(args.Using.Value).EntityName ?? string.Empty;
|
||||
|
||||
Verb insertVerb = new();
|
||||
insertVerb.Act = () => Insert(uid, slot, args.Using.Value);
|
||||
|
||||
@@ -49,21 +49,21 @@ namespace Content.Shared.Disposal
|
||||
|
||||
public virtual bool CanInsert(SharedDisposalUnitComponent component, EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(component.Owner).Anchored)
|
||||
if (!EntityManager.GetComponent<TransformComponent>(component.Owner).Anchored)
|
||||
return false;
|
||||
|
||||
// TODO: Probably just need a disposable tag.
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out SharedItemComponent? storable) &&
|
||||
!IoCManager.Resolve<IEntityManager>().HasComponent<SharedBodyComponent>(entity))
|
||||
if (!EntityManager.TryGetComponent(entity, out SharedItemComponent? storable) &&
|
||||
!EntityManager.HasComponent<SharedBodyComponent>(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IPhysBody? physics) ||
|
||||
if (!EntityManager.TryGetComponent(entity, out IPhysBody? physics) ||
|
||||
!physics.CanCollide && storable == null)
|
||||
{
|
||||
if (!(IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out MobStateComponent? damageState) && damageState.IsDead()))
|
||||
if (!(EntityManager.TryGetComponent(entity, out MobStateComponent? damageState) && damageState.IsDead()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,24 +64,24 @@ namespace Content.Shared.Examine
|
||||
[Pure]
|
||||
public bool CanExamine(EntityUid examiner, EntityUid examined)
|
||||
{
|
||||
return CanExamine(examiner, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(examined).MapPosition,
|
||||
return CanExamine(examiner, EntityManager.GetComponent<TransformComponent>(examined).MapPosition,
|
||||
entity => entity == examiner || entity == examined);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public virtual bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(examiner, out ExaminerComponent? examinerComponent))
|
||||
if (!EntityManager.TryGetComponent(examiner, out ExaminerComponent? examinerComponent))
|
||||
return false;
|
||||
|
||||
if (!examinerComponent.DoRangeCheck)
|
||||
return true;
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(examiner).MapID != target.MapId)
|
||||
if (EntityManager.GetComponent<TransformComponent>(examiner).MapID != target.MapId)
|
||||
return false;
|
||||
|
||||
return InRangeUnOccluded(
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(examiner).MapPosition,
|
||||
EntityManager.GetComponent<TransformComponent>(examiner).MapPosition,
|
||||
target,
|
||||
GetExaminerRange(examiner),
|
||||
predicate: predicate,
|
||||
@@ -128,12 +128,12 @@ namespace Content.Shared.Examine
|
||||
|
||||
foreach (var result in rayResults)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(result.HitEntity, out OccluderComponent? o))
|
||||
if (!EntityManager.TryGetComponent(result.HitEntity, out OccluderComponent? o))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var bBox = o.BoundingBox.Translated(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(o.Owner).WorldPosition);
|
||||
var bBox = o.BoundingBox.Translated(EntityManager.GetComponent<TransformComponent>(o.Owner).WorldPosition);
|
||||
|
||||
if (bBox.Contains(origin.Position) || bBox.Contains(other.Position))
|
||||
{
|
||||
@@ -148,54 +148,54 @@ namespace Content.Shared.Examine
|
||||
|
||||
public static bool InRangeUnOccluded(EntityUid origin, EntityUid other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(other).MapPosition;
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = EntityManager.GetComponent<TransformComponent>(other).MapPosition;
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(EntityUid origin, IComponent other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(other.Owner).MapPosition;
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = EntityManager.GetComponent<TransformComponent>(other.Owner).MapPosition;
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(EntityUid origin, EntityCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = other.ToMap(IoCManager.Resolve<IEntityManager>());
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var otherPos = other.ToMap(EntityManager);
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(EntityUid origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(origin).MapPosition;
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(origin).MapPosition;
|
||||
|
||||
return InRangeUnOccluded(originPos, other, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(ITargetedInteractEventArgs args, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).MapPosition;
|
||||
var otherPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Target).MapPosition;
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(args.User).MapPosition;
|
||||
var otherPos = EntityManager.GetComponent<TransformComponent>(args.Target).MapPosition;
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(DragDropEvent args, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.User).MapPosition;
|
||||
var otherPos = args.DropLocation.ToMap(IoCManager.Resolve<IEntityManager>());
|
||||
var originPos = EntityManager.GetComponent<TransformComponent>(args.User).MapPosition;
|
||||
var otherPos = args.DropLocation.ToMap(EntityManager);
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
public static bool InRangeUnOccluded(AfterInteractEventArgs args, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var entityManager = EntityManager;
|
||||
var originPos = entityManager.GetComponent<TransformComponent>(args.User).MapPosition;
|
||||
var target = args.Target;
|
||||
var otherPos = (target != null ? entityManager.GetComponent<TransformComponent>(target.Value).MapPosition : args.ClickLocation.ToMap(entityManager));
|
||||
@@ -215,9 +215,9 @@ namespace Content.Shared.Examine
|
||||
var doNewline = false;
|
||||
|
||||
//Add an entity description if one is declared
|
||||
if (!string.IsNullOrEmpty(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityDescription))
|
||||
if (!string.IsNullOrEmpty(EntityManager.GetComponent<MetaDataComponent>(entity).EntityDescription))
|
||||
{
|
||||
message.AddText(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityDescription);
|
||||
message.AddText(EntityManager.GetComponent<MetaDataComponent>(entity).EntityDescription);
|
||||
doNewline = true;
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace Content.Shared.Examine
|
||||
RaiseLocalEvent(entity, examinedEvent);
|
||||
|
||||
//Add component statuses from components that report one
|
||||
foreach (var examineComponent in IoCManager.Resolve<IEntityManager>().GetComponents<IExamine>(entity))
|
||||
foreach (var examineComponent in EntityManager.GetComponents<IExamine>(entity))
|
||||
{
|
||||
var subMessage = new FormattedMessage();
|
||||
examineComponent.Examine(subMessage, isInDetailsRange);
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Shared.Interaction
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
public bool TryFaceCoordinates(EntityUid user, Vector2 coordinates)
|
||||
{
|
||||
var diff = coordinates - IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).MapPosition.Position;
|
||||
var diff = coordinates - EntityManager.GetComponent<TransformComponent>(user).MapPosition.Position;
|
||||
if (diff.LengthSquared <= 0.01f)
|
||||
return true;
|
||||
var diffAngle = Angle.FromWorldVec(diff);
|
||||
@@ -47,12 +47,12 @@ namespace Content.Shared.Interaction
|
||||
{
|
||||
if (_actionBlockerSystem.CanChangeDirection(user))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(user).WorldRotation = diffAngle;
|
||||
EntityManager.GetComponent<TransformComponent>(user).WorldRotation = diffAngle;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(user, out SharedBuckleComponent? buckle) && buckle.Buckled)
|
||||
if (EntityManager.TryGetComponent(user, out SharedBuckleComponent? buckle) && buckle.Buckled)
|
||||
{
|
||||
var suid = buckle.LastEntityBuckledTo;
|
||||
if (suid != null)
|
||||
@@ -64,7 +64,7 @@ namespace Content.Shared.Interaction
|
||||
// (Since the user being buckled to it holds it down with their weight.)
|
||||
// This is logically equivalent to RotateWhileAnchored.
|
||||
// Barstools and office chairs have independent wheels, while regular chairs don't.
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(rotatable.Owner).WorldRotation = diffAngle;
|
||||
EntityManager.GetComponent<TransformComponent>(rotatable.Owner).WorldRotation = diffAngle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
|
||||
if (otherBody.BodyType != BodyType.Dynamic || !otherFixture.Hard) return;
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ourFixture.Body.Owner, out IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrength * frameTime);
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ namespace Content.Shared.Movement.EntitySystems
|
||||
|
||||
var ent = session?.AttachedEntity;
|
||||
|
||||
if (ent == null || !IoCManager.Resolve<IEntityManager>().EntityExists(ent.Value))
|
||||
if (ent == null || !EntityManager.EntityExists(ent.Value))
|
||||
return false;
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ent.Value, out T? comp))
|
||||
if (!EntityManager.TryGetComponent(ent.Value, out T? comp))
|
||||
return false;
|
||||
|
||||
component = comp;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Content.Shared.Nutrition.EntitySystems
|
||||
|
||||
private void OnCreamPiedHitBy(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().EntityExists(args.Thrown) || !IoCManager.Resolve<IEntityManager>().TryGetComponent(args.Thrown, out CreamPieComponent? creamPie)) return;
|
||||
if (!EntityManager.EntityExists(args.Thrown) || !EntityManager.TryGetComponent(args.Thrown, out CreamPieComponent? creamPie)) return;
|
||||
|
||||
SetCreamPied(uid, creamPied, true);
|
||||
|
||||
|
||||
@@ -52,19 +52,19 @@ namespace Content.Shared.Placeable
|
||||
if (!surface.IsPlaceable)
|
||||
return;
|
||||
|
||||
if(!IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedHandsComponent?>(args.User, out var handComponent))
|
||||
if(!EntityManager.TryGetComponent<SharedHandsComponent?>(args.User, out var handComponent))
|
||||
return;
|
||||
|
||||
if (!args.ClickLocation.IsValid(IoCManager.Resolve<IEntityManager>()))
|
||||
if (!args.ClickLocation.IsValid(EntityManager))
|
||||
return;
|
||||
|
||||
if(!handComponent.TryDropEntity(args.Used, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(surface.Owner).Coordinates))
|
||||
if(!handComponent.TryDropEntity(args.Used, EntityManager.GetComponent<TransformComponent>(surface.Owner).Coordinates))
|
||||
return;
|
||||
|
||||
if (surface.PlaceCentered)
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Used).LocalPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Target).LocalPosition + surface.PositionOffset;
|
||||
EntityManager.GetComponent<TransformComponent>(args.Used).LocalPosition = EntityManager.GetComponent<TransformComponent>(args.Target).LocalPosition + surface.PositionOffset;
|
||||
else
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(args.Used).Coordinates = args.ClickLocation;
|
||||
EntityManager.GetComponent<TransformComponent>(args.Used).Coordinates = args.ClickLocation;
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user