Remove more IoCManager IEntityManager resolves

This commit is contained in:
Vera Aguilera Puerto
2021-12-08 10:40:19 +01:00
parent 8985a672de
commit 4919f1db69
4 changed files with 41 additions and 39 deletions

View File

@@ -26,6 +26,7 @@ namespace Content.Client.IconSmoothing
[RegisterComponent] [RegisterComponent]
public class IconSmoothComponent : Component public class IconSmoothComponent : Component
{ {
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[DataField("mode")] [DataField("mode")]
@@ -63,7 +64,7 @@ namespace Content.Client.IconSmoothing
{ {
base.Initialize(); base.Initialize();
Sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(Owner); Sprite = _entMan.GetComponent<ISpriteComponent>(Owner);
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -71,12 +72,12 @@ namespace Content.Client.IconSmoothing
{ {
base.Startup(); base.Startup();
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored) if (_entMan.GetComponent<TransformComponent>(Owner).Anchored)
{ {
// ensures lastposition initial value is populated on spawn. Just calling // ensures lastposition initial value is populated on spawn. Just calling
// the hook here would cause a dirty event to fire needlessly // the hook here would cause a dirty event to fire needlessly
UpdateLastPosition(); UpdateLastPosition();
IoCManager.Resolve<IEntityManager>().EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, null, Mode)); _entMan.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, null, Mode));
} }
if (Sprite != null && Mode == IconSmoothingMode.Corners) if (Sprite != null && Mode == IconSmoothingMode.Corners)
@@ -95,9 +96,9 @@ namespace Content.Client.IconSmoothing
private void UpdateLastPosition() private void UpdateLastPosition()
{ {
if (_mapManager.TryGetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID, out var grid)) if (_mapManager.TryGetGrid(_entMan.GetComponent<TransformComponent>(Owner).GridID, out var grid))
{ {
_lastPosition = (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID, grid.TileIndicesFor(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates)); _lastPosition = (_entMan.GetComponent<TransformComponent>(Owner).GridID, grid.TileIndicesFor(_entMan.GetComponent<TransformComponent>(Owner).Coordinates));
} }
else else
{ {
@@ -109,9 +110,9 @@ namespace Content.Client.IconSmoothing
internal virtual void CalculateNewSprite() internal virtual void CalculateNewSprite()
{ {
if (!_mapManager.TryGetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID, out var grid)) if (!_mapManager.TryGetGrid(_entMan.GetComponent<TransformComponent>(Owner).GridID, out var grid))
{ {
Logger.Error($"Failed to calculate IconSmoothComponent sprite in {Owner} because grid {IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID} was missing."); Logger.Error($"Failed to calculate IconSmoothComponent sprite in {Owner} because grid {_entMan.GetComponent<TransformComponent>(Owner).GridID} was missing.");
return; return;
} }
CalculateNewSprite(grid); CalculateNewSprite(grid);
@@ -136,14 +137,14 @@ namespace Content.Client.IconSmoothing
private void CalculateNewSpriteCardinal(IMapGrid grid) private void CalculateNewSpriteCardinal(IMapGrid grid)
{ {
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored || Sprite == null) if (!_entMan.GetComponent<TransformComponent>(Owner).Anchored || Sprite == null)
{ {
return; return;
} }
var dirs = CardinalConnectDirs.None; var dirs = CardinalConnectDirs.None;
var position = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates; var position = _entMan.GetComponent<TransformComponent>(Owner).Coordinates;
if (MatchingEntity(grid.GetInDir(position, Direction.North))) if (MatchingEntity(grid.GetInDir(position, Direction.North)))
dirs |= CardinalConnectDirs.North; dirs |= CardinalConnectDirs.North;
if (MatchingEntity(grid.GetInDir(position, Direction.South))) if (MatchingEntity(grid.GetInDir(position, Direction.South)))
@@ -173,12 +174,12 @@ namespace Content.Client.IconSmoothing
protected (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(IMapGrid grid) protected (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill(IMapGrid grid)
{ {
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored) if (!_entMan.GetComponent<TransformComponent>(Owner).Anchored)
{ {
return (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None); return (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None);
} }
var position = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates; var position = _entMan.GetComponent<TransformComponent>(Owner).Coordinates;
var n = MatchingEntity(grid.GetInDir(position, Direction.North)); var n = MatchingEntity(grid.GetInDir(position, Direction.North));
var ne = MatchingEntity(grid.GetInDir(position, Direction.NorthEast)); var ne = MatchingEntity(grid.GetInDir(position, Direction.NorthEast));
var e = MatchingEntity(grid.GetInDir(position, Direction.East)); var e = MatchingEntity(grid.GetInDir(position, Direction.East));
@@ -240,7 +241,7 @@ namespace Content.Client.IconSmoothing
} }
// Local is fine as we already know it's parented to the grid (due to the way anchoring works). // Local is fine as we already know it's parented to the grid (due to the way anchoring works).
switch (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).LocalRotation.GetCardinalDir()) switch (_entMan.GetComponent<TransformComponent>(Owner).LocalRotation.GetCardinalDir())
{ {
case Direction.North: case Direction.North:
return (cornerSW, cornerSE, cornerNE, cornerNW); return (cornerSW, cornerSE, cornerNE, cornerNW);
@@ -258,17 +259,17 @@ namespace Content.Client.IconSmoothing
{ {
base.Shutdown(); base.Shutdown();
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored) if (_entMan.GetComponent<TransformComponent>(Owner).Anchored)
{ {
IoCManager.Resolve<IEntityManager>().EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode)); _entMan.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode));
} }
} }
public void AnchorStateChanged() public void AnchorStateChanged()
{ {
if (IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored) if (_entMan.GetComponent<TransformComponent>(Owner).Anchored)
{ {
IoCManager.Resolve<IEntityManager>().EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode)); _entMan.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode));
UpdateLastPosition(); UpdateLastPosition();
} }
} }
@@ -278,7 +279,7 @@ namespace Content.Client.IconSmoothing
{ {
foreach (var entity in candidates) foreach (var entity in candidates)
{ {
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out IconSmoothComponent? other)) if (!_entMan.TryGetComponent(entity, out IconSmoothComponent? other))
{ {
continue; continue;
} }

View File

@@ -15,6 +15,7 @@ namespace Content.Server.Construction.Components
[RegisterComponent] [RegisterComponent]
public class MachineFrameComponent : Component, IInteractUsing public class MachineFrameComponent : Component, IInteractUsing
{ {
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!; [Dependency] private readonly IComponentFactory _componentFactory = default!;
public const string PartContainer = "machine_parts"; public const string PartContainer = "machine_parts";
@@ -121,7 +122,7 @@ namespace Content.Server.Construction.Components
RegenerateProgress(); RegenerateProgress();
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ConstructionComponent?>(Owner, out var construction)) if (_entMan.TryGetComponent<ConstructionComponent?>(Owner, out var construction))
{ {
// Attempt to set pathfinding to the machine node... // Attempt to set pathfinding to the machine node...
EntitySystem.Get<ConstructionSystem>().SetPathfindingTarget(Owner, "machine", construction); EntitySystem.Get<ConstructionSystem>().SetPathfindingTarget(Owner, "machine", construction);
@@ -167,7 +168,7 @@ namespace Content.Server.Construction.Components
if (!HasBoard) if (!HasBoard)
{ {
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out appearance)) if (_entMan.TryGetComponent(Owner, out appearance))
{ {
appearance.SetData(MachineFrameVisuals.State, 1); appearance.SetData(MachineFrameVisuals.State, 1);
} }
@@ -186,10 +187,10 @@ namespace Content.Server.Construction.Components
var board = _boardContainer.ContainedEntities[0]; var board = _boardContainer.ContainedEntities[0];
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(board, out var machineBoard)) if (!_entMan.TryGetComponent<MachineBoardComponent?>(board, out var machineBoard))
return; return;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out appearance)) if (_entMan.TryGetComponent(Owner, out appearance))
{ {
appearance.SetData(MachineFrameVisuals.State, 2); appearance.SetData(MachineFrameVisuals.State, 2);
} }
@@ -198,7 +199,7 @@ namespace Content.Server.Construction.Components
foreach (var part in _partContainer.ContainedEntities) foreach (var part in _partContainer.ContainedEntities)
{ {
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(part, out var machinePart)) if (_entMan.TryGetComponent<MachinePartComponent?>(part, out var machinePart))
{ {
// Check this is part of the requirements... // Check this is part of the requirements...
if (!Requirements.ContainsKey(machinePart.PartType)) if (!Requirements.ContainsKey(machinePart.PartType))
@@ -210,7 +211,7 @@ namespace Content.Server.Construction.Components
_progress[machinePart.PartType]++; _progress[machinePart.PartType]++;
} }
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(part, out var stack)) if (_entMan.TryGetComponent<StackComponent?>(part, out var stack))
{ {
var type = stack.StackTypeId; var type = stack.StackTypeId;
// Check this is part of the requirements... // Check this is part of the requirements...
@@ -228,7 +229,7 @@ namespace Content.Server.Construction.Components
{ {
var registration = _componentFactory.GetRegistration(compName); var registration = _componentFactory.GetRegistration(compName);
if (!IoCManager.Resolve<IEntityManager>().HasComponent(part, registration.Type)) if (!_entMan.HasComponent(part, registration.Type))
continue; continue;
if (!_componentProgress.ContainsKey(compName)) if (!_componentProgress.ContainsKey(compName))
@@ -253,7 +254,7 @@ namespace Content.Server.Construction.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{ {
if (!HasBoard && IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(eventArgs.Using, out var machineBoard)) if (!HasBoard && _entMan.TryGetComponent<MachineBoardComponent?>(eventArgs.Using, out var machineBoard))
{ {
if (eventArgs.Using.TryRemoveFromContainer()) if (eventArgs.Using.TryRemoveFromContainer())
{ {
@@ -263,12 +264,12 @@ namespace Content.Server.Construction.Components
// Setup requirements and progress... // Setup requirements and progress...
ResetProgressAndRequirements(machineBoard); ResetProgressAndRequirements(machineBoard);
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(Owner, out var appearance)) if (_entMan.TryGetComponent<AppearanceComponent?>(Owner, out var appearance))
{ {
appearance.SetData(MachineFrameVisuals.State, 2); appearance.SetData(MachineFrameVisuals.State, 2);
} }
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ConstructionComponent? construction)) if (_entMan.TryGetComponent(Owner, out ConstructionComponent? construction))
{ {
// So prying the components off works correctly. // So prying the components off works correctly.
EntitySystem.Get<ConstructionSystem>().ResetEdge(Owner, construction); EntitySystem.Get<ConstructionSystem>().ResetEdge(Owner, construction);
@@ -279,7 +280,7 @@ namespace Content.Server.Construction.Components
} }
else if (HasBoard) else if (HasBoard)
{ {
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(eventArgs.Using, out var machinePart)) if (_entMan.TryGetComponent<MachinePartComponent?>(eventArgs.Using, out var machinePart))
{ {
if (!Requirements.ContainsKey(machinePart.PartType)) if (!Requirements.ContainsKey(machinePart.PartType))
return false; return false;
@@ -292,7 +293,7 @@ namespace Content.Server.Construction.Components
} }
} }
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(eventArgs.Using, out var stack)) if (_entMan.TryGetComponent<StackComponent?>(eventArgs.Using, out var stack))
{ {
var type = stack.StackTypeId; var type = stack.StackTypeId;
if (!MaterialRequirements.ContainsKey(type)) if (!MaterialRequirements.ContainsKey(type))
@@ -313,7 +314,7 @@ namespace Content.Server.Construction.Components
return true; return true;
} }
var splitStack = EntitySystem.Get<StackSystem>().Split(eventArgs.Using, needed, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates, stack); var splitStack = EntitySystem.Get<StackSystem>().Split(eventArgs.Using, needed, _entMan.GetComponent<TransformComponent>(Owner).Coordinates, stack);
if (splitStack == null) if (splitStack == null)
return false; return false;
@@ -332,7 +333,7 @@ namespace Content.Server.Construction.Components
var registration = _componentFactory.GetRegistration(compName); var registration = _componentFactory.GetRegistration(compName);
if (!IoCManager.Resolve<IEntityManager>().HasComponent(eventArgs.Using, registration.Type)) if (!_entMan.HasComponent(eventArgs.Using, registration.Type))
continue; continue;
if (!eventArgs.Using.TryRemoveFromContainer() || !_partContainer.Insert(eventArgs.Using)) continue; if (!eventArgs.Using.TryRemoveFromContainer() || !_partContainer.Insert(eventArgs.Using)) continue;

View File

@@ -73,7 +73,7 @@ namespace Content.Server.Light.EntitySystems
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
var entity = EntityManager.SpawnEntity(prototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(light.Owner).Coordinates); var entity = EntityManager.SpawnEntity(prototype, EntityManager.GetComponent<TransformComponent>(light.Owner).Coordinates);
light.LightBulbContainer.Insert(entity); light.LightBulbContainer.Insert(entity);
} }
@@ -336,7 +336,7 @@ namespace Content.Server.Light.EntitySystems
light.IsBlinking = isNowBlinking; light.IsBlinking = isNowBlinking;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(light.Owner, out AppearanceComponent? appearance)) if (!EntityManager.TryGetComponent(light.Owner, out AppearanceComponent? appearance))
return; return;
appearance.SetData(PoweredLightVisuals.Blinking, isNowBlinking); appearance.SetData(PoweredLightVisuals.Blinking, isNowBlinking);
} }

View File

@@ -55,7 +55,7 @@ namespace Content.Shared.Singularity
value = Math.Clamp(value, 0, 6); value = Math.Clamp(value, 0, 6);
var physics = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<PhysicsComponent>(singularity.Owner); var physics = EntityManager.GetComponentOrNull<PhysicsComponent>(singularity.Owner);
if (singularity.Level > 1 && value <= 1) if (singularity.Level > 1 && value <= 1)
{ {
@@ -68,12 +68,12 @@ namespace Content.Shared.Singularity
singularity.Level = value; singularity.Level = value;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(singularity.Owner, out SharedRadiationPulseComponent? pulse)) if (EntityManager.TryGetComponent(singularity.Owner, out SharedRadiationPulseComponent? pulse))
{ {
pulse.RadsPerSecond = 10 * value; pulse.RadsPerSecond = 10 * value;
} }
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(singularity.Owner, out AppearanceComponent? appearance)) if (EntityManager.TryGetComponent(singularity.Owner, out AppearanceComponent? appearance))
{ {
appearance.SetData(SingularityVisuals.Level, value); appearance.SetData(SingularityVisuals.Level, value);
} }
@@ -83,7 +83,7 @@ namespace Content.Shared.Singularity
circle.Radius = value - 0.5f; circle.Radius = value - 0.5f;
} }
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(singularity.Owner, out SingularityDistortionComponent? distortion)) if (EntityManager.TryGetComponent(singularity.Owner, out SingularityDistortionComponent? distortion))
{ {
distortion.Falloff = GetFalloff(value); distortion.Falloff = GetFalloff(value);
distortion.Intensity = GetIntensity(value); distortion.Intensity = GetIntensity(value);
@@ -102,8 +102,8 @@ namespace Content.Shared.Singularity
{ {
var other = args.BodyB.Owner; var other = args.BodyB.Owner;
if ((!IoCManager.Resolve<IEntityManager>().HasComponent<SharedContainmentFieldComponent>(other) && if ((!EntityManager.HasComponent<SharedContainmentFieldComponent>(other) &&
!IoCManager.Resolve<IEntityManager>().HasComponent<SharedContainmentFieldGeneratorComponent>(other)) || !EntityManager.HasComponent<SharedContainmentFieldGeneratorComponent>(other)) ||
component.Level >= 4) component.Level >= 4)
{ {
args.Cancel(); args.Cancel();