Remove many resolves on Content.Server
This commit is contained in:
@@ -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"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user