using Ashfall.Core;
using Ashfall.Runtime;
using NUnit.Framework;
using UnityEngine;
namespace Ashfall.Tests
{
public sealed class WorldPersistenceTests
{
[Test]
public void UnityJsonRoundTripPreservesNestedFloorsInventoryAndWorm()
{
var sim = new GameSimulation(WorldFactory.Create(), ContentCatalog.CreateDefault());
var p = sim.Connect("test-worm", "蠕虫", Species.Brood);
p.location = WorldFactory.At(sim.World.Vehicle("crawler").spaceId, 1, new V2(1, 2));
var codec = new UnityWorldCodec(); var restored = codec.Decode(codec.Encode(sim.World));
SaveStore.Validate(restored);
Assert.That(restored.Player(p.id).IsWorm, Is.True);
Assert.That(restored.Player(p.id).location.floor, Is.EqualTo(1));
Assert.That(restored.vehicles.Count, Is.EqualTo(3));
Assert.That(restored.warehouse.Count("sample"), Is.EqualTo(4));
Assert.That(restored.pieces.Count, Is.EqualTo(sim.World.pieces.Count));
}
[Test]
public void SpriteAtlasesAreAvailableAtRuntime()
{
Assert.That(Resources.Load<Texture2D>("Art/ExpeditionAtlas"), Is.Not.Null);
Assert.That(Resources.Load<Texture2D>("Art/LifeformsAtlas"), Is.Not.Null);
ContentCatalog.CreateDefault().Validate();
}
[Test]
public void EvolvingSurvivesUnitySerialization()
{
var sim = new GameSimulation(WorldFactory.Create(), ContentCatalog.CreateDefault());
var p = sim.Connect("worm", "幼体", Species.Brood);
p.location = sim.World.facilities.Find(f => f.id == "base.molt").location.Copy();
p.inventory.Add("biomass", 20); p.inventory.Add("sample", 1);
Assert.That(sim.Execute(p.id, new GameCommand { sequence = 1, kind = CommandKind.Evolve, targetId = "base.molt" }).success, Is.True);
var codec = new UnityWorldCodec(); var copy = codec.Decode(codec.Encode(sim.World));
Assert.That(copy.Player("worm").broodForm, Is.EqualTo(BroodForm.Adult));
}
}
}
using Ashfall.Core;
using Ashfall.Runtime;
using NUnit.Framework;
using UnityEngine;
namespace Ashfall.Tests
{
public sealed class WorldPersistenceTests
{
[Test]
public void UnityJsonRoundTripPreservesNestedFloorsInventoryAndWorm()
{
var sim = new GameSimulation(WorldFactory.Create(), ContentCatalog.CreateDefault());
var p = sim.Connect("test-worm", "蠕虫", Species.Brood);
p.location = WorldFactory.At(sim.World.Vehicle("crawler").spaceId, 1, new V2(1, 2));
var codec = new UnityWorldCodec(); var restored = codec.Decode(codec.Encode(sim.World));
SaveStore.Validate(restored);
Assert.That(restored.Player(p.id).IsWorm, Is.True);
Assert.That(restored.Player(p.id).location.floor, Is.EqualTo(1));
Assert.That(restored.vehicles.Count, Is.EqualTo(3));
Assert.That(restored.warehouse.Count("sample"), Is.EqualTo(4));
Assert.That(restored.pieces.Count, Is.EqualTo(sim.World.pieces.Count));
}
[Test]
public void SpriteAtlasesAreAvailableAtRuntime()
{
Assert.That(Resources.Load<Texture2D>("Art/ExpeditionAtlas"), Is.Not.Null);
Assert.That(Resources.Load<Texture2D>("Art/LifeformsAtlas"), Is.Not.Null);
ContentCatalog.CreateDefault().Validate();
}
[Test]
public void EvolvingSurvivesUnitySerialization()
{
var sim = new GameSimulation(WorldFactory.Create(), ContentCatalog.CreateDefault());
var p = sim.Connect("worm", "幼体", Species.Brood);
p.location = sim.World.facilities.Find(f => f.id == "base.molt").location.Copy();
p.inventory.Add("biomass", 20); p.inventory.Add("sample", 1);
Assert.That(sim.Execute(p.id, new GameCommand { sequence = 1, kind = CommandKind.Evolve, targetId = "base.molt" }).success, Is.True);
var codec = new UnityWorldCodec(); var copy = codec.Decode(codec.Encode(sim.World));
Assert.That(copy.Player("worm").broodForm, Is.EqualTo(BroodForm.Adult));
}
}
}