Skip to content

Commit

Permalink
fix params
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Oct 9, 2024
1 parent 5d8829b commit 9bca9b3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,23 @@ export class GameWorld {
entB.onCollision?.(entA, shapeColA.point2);
}

/**
* Add an entity to the world. If the entity is coming from a remote source, provide the uuid.
* @param entity
* @param uuid
* @returns
*/
public addEntity<T extends IGameEntity>(entity: T, uuid?: string): T {
if ([...this.entities.values()].includes(entity)) {
console.warn(`Tried to add entity twice to game world`, entity);
return entity;
}
uuid = uuid ?? globalThis.crypto.randomUUID();
this.entities.set(uuid, entity);
const entUuid = uuid ?? globalThis.crypto.randomUUID();
this.entities.set(entUuid, entity);
const tickerFn = (dt: Ticker) => {
if (entity.destroyed) {
this.ticker.remove(tickerFn);
this.entities.delete(uuid);
this.entities.delete(entUuid);
return;
}
entity.update?.(dt.deltaTime);
Expand Down

0 comments on commit 9bca9b3

Please sign in to comment.