Skip to content

Commit

Permalink
renamed schema to scene and added callbacks for default physics and r…
Browse files Browse the repository at this point in the history
…ender (#77)
  • Loading branch information
kpal81xd authored Aug 14, 2024
1 parent d4a0654 commit 8f22e4b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export * from './settings/scene.js';
export * from './history.js';
export * from './selection.js';
export * from './schema.js';
export * from './schema/components.js';
export * from './schema/assets.js';
export * from './schema/components.js';
export * from './schema/scene.js';
export * from './schema/settings.js';
export * from './realtime/connection.js';
export * from './realtime/scene.js';
Expand Down
21 changes: 16 additions & 5 deletions src/schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssetsSchema } from './schema/assets.js';
import { ComponentSchema } from './schema/components.js';
import { SceneSchema } from './schema/scene.js';
import { SettingsSchema } from './schema/settings.js';

/**
Expand All @@ -13,11 +14,21 @@ class Schema {
*/
constructor(schema) {
this._schema = schema;
this._componentSchema = new ComponentSchema(this);
this._assetsSchema = new AssetsSchema(this);
this._componentSchema = new ComponentSchema(this);
this._sceneSchema = new SceneSchema(this);
this._settingsSchema = new SettingsSchema(this);
}

/**
* Gets the assets schema
*
* @type {AssetsSchema}
*/
get assets() {
return this._assetsSchema;
}

/**
* Gets the component schema
*
Expand All @@ -28,12 +39,12 @@ class Schema {
}

/**
* Gets the assets schema
* Gets the scene schema
*
* @type {AssetsSchema}
* @type {SceneSchema}
*/
get assets() {
return this._assetsSchema;
get scene() {
return this._sceneSchema;
}

/**
Expand Down
66 changes: 66 additions & 0 deletions src/schema/scene.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { utils } from '../utils.js';

/**
* Provides methods to access the render schema
*/
class SceneSchema {
/** @typedef {import("../schema.js").Schema} Schema */

/**
* Creates new instance of API
*
* @category Internal
* @param {Schema} schema - The schema API
*/
constructor(schema) {
this._schemaApi = schema;
this._schema = this._schemaApi._schema.scene;
}

_getDefaultData(obj) {
const result = {};
for (const key in obj) {
if (key.startsWith('$')) continue;
if (!(obj[key] instanceof Object)) continue;

if (obj[key].hasOwnProperty('$default')) {
result[key] = utils.deepCopy(obj[key].$default);
continue;
} else {
const subDefaults = this._getDefaultData(obj[key]);
if (Object.keys(subDefaults).length) {
result[key] = subDefaults;
}
}
}
return result;
}

/**
* Get the default physics scene settings for the project
*
* @returns {*} The default physics scene settings
* @example
* ```javascript
* const scenePhysicsSettings = editor.schema.scene.getDefaultPhysicsSettings();
* ```
*/
getDefaultPhysicsSettings() {
return this._getDefaultData(this._schema.settings.physics);
}

/**
* Get the default render scene settings for the project
*
* @returns {*} The default physics scene settings
* @example
* ```javascript
* const sceneRenderSettings = editor.schema.scene.getDefaultRenderSettings();
* ```
*/
getDefaultRenderSettings() {
return this._getDefaultData(this._schema.settings.render);
}
}

export { SceneSchema };

0 comments on commit 8f22e4b

Please sign in to comment.