Skip to content

Commit

Permalink
add config file to set defaultParent config
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Aug 30, 2024
1 parent 6bf2daa commit 1519c50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthProvider, GeoProvider } from './contexts';
import Events from './lib/Events';
import { AssetsLoader } from './lib/assetsLoader';
import { initCameras } from './lib/cameras';
import { Config } from './lib/config';
import { History } from './lib/history';
import { Shortcuts } from './lib/shortcuts';
import { Viewport } from './lib/viewport';
Expand All @@ -17,6 +18,7 @@ import { commandsByType } from './lib/commands/index.js';
function Inspector() {
this.assetsLoader = new AssetsLoader();
this.exporters = { gltf: new GLTFExporter() };
this.config = new Config();
this.history = new History();
this.isFirstOpen = true;
this.modules = {};
Expand Down
3 changes: 2 additions & 1 deletion src/editor/lib/commands/EntityCreateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class EntityCreateCommand extends Command {
this.editor.selectEntity(entity);
};
const parentEl =
this.definition.parentEl ?? document.querySelector('#street-container');
this.definition.parentEl ??
document.querySelector(this.editor.config.defaultParent);
// If we undo and redo, use the previous id so next redo actions (for example entityupdate to move the position) works correctly
if (this.entityId) {
definition = { ...this.definition, id: this.entityId };
Expand Down
6 changes: 6 additions & 0 deletions src/editor/lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function Config() {
return {
// Default parent to add new elements to
defaultParent: '#street-container'
};
}
4 changes: 3 additions & 1 deletion src/editor/lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ export function createEntity(definition, cb, parentEl = undefined) {
if (parentEl) {
parentEl.appendChild(entity);
} else {
document.getElementById('street-container').appendChild(entity);
document
.querySelector(AFRAME.INSPECTOR.config.defaultParent)
.appendChild(entity);
}

return entity;
Expand Down

0 comments on commit 1519c50

Please sign in to comment.