Skip to content

Commit

Permalink
Add getComponentId
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeGensler committed Jun 19, 2023
1 parent 19b034c commit 43e0276
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-trains-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'thyseus': minor
---

Add World.prototype.getComponentId
14 changes: 14 additions & 0 deletions src/world/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ export class World {
this.entities.setRow(entityId, targetTable.length - 1);
}

/**
* Gets the internal id for a component in this world.
* May differ from world to world.
* @param componentType The component type to get an id for.
* @returns The numeric id of the component.
*/
getComponentId(componentType: Struct): number {
DEV_ASSERT(
this.components.includes(componentType),
`Tried to get id of unregistered component "${componentType.name}"`,
);
return this.components.indexOf(componentType);
}

#getTable(archetype: bigint): Table {
let table = this.#archetypeToTable.get(archetype);
if (table) {
Expand Down

0 comments on commit 43e0276

Please sign in to comment.