bitECS
bitECS copied to clipboard
✨ classic: added definePrefab and registerPrefab
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 aPrefabToken
, containing a list of components and aMap<World, eid>
-
registerPrefab
assigns an eid to the prefab by internally callingaddPrefab
, and pairs the eid with the world in thePrefabToken
world -> eid map - Calling
IsA
(or any other relation) on aPrefabToken
stores it in the relation's$pairsMap
and the component's$pairTarget
, as it would for an eid -
getRelationTargets
checks if$pairTarget
is aPrefabToken
and converts it to an eid, using the world -> eid map ofPrefabToken
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.