Skip to content

Commit

Permalink
feat(core): connect all existing configs with manager
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Aug 31, 2024
1 parent e62f783 commit fde9faa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/core/Clipper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Components } from "../Components";
import { Raycasters } from "../Raycasters";
import { Worlds } from "../Worlds";
import { ClipperConfig, ClipperConfigManager } from "./src/clipper-config";
import { ConfigManager } from "../ConfigManager";

export * from "./src";

Expand Down Expand Up @@ -186,11 +187,18 @@ export class Clipper
constructor(components: Components) {
super(components);
this.components.add(Clipper.uuid, this);

const configs = components.get(ConfigManager);
configs.list.add(this.config);
}

/** {@link Disposable.dispose} */
dispose() {
this._enabled = false;

const configs = this.components.get(ConfigManager);
configs.list.delete(this.config);

for (const plane of this.list) {
plane.dispose();
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/core/ConfigManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from "../Types";
import { Component, DataSet } from "../Types";
import { Components } from "../Components";
import { Configurator } from "./src";

Expand All @@ -8,7 +8,10 @@ export * from "./src";
* A tool to manage all the configuration from the app centrally.
*/
export class ConfigManager extends Component {
list = new Set<Configurator<any, any>>();
/**
* The list of all configurations of this app.
*/
list = new DataSet<Configurator<any, any>>();

/** {@link Component.enabled} */
enabled = true;
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/core/Cullers/src/culler-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CullerRendererConfig,
CullerRendererConfigManager,
} from "./culler-renderer-config";
import { ConfigManager } from "../../ConfigManager";

/**
* A base renderer to determine visibility on screen.
Expand Down Expand Up @@ -102,6 +103,9 @@ export class CullerRenderer
"Culler renderer",
);

const configs = this.components.get(ConfigManager);
configs.list.add(this.config);

this.world = world;
this.renderer = new THREE.WebGLRenderer();

Expand Down Expand Up @@ -136,6 +140,10 @@ export class CullerRenderer
dispose() {
this.enabled = false;
this.config.autoUpdate = false;

const configs = this.components.get(ConfigManager);
configs.list.delete(this.config);

for (const child of this.scene.children) {
child.removeFromParent();
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/core/Worlds/src/simple-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SimpleSceneConfig,
SimpleSceneConfigManager,
} from "./simple-scene-config";
import { ConfigManager } from "../../ConfigManager";

/**
* A basic 3D [scene](https://threejs.org/docs/#api/en/scenes/Scene) to add objects hierarchically, and easily dispose them when you are finished with it.
Expand Down Expand Up @@ -45,6 +46,9 @@ export class SimpleScene
super(components);
this.three = new THREE.Scene();
this.three.background = new THREE.Color(0x202932);

const configs = this.components.get(ConfigManager);
configs.list.add(this.config);
}

/** {@link Configurable.setup} */
Expand Down Expand Up @@ -78,4 +82,10 @@ export class SimpleScene
this.isSetup = true;
this.onSetup.trigger();
}

dispose() {
super.dispose();
const configs = this.components.get(ConfigManager);
configs.list.delete(this.config);
}
}

0 comments on commit fde9faa

Please sign in to comment.