NSSTC / sim-ecs

Batteries included TypeScript ECS
https://nsstc.github.io/sim-ecs/
Mozilla Public License 2.0
84 stars 12 forks source link

Implement serializer #16

Closed minecrawler closed 3 years ago

minecrawler commented 4 years ago

Imagine having a component like this:

class MyComponent {
  health: number
  target: IEntity
}

When running the ECS and adding such components to entities, everything will work as expected. However, as soon as save() is called, the target field will be serialized as independent entity, even though it really should reference another living entity. In order to handle it correctly, we need a serializer, which knows how to serialize the reference. We already have a deserializer, which can provide logic to reverse the process :)

I wonder if an entity ID might make sense, or if I should leave it to the user to add one (via component). Not every application needs to reference entities, and for those, having an ID is overhead.