friflo / Friflo.Engine.ECS

C# ECS 🔥 high-performance
https://friflo.gitbook.io/friflo.engine.ecs
GNU Lesser General Public License v3.0
158 stars 11 forks source link

After serialization/deserialization indexed components don't work #15

Closed Belzebbuz closed 2 weeks ago

Belzebbuz commented 2 months ago

After serialization/deserialization indexed components don't work

[Fact]
public void AddTwoEntitiesWithDifferentIndexesThenSaveIt_ShouldReturnSingleIndexedValue()
{
  var id1 = Guid.NewGuid().ToString();
  var id2 = Guid.NewGuid().ToString();
  var store = new EntityStore();
  var entityA = store.CreateEntity();
  entityA.AddComponent(new Index() { value = id1 });
  var entityB = store.CreateEntity();
  entityB.AddComponent(new Index() { value = id2 });

  var newStoreEntity1 = store.GetEntitiesWithComponentValue<Index,string>(id1).ToArray();
  newStoreEntity1.Length.Should().Be(1); // THIS OK

  using var stream = new MemoryStream();
  var serializer = new EntitySerializer();
  serializer.WriteStore(store,stream);

  var readStore = new EntityStore();
  serializer.ReadIntoStore(readStore, stream);
  readStore.Count.Should().Be(2);

  var readEntity1 = readStore.GetEntitiesWithComponentValue<Index,string>(id1).ToArray(); 
  readEntity1.Length.Should().Be(1); // THIS FAILED
}
private struct Index() : IIndexedComponent<string>
{
  public string value;
  public string GetIndexedValue() => value;
}
friflo commented 2 weeks ago

Fixed by: https://github.com/friflo/Friflo.Engine.ECS/commit/784c76577c7749202ac3b6d580a514ae76829a58

friflo commented 6 days ago

Fixed in 3.0.0-preview.14