Skip to content

Commit

Permalink
object simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
ptc-rdeleeuw committed Jul 5, 2024
1 parent 71a4406 commit d1bcc3f
Show file tree
Hide file tree
Showing 62 changed files with 1,113 additions and 1,765 deletions.
2 changes: 1 addition & 1 deletion addons/vuforia-spatial-core-addon
13 changes: 2 additions & 11 deletions libraries/objectDefaultFiles/scene/AnchoredGroupNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ class AnchoredGroupNode extends ObjectNode {
*
* @param {ObjectInterface} listener
*/
constructor(listener) {
super(listener, AnchoredGroupNode.TYPE);
}

/**
*
* @param {string} toolId
* @returns {AnchoredGroupNodeState}
*/
getStateForTool(toolId) {
return {};
constructor() {
super(AnchoredGroupNode.TYPE);
}
}

Expand Down
25 changes: 0 additions & 25 deletions libraries/objectDefaultFiles/scene/AnchoredGroupStore.js

This file was deleted.

14 changes: 4 additions & 10 deletions libraries/objectDefaultFiles/scene/BaseEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BaseEntity {
/** @type {{order: number, component: ComponentInterface}[]} */
#components;

/** @type {EntityInterface} */
/** @type {{[key: string]: BaseEntity}} */
#children;

constructor() {
Expand Down Expand Up @@ -84,6 +84,9 @@ class BaseEntity {
*/
updateComponents() {
for (let entry of this.#components) {
if (!entry || !entry.component || !entry.component.update) {
console.log("here");
}
entry.component.update();
}
for (let child of Object.values(this.#children)) {
Expand Down Expand Up @@ -117,15 +120,6 @@ class BaseEntity {
delete this.#children[key];
}

/**
*
* @param {string} _name
* @returns {BaseEntity}
*/
createEntity(_name) {
throw Error("Can't instantiate abstract class");
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import ComponentsNode from "./ComponentsNode.js";
import EntitiesNode from "./EntitiesNode.js";
import ObjectNode from "./ObjectNode.js";
import TransformComponentNode from "./TransformComponentNode.js";

/**
* @typedef {import("./BaseNode.js").BaseNodeState} BaseNodeState
Expand All @@ -16,28 +19,26 @@ import ObjectNode from "./ObjectNode.js";
* @typedef {{getPosition: () => Vector3Value, setPosition: (position: Vector3Value) => void, getRotation: () => QuaternionValue, setRotation: (rotation: QuaternionValue) => void, getScale: () => Vector3Value, setScale: (scale: Vector3Value) => void}} EntityInterface
*/

class EntityNode extends ObjectNode {
class BaseEntityNode extends ObjectNode {
static TYPE = "Object.Entity";

/** @tpye {EntityInterface} */
#entity;

Check warning on line 27 in libraries/objectDefaultFiles/scene/BaseEntityNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 27 in libraries/objectDefaultFiles/scene/BaseEntityNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
/**
*
* @param {DictionaryInterface} listener
* @param {EntityInterface} entity
* @param {string} type
*/
constructor(listener, type = EntityNode.TYPE) {
super(listener, type);
this.get("components").setEntityNode(this);
if (!this.get("components").has("0")) {
this.get("components").set("0", listener.createTransform(), false);
}
constructor(entity, type = BaseEntityNode.TYPE) {
super(type);
this._set("children", new EntitiesNode(this));
this._set("components", new ComponentsNode(this));
this.#entity = entity

Check warning on line 36 in libraries/objectDefaultFiles/scene/BaseEntityNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check warning on line 36 in libraries/objectDefaultFiles/scene/BaseEntityNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Missing semicolon
this.setComponent("0", new TransformComponentNode(this.#entity), false);
}

/**
*
* @returns {EntityInterface|null}
*/
getEntity() {
return this.getListener().getEntity();
get entity() {
return this.#entity;
}

/**
Expand All @@ -62,20 +63,12 @@ class EntityNode extends ObjectNode {
this.get("children").set(name, entity, makeDirty);
}

createEntity(key, state) {
return this.getListener().createEntity(key, state);
}

createComponent(order, state) {
return this.getListener().createComponent(order, state);
}

/**
*
* @param {number} order
* @param {ComponentNode} component
*/
addComponent(order, component, makeDirty = true) {
setComponent(order, component, makeDirty = true) {
this.get("components").set(order, component, makeDirty);
}

Expand All @@ -95,24 +88,29 @@ class EntityNode extends ObjectNode {
return this.getComponentByType(type) !== undefined;
}

setPosition(x, y, z) {
/**
* @param {Vector3Value} value
*/
set position(value) {
const transform = this.get("components").get(0);
transform.setPosition({x, y, z});
transform.position = value;
}

setRotation(x, y, z, w) {
/**
* @param {QuaternionValue} value
*/
set rotation(value) {
const transform = this.get("components").get(0);
transform.setRotation({x, y, z, w});
transform.rotation = value;
}

setScale(x, y, z) {
/**
* @param {Vector3Value} value
*/
set scale(value) {
const transform = this.get("components").get(0);
transform.setScale({x, y, z});
}

dispose() {
this.getEntity().dispose();
transform.scale = value;
}
}

export default EntityNode;
export default BaseEntityNode;
50 changes: 0 additions & 50 deletions libraries/objectDefaultFiles/scene/BaseEntityStore.js

This file was deleted.

11 changes: 5 additions & 6 deletions libraries/objectDefaultFiles/scene/BaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class BaseNode {
* @returns {string|null}
*/
getName() {
const parent = this.getParent();
if (parent) {
for (const entry of parent.entries()) {
if (this.parent) {
for (const entry of this.parent.entries()) {
if (entry[1] === this) {
return entry[0];
}
Expand All @@ -43,7 +42,7 @@ class BaseNode {
*
* @returns {BaseNode|null}
*/
getParent() {
get parent() {
const parent = this.#parent ? this.#parent.deref() : null;
return parent ? parent : null;
}
Expand All @@ -52,7 +51,7 @@ class BaseNode {
* internal use only, doesn't propogate isDirty
* @param {BaseNode|null} parent
*/
setParent(parent) {
set parent(parent) {
this.#parent = parent ? new WeakRef(parent) : null;

Check warning on line 55 in libraries/objectDefaultFiles/scene/BaseNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'WeakRef' is not defined

Check warning on line 55 in libraries/objectDefaultFiles/scene/BaseNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

'WeakRef' is not defined
}

Expand Down Expand Up @@ -139,7 +138,7 @@ class BaseNode {
* @param {BaseNode} node
*/
static setParentDirty(node) {
const parent = node.getParent();
const parent = node.parent;
if (parent && (!parent.isInternalDirty())) {
parent.setInternalDirty();
BaseNode.setParentDirty(parent);
Expand Down
61 changes: 52 additions & 9 deletions libraries/objectDefaultFiles/scene/ColorNode.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,87 @@
import ObjectNode from "./ObjectNode.js";
import ValueNode from "./ValueNode.js";

/**
* @typedef {import("./BaseNode.js").BaseNodeDelta} BaseNodeDelta
* @typedef {import("./ValueNode.js").ValueNodeDelta} ValueNodeDelta
* @typedef {import("./ObjectNode.js").ObjectInterface} ObjectInterface
* @typedef {{r: number, g: number, b: number}} ColorValue
* @typedef {BaseNodeDelta & {properties?: {r?: ValueNodeDelta, g?: ValueNodeDelta, b?: ValueNodeDelta}}} ColorDelta
* @typedef {(node: ColorNode) => void} onChangedFunc
*/

class ColorNode extends ObjectNode {
static TYPE = "Object.Color";

/** @type {onChangedFunc|null} */
#onChanged

Check warning on line 17 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check warning on line 17 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Missing semicolon

/**
*
* @param {ObjectInterface} listener
* @param {ObjectInterface} value
*/
constructor(listener) {
super(listener, ColorNode.TYPE);
constructor(value = {r: 0, g: 0, b: 0}) {
super(ColorNode.TYPE);
this.#addValue("r", value.r);
this.#addValue("g", value.g);
this.#addValue("b", value.b);
this.#onChanged = null;
}

/**
* @param {ColorValue} value
*

Check warning on line 32 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 32 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
* @param {string} key

Check warning on line 33 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 33 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
* @param {number} value

Check warning on line 34 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 34 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
*/
setValue(value) {
this.get("r").value = value.r;
this.get("g").value = value.g;
this.get("b").value = value.b;
#addValue(key, value) {
const node = new ValueNode(value);
node.onChanged = (_node) => {this.#safeOnChanged();};
this._set(key, node);
}

/**
*

Check warning on line 43 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 43 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
*/
#safeOnChanged() {
if (this.#onChanged) {
this.#onChanged(this);
}
}

/**
* @returns {onChangedFunc}

Check warning on line 52 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 52 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
*/
get onChanged() {
return this.#onChanged;
}

Check warning on line 57 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed

Check warning on line 57 in libraries/objectDefaultFiles/scene/ColorNode.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Trailing spaces not allowed
/**
* @param {onChangedFunc} onChanged
*/
set onChanged(onChanged) {
this.#onChanged = onChanged;
}

/**
*
* @returns {ColorValue}
*/
getValue() {
get value() {
return {
"r": this.get("r").value,
"g": this.get("g").value,
"b": this.get("b").value
};
}

/**
* @param {ColorValue} value
*/
set value(value) {
this.get("r").value = value.r;
this.get("g").value = value.g;
this.get("b").value = value.b;
}
}

export default ColorNode;
Loading

0 comments on commit d1bcc3f

Please sign in to comment.