mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
MapManager_Tests now work on both client and server sides.
This commit is contained in:
@@ -193,7 +193,7 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public override IEntity CreateEntityUninitialized(string prototypeName, GridCoordinates coordinates)
|
||||
{
|
||||
var newEntity = CreateEntity(prototypeName, NewClientEntityUid());
|
||||
var newEntity = CreateEntity(prototypeName, GenerateEntityUid());
|
||||
if (coordinates.GridID != GridId.Invalid)
|
||||
{
|
||||
var gridEntityId = _mapManager.GetGrid(coordinates.GridID).GridEntityId;
|
||||
@@ -205,18 +205,17 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public override IEntity CreateEntityUninitialized(string prototypeName, MapCoordinates coordinates)
|
||||
{
|
||||
var newEntity = CreateEntity(prototypeName, NewClientEntityUid());
|
||||
if (coordinates.MapId != MapId.Nullspace)
|
||||
{
|
||||
newEntity.Transform.AttachParent(_mapManager.GetMapEntity(coordinates.MapId));
|
||||
newEntity.Transform.WorldPosition = coordinates.Position;
|
||||
}
|
||||
var newEntity = CreateEntity(prototypeName, GenerateEntityUid());
|
||||
newEntity.Transform.AttachParent(_mapManager.GetMapEntity(coordinates.MapId));
|
||||
newEntity.Transform.WorldPosition = coordinates.Position;
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
public override IEntity SpawnEntity(string protoName, GridCoordinates coordinates)
|
||||
{
|
||||
return SpawnEntityNoMapInit(protoName, coordinates);
|
||||
var newEnt = CreateEntityUninitialized(protoName, coordinates);
|
||||
InitializeAndStartEntity((Entity)newEnt);
|
||||
return newEnt;
|
||||
}
|
||||
|
||||
public override IEntity SpawnEntityNoMapInit(string protoName, GridCoordinates coordinates)
|
||||
@@ -228,19 +227,20 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
public override IEntity SpawnEntityAt(string entityType, GridCoordinates coordinates)
|
||||
{
|
||||
return SpawnEntity(entityType, coordinates);
|
||||
var newEnt = CreateEntityUninitialized(entityType, coordinates);
|
||||
InitializeAndStartEntity((Entity)newEnt);
|
||||
return newEnt;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEntity SpawnEntityAt(string entityType, MapCoordinates coordinates)
|
||||
{
|
||||
var grid = _mapManager.FindGridAt(coordinates);
|
||||
var gridCoords = new GridCoordinates(grid.WorldToLocal(coordinates.Position), grid);
|
||||
|
||||
return SpawnEntityAt(entityType, gridCoords);
|
||||
var entity = CreateEntityUninitialized(entityType, coordinates);
|
||||
InitializeAndStartEntity((Entity)entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private EntityUid NewClientEntityUid()
|
||||
protected override EntityUid GenerateEntityUid()
|
||||
{
|
||||
return new EntityUid(_nextClientEntityUid++);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Robust.Server.GameObjects
|
||||
[Dependency] private readonly IPauseManager _pauseManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private int _nextServerEntityUid = (int)EntityUid.FirstUid;
|
||||
|
||||
private readonly List<(GameTick tick, EntityUid uid)> _deletionHistory = new List<(GameTick, EntityUid)>();
|
||||
|
||||
public override IEntity CreateEntityUninitialized(string prototypeName)
|
||||
@@ -249,6 +251,11 @@ namespace Robust.Server.GameObjects
|
||||
return AllocEntity(prototypeName, uid);
|
||||
}
|
||||
|
||||
protected override EntityUid GenerateEntityUid()
|
||||
{
|
||||
return new EntityUid(_nextServerEntityUid++);
|
||||
}
|
||||
|
||||
void IServerEntityManagerInternal.FinishEntityLoad(IEntity entity, IEntityLoadContext context)
|
||||
{
|
||||
LoadEntity((Entity) entity, context);
|
||||
|
||||
@@ -64,8 +64,6 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
protected readonly Queue<IncomingEntityMessage> NetworkMessageBuffer = new Queue<IncomingEntityMessage>();
|
||||
|
||||
protected int NextUid = (int)EntityUid.FirstUid;
|
||||
|
||||
private readonly IEntityEventBus _eventBus = new EntityEventBus();
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -240,7 +238,7 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (uid == null)
|
||||
{
|
||||
uid = new EntityUid(NextUid++);
|
||||
uid = GenerateEntityUid();
|
||||
}
|
||||
|
||||
if (EntityExists(uid.Value))
|
||||
@@ -402,6 +400,8 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
|
||||
#endregion message processing
|
||||
|
||||
protected abstract EntityUid GenerateEntityUid();
|
||||
}
|
||||
|
||||
public enum EntityMessageType
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Map;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -13,6 +12,8 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
[TestFixture, TestOf(typeof(MapManager))]
|
||||
class MapManager_Tests : RobustUnitTest
|
||||
{
|
||||
public override UnitTestProject Project => UnitTestProject.Server;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -61,7 +62,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
public void Restart_NullspaceMap_IsEmptied()
|
||||
{
|
||||
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||
var entMan = IoCManager.Resolve<IServerEntityManager>();
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
mapMan.CreateNewMapEntity(MapId.Nullspace);
|
||||
|
||||
@@ -85,7 +86,7 @@ namespace Robust.UnitTesting.Shared.Map
|
||||
// Arrange
|
||||
var mapID = new MapId(11);
|
||||
var mapMan = IoCManager.Resolve<IMapManager>();
|
||||
var entMan = IoCManager.Resolve<IServerEntityManager>();
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
mapMan.CreateMap(new MapId(7));
|
||||
mapMan.CreateMap(mapID);
|
||||
|
||||
Reference in New Issue
Block a user