bitECS icon indicating copy to clipboard operation
bitECS copied to clipboard

✨ classic: added definePrefab and registerPrefab

Open pietrovismara opened this issue 1 month ago • 0 comments

Unfortunately there are several formatting changes included as prettier took over a bunch of unformatted code.

The gist of the changes is the following:

  • definePrefab returns a PrefabToken, containing a list of components and a Map<World, eid>
  • registerPrefab assigns an eid to the prefab by internally calling addPrefab, and pairs the eid with the world in the PrefabToken world -> eid map
  • Calling IsA (or any other relation) on a PrefabToken stores it in the relation's $pairsMap and the component's $pairTarget, as it would for an eid
  • getRelationTargets checks if $pairTarget is a PrefabToken and converts it to an eid, using the world -> eid map of PrefabToken

I left the definition of the Prefab component in Entity.ts, as moving it out of there would cause circular dependency issues. I suggest a separate refactor to prevent such issues.

See the included integration test (Prefab.test.ts) for usage.

pietrovismara avatar May 22 '24 13:05 pietrovismara