Adds an integration test for saving and loading a multi grid map.
Fixes a bug in SharedGalacticMarketComponent where the products were not being cleared between calls to ExposeData.
This commit is contained in:
71
Content.IntegrationTests/Tests/SaveLoadMapTest.cs
Normal file
71
Content.IntegrationTests/Tests/SaveLoadMapTest.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Robust.Server.Interfaces.Maps;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Map;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
|
namespace Content.IntegrationTests.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
class SaveLoadMapTest : ContentIntegrationTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task SaveLoadMultiGridMap()
|
||||||
|
{
|
||||||
|
const string mapPath = @"Maps/Test/TestMap.yml";
|
||||||
|
|
||||||
|
var server = StartServer();
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
var mapLoader = server.ResolveDependency<IMapLoader>();
|
||||||
|
var mapManager = server.ResolveDependency<IMapManager>();
|
||||||
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||||
|
|
||||||
|
server.Post(() =>
|
||||||
|
{
|
||||||
|
var mapId = mapManager.CreateMap(new MapId(5));
|
||||||
|
|
||||||
|
{
|
||||||
|
var mapGrid = mapManager.CreateGrid(mapId);
|
||||||
|
var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
|
||||||
|
mapGridEnt.Transform.WorldPosition = new Vector2(10, 10);
|
||||||
|
mapGrid.SetTile(new MapIndices(0,0), new Tile(1, 512));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var mapGrid = mapManager.CreateGrid(mapId);
|
||||||
|
var mapGridEnt = entityManager.GetEntity(mapGrid.GridEntityId);
|
||||||
|
mapGridEnt.Transform.WorldPosition = new Vector2(-8, -8);
|
||||||
|
mapGrid.SetTile(new MapIndices(0, 0), new Tile(2, 511));
|
||||||
|
}
|
||||||
|
|
||||||
|
mapLoader.SaveMap(mapId, mapPath);
|
||||||
|
|
||||||
|
mapManager.DeleteMap(new MapId(5));
|
||||||
|
});
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
|
||||||
|
server.Post(() =>
|
||||||
|
{
|
||||||
|
mapLoader.LoadMap(new MapId(10), mapPath);
|
||||||
|
});
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
|
||||||
|
{
|
||||||
|
if(!mapManager.TryFindGridAt(new MapId(10), new Vector2(10,10), out var mapGrid))
|
||||||
|
Assert.Fail();
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector2(10, 10), mapGrid.WorldPosition);
|
||||||
|
Assert.AreEqual(new Tile(1, 512), mapGrid.GetTileRef(new MapIndices(0, 0)).Tile);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
if (!mapManager.TryFindGridAt(new MapId(10), new Vector2(-8, -8), out var mapGrid))
|
||||||
|
Assert.Fail();
|
||||||
|
|
||||||
|
Assert.AreEqual(new Vector2(-8, -8), mapGrid.WorldPosition);
|
||||||
|
Assert.AreEqual(new Tile(2, 511), mapGrid.GetTileRef(new MapIndices(0, 0)).Tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,7 @@ namespace Content.Shared.GameObjects.Components.Cargo
|
|||||||
{
|
{
|
||||||
var products = serializer.ReadDataField("products", new List<string>());
|
var products = serializer.ReadDataField("products", new List<string>());
|
||||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||||
|
_products.Clear();
|
||||||
foreach (var id in products)
|
foreach (var id in products)
|
||||||
{
|
{
|
||||||
if (!prototypeManager.TryIndex(id, out CargoProductPrototype product))
|
if (!prototypeManager.TryIndex(id, out CargoProductPrototype product))
|
||||||
|
|||||||
Reference in New Issue
Block a user