diff --git a/dist/r3.js b/dist/r3.js index a4a9544..09b6706 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -17,12 +17,12 @@ class R3 { /** * static Version - Current R3 version */ -R3.Version = '3.0.245'; +R3.Version = '3.0.255'; /** * static CompileDate - Current compile date of R3 */ -R3.CompileDate = '2021 Oct 02 - 10:26:44 am'; +R3.CompileDate = '2021 Oct 02 - 14:30:13 pm'; class System { @@ -482,53 +482,57 @@ class SystemLinking extends System { value ) { - /** - * First we check if this is a required property - */ - if (!r3Object.required.hasOwnProperty(property)) { - return; - } - - /** - * We know this property is required - so continue.. - */ - if (r3Object.required[property] instanceof Array) { + for (let r = 0; r < r3Object.required.length; r++) { /** - * First we need to check that this value conforms to the requirement of being an Array + * First we check if this is a required property */ - if (!(value instanceof Array)) { - throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array'); - } - - if (value.length === 0) { + if (!r3Object.required[r].hasOwnProperty(property)) { return; } /** - * Check all items in the array are valid objects of type r3Object.required[property] + * We know this property is required - so continue.. */ - for (let i = 0; i < value.length; i++) { - r3Object.required[property].map( - function(constructor) { - if (!(value[i] instanceof constructor)) { - throw new TypeError('The property ' + property + ' of this object is not of the correct type'); + if (r3Object.required[r][property] instanceof Array) { + + /** + * First we need to check that this value conforms to the requirement of being an Array + */ + if (!(value instanceof Array)) { + throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array'); + } + + if (value.length === 0) { + return; + } + + /** + * Check all items in the array are valid objects of type r3Object.required[property] + */ + for (let i = 0; i < value.length; i++) { + r3Object.required[r][property].map( + function (constructor) { + if (!(value[i] instanceof constructor)) { + throw new TypeError('The property ' + property + ' of this object is not of the correct type'); + } } - } - ); - } - } else { + ); + } + } else { - if (value === null) { - return; - } + if (value === null) { + return; + } - if (typeof value === 'undefined') { - return; - } + if (typeof value === 'undefined') { + return; + } + + if (!(value instanceof r3Object.required[r][property])) { + throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type') + } - if (!(value instanceof r3Object.required[property])) { - throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type') } } @@ -556,33 +560,55 @@ class SystemLinking extends System { * In this case - we should check its existing components and have their relationships * severed */ - if (value.length === 0) { + // if (value.length === 0) { + // + // if (r3Object[property] instanceof Array) { + // for (let i = 0; i < r3Object[property].length; i++) { + // if (r3Object[property][i] instanceof R3Object) { + // r3Object.dirty = true; + // Utils.RemoveFromArray(r3Object[property][i].parents, r3Object); + // } + // } + // } + // + // } else { - if (r3Object[property] instanceof Array) { - for (let i = 0; i < r3Object[property].length; i++) { - if (r3Object[property][i] instanceof R3Object) { - r3Object.dirty = true; - Utils.RemoveFromArray(r3Object[property][i].parents, r3Object); + /** + * We need to check if we removed an item from the existing array + */ + if (r3Object[property].length > 0) { + /** + * Find the missing value (if any) from the old array + */ + + let unlinked = r3Object[property].reduce( + function(result, object) { + if (value.indexOf(object) === -1) { + result.push(object); + } + return result; + }, + [] + ); + + unlinked.map( + function(unlinkObject) { + Utils.RemoveFromArray(unlinkObject.parents, r3Object); + Utils.RemoveFromArray(r3Object.children, unlinkObject); + if (r3Object instanceof Entity) { + Utils.RemoveFromArray(r3Object.components, unlinkObject); } } - } + ); - } else { + } - /** - * We need to check if we removed an item from the existing array - */ - if (r3Object[property].length > 0) { - - } - - for (let i = 0; i < value.length; i++) { - if (value[i] instanceof R3Object) { - Utils.PushUnique(value[i].parents, r3Object); - Utils.PushUnique(r3Object.children, value[i]); - if (r3Object instanceof Entity) { - Utils.PushUnique(r3Object.components, value[i]); - } + for (let i = 0; i < value.length; i++) { + if (value[i] instanceof R3Object) { + Utils.PushUnique(value[i].parents, r3Object); + Utils.PushUnique(r3Object.children, value[i]); + if (r3Object instanceof Entity) { + Utils.PushUnique(r3Object.components, value[i]); } } } @@ -597,6 +623,18 @@ class SystemLinking extends System { } } + if (value === null || typeof value === 'undefined') { + + if (r3Object[property] instanceof R3Object) { + Utils.RemoveFromArray(r3Object[property].parents, r3Object); + Utils.RemoveFromArray(r3Object.children, r3Object[property]); + if (r3Object instanceof Entity) { + Utils.RemoveFromArray(r3Object.components, r3Object[property]); + } + } + + } + } /** @@ -2067,6 +2105,10 @@ class R3Object extends Event { constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } @@ -2152,6 +2194,8 @@ class R3Object extends Event { */ initialize() { + this.initialized = true; + if (this.initializeDepth === this.maxDepth) { throw new Error('You should not try to instantiate this base class - extend it rather...'); } else { @@ -2160,23 +2204,6 @@ class R3Object extends Event { } - /** - * setInitialized() - * - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this Object will still be initialized - * after 'property' will assume 'value' - * @param property=null - * @param value=null - */ - setInitialized( - property=null, - value=null - ) { - - this.initialized = true; - - } - } R3Object.PROJECT = 0x0; @@ -2222,28 +2249,6 @@ class Project extends R3Object { options.maxDepth = options.callDepth; - /** - * started - Indicates whether or not this entity is active (subscribing to events) or not - */ - if (typeof options.started === 'undefined') { - options.started = false; - } - /** - * subscriptions - An association object which hold the subscription handles for Events this system is listening - * to. The system can stop receiving events by calling remove() on a handle. - */ - if (typeof options.subscriptions === 'undefined') { - options.subscriptions = {}; - } - /** - * dirty - When dirty is true, it means that this entity is in transition from having a Component to not - * having this Component, and will probably end up in an uninitialized state. During the next few - * clock cycles this child Component will have its parent reference to this entity removed. - */ - if (typeof options.dirty === 'undefined') { - options.dirty = false; - } - super(options); this.underConstruction = true; @@ -2276,45 +2281,12 @@ class Project extends R3Object { } - /** - * start() - * - Starts the Object by subscribing to all Events - */ - start() { - - this.started = true; - - if (this instanceof R3.Entity) { - this.emit( - Event.ENTITY_STARTED, - this - ); - } - - console.log('Started transient system: Project'); - - } - - /** - * stop() - * - Stops this Object by removing all subscriptions to events - */ - stop() { - - this.started = false; - - console.log('Stopped transient system: Project'); - - } - } class Entity extends R3Object { constructor(options) { - super(options); - if (typeof options === 'undefined') { options = {}; } @@ -2331,6 +2303,8 @@ class Entity extends R3Object { options.maxDepth = options.callDepth; + super(options); + Object.assign(this, options); this.emit(Event.ENTITY_CREATED, this); @@ -2349,7 +2323,8 @@ class Entity extends R3Object { */ initialize() { - this.setInitialized(); + super.initialize(); + Event.Emit(Event.ENTITY_INITIALIZED, this); if (this.initializeDepth === this.maxDepth) { @@ -2385,10 +2360,6 @@ class EntitySlider extends Entity { options.maxDepth = 0; } - if (typeof options.initialized === 'undefined') { - options.initialized = false; - } - if (typeof options.callDepth === 'undefined') { options.callDepth = 0; } else { @@ -2397,18 +2368,8 @@ class EntitySlider extends Entity { options.maxDepth = options.callDepth; - /** - * initialized - A boolean which indicates whether or not this Entity has initialized - */ - if (typeof options.initialized === 'undefined') { - options.initialized = false; - } - /** - * initializeDepth - The amount of times this Entity passed through initialize() functions - */ - if (typeof options.initializeDepth === 'undefined') { - options.initializeDepth = 0; - } + super(options); + /** * components - A list of components that this entity is composed of */ @@ -2429,7 +2390,12 @@ class EntitySlider extends Entity { options.subscriptions = {}; } - super(options); + /** + * We need to assign some options here to the entity + * because SystemLinking requires 'components[]' to + * exist when determining parent / child relationships + */ + Object.assign(this, options); /** * canvas - The Canvas Component to which this entity binds its custom code components @@ -2707,6 +2673,10 @@ class Component extends R3Object { constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } @@ -2740,6 +2710,7 @@ class Component extends R3Object { initialize() { super.initialize(); + Event.Emit(Event.COMPONENT_INITIALIZED, this); if (this.initializeDepth === this.maxDepth) { diff --git a/package.json b/package.json index 93e7087..86424c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version": "3.0.245", + "version": "3.0.255", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index f910d39..4f866b8 100755 --- a/r3.php +++ b/r3.php @@ -1,13 +1,12 @@ #!/usr/bin/php file); + //if the file extends another file it is not important for testing because it will be imported from the base index $important = true; if (preg_match('/src\/r3/', $file)) { @@ -1407,6 +1435,11 @@ function buildImportsAndBody(&$imports, &$body, &$tests, &$testImports, $node, $ if ($important) { array_push($testImports, "const " . $child->name . ' = require(\'../src/r3/r3-' . str_replace('r3object','object', strtolower($type)) . '/' . $file . "');"); array_push($tests, "\t\t\tconst " . lcfirst($child->name) . " = new " . $child->name . '();'); + + if ($type === 'Component' || $type === 'Entity') { + array_push($tests, "\t\t\tassert.isTrue(" . lcfirst($child->name) . ".initialized);"); + } + } $child->nameSpace = $nameSpace; diff --git a/src/r3/r3-component/r3-component.js b/src/r3/r3-component/r3-component.js index 88e70a4..c56b416 100644 --- a/src/r3/r3-component/r3-component.js +++ b/src/r3/r3-component/r3-component.js @@ -50,6 +50,10 @@ class Component extends R3Object { //GENERATED_CONSTRUCTOR_START constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } @@ -100,10 +104,10 @@ class Component extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START + super.initialize(); //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - super.initialize(); Event.Emit(Event.COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END diff --git a/src/r3/r3-entity/r3-entity-slider.js b/src/r3/r3-entity/r3-entity-slider.js index 6dad83f..7256e57 100644 --- a/src/r3/r3-entity/r3-entity-slider.js +++ b/src/r3/r3-entity/r3-entity-slider.js @@ -18,8 +18,6 @@ const Entity = require('./r3-entity.js'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - initialized=false - A boolean which indicates whether or not this Entity has initialized - initializeDepth=0 - The amount of times this Entity passed through initialize() functions components=[] - A list of components that this entity is composed of started=false - Indicates whether or not this entity is active (subscribing to events) or not subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. @@ -80,10 +78,6 @@ class EntitySlider extends Entity { options.maxDepth = 0; } - if (typeof options.initialized === 'undefined') { - options.initialized = false; - } - if (typeof options.callDepth === 'undefined') { options.callDepth = 0; } else { @@ -92,19 +86,9 @@ class EntitySlider extends Entity { options.maxDepth = options.callDepth; + super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START - /** - * initialized - A boolean which indicates whether or not this Entity has initialized - */ - if (typeof options.initialized === 'undefined') { - options.initialized = false; - } - /** - * initializeDepth - The amount of times this Entity passed through initialize() functions - */ - if (typeof options.initializeDepth === 'undefined') { - options.initializeDepth = 0; - } /** * components - A list of components that this entity is composed of */ @@ -126,7 +110,12 @@ class EntitySlider extends Entity { } //GENERATED_TEMPLATE_OPTIONS_INIT_END - super(options); + /** + * We need to assign some options here to the entity + * because SystemLinking requires 'components[]' to + * exist when determining parent / child relationships + */ + Object.assign(this, options); //GENERATED_OPTIONS_INIT_START /** diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js index bd51fd4..c0d4571 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -46,8 +46,6 @@ class Entity extends R3Object { //GENERATED_CONSTRUCTOR_START constructor(options) { - super(options); - if (typeof options === 'undefined') { options = {}; } @@ -64,6 +62,8 @@ class Entity extends R3Object { options.maxDepth = options.callDepth; + super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START //GENERATED_TEMPLATE_OPTIONS_INIT_END @@ -100,10 +100,10 @@ class Entity extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START + super.initialize(); //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - this.setInitialized(); Event.Emit(Event.ENTITY_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END diff --git a/src/r3/r3-object/r3-object.js b/src/r3/r3-object/r3-object.js index 5a924cc..5683563 100644 --- a/src/r3/r3-object/r3-object.js +++ b/src/r3/r3-object/r3-object.js @@ -37,7 +37,6 @@ const Utils = require('.././r3-utils'); TEMPLATE_METHODS_START initialize() - Initializes this Object if all of its required Objects are initialized - setInitialized(property=null, value=null) - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this Object will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -56,6 +55,10 @@ class R3Object extends Event { //GENERATED_CONSTRUCTOR_START constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } @@ -158,6 +161,7 @@ class R3Object extends Event { initialize() { //GENERATED_INITIALIZE_METHOD_START + this.initialized = true; //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START @@ -171,31 +175,6 @@ class R3Object extends Event { } //GENERATED_INITIALIZE_METHOD_AFTER_END - } - - /** - * setInitialized() - * - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this Object will still be initialized - * after 'property' will assume 'value' - * @param property=null - * @param value=null - */ - setInitialized( - property=null, - value=null - ) { - - //GENERATED_SET_INITIALIZED_METHOD_START - this.initialized = true; - //GENERATED_SET_INITIALIZED_METHOD_END - - //CUSTOM_SET_INITIALIZED_METHOD_START - //CUSTOM_SET_INITIALIZED_METHOD_END - - //GENERATED_SET_INITIALIZED_METHOD_AFTER_START - //GENERATED_SET_INITIALIZED_METHOD_AFTER_END - } //GENERATED_TEMPLATE_METHODS_END diff --git a/src/r3/r3-object/r3-project.js b/src/r3/r3-object/r3-project.js index 84a6fa2..70278c7 100644 --- a/src/r3/r3-object/r3-project.js +++ b/src/r3/r3-object/r3-project.js @@ -17,9 +17,6 @@ const R3Object = require('./r3-object.js'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - started=false - Indicates whether or not this entity is active (subscribing to events) or not - subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. - dirty=false - When dirty is true, it means that this entity is in transition from having a Component to not having this Component, and will probably end up in an uninitialized state. During the next few clock cycles this child Component will have its parent reference to this entity removed. TEMPLATE_OPTIONS_END CUSTOM_OPTIONS_START @@ -36,8 +33,6 @@ const R3Object = require('./r3-object.js'); TEMPLATE_METHODS_START initialize() - Initializes this Object if all of its required Objects are initialized - start() - Starts the Object by subscribing to all Events - stop() - Stops this Object by removing all subscriptions to events TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -79,32 +74,11 @@ class Project extends R3Object { options.maxDepth = options.callDepth; - //GENERATED_TEMPLATE_OPTIONS_INIT_START - /** - * started - Indicates whether or not this entity is active (subscribing to events) or not - */ - if (typeof options.started === 'undefined') { - options.started = false; - } - /** - * subscriptions - An association object which hold the subscription handles for Events this system is listening - * to. The system can stop receiving events by calling remove() on a handle. - */ - if (typeof options.subscriptions === 'undefined') { - options.subscriptions = {}; - } - /** - * dirty - When dirty is true, it means that this entity is in transition from having a Component to not - * having this Component, and will probably end up in an uninitialized state. During the next few - * clock cycles this child Component will have its parent reference to this entity removed. - */ - if (typeof options.dirty === 'undefined') { - options.dirty = false; - } - //GENERATED_TEMPLATE_OPTIONS_INIT_END - super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START + //GENERATED_TEMPLATE_OPTIONS_INIT_END + //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END @@ -157,67 +131,6 @@ class Project extends R3Object { } //GENERATED_INITIALIZE_METHOD_AFTER_END - } - - /** - * start() - * - Starts the Object by subscribing to all Events - */ - start() { - - //GENERATED_START_METHOD_START - - //GENERATED_EVENT_LISTENERS_START_START - //GENERATED_EVENT_LISTENERS_START_END - - //CUSTOM_BEFORE_SYSTEM_START_START - //CUSTOM_BEFORE_SYSTEM_START_END - - this.started = true; - - if (this instanceof R3.Entity) { - this.emit( - Event.ENTITY_STARTED, - this - ); - } - - console.log('Started transient system: Project'); - //GENERATED_START_METHOD_END - - //CUSTOM_START_METHOD_START - //CUSTOM_START_METHOD_END - - //GENERATED_START_METHOD_AFTER_START - //GENERATED_START_METHOD_AFTER_END - - } - - /** - * stop() - * - Stops this Object by removing all subscriptions to events - */ - stop() { - - //GENERATED_STOP_METHOD_START - - //GENERATED_EVENT_LISTENERS_STOP_START - //GENERATED_EVENT_LISTENERS_STOP_END - - //CUSTOM_BEFORE_SYSTEM_STOP_START - //CUSTOM_BEFORE_SYSTEM_STOP_END - - this.started = false; - - console.log('Stopped transient system: Project'); - //GENERATED_STOP_METHOD_END - - //CUSTOM_STOP_METHOD_START - //CUSTOM_STOP_METHOD_END - - //GENERATED_STOP_METHOD_AFTER_START - //GENERATED_STOP_METHOD_AFTER_END - } //GENERATED_TEMPLATE_METHODS_END diff --git a/src/r3/r3-system/r3-system-linking.js b/src/r3/r3-system/r3-system-linking.js index ca6b496..59df184 100644 --- a/src/r3/r3-system/r3-system-linking.js +++ b/src/r3/r3-system/r3-system-linking.js @@ -248,6 +248,20 @@ class SystemLinking extends System { * First we need to check that this value conforms to the requirement of being an Array */ if (!(value instanceof Array)) { + + if (r3Object.underConstruction) { + /** + * We are about to throw during a construction process. This means this r3Object will not + * be created - and so we need tell all of its children that this object is no longer their + * parent so that it can be garbage collected + */ + r3Object.children.map( + function(child) { + Utils.RemoveFromArray(child.parents, r3Object); + } + ); + } + throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array'); } @@ -262,6 +276,20 @@ class SystemLinking extends System { r3Object.required[r][property].map( function (constructor) { if (!(value[i] instanceof constructor)) { + + if (r3Object.underConstruction) { + /** + * We are about to throw during a construction process. This means this r3Object will not + * be created - and so we need tell all of its children that this object is no longer their + * parent so that it can be garbage collected + */ + r3Object.children.map( + function(child) { + Utils.RemoveFromArray(child.parents, r3Object); + } + ); + } + throw new TypeError('The property ' + property + ' of this object is not of the correct type'); } } @@ -278,6 +306,20 @@ class SystemLinking extends System { } if (!(value instanceof r3Object.required[r][property])) { + + if (r3Object.underConstruction) { + /** + * We are about to throw during a construction process. This means this r3Object will not + * be created - and so we need tell all of its children that this object is no longer their + * parent so that it can be garbage collected + */ + r3Object.children.map( + function(child) { + Utils.RemoveFromArray(child.parents, r3Object); + } + ); + } + throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type') } @@ -309,60 +351,41 @@ class SystemLinking extends System { if (value instanceof Array) { /** - * This object could have its property set to an empty array. - * In this case - we should check its existing components and have their relationships - * severed + * We need to check if we removed an item from the existing array */ - if (value.length === 0) { + if (r3Object[property].length > 0) { + /** + * Find the missing value (if any) from the old array + */ - if (r3Object[property] instanceof Array) { - for (let i = 0; i < r3Object[property].length; i++) { - if (r3Object[property][i] instanceof R3Object) { - r3Object.dirty = true; - Utils.RemoveFromArray(r3Object[property][i].parents, r3Object); + let unlinked = r3Object[property].reduce( + function(result, object) { + if (value.indexOf(object) === -1) { + result.push(object); + } + return result; + }, + [] + ); + + unlinked.map( + function(unlinkObject) { + Utils.RemoveFromArray(unlinkObject.parents, r3Object); + Utils.RemoveFromArray(r3Object.children, unlinkObject); + if (r3Object instanceof Entity) { + Utils.RemoveFromArray(r3Object.components, unlinkObject); } } - } + ); - } else { + } - /** - * We need to check if we removed an item from the existing array - */ - if (r3Object[property].length > 0) { - /** - * Find the missing value (if any) from the old array - */ - - let unlinked = r3Object[property].reduce( - function(result, object) { - if (value.indexOf(object) === -1) { - result.push(object); - } - return result; - }, - [] - ); - - unlinked.map( - function(unlinkObject) { - Utils.RemoveFromArray(unlinkObject.parents, r3Object); - Utils.RemoveFromArray(r3Object.children, unlinkObject); - if (r3Object instanceof Entity) { - Utils.RemoveFromArray(r3Object.components, unlinkObject); - } - } - ); - - } - - for (let i = 0; i < value.length; i++) { - if (value[i] instanceof R3Object) { - Utils.PushUnique(value[i].parents, r3Object); - Utils.PushUnique(r3Object.children, value[i]); - if (r3Object instanceof Entity) { - Utils.PushUnique(r3Object.components, value[i]); - } + for (let i = 0; i < value.length; i++) { + if (value[i] instanceof R3Object) { + Utils.PushUnique(value[i].parents, r3Object); + Utils.PushUnique(r3Object.children, value[i]); + if (r3Object instanceof Entity) { + Utils.PushUnique(r3Object.components, value[i]); } } } @@ -376,6 +399,19 @@ class SystemLinking extends System { Utils.PushUnique(r3Object.components, value); } } + + if (value === null || typeof value === 'undefined') { + + if (r3Object[property] instanceof R3Object) { + Utils.RemoveFromArray(r3Object[property].parents, r3Object); + Utils.RemoveFromArray(r3Object.children, r3Object[property]); + if (r3Object instanceof Entity) { + Utils.RemoveFromArray(r3Object.components, r3Object[property]); + } + } + + } + //CUSTOM_STATIC_SET_PARENT_CHILD_RELATIONSHIPS_METHOD_END } diff --git a/src/r3/r3.js b/src/r3/r3.js index 06f2fef..b792587 100644 --- a/src/r3/r3.js +++ b/src/r3/r3.js @@ -90,12 +90,12 @@ class R3 { /** * static Version - Current R3 version */ -R3.Version = '3.0.245'; +R3.Version = '3.0.255'; /** * static CompileDate - Current compile date of R3 */ -R3.CompileDate = '2021 Oct 02 - 10:26:44 am'; +R3.CompileDate = '2021 Oct 02 - 14:30:13 pm'; //GENERATED_STATIC_OPTIONS_INIT_END diff --git a/src/templates/base_set_initialized.template b/src/templates/base_initialize.template similarity index 100% rename from src/templates/base_set_initialized.template rename to src/templates/base_initialize.template diff --git a/src/templates/component_base_constructor.template b/src/templates/component_base_constructor.template index aa4b959..a762b82 100644 --- a/src/templates/component_base_constructor.template +++ b/src/templates/component_base_constructor.template @@ -1,5 +1,9 @@ constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } diff --git a/src/templates/component_base_initialize.template b/src/templates/component_base_initialize.template new file mode 100644 index 0000000..f8b476f --- /dev/null +++ b/src/templates/component_base_initialize.template @@ -0,0 +1 @@ + super.initialize(); \ No newline at end of file diff --git a/src/templates/entity_base_constructor.template b/src/templates/entity_base_constructor.template index 79e8e15..da9f121 100644 --- a/src/templates/entity_base_constructor.template +++ b/src/templates/entity_base_constructor.template @@ -1,7 +1,5 @@ constructor(options) { - super(options); - if (typeof options === 'undefined') { options = {}; } @@ -18,6 +16,8 @@ options.maxDepth = options.callDepth; + super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START //GENERATED_TEMPLATE_OPTIONS_INIT_END diff --git a/src/templates/entity_base_initialize.template b/src/templates/entity_base_initialize.template new file mode 100644 index 0000000..f8b476f --- /dev/null +++ b/src/templates/entity_base_initialize.template @@ -0,0 +1 @@ + super.initialize(); \ No newline at end of file diff --git a/src/templates/entity_extends.template b/src/templates/entity_extends.template index ec224c0..c01351a 100644 --- a/src/templates/entity_extends.template +++ b/src/templates/entity_extends.template @@ -14,8 +14,6 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - initialized=false - A boolean which indicates whether or not this Entity has initialized - initializeDepth=0 - The amount of times this Entity passed through initialize() functions components=[] - A list of components that this entity is composed of started=false - Indicates whether or not this entity is active (subscribing to events) or not subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. diff --git a/src/templates/entity_extends_constructor.template b/src/templates/entity_extends_constructor.template index d08108c..2d4a191 100644 --- a/src/templates/entity_extends_constructor.template +++ b/src/templates/entity_extends_constructor.template @@ -8,10 +8,6 @@ options.maxDepth = 0; } - if (typeof options.initialized === 'undefined') { - options.initialized = false; - } - if (typeof options.callDepth === 'undefined') { options.callDepth = 0; } else { @@ -20,10 +16,17 @@ options.maxDepth = options.callDepth; + super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START //GENERATED_TEMPLATE_OPTIONS_INIT_END - super(options); + /** + * We need to assign some options here to the entity + * because SystemLinking requires 'components[]' to + * exist when determining parent / child relationships + */ + Object.assign(this, options); //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END diff --git a/src/templates/object_base.template b/src/templates/object_base.template index 94a3be8..fe972ff 100644 --- a/src/templates/object_base.template +++ b/src/templates/object_base.template @@ -35,7 +35,6 @@ const Utils = require('INCLUDE_PATH/r3-utils'); TEMPLATE_METHODS_START initialize() - Initializes this Object if all of its required Objects are initialized - setInitialized(property=null, value=null) - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this Object will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/object_base_constructor.template b/src/templates/object_base_constructor.template index 95c9768..2e625b1 100644 --- a/src/templates/object_base_constructor.template +++ b/src/templates/object_base_constructor.template @@ -1,5 +1,9 @@ constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + if (typeof options.maxDepth === 'undefined') { options.maxDepth = 0; } diff --git a/src/templates/object_extends.template b/src/templates/object_extends.template index 4124a4c..bd8a11a 100644 --- a/src/templates/object_extends.template +++ b/src/templates/object_extends.template @@ -15,9 +15,6 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - started=false - Indicates whether or not this entity is active (subscribing to events) or not - subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. - dirty=false - When dirty is true, it means that this entity is in transition from having a Component to not having this Component, and will probably end up in an uninitialized state. During the next few clock cycles this child Component will have its parent reference to this entity removed. TEMPLATE_OPTIONS_END CUSTOM_OPTIONS_START @@ -34,8 +31,6 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME'); TEMPLATE_METHODS_START initialize() - Initializes this Object if all of its required Objects are initialized - start() - Starts the Object by subscribing to all Events - stop() - Stops this Object by removing all subscriptions to events TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/object_extends_constructor.template b/src/templates/object_extends_constructor.template index d08108c..552bdc1 100644 --- a/src/templates/object_extends_constructor.template +++ b/src/templates/object_extends_constructor.template @@ -20,11 +20,11 @@ options.maxDepth = options.callDepth; + super(options); + //GENERATED_TEMPLATE_OPTIONS_INIT_START //GENERATED_TEMPLATE_OPTIONS_INIT_END - super(options); - //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END diff --git a/src/templates/token.db b/src/templates/token.db index cc89a24..e4b0954 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -36,8 +36,6 @@ GENERATED_ON_TOUCH_START_METHOD_AFTER GENERATED_OPTIONS_INIT GENERATED_OUT_OF_CLASS_IMPLEMENTATION GENERATED_REQUIRED_COMPONENTS -GENERATED_SET_INITIALIZED_METHOD -GENERATED_SET_INITIALIZED_METHOD_AFTER GENERATED_SET_RUNTIME_METHOD GENERATED_SET_RUNTIME_METHOD_AFTER GENERATED_SOURCE @@ -128,7 +126,6 @@ CUSTOM_OPTIONS CUSTOM_OPTIONS_INIT CUSTOM_OUT_OF_CLASS_IMPLEMENTATION CUSTOM_REQUIRED_COMPONENTS -CUSTOM_SET_INITIALIZED_METHOD CUSTOM_SET_RUNTIME_METHOD CUSTOM_START_METHOD CUSTOM_STATIC_ACTIVATE_INSTANCES_METHOD diff --git a/test/R3.test.js b/test/R3.test.js index 7e3f36f..2c20ef5 100644 --- a/test/R3.test.js +++ b/test/R3.test.js @@ -67,18 +67,31 @@ describe('R3 Tests', () => { //GENERATED_COMPONENT_CREATE_START const componentCode = new ComponentCode(); + assert.isTrue(componentCode.initialized); const componentDOM = new ComponentDOM(); + assert.isTrue(componentDOM.initialized); const componentCanvas = new ComponentCanvas(); + assert.isTrue(componentCanvas.initialized); const componentGeometry = new ComponentGeometry(); + assert.isTrue(componentGeometry.initialized); const componentBufferGeometry = new ComponentBufferGeometry(); + assert.isTrue(componentBufferGeometry.initialized); const componentPlaneGeometry = new ComponentPlaneGeometry(); + assert.isTrue(componentPlaneGeometry.initialized); const componentGraphics = new ComponentGraphics(); + assert.isTrue(componentGraphics.initialized); const componentImage = new ComponentImage(); + assert.isTrue(componentImage.initialized); const componentInput = new ComponentInput(); + assert.isTrue(componentInput.initialized); const componentTouch = new ComponentTouch(); + assert.isTrue(componentTouch.initialized); const componentMaterial = new ComponentMaterial(); + assert.isTrue(componentMaterial.initialized); const componentMesh = new ComponentMesh(); + assert.isTrue(componentMesh.initialized); const componentTexture = new ComponentTexture(); + assert.isTrue(componentTexture.initialized); //GENERATED_COMPONENT_CREATE_END } @@ -90,6 +103,7 @@ describe('R3 Tests', () => { //GENERATED_ENTITY_CREATE_START const entitySlider = new EntitySlider(); + assert.isTrue(entitySlider.initialized); //GENERATED_ENTITY_CREATE_END } @@ -136,7 +150,11 @@ describe('R3 Tests', () => { 'Linking system sets parent / child relationships correctly', () => { - const slider1 = new EntitySlider(); + const slider1 = new EntitySlider( + { + name : 'slider1' + } + ); const canvas = new ComponentCanvas(); const touch = new ComponentTouch(); @@ -164,6 +182,7 @@ describe('R3 Tests', () => { const slider2 = new EntitySlider( { + name : 'slider2', canvas : canvas, images : [image1, image2] } @@ -180,6 +199,7 @@ describe('R3 Tests', () => { try { const slider3 = new EntitySlider( { + name: 'badSlider3', canvas: canvas, images: null } @@ -188,7 +208,12 @@ describe('R3 Tests', () => { assert.isTrue(err instanceof TypeError); } - const slider3 = new EntitySlider({canvas}); + const slider3 = new EntitySlider( + { + name : 'slider3', + canvas + } + ); slider3.images = [image1, image2, image3]; assert.deepEqual(image1.parents, [slider1, slider2, slider3]); @@ -207,8 +232,36 @@ describe('R3 Tests', () => { assert.deepEqual(image1.parents, [slider1, slider2]); assert.deepEqual(image2.parents, [slider2]); assert.deepEqual(image3.parents, []); + assert.deepEqual(slider3.children, [canvas]); + assert.deepEqual(slider3.components, [canvas]); + slider3.canvas = null; + assert.deepEqual(canvas.parents, [slider1, slider2]); + assert.deepEqual(slider3.children, []); + assert.deepEqual(slider3.components, []); + try { + const slider4 = new EntitySlider( + { + canvas, + images: [{}] + } + ); + } catch (err) { + assert.isTrue(err instanceof TypeError); + } + + assert.deepEqual(canvas.parents, [slider1, slider2]); + + try { + const slider5 = new EntitySlider( + { + canvas : image1 + } + ); + } catch (err) { + assert.isTrue(err instanceof TypeError); + } } ); diff --git a/version b/version index 8fa76b2..ee8ae56 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.245 \ No newline at end of file +3.0.255 \ No newline at end of file