Skip to content

Commit

Permalink
feat(core): adds name to SimpleWorld and creation events to Worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed May 29, 2024
1 parent 038629e commit 9c39280
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/core/src/core/Worlds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class Worlds extends Component implements Updateable, Disposable {
*/
readonly onDisposed = new Event();

readonly onWorldCreated = new Event<World>();
readonly onWorldDeleted = new Event<string>();

/**
* A collection of worlds managed by this component.
* The key is the unique identifier (UUID) of the world, and the value is the World instance.
Expand All @@ -56,17 +59,15 @@ export class Worlds extends Component implements Updateable, Disposable {
}

/**
* Creates a new instance of a SimpleWorld and adds it to the list of worlds.
*
* @template T - The type of the scene, extending from BaseScene. Defaults to BaseScene.
* @template U - The type of the camera, extending from BaseCamera. Defaults to BaseCamera.
* @template S - The type of the renderer, extending from BaseRenderer. Defaults to BaseRenderer.
*
* @returns {SimpleWorld<T, U, S>} - The newly created SimpleWorld instance.
*
* @throws {Error} - Throws an error if a world with the same UUID already exists in the list.
*/
create<
* Creates a new instance of a SimpleWorld and adds it to the list of worlds.
*
* @template T - The type of the scene, extending from BaseScene. Defaults to BaseScene.
* @template U - The type of the camera, extending from BaseCamera. Defaults to BaseCamera.
* @template S - The type of the renderer, extending from BaseRenderer. Defaults to BaseRenderer.
*
* @throws {Error} - Throws an error if a world with the same UUID already exists in the list.
*/
create<
T extends BaseScene = BaseScene,
U extends BaseCamera = BaseCamera,
S extends BaseRenderer = BaseRenderer,
Expand All @@ -77,12 +78,15 @@ create<
throw new Error("There is already a world with this name!");
}
this.list.set(id, world);
this.onWorldCreated.trigger(world);
return world;
}

delete(world: World) {
const uuid = world.uuid;
this.list.delete(world.uuid);
world.dispose();
this.onWorldDeleted.trigger(uuid);
}

dispose() {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/core/Worlds/src/simple-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class SimpleWorld<

uuid = UUID.create();

name?: string;

readonly onDisposed = new Event();

private _scene?: T;
Expand Down

0 comments on commit 9c39280

Please sign in to comment.