Add a check for construction ghosts beeing present to ConstructionSystem/SpawnGhost (#1642)

This commit is contained in:
Julian Giebel
2020-08-11 01:55:18 +02:00
committed by GitHub
parent b7dbd74947
commit 27bbb89fbf

View File

@@ -153,6 +153,11 @@ namespace Content.Client.GameObjects.EntitySystems
/// </summary>
public void SpawnGhost(ConstructionPrototype prototype, GridCoordinates loc, Direction dir)
{
if (GhostPresent(loc))
{
return;
}
var ghost = _entityManager.SpawnEntity("constructionghost", loc);
var comp = ghost.GetComponent<ConstructionGhostComponent>();
comp.Prototype = prototype;
@@ -167,6 +172,22 @@ namespace Content.Client.GameObjects.EntitySystems
sprite.LayerSetVisible(0, true);
}
/// <summary>
/// Checks if any construction ghosts are present at the given position
/// </summary>
private bool GhostPresent(GridCoordinates loc)
{
foreach (KeyValuePair<int, ConstructionGhostComponent> ghost in _ghosts)
{
if (ghost.Value.Owner.Transform.GridPosition.Equals(loc))
{
return true;
}
}
return false;
}
private void TryStartConstruction(int ghostId)
{
var ghost = _ghosts[ghostId];