Log better error for incorrect Construction Graphs.

Also improves integration tests for them to catch more errors.
This commit is contained in:
Vera Aguilera Puerto
2022-03-04 16:53:06 +01:00
parent 0b0de4fe10
commit 37fb2bd3c7
2 changed files with 20 additions and 5 deletions

View File

@@ -234,10 +234,15 @@ namespace Content.Server.Construction
return null;
}
var newEntity = EntityManager.SpawnEntity(graph.Nodes[edge.Target].Entity, EntityManager.GetComponent<TransformComponent>(user).Coordinates);
var newEntityProto = graph.Nodes[edge.Target].Entity;
var newEntity = EntityManager.SpawnEntity(newEntityProto, EntityManager.GetComponent<TransformComponent>(user).Coordinates);
// Yes, this should throw if it's missing the component.
var construction = EntityManager.GetComponent<ConstructionComponent>(newEntity);
if (!TryComp(newEntity, out ConstructionComponent? construction))
{
_sawmill.Error($"Initial construction does not have a valid target entity! It is missing a ConstructionComponent.\nGraph: {graph.ID}, Initial Target: {edge.Target}, Ent. Prototype: {newEntityProto}\nCreated Entity {ToPrettyString(newEntity)} will be deleted.");
Del(newEntity); // Screw you, make proper construction graphs.
return null;
}
// We attempt to set the pathfinding target.
SetPathfindingTarget(newEntity, targetNode.Name, construction);