Skip to content

Commit

Permalink
more placement manager fixes (#5186)
Browse files Browse the repository at this point in the history
* more placement manager fixes

* Update Robust.Shared/GameObjects/EntityManager.cs

Co-authored-by: ShadowCommander <[email protected]>

---------

Co-authored-by: ShadowCommander <[email protected]>
  • Loading branch information
EmoGarbage404 and ShadowCommander authored Jun 1, 2024
1 parent 895bfb8 commit 783d529
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Robust.Server/Placement/PlacementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void HandlePlacementRequest(MsgPlacement msg)
}
}

var created = _entityManager.Spawn(entityTemplateName, _xformSystem.ToMapCoordinates(coordinates), rotation: dirRcv.ToAngle());
var created = _entityManager.SpawnAttachedTo(entityTemplateName, coordinates, rotation: dirRcv.ToAngle());

var placementCreateEvent = new PlacementEntityEvent(created, coordinates, PlacementEventAction.Create, msg.MsgChannel.UserId);
_entityManager.EventBus.RaiseEvent(EventSource.Local, placementCreateEvent);
Expand Down
4 changes: 2 additions & 2 deletions Robust.Shared/GameObjects/EntityManager.Spawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public EntityUid[] SpawnEntities(MapCoordinates coordinates, List<string?> proto
return ents;
}

public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null)
public virtual EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default)
{
if (!coordinates.IsValid(this))
throw new InvalidOperationException($"Tried to spawn entity {protoName} on invalid coordinates {coordinates}.");

var entity = CreateEntityUninitialized(protoName, coordinates, overrides);
var entity = CreateEntityUninitialized(protoName, coordinates, overrides, rotation);
InitializeAndStartEntity(entity, coordinates.GetMapId(this));
return entity;
}
Expand Down
6 changes: 4 additions & 2 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, Compon
}

/// <inheritdoc />
public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null)
public virtual EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default)
{
var newEntity = CreateEntity(prototypeName, out _, overrides);
_xforms.SetCoordinates(newEntity, TransformQuery.GetComponent(newEntity), coordinates, unanchor: false);

var xformComp = TransformQuery.GetComponent(newEntity);
_xforms.SetCoordinates(newEntity, xformComp, coordinates, rotation: rotation, unanchor: false);
return newEntity;
}

Expand Down
2 changes: 1 addition & 1 deletion Robust.Shared/GameObjects/IEntityManager.Spawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EntityUid[] SpawnEntities(EntityCoordinates coordinates, List<string?> protoName
/// <summary>
/// Spawns an entity and then parents it to the entity that the given entity coordinates are relative to.
/// </summary>
EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null);
EntityUid SpawnAttachedTo(string? protoName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default);

/// <summary>
/// Resolves the given entity coordinates into world coordinates and spawns an entity at that location. The
Expand Down
2 changes: 1 addition & 1 deletion Robust.Shared/GameObjects/IEntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public partial interface IEntityManager
/// <param name="coordinates">Coordinates to set position and parent of the newly spawned entity to.</param>
/// <param name="overrides"><inheritdoc cref="CreateEntityUninitialized(string?, MapCoordinates , ComponentRegistry?, Angle)"/></param>
/// <returns><inheritdoc cref="CreateEntityUninitialized(string?, MapCoordinates , ComponentRegistry?, Angle)"/></returns>
EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null);
EntityUid CreateEntityUninitialized(string? prototypeName, EntityCoordinates coordinates, ComponentRegistry? overrides = null, Angle rotation = default);

/// <summary>
/// Creates an uninitialized entity and puts it on the grid or map at the MapCoordinates provided.
Expand Down

0 comments on commit 783d529

Please sign in to comment.