diff --git a/dist/index.html b/dist/index.html index 9a936c9..44042fe 100644 --- a/dist/index.html +++ b/dist/index.html @@ -36,11 +36,10 @@ } ); - slider.canvas = canvas; - slider.images = [image]; - slider.canvas = null; - slider.canvas = canvas; - slider.images = [image]; + slider.canvas = canvas; + slider.images = [image]; + slider.canvas = null; + slider.canvas = canvas; }); diff --git a/dist/r3.js b/dist/r3.js index 876915a..63a9eba 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.58'; - static compileDate = '2021 Sep 23 - 11:36:17 am'; + static version = '3.0.67'; + static compileDate = '2021 Sep 23 - 14:00:26 pm'; } class Runtime { @@ -1363,6 +1363,11 @@ class SystemLinking extends System { SystemLinking.OnEntityPropertyUpdate ); + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED'] = Event.Subscribe( + Event.ENTITY_PROPERTY_UPDATED, + SystemLinking.OnEntityPropertyUpdated + ); + SystemLinking.Started = true; console.log('Started system: SystemLinking'); @@ -1394,6 +1399,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'].remove(); delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE']; + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED'].remove(); + delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED']; + SystemLinking.Started = false; console.log('Stopped system: SystemLinking'); @@ -1495,27 +1503,37 @@ class SystemLinking extends System { */ static OnEntityPropertyUpdate(object) { - console.log('Entity object update', object); - console.log('canvas = ' + object.entity.canvas); - console.log('images = ' + object.entity.images); + console.log('Entity object update of property ' + object.property); + + if (!object.entity.underConstruction) { + + if (object.entity.initialized) { + /** + * Check if this object will still be initialized after this assignment completes + */ + object.entity.setInitialized(object.property, object.value); + if (!object.entity.initialized) { + object.entity.initialized = true; + object.entity.stop(); + } + } + } + + } + + /** + * OnEntityPropertyUpdated() + * - Listens to events of type Event.ENTITY_PROPERTY_UPDATED and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnEntityPropertyUpdated(object) { if (!object.entity.underConstruction) { object.entity.initializeDepth = 0; object.entity.initialize(); - - if (object.entity.started && !object.entity.initialized) { - object.entity.stop(); - } - } - // if (!object.entity.initialized) { - // object.entity.initialize(); - // } else { - // object.entity.stop(); - // } - // object.entity.initialize(); - } } @@ -2341,40 +2359,41 @@ Event.DOM_COMPONENT_INITIALIZED = 0x8; Event.ENTITY_CREATED = 0x9; Event.ENTITY_INITIALIZED = 0xa; Event.ENTITY_PROPERTY_UPDATE = 0xb; -Event.ENTITY_STARTED = 0xc; -Event.GET_API_URL = 0xd; -Event.GET_RUNTIME = 0xe; -Event.GET_WINDOW_SIZE = 0xf; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0x10; -Event.IMAGE_COMPONENT_INITIALIZED = 0x11; -Event.IMAGE_INSTANCE_CREATED = 0x12; -Event.INPUT_COMPONENT_INITIALIZED = 0x13; -Event.INSTANCE_CREATED = 0x14; -Event.INSTANCE_DISPOSED = 0x15; -Event.KEYBOARD_DOWN = 0x16; -Event.KEYBOARD_UP = 0x17; -Event.MOUSE_DOWN = 0x18; -Event.MOUSE_MOVE = 0x19; -Event.MOUSE_UP = 0x1a; -Event.MOUSE_WHEEL = 0x1b; -Event.OBJECT_CREATED = 0x1c; -Event.OBJECT_INITIALIZED = 0x1d; -Event.PAUSE = 0x1e; -Event.PROJECT_INITIALIZED = 0x1f; -Event.RESTART = 0x20; -Event.SLIDER_ENTITY_INITIALIZED = 0x21; -Event.START = 0x22; -Event.TOUCH_CANCEL = 0x23; -Event.TOUCH_END = 0x24; -Event.TOUCH_MOVE = 0x25; -Event.TOUCH_START = 0x26; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x27; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x28; -Event.UPDATE_INSTANCE_AFTER = 0x29; -Event.UPDATE_INSTANCE_BEFORE = 0x2a; -Event.UPDATE_INSTANCE_PROPERTY = 0x2b; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2c; -Event.MAX_EVENTS = 0x2d; +Event.ENTITY_PROPERTY_UPDATED = 0xc; +Event.ENTITY_STARTED = 0xd; +Event.GET_API_URL = 0xe; +Event.GET_RUNTIME = 0xf; +Event.GET_WINDOW_SIZE = 0x10; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0x11; +Event.IMAGE_COMPONENT_INITIALIZED = 0x12; +Event.IMAGE_INSTANCE_CREATED = 0x13; +Event.INPUT_COMPONENT_INITIALIZED = 0x14; +Event.INSTANCE_CREATED = 0x15; +Event.INSTANCE_DISPOSED = 0x16; +Event.KEYBOARD_DOWN = 0x17; +Event.KEYBOARD_UP = 0x18; +Event.MOUSE_DOWN = 0x19; +Event.MOUSE_MOVE = 0x1a; +Event.MOUSE_UP = 0x1b; +Event.MOUSE_WHEEL = 0x1c; +Event.OBJECT_CREATED = 0x1d; +Event.OBJECT_INITIALIZED = 0x1e; +Event.PAUSE = 0x1f; +Event.PROJECT_INITIALIZED = 0x20; +Event.RESTART = 0x21; +Event.SLIDER_ENTITY_INITIALIZED = 0x22; +Event.START = 0x23; +Event.TOUCH_CANCEL = 0x24; +Event.TOUCH_END = 0x25; +Event.TOUCH_MOVE = 0x26; +Event.TOUCH_START = 0x27; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x28; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x29; +Event.UPDATE_INSTANCE_AFTER = 0x2a; +Event.UPDATE_INSTANCE_BEFORE = 0x2b; +Event.UPDATE_INSTANCE_PROPERTY = 0x2c; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2d; +Event.MAX_EVENTS = 0x2e; Event.GetEventName = function(eventId) { @@ -2390,39 +2409,40 @@ Event.GetEventName = function(eventId) { case 0x9 : return 'entity_created'; case 0xa : return 'entity_initialized'; case 0xb : return 'entity_property_update'; - case 0xc : return 'entity_started'; - case 0xd : return 'get_api_url'; - case 0xe : return 'get_runtime'; - case 0xf : return 'get_window_size'; - case 0x10 : return 'graphics_component_initialized'; - case 0x11 : return 'image_component_initialized'; - case 0x12 : return 'image_instance_created'; - case 0x13 : return 'input_component_initialized'; - case 0x14 : return 'instance_created'; - case 0x15 : return 'instance_disposed'; - case 0x16 : return 'keyboard_down'; - case 0x17 : return 'keyboard_up'; - case 0x18 : return 'mouse_down'; - case 0x19 : return 'mouse_move'; - case 0x1a : return 'mouse_up'; - case 0x1b : return 'mouse_wheel'; - case 0x1c : return 'object_created'; - case 0x1d : return 'object_initialized'; - case 0x1e : return 'pause'; - case 0x1f : return 'project_initialized'; - case 0x20 : return 'restart'; - case 0x21 : return 'slider_entity_initialized'; - case 0x22 : return 'start'; - case 0x23 : return 'touch_cancel'; - case 0x24 : return 'touch_end'; - case 0x25 : return 'touch_move'; - case 0x26 : return 'touch_start'; - case 0x27 : return 'update_from_instance_after'; - case 0x28 : return 'update_from_instance_before'; - case 0x29 : return 'update_instance_after'; - case 0x2a : return 'update_instance_before'; - case 0x2b : return 'update_instance_property'; - case 0x2c : return 'update_property_from_instance'; + case 0xc : return 'entity_property_updated'; + case 0xd : return 'entity_started'; + case 0xe : return 'get_api_url'; + case 0xf : return 'get_runtime'; + case 0x10 : return 'get_window_size'; + case 0x11 : return 'graphics_component_initialized'; + case 0x12 : return 'image_component_initialized'; + case 0x13 : return 'image_instance_created'; + case 0x14 : return 'input_component_initialized'; + case 0x15 : return 'instance_created'; + case 0x16 : return 'instance_disposed'; + case 0x17 : return 'keyboard_down'; + case 0x18 : return 'keyboard_up'; + case 0x19 : return 'mouse_down'; + case 0x1a : return 'mouse_move'; + case 0x1b : return 'mouse_up'; + case 0x1c : return 'mouse_wheel'; + case 0x1d : return 'object_created'; + case 0x1e : return 'object_initialized'; + case 0x1f : return 'pause'; + case 0x20 : return 'project_initialized'; + case 0x21 : return 'restart'; + case 0x22 : return 'slider_entity_initialized'; + case 0x23 : return 'start'; + case 0x24 : return 'touch_cancel'; + case 0x25 : return 'touch_end'; + case 0x26 : return 'touch_move'; + case 0x27 : return 'touch_start'; + case 0x28 : return 'update_from_instance_after'; + case 0x29 : return 'update_from_instance_before'; + case 0x2a : return 'update_instance_after'; + case 0x2b : return 'update_instance_before'; + case 0x2c : return 'update_instance_property'; + case 0x2d : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } @@ -2649,7 +2669,7 @@ class Entity extends R3Object { /** * initialize() - * - Should raises an event(s) which indicates that this object initialized + * - Starts the Entity if all of its sub-Components are initialized */ initialize() { @@ -2668,82 +2688,98 @@ class Entity extends R3Object { /** * setInitialized() - * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this component will still be initialized + * after 'property' will assume 'value' + * @param property=null + * @param value=null */ - setInitialized() { + setInitialized( + property=null, + value=null + ) { - let ready = true; - for (let property in this.required) { - if (this.required.hasOwnProperty(property)) { + let isReady = function(property, value) { - console.log('checking requirements for ' + property); + console.log('checking requirements for ' + property); - let initialized = true; + if (this.required[property] instanceof Array) { - if (this.required[property] instanceof Array) { + /** + * First we need to check if we have this array defined + */ + if (!(value instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined - it should be an array'); + } - /** - * First we need to check if we have this array defined - */ - if (!(this[property] instanceof Array)) { - throw new Error('The property ' + property + ' of this object was not properly defined'); + if (value.length === 0) { + return false; + } + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < value.length; i++) { + this.required[property].map( + function(constructor) { + if (!(value[i] instanceof constructor)) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + }.bind(this) + ); + } + + for (let i = 0; i < value.length; i++) { + if (value[i].initialized !== true) { + return false; } + } - if (this[property].length === 0) { - initialized = false; - } + return true; - let isInstance = false; - - /** - * Check all properties are an instance of this.required[property] - */ - for (let i = 0; i < this[property].length; i++) { - this.required[property].map( - function(constructor) { - if (this[property][i] instanceof constructor) { - isInstance = true; - } - }.bind(this) - ); - - if (!isInstance) { - throw new Error('The property ' + property + ' of this object is not of the correct type'); - } - } - - for (let i = 0; i < this[property].length; i++) { - if (this[property][i].initialized !== true) { - initialized = false; - } - } + } else { + if (value === null) { + return false; } else { - if (this[property] === null) { - initialized = false; + if (typeof value === 'undefined') { + throw new Error('The ' + property + ' is not defined'); + } + + if (!(value instanceof this.required[property])) { + throw new Error('The property ' + property + ' of this object is not of the correct type') + } + + if (value.initialized !== true) { + return false; + } + + return true; + } + } + }.bind(this); + + for (let requiredProperty in this.required) { + if (this.required.hasOwnProperty(requiredProperty)) { + if (requiredProperty === property) { + if (isReady(property, value)) { + this.initialized = true; } else { - - if (typeof this[property] === 'undefined') { - throw new Error('The ' + property + ' was not properly defined'); - } - - if (this[property].initialized !== true) { - initialized = false; - } + this.initialized = false; + return; + } + } else { + if (isReady(requiredProperty, this[requiredProperty])) { + this.initialized = true; + } else { + this.initialized = false; + return; } } - - if (!initialized) { - ready = false; - console.log('This property ' + property + ' is not yet initialized'); - } - } } - this.initialized = ready; - } } @@ -2949,7 +2985,6 @@ class EntitySlider extends Entity { configurable : true, enumerable : true, set: function(x) { - this.imagesBackup = x; Event.Emit( Event.ENTITY_PROPERTY_UPDATE, { @@ -2958,6 +2993,15 @@ class EntitySlider extends Entity { value : x } ); + this.imagesBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATED, + { + entity : this, + property : 'images', + value : x + } + ); return x; }, get : function() { @@ -2976,7 +3020,6 @@ class EntitySlider extends Entity { configurable : true, enumerable : true, set: function(x) { - this.canvasBackup = x; Event.Emit( Event.ENTITY_PROPERTY_UPDATE, { @@ -2985,6 +3028,15 @@ class EntitySlider extends Entity { value : x } ); + this.canvasBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATED, + { + entity : this, + property : 'canvas', + value : x + } + ); return x; }, get : function() { @@ -3009,7 +3061,7 @@ class EntitySlider extends Entity { /** * initialize() - * - Notifies all systems listening that this component initialized. + * - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). */ initialize() { @@ -3038,11 +3090,18 @@ class EntitySlider extends Entity { /** * setInitialized() - * - Checks all required Components for this Entity initialized and can perform some custom actions + * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this component will still be initialized + * after 'property' will assume 'value' + * @param property=null + * @param value=null */ - setInitialized() { + setInitialized( + property=null, + value=null + ) { - super.setInitialized(); + super.setInitialized(property, value); } diff --git a/package.json b/package.json index 64d90dd..afa2e21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "3.0.58", + "version" : "3.0.67", "description": "", "private": true, "dependencies": { diff --git a/src/r3/r3-entity/r3-entity-slider.js b/src/r3/r3-entity/r3-entity-slider.js index 17a193f..5e5c660 100644 --- a/src/r3/r3-entity/r3-entity-slider.js +++ b/src/r3/r3-entity/r3-entity-slider.js @@ -127,8 +127,8 @@ const Entity = require('.././r3-entity.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - initialize() - Notifies all systems listening that this component initialized. - setInitialized() - Checks all required Components for this Entity initialized and can perform some custom actions + initialize() - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). + setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END @@ -255,7 +255,6 @@ class EntitySlider extends Entity { configurable : true, enumerable : true, set: function(x) { - this.imagesBackup = x; Event.Emit( Event.ENTITY_PROPERTY_UPDATE, { @@ -264,6 +263,15 @@ class EntitySlider extends Entity { value : x } ); + this.imagesBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATED, + { + entity : this, + property : 'images', + value : x + } + ); return x; }, get : function() { @@ -282,7 +290,6 @@ class EntitySlider extends Entity { configurable : true, enumerable : true, set: function(x) { - this.canvasBackup = x; Event.Emit( Event.ENTITY_PROPERTY_UPDATE, { @@ -291,6 +298,15 @@ class EntitySlider extends Entity { value : x } ); + this.canvasBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATED, + { + entity : this, + property : 'canvas', + value : x + } + ); return x; }, get : function() { @@ -327,7 +343,7 @@ class EntitySlider extends Entity { /** * initialize() - * - Notifies all systems listening that this component initialized. + * - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). */ initialize() { @@ -362,12 +378,19 @@ class EntitySlider extends Entity { /** * setInitialized() - * - Checks all required Components for this Entity initialized and can perform some custom actions + * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this component will still be initialized + * after 'property' will assume 'value' + * @param property=null + * @param value=null */ - setInitialized() { + setInitialized( + property=null, + value=null + ) { //GENERATED_SET_INITIALIZED_METHOD_START - super.setInitialized(); + super.setInitialized(property, value); //GENERATED_SET_INITIALIZED_METHOD_END //CUSTOM_SET_INITIALIZED_METHOD_START diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js index 2769e56..14ca2d2 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -98,8 +98,8 @@ const R3Object = require('.././r3-r3-object.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - initialize() - Should raises an event(s) which indicates that this object initialized - setInitialized() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + initialize() - Starts the Entity if all of its sub-Components are initialized + setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -167,7 +167,7 @@ class Entity extends R3Object { /** * initialize() - * - Should raises an event(s) which indicates that this object initialized + * - Starts the Entity if all of its sub-Components are initialized */ initialize() { @@ -193,83 +193,99 @@ class Entity extends R3Object { /** * setInitialized() - * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this component will still be initialized + * after 'property' will assume 'value' + * @param property=null + * @param value=null */ - setInitialized() { + setInitialized( + property=null, + value=null + ) { //GENERATED_SET_INITIALIZED_METHOD_START - let ready = true; - for (let property in this.required) { - if (this.required.hasOwnProperty(property)) { - console.log('checking requirements for ' + property); + let isReady = function(property, value) { - let initialized = true; + console.log('checking requirements for ' + property); - if (this.required[property] instanceof Array) { + if (this.required[property] instanceof Array) { - /** - * First we need to check if we have this array defined - */ - if (!(this[property] instanceof Array)) { - throw new Error('The property ' + property + ' of this object was not properly defined'); + /** + * First we need to check if we have this array defined + */ + if (!(value instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined - it should be an array'); + } + + if (value.length === 0) { + return false; + } + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < value.length; i++) { + this.required[property].map( + function(constructor) { + if (!(value[i] instanceof constructor)) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + }.bind(this) + ); + } + + for (let i = 0; i < value.length; i++) { + if (value[i].initialized !== true) { + return false; } + } - if (this[property].length === 0) { - initialized = false; - } + return true; - let isInstance = false; - - /** - * Check all properties are an instance of this.required[property] - */ - for (let i = 0; i < this[property].length; i++) { - this.required[property].map( - function(constructor) { - if (this[property][i] instanceof constructor) { - isInstance = true; - } - }.bind(this) - ); - - if (!isInstance) { - throw new Error('The property ' + property + ' of this object is not of the correct type'); - } - } - - for (let i = 0; i < this[property].length; i++) { - if (this[property][i].initialized !== true) { - initialized = false; - } - } + } else { + if (value === null) { + return false; } else { - if (this[property] === null) { - initialized = false; + if (typeof value === 'undefined') { + throw new Error('The ' + property + ' is not defined'); + } + + if (!(value instanceof this.required[property])) { + throw new Error('The property ' + property + ' of this object is not of the correct type') + } + + if (value.initialized !== true) { + return false; + } + + return true; + } + } + }.bind(this); + + for (let requiredProperty in this.required) { + if (this.required.hasOwnProperty(requiredProperty)) { + if (requiredProperty === property) { + if (isReady(property, value)) { + this.initialized = true; } else { - - if (typeof this[property] === 'undefined') { - throw new Error('The ' + property + ' was not properly defined'); - } - - if (this[property].initialized !== true) { - initialized = false; - } + this.initialized = false; + return; + } + } else { + if (isReady(requiredProperty, this[requiredProperty])) { + this.initialized = true; + } else { + this.initialized = false; + return; } } - - if (!initialized) { - ready = false; - console.log('This property ' + property + ' is not yet initialized'); - } - - } } - - this.initialized = ready; //GENERATED_SET_INITIALIZED_METHOD_END //CUSTOM_SET_INITIALIZED_METHOD_START diff --git a/src/r3/r3-event.js b/src/r3/r3-event.js index 76e6fa9..c49739f 100644 --- a/src/r3/r3-event.js +++ b/src/r3/r3-event.js @@ -356,40 +356,41 @@ Event.DOM_COMPONENT_INITIALIZED = 0x8; Event.ENTITY_CREATED = 0x9; Event.ENTITY_INITIALIZED = 0xa; Event.ENTITY_PROPERTY_UPDATE = 0xb; -Event.ENTITY_STARTED = 0xc; -Event.GET_API_URL = 0xd; -Event.GET_RUNTIME = 0xe; -Event.GET_WINDOW_SIZE = 0xf; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0x10; -Event.IMAGE_COMPONENT_INITIALIZED = 0x11; -Event.IMAGE_INSTANCE_CREATED = 0x12; -Event.INPUT_COMPONENT_INITIALIZED = 0x13; -Event.INSTANCE_CREATED = 0x14; -Event.INSTANCE_DISPOSED = 0x15; -Event.KEYBOARD_DOWN = 0x16; -Event.KEYBOARD_UP = 0x17; -Event.MOUSE_DOWN = 0x18; -Event.MOUSE_MOVE = 0x19; -Event.MOUSE_UP = 0x1a; -Event.MOUSE_WHEEL = 0x1b; -Event.OBJECT_CREATED = 0x1c; -Event.OBJECT_INITIALIZED = 0x1d; -Event.PAUSE = 0x1e; -Event.PROJECT_INITIALIZED = 0x1f; -Event.RESTART = 0x20; -Event.SLIDER_ENTITY_INITIALIZED = 0x21; -Event.START = 0x22; -Event.TOUCH_CANCEL = 0x23; -Event.TOUCH_END = 0x24; -Event.TOUCH_MOVE = 0x25; -Event.TOUCH_START = 0x26; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x27; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x28; -Event.UPDATE_INSTANCE_AFTER = 0x29; -Event.UPDATE_INSTANCE_BEFORE = 0x2a; -Event.UPDATE_INSTANCE_PROPERTY = 0x2b; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2c; -Event.MAX_EVENTS = 0x2d; +Event.ENTITY_PROPERTY_UPDATED = 0xc; +Event.ENTITY_STARTED = 0xd; +Event.GET_API_URL = 0xe; +Event.GET_RUNTIME = 0xf; +Event.GET_WINDOW_SIZE = 0x10; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0x11; +Event.IMAGE_COMPONENT_INITIALIZED = 0x12; +Event.IMAGE_INSTANCE_CREATED = 0x13; +Event.INPUT_COMPONENT_INITIALIZED = 0x14; +Event.INSTANCE_CREATED = 0x15; +Event.INSTANCE_DISPOSED = 0x16; +Event.KEYBOARD_DOWN = 0x17; +Event.KEYBOARD_UP = 0x18; +Event.MOUSE_DOWN = 0x19; +Event.MOUSE_MOVE = 0x1a; +Event.MOUSE_UP = 0x1b; +Event.MOUSE_WHEEL = 0x1c; +Event.OBJECT_CREATED = 0x1d; +Event.OBJECT_INITIALIZED = 0x1e; +Event.PAUSE = 0x1f; +Event.PROJECT_INITIALIZED = 0x20; +Event.RESTART = 0x21; +Event.SLIDER_ENTITY_INITIALIZED = 0x22; +Event.START = 0x23; +Event.TOUCH_CANCEL = 0x24; +Event.TOUCH_END = 0x25; +Event.TOUCH_MOVE = 0x26; +Event.TOUCH_START = 0x27; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x28; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x29; +Event.UPDATE_INSTANCE_AFTER = 0x2a; +Event.UPDATE_INSTANCE_BEFORE = 0x2b; +Event.UPDATE_INSTANCE_PROPERTY = 0x2c; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2d; +Event.MAX_EVENTS = 0x2e; Event.GetEventName = function(eventId) { @@ -405,39 +406,40 @@ Event.GetEventName = function(eventId) { case 0x9 : return 'entity_created'; case 0xa : return 'entity_initialized'; case 0xb : return 'entity_property_update'; - case 0xc : return 'entity_started'; - case 0xd : return 'get_api_url'; - case 0xe : return 'get_runtime'; - case 0xf : return 'get_window_size'; - case 0x10 : return 'graphics_component_initialized'; - case 0x11 : return 'image_component_initialized'; - case 0x12 : return 'image_instance_created'; - case 0x13 : return 'input_component_initialized'; - case 0x14 : return 'instance_created'; - case 0x15 : return 'instance_disposed'; - case 0x16 : return 'keyboard_down'; - case 0x17 : return 'keyboard_up'; - case 0x18 : return 'mouse_down'; - case 0x19 : return 'mouse_move'; - case 0x1a : return 'mouse_up'; - case 0x1b : return 'mouse_wheel'; - case 0x1c : return 'object_created'; - case 0x1d : return 'object_initialized'; - case 0x1e : return 'pause'; - case 0x1f : return 'project_initialized'; - case 0x20 : return 'restart'; - case 0x21 : return 'slider_entity_initialized'; - case 0x22 : return 'start'; - case 0x23 : return 'touch_cancel'; - case 0x24 : return 'touch_end'; - case 0x25 : return 'touch_move'; - case 0x26 : return 'touch_start'; - case 0x27 : return 'update_from_instance_after'; - case 0x28 : return 'update_from_instance_before'; - case 0x29 : return 'update_instance_after'; - case 0x2a : return 'update_instance_before'; - case 0x2b : return 'update_instance_property'; - case 0x2c : return 'update_property_from_instance'; + case 0xc : return 'entity_property_updated'; + case 0xd : return 'entity_started'; + case 0xe : return 'get_api_url'; + case 0xf : return 'get_runtime'; + case 0x10 : return 'get_window_size'; + case 0x11 : return 'graphics_component_initialized'; + case 0x12 : return 'image_component_initialized'; + case 0x13 : return 'image_instance_created'; + case 0x14 : return 'input_component_initialized'; + case 0x15 : return 'instance_created'; + case 0x16 : return 'instance_disposed'; + case 0x17 : return 'keyboard_down'; + case 0x18 : return 'keyboard_up'; + case 0x19 : return 'mouse_down'; + case 0x1a : return 'mouse_move'; + case 0x1b : return 'mouse_up'; + case 0x1c : return 'mouse_wheel'; + case 0x1d : return 'object_created'; + case 0x1e : return 'object_initialized'; + case 0x1f : return 'pause'; + case 0x20 : return 'project_initialized'; + case 0x21 : return 'restart'; + case 0x22 : return 'slider_entity_initialized'; + case 0x23 : return 'start'; + case 0x24 : return 'touch_cancel'; + case 0x25 : return 'touch_end'; + case 0x26 : return 'touch_move'; + case 0x27 : return 'touch_start'; + case 0x28 : return 'update_from_instance_after'; + case 0x29 : return 'update_from_instance_before'; + case 0x2a : return 'update_instance_after'; + case 0x2b : return 'update_instance_before'; + case 0x2c : return 'update_instance_property'; + case 0x2d : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index f153653..baf2a84 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.58'; - static compileDate = '2021 Sep 23 - 11:36:17 am'; + static version = '3.0.67'; + static compileDate = '2021 Sep 23 - 14:00:26 pm'; } //GENERATED_IMPORTS_START diff --git a/src/r3/r3-system/r3-system-linking.js b/src/r3/r3-system/r3-system-linking.js index e72f033..0646da1 100644 --- a/src/r3/r3-system/r3-system-linking.js +++ b/src/r3/r3-system/r3-system-linking.js @@ -71,6 +71,7 @@ const System = require('.././r3-system.js'); Event.INSTANCE_CREATED Event.CREATE_INSTANCE_BEFORE - @returns boolean delayInstance which indicates whether or not instance creation is delayed (handled) by another system. (i.e. where instance creation order is of importance) Event.ENTITY_PROPERTY_UPDATE + Event.ENTITY_PROPERTY_UPDATED CUSTOM_STATIC_EVENT_LISTENERS_END TEMPLATE_METHODS_START @@ -164,6 +165,11 @@ class SystemLinking extends System { SystemLinking.OnEntityPropertyUpdate ); + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED'] = Event.Subscribe( + Event.ENTITY_PROPERTY_UPDATED, + SystemLinking.OnEntityPropertyUpdated + ); + //GENERATED_STATIC_EVENT_LISTENERS_START_END //CUSTOM_BEFORE_STATIC_SYSTEM_START_START @@ -208,6 +214,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'].remove(); delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE']; + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED'].remove(); + delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATED']; + //GENERATED_STATIC_EVENT_LISTENERS_STOP_END //CUSTOM_BEFORE_STATIC_SYSTEM_STOP_START @@ -357,28 +366,43 @@ class SystemLinking extends System { //GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_END //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_START - console.log('Entity object update', object); - console.log('canvas = ' + object.entity.canvas); - console.log('images = ' + object.entity.images); + console.log('Entity object update of property ' + object.property); + if (!object.entity.underConstruction) { + + if (object.entity.initialized) { + /** + * Check if this object will still be initialized after this assignment completes + */ + object.entity.setInitialized(object.property, object.value); + if (!object.entity.initialized) { + object.entity.initialized = true; + object.entity.stop(); + } + } + } + + //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_END + + } + + /** + * OnEntityPropertyUpdated() + * - Listens to events of type Event.ENTITY_PROPERTY_UPDATED and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnEntityPropertyUpdated(object) { + + //GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD_START + //GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD_END + + //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD_START if (!object.entity.underConstruction) { object.entity.initializeDepth = 0; object.entity.initialize(); - - if (object.entity.started && !object.entity.initialized) { - object.entity.stop(); - } - } - - - // if (!object.entity.initialized) { - // object.entity.initialize(); - // } else { - // object.entity.stop(); - // } - // object.entity.initialize(); - //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_END + //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD_END } //GENERATED_STATIC_EVENT_LISTENER_METHODS_END diff --git a/src/templates/base_set_initialized.template b/src/templates/base_set_initialized.template index a10c6c1..52a87c3 100644 --- a/src/templates/base_set_initialized.template +++ b/src/templates/base_set_initialized.template @@ -1,72 +1,81 @@ - let ready = true; - for (let property in this.required) { - if (this.required.hasOwnProperty(property)) { - console.log('checking requirements for ' + property); + let isReady = function(property, value) { - let initialized = true; + console.log('checking requirements for ' + property); - if (this.required[property] instanceof Array) { + if (this.required[property] instanceof Array) { - /** - * First we need to check if we have this array defined - */ - if (!(this[property] instanceof Array)) { - throw new Error('The property ' + property + ' of this object was not properly defined'); + /** + * First we need to check if we have this array defined + */ + if (!(value instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined - it should be an array'); + } + + if (value.length === 0) { + return false; + } + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < value.length; i++) { + this.required[property].map( + function(constructor) { + if (!(value[i] instanceof constructor)) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + }.bind(this) + ); + } + + for (let i = 0; i < value.length; i++) { + if (value[i].initialized !== true) { + return false; } + } - if (this[property].length === 0) { - initialized = false; - } + return true; - let isInstance = false; - - /** - * Check all properties are an instance of this.required[property] - */ - for (let i = 0; i < this[property].length; i++) { - this.required[property].map( - function(constructor) { - if (this[property][i] instanceof constructor) { - isInstance = true; - } - }.bind(this) - ); - - if (!isInstance) { - throw new Error('The property ' + property + ' of this object is not of the correct type'); - } - } - - for (let i = 0; i < this[property].length; i++) { - if (this[property][i].initialized !== true) { - initialized = false; - } - } + } else { + if (value === null) { + return false; } else { - if (this[property] === null) { - initialized = false; + if (typeof value === 'undefined') { + throw new Error('The ' + property + ' is not defined'); + } + + if (!(value instanceof this.required[property])) { + throw new Error('The property ' + property + ' of this object is not of the correct type') + } + + if (value.initialized !== true) { + return false; + } + + return true; + } + } + }.bind(this); + + for (let requiredProperty in this.required) { + if (this.required.hasOwnProperty(requiredProperty)) { + if (requiredProperty === property) { + if (isReady(property, value)) { + this.initialized = true; } else { - - if (typeof this[property] === 'undefined') { - throw new Error('The ' + property + ' was not properly defined'); - } - - if (this[property].initialized !== true) { - initialized = false; - } + this.initialized = false; + return; + } + } else { + if (isReady(requiredProperty, this[requiredProperty])) { + this.initialized = true; + } else { + this.initialized = false; + return; } } - - if (!initialized) { - ready = false; - console.log('This property ' + property + ' is not yet initialized'); - } - - } - } - - this.initialized = ready; \ No newline at end of file + } \ No newline at end of file diff --git a/src/templates/entity_base.template b/src/templates/entity_base.template index e4ceca4..63e1012 100644 --- a/src/templates/entity_base.template +++ b/src/templates/entity_base.template @@ -21,8 +21,8 @@ const R3Object = require('.././r3-r3-object.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - initialize() - Should raises an event(s) which indicates that this object initialized - setInitialized() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + initialize() - Starts the Entity if all of its sub-Components are initialized + setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/entity_extends.template b/src/templates/entity_extends.template index 93a67cd..070918b 100644 --- a/src/templates/entity_extends.template +++ b/src/templates/entity_extends.template @@ -27,8 +27,8 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - initialize() - Notifies all systems listening that this component initialized. - setInitialized() - Checks all required Components for this Entity initialized and can perform some custom actions + initialize() - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). + setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END diff --git a/src/templates/extends_set_initialized.template b/src/templates/extends_set_initialized.template index c125a28..fdee037 100644 --- a/src/templates/extends_set_initialized.template +++ b/src/templates/extends_set_initialized.template @@ -1 +1 @@ - super.setInitialized(); \ No newline at end of file + super.setInitialized(property, value); \ No newline at end of file diff --git a/src/templates/generated_required_components.template b/src/templates/generated_required_components.template index 1e9433f..75d5055 100644 --- a/src/templates/generated_required_components.template +++ b/src/templates/generated_required_components.template @@ -10,7 +10,6 @@ configurable : true, enumerable : true, set: function(x) { - this.KEYBackup = x; Event.Emit( Event.ENTITY_PROPERTY_UPDATE, { @@ -19,6 +18,15 @@ value : x } ); + this.KEYBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATED, + { + entity : this, + property : 'KEY', + value : x + } + ); return x; }, get : function() { diff --git a/src/templates/token.db b/src/templates/token.db index bed9873..c3355ef 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -53,6 +53,7 @@ GENERATED_STATIC_ON_COMPONENT_INITIALIZED_METHOD GENERATED_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD GENERATED_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD GENERATED_STATIC_ON_ENTITY_INITIALIZED_METHOD +GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD GENERATED_STATIC_ON_GET_API_URL_METHOD GENERATED_STATIC_ON_GET_RUNTIME_METHOD @@ -131,6 +132,7 @@ CUSTOM_STATIC_ON_COMPONENT_INITIALIZED_METHOD CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD CUSTOM_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD CUSTOM_STATIC_ON_ENTITY_INITIALIZED_METHOD +CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD CUSTOM_STATIC_ON_GET_API_URL_METHOD CUSTOM_STATIC_ON_GET_RUNTIME_METHOD diff --git a/version b/version index 3041e12..6cdf9d2 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.58 \ No newline at end of file +3.0.67 \ No newline at end of file