Remove many resolves on Content.Server

This commit is contained in:
Vera Aguilera Puerto
2021-12-08 17:04:21 +01:00
parent 420039f278
commit ba736f70df
72 changed files with 407 additions and 302 deletions

View File

@@ -74,7 +74,7 @@ namespace Content.Server.Construction.Commands
continue;
}
var prototype = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(child).EntityPrototype;
var prototype = entityManager.GetComponent<MetaDataComponent>(child).EntityPrototype;
while (true)
{
if (prototype?.Parent == null)
@@ -90,12 +90,14 @@ namespace Content.Server.Construction.Commands
continue;
}
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(child).Anchored)
var childTransform = entityManager.GetComponent<TransformComponent>(child);
if (!childTransform.Anchored)
{
continue;
}
var tile = grid.GetTileRef(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(child).Coordinates);
var tile = grid.GetTileRef(childTransform.Coordinates);
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
if (tileDef.Name == "underplating")
@@ -103,7 +105,7 @@ namespace Content.Server.Construction.Commands
continue;
}
grid.SetTile(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(child).Coordinates, underplatingTile);
grid.SetTile(childTransform.Coordinates, underplatingTile);
changed++;
}

View File

@@ -40,7 +40,7 @@ namespace Content.Server.Construction.Completions
var board = container.ContainedEntities[0];
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(board, out ComputerBoardComponent? boardComponent))
if (!entityManager.TryGetComponent(board, out ComputerBoardComponent? boardComponent))
{
Logger.Warning($"Computer entity {uid} had an invalid entity in container \"{Container}\"! Aborting build computer action.");
return;
@@ -50,7 +50,7 @@ namespace Content.Server.Construction.Completions
var transform = entityManager.GetComponent<TransformComponent>(uid);
var computer = entityManager.SpawnEntity(boardComponent.Prototype, transform.Coordinates);
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(computer).LocalRotation = transform.LocalRotation;
entityManager.GetComponent<TransformComponent>(computer).LocalRotation = transform.LocalRotation;
var computerContainer = containerSystem.EnsureContainer<Container>(computer, Container);
@@ -58,7 +58,7 @@ namespace Content.Server.Construction.Completions
foreach (var ent in computerContainer.ContainedEntities.ToArray())
{
computerContainer.ForceRemove(ent);
IoCManager.Resolve<IEntityManager>().DeleteEntity(ent);
entityManager.DeleteEntity(ent);
}
computerContainer.Insert(board);

View File

@@ -54,7 +54,7 @@ namespace Content.Server.Construction.Completions
var board = entBoardContainer.ContainedEntities[0];
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(board, out MachineBoardComponent? boardComponent))
if (!entityManager.TryGetComponent(board, out MachineBoardComponent? boardComponent))
{
Logger.Warning($"Machine frame entity {uid} had an invalid entity in container \"{MachineFrameComponent.BoardContainer}\"! Aborting build machine action.");
return;
@@ -64,7 +64,7 @@ namespace Content.Server.Construction.Completions
var transform = entityManager.GetComponent<TransformComponent>(uid);
var machine = entityManager.SpawnEntity(boardComponent.Prototype, transform.Coordinates);
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(machine).LocalRotation = transform.LocalRotation;
entityManager.GetComponent<TransformComponent>(machine).LocalRotation = transform.LocalRotation;
var boardContainer = machine.EnsureContainer<Container>(MachineFrameComponent.BoardContainer, out var existed);
@@ -92,14 +92,14 @@ namespace Content.Server.Construction.Completions
}
var constructionSystem = entityManager.EntitySysManager.GetEntitySystem<ConstructionSystem>();
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(machine, out ConstructionComponent? construction))
if (entityManager.TryGetComponent(machine, out ConstructionComponent? construction))
{
// We only add these two container. If some construction needs to take other containers into account, fix this.
constructionSystem.AddContainer(machine, MachineFrameComponent.BoardContainer, construction);
constructionSystem.AddContainer(machine, MachineFrameComponent.PartContainer, construction);
}
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(machine, out MachineComponent? machineComp))
if (entityManager.TryGetComponent(machine, out MachineComponent? machineComp))
{
machineComp.RefreshParts();
}

View File

@@ -22,7 +22,7 @@ namespace Content.Server.Construction.Completions
foreach (var contained in container.ContainedEntities.ToArray())
{
if(container.Remove(contained))
IoCManager.Resolve<IEntityManager>().QueueDeleteEntity(contained);
entityManager.QueueDeleteEntity(contained);
}
}
}

View File

@@ -25,8 +25,9 @@ namespace Content.Server.Construction.Completions
foreach (var contained in container.ContainedEntities.ToArray())
{
container.ForceRemove(contained);
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(contained).Coordinates = transform.Coordinates;
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(contained).AttachToGridOrMap();
var cTransform = entityManager.GetComponent<TransformComponent>(contained);
cTransform.Coordinates = transform.Coordinates;
cTransform.AttachToGridOrMap();
}
}
}

View File

@@ -26,7 +26,7 @@ namespace Content.Server.Construction.Completions
if (EntityPrototypeHelpers.HasComponent<StackComponent>(Prototype))
{
var stackEnt = entityManager.SpawnEntity(Prototype, coordinates);
var stack = IoCManager.Resolve<IEntityManager>().GetComponent<StackComponent>(stackEnt);
var stack = entityManager.GetComponent<StackComponent>(stackEnt);
entityManager.EntitySysManager.GetEntitySystem<StackSystem>().SetCount(stackEnt, Amount, stack);
}
else

View File

@@ -11,6 +11,8 @@ namespace Content.Server.Construction.Components
[RegisterComponent]
public class MachineComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entMan = default!;
public override string Name => "Machine";
[DataField("board")]
@@ -31,14 +33,14 @@ namespace Content.Server.Construction.Components
{
foreach (var entity in _partContainer.ContainedEntities)
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MachinePartComponent?>(entity, out var machinePart))
if (_entMan.TryGetComponent<MachinePartComponent?>(entity, out var machinePart))
yield return machinePart;
}
}
public void RefreshParts()
{
foreach (var refreshable in IoCManager.Resolve<IEntityManager>().GetComponents<IRefreshParts>(Owner))
foreach (var refreshable in _entMan.GetComponents<IRefreshParts>(Owner))
{
refreshable.RefreshParts(GetAllParts());
}
@@ -53,7 +55,7 @@ namespace Content.Server.Construction.Components
if (string.IsNullOrEmpty(BoardPrototype))
return;
var entityManager = IoCManager.Resolve<IEntityManager>();
var entityManager = _entMan;
if (existedBoard || existedParts)
{
@@ -62,14 +64,14 @@ namespace Content.Server.Construction.Components
return;
}
var board = entityManager.SpawnEntity(BoardPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var board = entityManager.SpawnEntity(BoardPrototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
if (!_boardContainer.Insert(board))
{
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}!");
throw new Exception($"Couldn't insert board with prototype {BoardPrototype} to machine with prototype {_entMan.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}!");
}
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<MachineBoardComponent?>(board, out var machineBoard))
if (!_entMan.TryGetComponent<MachineBoardComponent?>(board, out var machineBoard))
{
throw new Exception($"Entity with prototype {BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!");
}
@@ -78,29 +80,29 @@ namespace Content.Server.Construction.Components
{
for (var i = 0; i < amount; i++)
{
var p = entityManager.SpawnEntity(MachinePartComponent.Prototypes[part], IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var p = entityManager.SpawnEntity(MachinePartComponent.Prototypes[part], _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
if (!partContainer.Insert(p))
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}!");
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {_entMan.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}!");
}
}
foreach (var (stackType, amount) in machineBoard.MaterialRequirements)
{
var stack = EntitySystem.Get<StackSystem>().Spawn(amount, stackType, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var stack = EntitySystem.Get<StackSystem>().Spawn(amount, stackType, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
if (!partContainer.Insert(stack))
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {_entMan.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
}
foreach (var (compName, info) in machineBoard.ComponentRequirements)
{
for (var i = 0; i < info.Amount; i++)
{
var c = entityManager.SpawnEntity(info.DefaultPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var c = entityManager.SpawnEntity(info.DefaultPrototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
if(!partContainer.Insert(c))
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {_entMan.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
}
}
@@ -108,10 +110,10 @@ namespace Content.Server.Construction.Components
{
for (var i = 0; i < info.Amount; i++)
{
var c = entityManager.SpawnEntity(info.DefaultPrototype, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
var c = entityManager.SpawnEntity(info.DefaultPrototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
if(!partContainer.Insert(c))
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {_entMan.GetComponent<MetaDataComponent>(Owner).EntityPrototype?.ID ?? "N/A"}");
}
}
}

View File

@@ -19,6 +19,8 @@ namespace Content.Server.Construction.Components
[RegisterComponent]
public class WelderRefinableComponent : Component, IInteractUsing
{
[Dependency] private readonly IEntityManager _entMan = default!;
[DataField("refineResult")]
private HashSet<string>? _refineResult = new() { };
@@ -38,7 +40,7 @@ namespace Content.Server.Construction.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
// check if object is welder
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Using, out ToolComponent? tool))
if (!_entMan.TryGetComponent(eventArgs.Using, out ToolComponent? tool))
return false;
// check if someone is already welding object
@@ -57,17 +59,17 @@ namespace Content.Server.Construction.Components
}
// get last owner coordinates and delete it
var resultPosition = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates;
IoCManager.Resolve<IEntityManager>().DeleteEntity(Owner);
var resultPosition = _entMan.GetComponent<TransformComponent>(Owner).Coordinates;
_entMan.DeleteEntity(Owner);
// spawn each result after refine
foreach (var result in _refineResult!)
{
var droppedEnt = IoCManager.Resolve<IEntityManager>().SpawnEntity(result, resultPosition);
var droppedEnt = _entMan.SpawnEntity(result, resultPosition);
// TODO: If something has a stack... Just use a prototype with a single thing in the stack.
// This is not a good way to do it.
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<StackComponent?>(droppedEnt, out var stack))
if (_entMan.TryGetComponent<StackComponent?>(droppedEnt, out var stack))
EntitySystem.Get<StackSystem>().SetCount(droppedEnt,1, stack);
}

View File

@@ -31,14 +31,16 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out AirlockComponent? airlock)) return false;
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent(entity, out AirlockComponent? airlock)) return false;
if (airlock.BoltsDown != Value)
{
if (Value == true)
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-bolt", ("entityName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-bolt", ("entityName", Name: entMan.GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
else
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-unbolt", ("entityName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-unbolt", ("entityName", Name: entMan.GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
return true;
}

View File

@@ -56,7 +56,7 @@ namespace Content.Server.Construction.Conditions
foreach (var ent in entities)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent(ent, type))
if (entityManager.HasComponent(ent, type))
return HasEntity;
}

View File

@@ -29,14 +29,16 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ServerDoorComponent? door)) return false;
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent(entity, out ServerDoorComponent? door)) return false;
if (door.IsWeldedShut != Welded)
{
if (Welded == true)
args.PushMarkup(Loc.GetString("construction-examine-condition-door-weld", ("entityName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
args.PushMarkup(Loc.GetString("construction-examine-condition-door-weld", ("entityName", Name: entMan.GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
else
args.PushMarkup(Loc.GetString("construction-examine-condition-door-unweld", ("entityName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
args.PushMarkup(Loc.GetString("construction-examine-condition-door-unweld", ("entityName", Name: entMan.GetComponent<MetaDataComponent>(entity).EntityName)) + "\n");
return true;
}

View File

@@ -28,12 +28,14 @@ namespace Content.Server.Construction.Conditions
{
var entity = args.Examined;
var anchored = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Anchored;
switch (Anchored)
{
case true when !IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Anchored:
case true when !anchored:
args.PushMarkup(Loc.GetString("construction-examine-condition-entity-anchored"));
return true;
case false when IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).Anchored:
case false when anchored:
args.PushMarkup(Loc.GetString("construction-examine-condition-entity-unanchored"));
return true;
}