diff --git a/dist/r3.js b/dist/r3.js index 7d799ab..65bdb0f 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '2.0.758'; - static compileDate = '2021 Sep 18 - 11:04:13 am'; + static version = '2.0.784'; + static compileDate = '2021 Sep 19 - 21:28:13 pm'; } class Runtime { @@ -124,7 +124,7 @@ class RuntimeCodeMirror extends RuntimeCoder { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -148,8 +148,6 @@ class RuntimeDOM extends Runtime { } -Runtime.DOCUMENT = 0x9; - /** Class R3.Runtime.DOM.Document @@ -225,7 +223,7 @@ class RuntimeDocument extends RuntimeDOM { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -257,8 +255,6 @@ class RuntimeGUI extends Runtime { } -Runtime.CONTROL_KIT = 0xa; - /** Class R3.Runtime.GUI.ControlKit @@ -334,7 +330,7 @@ class RuntimeControlKit extends RuntimeGUI { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -358,8 +354,6 @@ class RuntimeGraphics extends Runtime { } -Runtime.THREE = 0xb; - /** Class R3.Runtime.Graphics.Three @@ -435,7 +429,7 @@ class RuntimeThree extends RuntimeGraphics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -459,9 +453,6 @@ class RuntimeImage extends Runtime { } -Runtime.NODE_JS_IMAGE = 0xc; -Runtime.WEB_IMAGE = 0xd; - /** Class R3.Runtime.Image.NodeJSImage @@ -537,7 +528,7 @@ class RuntimeNodeJSImage extends RuntimeImage { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -621,11 +612,18 @@ class RuntimeWebImage extends RuntimeImage { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { + if (component instanceof R3.Component.Graphics.Image) { + let image = document.createElement('img'); + image.setAttribute('src', component.src); + image.setAttribute('alt', component.alt); + return image; + } + } } @@ -645,8 +643,6 @@ class RuntimePhysics extends Runtime { } -Runtime.BULLET = 0xe; - /** Class R3.Runtime.Physics.Bullet @@ -722,7 +718,7 @@ class RuntimeBullet extends RuntimePhysics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -761,8 +757,6 @@ class RuntimeStatistics extends Runtime { } -Runtime.STATS = 0xf; - /** Class R3.Runtime.Statistics.Stats @@ -838,7 +832,7 @@ class RuntimeStats extends RuntimeStatistics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -967,8 +961,6 @@ class SystemDOM extends System { */ static OnDomComponentInitialized(object) { - object.createInstance(); - } } @@ -1287,7 +1279,8 @@ SystemInput.Subscriptions = {}; Static Properties: - + - BlacklistedComponents (Default value [] - A list of component constructors which should not be + permitted to create instances immediately) Methods: @@ -1335,6 +1328,11 @@ class SystemLinking extends System { SystemLinking.OnInstanceCreated ); + SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'] = Event.Subscribe( + Event.CREATE_INSTANCE_BEFORE, + SystemLinking.OnCreateInstanceBefore + ); + SystemLinking.Started = true; console.log('Started system: SystemLinking'); @@ -1357,6 +1355,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['INSTANCE_CREATED'].remove(); delete SystemLinking.Subscriptions['INSTANCE_CREATED']; + SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'].remove(); + delete SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE']; + SystemLinking.Started = false; console.log('Stopped system: SystemLinking'); @@ -1365,36 +1366,57 @@ class SystemLinking extends System { /** * OnObjectCreated() - * - Listens to events of type Event.OBJECT_CREATED and executes this function. + * - Listens to events of type OBJECT_CREATED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnObjectCreated(object) { - console.log('Object Created'); + console.log('object created'); } /** * OnObjectInitialized() - * - Listens to events of type Event.OBJECT_INITIALIZED and executes this function. + * - Listens to events of type OBJECT_INITIALIZED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnObjectInitialized(object) { - console.log('Object Initialized : ' + object.constructor.name); + console.log('object initialized'); } /** * OnInstanceCreated() - * - Listens to events of type Event.INSTANCE_CREATED and executes this function. + * - Listens to events of type INSTANCE_CREATED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnInstanceCreated(object) { + console.log('instance created'); + + } + + /** + * OnCreateInstanceBefore() + * - Listens to events of type CREATE_INSTANCE_BEFORE and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return boolean delayInstance which indicates whether or not instance creation is delayed (handled) by + * another system. (i.e. where instance creation order is of importance) + */ + static OnCreateInstanceBefore(object) { + + for (let i = 0; i < SystemLinking.BlacklistedComponents.length; i++) { + if (object instanceof SystemLinking.BlacklistedComponents) { + return true; + } + } + + return false; + } } @@ -1410,6 +1432,11 @@ SystemLinking.Started = false; */ SystemLinking.Subscriptions = {}; +/** + * static BlacklistedComponents - A list of component constructors which should not be permitted to create instances immediately + */ +SystemLinking.BlacklistedComponents = []; + /** Class R3.System.Render @@ -1513,6 +1540,13 @@ class SystemRender extends System { } } + if (object instanceof R3.Component.Graphics.Image) { + if (object.runtime instanceof R3.Runtime.Image.WebImage) { + document.body.appendChild(object.instance); + } + } + + } } @@ -1917,8 +1951,6 @@ class SystemStorage extends System { */ static OnImageComponentInitialized(object) { - object.createInstance(); - } } @@ -2158,87 +2190,89 @@ class Event { } -Event.COMPONENT_CREATED = 0x1; -Event.COMPONENT_INITIALIZED = 0x2; -Event.CREATE_INSTANCE_BEFORE = 0x3; -Event.DISPOSE_INSTANCE = 0x4; -Event.DISPOSE_OBJECT = 0x5; -Event.DOM_COMPONENT_INITIALIZED = 0x6; -Event.ENTITY_CREATED = 0x7; -Event.ENTITY_INITIALIZED = 0x8; -Event.GET_RUNTIME = 0x9; -Event.GET_WINDOW_SIZE = 0xa; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0xb; -Event.IMAGE_COMPONENT_INITIALIZED = 0xc; -Event.IMAGE_INITIALIZED = 0xd; -Event.INPUT_COMPONENT_INITIALIZED = 0xe; -Event.INSTANCE_CREATED = 0xf; -Event.INSTANCE_DISPOSED = 0x10; -Event.KEYBOARD_DOWN = 0x11; -Event.KEYBOARD_UP = 0x12; -Event.MOUSE_DOWN = 0x13; -Event.MOUSE_MOVE = 0x14; -Event.MOUSE_UP = 0x15; -Event.MOUSE_WHEEL = 0x16; -Event.OBJECT_CREATED = 0x17; -Event.OBJECT_INITIALIZED = 0x18; -Event.PAUSE = 0x19; -Event.PROJECT_INITIALIZED = 0x1a; -Event.RESTART = 0x1b; -Event.START = 0x1c; -Event.TOUCH_CANCEL = 0x1d; -Event.TOUCH_END = 0x1e; -Event.TOUCH_MOVE = 0x1f; -Event.TOUCH_START = 0x20; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x21; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x22; -Event.UPDATE_INSTANCE_AFTER = 0x23; -Event.UPDATE_INSTANCE_BEFORE = 0x24; -Event.UPDATE_INSTANCE_PROPERTY = 0x25; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x26; -Event.MAX_EVENTS = 0x27; +Event.BEFORE_RENDER = 0x1; +Event.COMPONENT_CREATED = 0x2; +Event.COMPONENT_INITIALIZED = 0x3; +Event.CREATE_INSTANCE_BEFORE = 0x4; +Event.DISPOSE_INSTANCE = 0x5; +Event.DISPOSE_OBJECT = 0x6; +Event.DOM_COMPONENT_INITIALIZED = 0x7; +Event.ENTITY_CREATED = 0x8; +Event.ENTITY_INITIALIZED = 0x9; +Event.GET_RUNTIME = 0xa; +Event.GET_WINDOW_SIZE = 0xb; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0xc; +Event.IMAGE_COMPONENT_INITIALIZED = 0xd; +Event.IMAGE_INITIALIZED = 0xe; +Event.INPUT_COMPONENT_INITIALIZED = 0xf; +Event.INSTANCE_CREATED = 0x10; +Event.INSTANCE_DISPOSED = 0x11; +Event.KEYBOARD_DOWN = 0x12; +Event.KEYBOARD_UP = 0x13; +Event.MOUSE_DOWN = 0x14; +Event.MOUSE_MOVE = 0x15; +Event.MOUSE_UP = 0x16; +Event.MOUSE_WHEEL = 0x17; +Event.OBJECT_CREATED = 0x18; +Event.OBJECT_INITIALIZED = 0x19; +Event.PAUSE = 0x1a; +Event.PROJECT_INITIALIZED = 0x1b; +Event.RESTART = 0x1c; +Event.START = 0x1d; +Event.TOUCH_CANCEL = 0x1e; +Event.TOUCH_END = 0x1f; +Event.TOUCH_MOVE = 0x20; +Event.TOUCH_START = 0x21; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x22; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x23; +Event.UPDATE_INSTANCE_AFTER = 0x24; +Event.UPDATE_INSTANCE_BEFORE = 0x25; +Event.UPDATE_INSTANCE_PROPERTY = 0x26; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x27; +Event.MAX_EVENTS = 0x28; Event.GetEventName = function(eventId) { switch(eventId) { - case 0x1 : return 'component_created'; - case 0x2 : return 'component_initialized'; - case 0x3 : return 'create_instance_before'; - case 0x4 : return 'dispose_instance'; - case 0x5 : return 'dispose_object'; - case 0x6 : return 'dom_component_initialized'; - case 0x7 : return 'entity_created'; - case 0x8 : return 'entity_initialized'; - case 0x9 : return 'get_runtime'; - case 0xa : return 'get_window_size'; - case 0xb : return 'graphics_component_initialized'; - case 0xc : return 'image_component_initialized'; - case 0xd : return 'image_initialized'; - case 0xe : return 'input_component_initialized'; - case 0xf : return 'instance_created'; - case 0x10 : return 'instance_disposed'; - case 0x11 : return 'keyboard_down'; - case 0x12 : return 'keyboard_up'; - case 0x13 : return 'mouse_down'; - case 0x14 : return 'mouse_move'; - case 0x15 : return 'mouse_up'; - case 0x16 : return 'mouse_wheel'; - case 0x17 : return 'object_created'; - case 0x18 : return 'object_initialized'; - case 0x19 : return 'pause'; - case 0x1a : return 'project_initialized'; - case 0x1b : return 'restart'; - case 0x1c : return 'start'; - case 0x1d : return 'touch_cancel'; - case 0x1e : return 'touch_end'; - case 0x1f : return 'touch_move'; - case 0x20 : return 'touch_start'; - case 0x21 : return 'update_from_instance_after'; - case 0x22 : return 'update_from_instance_before'; - case 0x23 : return 'update_instance_after'; - case 0x24 : return 'update_instance_before'; - case 0x25 : return 'update_instance_property'; - case 0x26 : return 'update_property_from_instance'; + case 0x1 : return 'before_render'; + case 0x2 : return 'component_created'; + case 0x3 : return 'component_initialized'; + case 0x4 : return 'create_instance_before'; + case 0x5 : return 'dispose_instance'; + case 0x6 : return 'dispose_object'; + case 0x7 : return 'dom_component_initialized'; + case 0x8 : return 'entity_created'; + case 0x9 : return 'entity_initialized'; + case 0xa : return 'get_runtime'; + case 0xb : return 'get_window_size'; + case 0xc : return 'graphics_component_initialized'; + case 0xd : return 'image_component_initialized'; + case 0xe : return 'image_initialized'; + case 0xf : return 'input_component_initialized'; + case 0x10 : return 'instance_created'; + case 0x11 : return 'instance_disposed'; + case 0x12 : return 'keyboard_down'; + case 0x13 : return 'keyboard_up'; + case 0x14 : return 'mouse_down'; + case 0x15 : return 'mouse_move'; + case 0x16 : return 'mouse_up'; + case 0x17 : return 'mouse_wheel'; + case 0x18 : return 'object_created'; + case 0x19 : return 'object_initialized'; + case 0x1a : return 'pause'; + case 0x1b : return 'project_initialized'; + case 0x1c : return 'restart'; + case 0x1d : return 'start'; + case 0x1e : return 'touch_cancel'; + case 0x1f : return 'touch_end'; + case 0x20 : return 'touch_move'; + case 0x21 : return 'touch_start'; + case 0x22 : return 'update_from_instance_after'; + case 0x23 : return 'update_from_instance_before'; + case 0x24 : return 'update_instance_after'; + case 0x25 : return 'update_instance_before'; + case 0x26 : return 'update_instance_property'; + case 0x27 : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } @@ -2364,14 +2398,22 @@ class R3Object extends Event { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); + Event.Emit(Event.OBJECT_INITIALIZED, this); + + this.createInstance(); + } } @@ -2492,11 +2534,19 @@ class Entity extends R3Object { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + this.createInstance(); } Event.Emit(Event.OBJECT_INITIALIZED, this); @@ -2775,15 +2825,22 @@ class Component extends R3Object { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); + Event.Emit(Event.COMPONENT_INITIALIZED, this); + + this.createInstance(); + } } @@ -2793,13 +2850,19 @@ class Component extends R3Object { */ createInstance() { - this.emit(Event.CREATE_INSTANCE_BEFORE, this); - - this.setRuntime(); - - this.instance = this.runtime.buildInstance(this); - - this.emit(Event.INSTANCE_CREATED, this); + this.emit( + Event.CREATE_INSTANCE_BEFORE, + this, + function(delayInstance) { + if (delayInstance === true) { + console.log('Instance creation delayed for ' + this.name); + } else { + this.setRuntime(); + this.instance = this.runtime.buildInstance(this); + this.emit(Event.INSTANCE_CREATED, this); + } + } + ); } @@ -3077,16 +3140,22 @@ class ComponentDOM extends Component { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.DOM_COMPONENT_INITIALIZED, this); + Event.Emit(Event.DOM_COMPONENT_INITIALIZED, this); + + this.createInstance(); + } } @@ -3574,16 +3643,22 @@ class ComponentGraphics extends Component { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); + Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); + + this.createInstance(); + } } @@ -3692,15 +3767,21 @@ class ComponentGraphics extends Component { Properties: + - src (Default value + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSotDu0g4pChumhBVMRRq1CECqFWaNXB5NIvaNKQpLg4Cq4FBz8Wqw4uzro6uAqC4AeIm5uToouU+L+k0CLWg+N+vLv3uHsHCPUy06yucUDTbTOViIuZ7KoYeEUvwgghgFGZWcacJCXRcXzdw8fXuxjP6nzuzxFScxYDfCLxLDNMm3iDeHrTNjjvE0dYUVaJz4nHTLog8SPXFY/fOBdcFnhmxEyn5okjxGKhjZU2ZkVTI54ijqqaTvlCxmOV8xZnrVxlzXvyFwZz+soy12kOIYFFLEGCCAVVlFCGjRitOikWUrQf7+AfdP0SuRRylcDIsYAKNMiuH/wPfndr5ScnvKRgHOh+cZyPYSCwCzRqjvN97DiNE8D/DFzpLX+lDsx8kl5radEjoH8buLhuacoecLkDDDwZsim7kp+mkM8D72f0TVkgfAv0rXm9Nfdx+gCkqavkDXBwCIwUKHu9w7t72nv790yzvx9QEXKZwXQv9wAAAAZiS0dEADIANAAxUB4d7wAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+UJEw0JHX/9/lIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12Ng+M+gBgADKAEm2Ka93QAAAABJRU5ErkJggg) + - alt (Default value '15% opaque 1x1 green pixel' - The alt attribute of this image) - fileName (Default value Utils.LowerUnderscore(options.name) - Name of the image under which it is stored) - - extension (Default value '.unknown' - Extension of the file name including the '.' (ex. '.jpg')) - - path (Default value '/' - Path on the server to the file, excluding filename) - - contentType (Default value 'application/octet-stream' - Content type of the file (based on the - extension, ex. 'image/jpeg')) - - size (Default value 0 - Size of the file in bytes) - - width (Default value 0 - Width of the image in pixels) - - height (Default value 0 - height of the image in pixels) + - extension (Default value '.png' - Extension of the file name including the '.' (ex. '.jpg')) + - external_path (Default value '/images/' + options.id + '.png' - Path to the image relative to the + project defined API URL) + - internal_path (Default value '/tmp/' + options.id + '.png' - Server side path on the server to the + file, excluding filename) + - contentType (Default value 'image/png' - Content type of the file (based on the extension, ex. + 'image/jpeg')) + - size (Default value 565 - Size of the file in bytes) + - width (Default value 1 - Width of the image in pixels) + - height (Default value 1 - height of the image in pixels) - orientation (Default value 'square' - The orientation of the image, one of 'square', 'landscape', 'portrait') @@ -3752,6 +3833,18 @@ class ComponentImage extends ComponentGraphics { options.instance = null; } + /** + * src - The src attribute of this image, defaults to a 15% opaque 1x1 green pixel + */ + if (typeof options.src === 'undefined') { + options.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSotDu0g4pChumhBVMRRq1CECqFWaNXB5NIvaNKQpLg4Cq4FBz8Wqw4uzro6uAqC4AeIm5uToouU+L+k0CLWg+N+vLv3uHsHCPUy06yucUDTbTOViIuZ7KoYeEUvwgghgFGZWcacJCXRcXzdw8fXuxjP6nzuzxFScxYDfCLxLDNMm3iDeHrTNjjvE0dYUVaJz4nHTLog8SPXFY/fOBdcFnhmxEyn5okjxGKhjZU2ZkVTI54ijqqaTvlCxmOV8xZnrVxlzXvyFwZz+soy12kOIYFFLEGCCAVVlFCGjRitOikWUrQf7+AfdP0SuRRylcDIsYAKNMiuH/wPfndr5ScnvKRgHOh+cZyPYSCwCzRqjvN97DiNE8D/DFzpLX+lDsx8kl5radEjoH8buLhuacoecLkDDDwZsim7kp+mkM8D72f0TVkgfAv0rXm9Nfdx+gCkqavkDXBwCIwUKHu9w7t72nv790yzvx9QEXKZwXQv9wAAAAZiS0dEADIANAAxUB4d7wAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+UJEw0JHX/9/lIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12Ng+M+gBgADKAEm2Ka93QAAAABJRU5ErkJggg=='; + } + /** + * alt - The alt attribute of this image + */ + if (typeof options.alt === 'undefined') { + options.alt = '15% opaque 1x1 green pixel'; + } /** * fileName - Name of the image under which it is stored */ @@ -3762,37 +3855,43 @@ class ComponentImage extends ComponentGraphics { * extension - Extension of the file name including the '.' (ex. '.jpg') */ if (typeof options.extension === 'undefined') { - options.extension = '.unknown'; + options.extension = '.png'; } /** - * path - Path on the server to the file, excluding filename + * external_path - Path to the image relative to the project defined API URL */ - if (typeof options.path === 'undefined') { - options.path = '/'; + if (typeof options.external_path === 'undefined') { + options.external_path = '/images/' + options.id + '.png'; + } + /** + * internal_path - Server side path on the server to the file, excluding filename + */ + if (typeof options.internal_path === 'undefined') { + options.internal_path = '/tmp/' + options.id + '.png'; } /** * contentType - Content type of the file (based on the extension, ex. 'image/jpeg') */ if (typeof options.contentType === 'undefined') { - options.contentType = 'application/octet-stream'; + options.contentType = 'image/png'; } /** * size - Size of the file in bytes */ if (typeof options.size === 'undefined') { - options.size = 0; + options.size = 565; } /** * width - Width of the image in pixels */ if (typeof options.width === 'undefined') { - options.width = 0; + options.width = 1; } /** * height - height of the image in pixels */ if (typeof options.height === 'undefined') { - options.height = 0; + options.height = 1; } /** * orientation - The orientation of the image, one of 'square', 'landscape', 'portrait' @@ -3844,6 +3943,62 @@ class ComponentImage extends ComponentGraphics { this.emit(Event.UPDATE_INSTANCE_BEFORE, this); + if (property === 'src') { + this.instance.src = this.src; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'src', + instanceProperty : 'src' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'alt') { + this.instance.alt = this.alt; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'alt', + instanceProperty : 'alt' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'external_path') { + this.instance.external_path = this.external_path; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'external_path', + instanceProperty : 'external_path' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'internal_path') { + this.instance.internal_path = this.internal_path; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'internal_path', + instanceProperty : 'internal_path' + } + ); + if (property !== 'all') { + return; + } + } if (property === 'size') { this.instance.size = this.size; this.emit( @@ -3914,6 +4069,62 @@ class ComponentImage extends ComponentGraphics { this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this); + if (property === 'src' || property === 'all') { + this.src = this.instance.src; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'src', + instanceProperty : 'src' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'alt' || property === 'all') { + this.alt = this.instance.alt; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'alt', + instanceProperty : 'alt' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'external_path' || property === 'all') { + this.external_path = this.instance.external_path; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'external_path', + instanceProperty : 'external_path' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'internal_path' || property === 'all') { + this.internal_path = this.instance.internal_path; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'internal_path', + instanceProperty : 'internal_path' + } + ); + if (property !== 'all') { + return; + } + } if (property === 'size' || property === 'all') { this.size = this.instance.size; this.emit( @@ -3981,17 +4192,22 @@ class ComponentImage extends ComponentGraphics { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); - Event.Emit(Event.IMAGE_COMPONENT_INITIALIZED, this); + Event.Emit(Event.IMAGE_COMPONENT_INITIALIZED, this); + + this.createInstance(); + } } @@ -4744,16 +4960,22 @@ class ComponentInput extends Component { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; - } - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.INPUT_COMPONENT_INITIALIZED, this); + Event.Emit(Event.INPUT_COMPONENT_INITIALIZED, this); + + this.createInstance(); + } } @@ -5067,11 +5289,19 @@ class Project extends R3Object { */ initialize() { - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + this.createInstance(); } Event.Emit(Event.OBJECT_INITIALIZED, this); diff --git a/package.json b/package.json index 458521d..80ffade 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "2.0.758", + "version" : "2.0.784", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index c4ddc87..f6f1654 100755 --- a/r3.php +++ b/r3.php @@ -505,13 +505,15 @@ function extractOption($item, $template) { $item = trim($item); - $key_value = preg_split('/=/', $item); + $matches = []; + + $key_value = preg_match('/^(\s*\w+)=(.*)$/', $item, $matches); if ($key_value === false) { return ''; } - $key = $key_value[0]; - $value = $key_value[1]; + $key = $matches[1]; + $value = $matches[2]; $comment_value = preg_split('/\s+-\s+/', $value); $comment = ''; @@ -713,6 +715,43 @@ function generateUpdateFromInstanceOptions($file, $tokens, $token, $section, $ma } } +function getEventListenerInfo($item) +{ + $item = trim($item); + + $eventName = preg_replace('/Event./', '', $item); + + $returns = null; + $comment = null; + + $values = preg_split('/\s*-\s*/', $eventName); + + if (sizeof($values) > 1) { + $eventName = $values[0]; + $comment = $values[1]; + } + + $values = preg_split('/@return[s]*\s*/', $comment); + if (sizeof($values) > 1) { + $comment = $values[0]; + $returns = $values[1]; + } + + $methodName = 'ON_'.$eventName; + + $methodTokenName = $methodName; + + $methodName = to_camel_case_from_upper_underscore($methodName); + + return [ + 'eventName' => $eventName, + 'returns' => $returns, + 'comment' => $comment, + 'methodName' => $methodName, + 'methodTokenName' => $methodTokenName + ]; +} + function generateEventListenersStart($file, $tokens) { $token = 'CUSTOM_EVENT_LISTENERS'; @@ -731,17 +770,12 @@ function generateEventListenersStart($file, $tokens) foreach ($store as $item) { - $item = trim($item); + $info = getEventListenerInfo($item); - $eventName = preg_replace('/Event./', '', $item); - $methodName = 'ON_'.$eventName; - - $methodName = to_camel_case_from_upper_underscore($methodName); - - $updates = str_replace('FULL_EVENT_NAME', $item, $template); - $updates = str_replace('EVENT_NAME', $eventName, $updates); - $updates = str_replace('CALL_BACK', $methodName, $updates); + $updates = str_replace('FULL_EVENT_NAME', 'Event.' . $info['eventName'], $template); + $updates = str_replace('EVENT_NAME', $info['eventName'], $updates); + $updates = str_replace('CALL_BACK', $info['methodName'], $updates); $updated .= $updates; } @@ -766,11 +800,10 @@ function generateEventListenersStop($file, $tokens) $updated = ''; foreach ($store as $item) { - $item = trim($item); - $eventName = preg_replace('/Event./', '', $item); + $info = getEventListenerInfo($item); - $updates = str_replace('EVENT_NAME', $eventName, $template); + $updates = str_replace('EVENT_NAME', $info['eventName'], $template); $updated .= $updates; } @@ -796,17 +829,11 @@ function generateStaticEventListenersStart($file, $tokens) foreach ($store as $item) { - $item = trim($item); + $info = getEventListenerInfo($item); - $eventName = preg_replace('/Event./', '', $item); - - $methodName = 'ON_'.$eventName; - - $methodName = to_camel_case_from_upper_underscore($methodName); - - $updates = str_replace('FULL_EVENT_NAME', $item, $template); - $updates = str_replace('EVENT_NAME', $eventName, $updates); - $updates = str_replace('CALL_BACK', $methodName, $updates); + $updates = str_replace('FULL_EVENT_NAME', 'Event.' . $info['eventName'], $template); + $updates = str_replace('EVENT_NAME', $info['eventName'], $updates); + $updates = str_replace('CALL_BACK', $info['methodName'], $updates); $updated .= $updates; } @@ -831,11 +858,10 @@ function generateStaticEventListenersStop($file, $tokens) $updated = ''; foreach ($store as $item) { - $item = trim($item); - $eventName = preg_replace('/Event./', '', $item); + $info = getEventListenerInfo($item); - $updates = str_replace('EVENT_NAME', $eventName, $template); + $updates = str_replace('EVENT_NAME', $info['eventName'], $template); $updated .= $updates; } @@ -1051,15 +1077,7 @@ function getStaticEventListenerUpdates($template, $tokens, $token) foreach ($store as $item) { - $item = trim($item); - - $eventName = preg_replace('/Event./', '', $item); - - $methodName = 'ON_'.$eventName; - - $methodTokenName = $methodName; - - $methodName = to_camel_case_from_upper_underscore($methodName); + $info = getEventListenerInfo($item); $updated = $template; @@ -1067,9 +1085,9 @@ function getStaticEventListenerUpdates($template, $tokens, $token) $params = "\n * @param " . $methodArgs . " (The event data passed as argument - typically an R3Object)"; - $returns = "\n * @return null"; + $returns = "\n * @return " . $info['returns']?:'null'; - $potentialTemplate = strtolower('src/templates/static_' . $methodTokenName . '.template'); + $potentialTemplate = strtolower('src/templates/static_' . $info['methodTokenName'] . '.template'); if (file_exists($potentialTemplate)) { $functionTemplate = file_get_contents($potentialTemplate); @@ -1078,12 +1096,13 @@ function getStaticEventListenerUpdates($template, $tokens, $token) $updated = preg_replace('/^.*?FUNCTION_TEMPLATE.*\n/m', '', $updated); } - $updated = str_replace('METHOD_NAME_UPPERCASE', $methodTokenName, $updated); - $updated = str_replace('METHOD_NAME', $methodName, $updated); + $updated = str_replace('METHOD_NAME_UPPERCASE', $info['methodTokenName'], $updated); + $updated = str_replace('METHOD_NAME', $info['methodName'], $updated); $updated = str_replace('METHOD_ARGS', $methodArgs, $updated); - $comment = 'Listens to events of type ' . $item . ' and executes this function.'; + $comment = 'Listens to events of type ' . $info['eventName'] . ' and executes this function. ' . $info['comment']; $comment = wordwrap($comment, 110, "\n * "); + $returns = wordwrap($returns, 110, "\n * "); $updated = str_replace('COMMENT', $comment, $updated); $updated = str_replace('PARAMS', $params, $updated); diff --git a/src/r3/r3-component/r3-component-d-o-m.js b/src/r3/r3-component/r3-component-d-o-m.js index 7cdcbd2..445efcd 100644 --- a/src/r3/r3-component/r3-component-d-o-m.js +++ b/src/r3/r3-component/r3-component-d-o-m.js @@ -306,18 +306,27 @@ class ComponentDOM extends Component { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.DOM_COMPONENT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.DOM_COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } diff --git a/src/r3/r3-component/r3-component-graphics.js b/src/r3/r3-component/r3-component-graphics.js index efd5ee9..f98c960 100644 --- a/src/r3/r3-component/r3-component-graphics.js +++ b/src/r3/r3-component/r3-component-graphics.js @@ -270,18 +270,27 @@ class ComponentGraphics extends Component { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } diff --git a/src/r3/r3-component/r3-component-image.js b/src/r3/r3-component/r3-component-image.js index 723d508..b980366 100644 --- a/src/r3/r3-component/r3-component-image.js +++ b/src/r3/r3-component/r3-component-image.js @@ -107,15 +107,21 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); Properties: + - src (Default value + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSotDu0g4pChumhBVMRRq1CECqFWaNXB5NIvaNKQpLg4Cq4FBz8Wqw4uzro6uAqC4AeIm5uToouU+L+k0CLWg+N+vLv3uHsHCPUy06yucUDTbTOViIuZ7KoYeEUvwgghgFGZWcacJCXRcXzdw8fXuxjP6nzuzxFScxYDfCLxLDNMm3iDeHrTNjjvE0dYUVaJz4nHTLog8SPXFY/fOBdcFnhmxEyn5okjxGKhjZU2ZkVTI54ijqqaTvlCxmOV8xZnrVxlzXvyFwZz+soy12kOIYFFLEGCCAVVlFCGjRitOikWUrQf7+AfdP0SuRRylcDIsYAKNMiuH/wPfndr5ScnvKRgHOh+cZyPYSCwCzRqjvN97DiNE8D/DFzpLX+lDsx8kl5radEjoH8buLhuacoecLkDDDwZsim7kp+mkM8D72f0TVkgfAv0rXm9Nfdx+gCkqavkDXBwCIwUKHu9w7t72nv790yzvx9QEXKZwXQv9wAAAAZiS0dEADIANAAxUB4d7wAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+UJEw0JHX/9/lIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12Ng+M+gBgADKAEm2Ka93QAAAABJRU5ErkJggg) + - alt (Default value '15% opaque 1x1 green pixel' - The alt attribute of this image) - fileName (Default value Utils.LowerUnderscore(options.name) - Name of the image under which it is stored) - - extension (Default value '.unknown' - Extension of the file name including the '.' (ex. '.jpg')) - - path (Default value '/' - Path on the server to the file, excluding filename) - - contentType (Default value 'application/octet-stream' - Content type of the file (based on the - extension, ex. 'image/jpeg')) - - size (Default value 0 - Size of the file in bytes) - - width (Default value 0 - Width of the image in pixels) - - height (Default value 0 - height of the image in pixels) + - extension (Default value '.png' - Extension of the file name including the '.' (ex. '.jpg')) + - external_path (Default value '/images/' + options.id + '.png' - Path to the image relative to the + project defined API URL) + - internal_path (Default value '/tmp/' + options.id + '.png' - Server side path on the server to the + file, excluding filename) + - contentType (Default value 'image/png' - Content type of the file (based on the extension, ex. + 'image/jpeg')) + - size (Default value 565 - Size of the file in bytes) + - width (Default value 1 - Width of the image in pixels) + - height (Default value 1 - height of the image in pixels) - orientation (Default value 'square' - The orientation of the image, one of 'square', 'landscape', 'portrait') @@ -140,13 +146,16 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); TEMPLATE_OPTIONS_END CUSTOM_OPTIONS_START + src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSotDu0g4pChumhBVMRRq1CECqFWaNXB5NIvaNKQpLg4Cq4FBz8Wqw4uzro6uAqC4AeIm5uToouU+L+k0CLWg+N+vLv3uHsHCPUy06yucUDTbTOViIuZ7KoYeEUvwgghgFGZWcacJCXRcXzdw8fXuxjP6nzuzxFScxYDfCLxLDNMm3iDeHrTNjjvE0dYUVaJz4nHTLog8SPXFY/fOBdcFnhmxEyn5okjxGKhjZU2ZkVTI54ijqqaTvlCxmOV8xZnrVxlzXvyFwZz+soy12kOIYFFLEGCCAVVlFCGjRitOikWUrQf7+AfdP0SuRRylcDIsYAKNMiuH/wPfndr5ScnvKRgHOh+cZyPYSCwCzRqjvN97DiNE8D/DFzpLX+lDsx8kl5radEjoH8buLhuacoecLkDDDwZsim7kp+mkM8D72f0TVkgfAv0rXm9Nfdx+gCkqavkDXBwCIwUKHu9w7t72nv790yzvx9QEXKZwXQv9wAAAAZiS0dEADIANAAxUB4d7wAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+UJEw0JHX/9/lIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12Ng+M+gBgADKAEm2Ka93QAAAABJRU5ErkJggg==' - The src attribute of this image, defaults to a 15% opaque 1x1 green pixel + alt='15% opaque 1x1 green pixel' - The alt attribute of this image fileName=Utils.LowerUnderscore(options.name) - Name of the image under which it is stored - extension='.unknown' - Extension of the file name including the '.' (ex. '.jpg') - path='/' - Path on the server to the file, excluding filename - contentType='application/octet-stream' - Content type of the file (based on the extension, ex. 'image/jpeg') - size=0 - Size of the file in bytes - width=0 - Width of the image in pixels - height=0 - height of the image in pixels + extension='.png' - Extension of the file name including the '.' (ex. '.jpg') + external_path='/images/' + options.id + '.png' - Path to the image relative to the project defined API URL + internal_path='/tmp/' + options.id + '.png' - Server side path on the server to the file, excluding filename + contentType='image/png' - Content type of the file (based on the extension, ex. 'image/jpeg') + size=565 - Size of the file in bytes + width=1 - Width of the image in pixels + height=1 - height of the image in pixels orientation='square' - The orientation of the image, one of 'square', 'landscape', 'portrait' CUSTOM_OPTIONS_END @@ -228,6 +237,18 @@ class ComponentImage extends ComponentGraphics { //GENERATED_TEMPLATE_OPTIONS_INIT_END //GENERATED_OPTIONS_INIT_START + /** + * src - The src attribute of this image, defaults to a 15% opaque 1x1 green pixel + */ + if (typeof options.src === 'undefined') { + options.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSotDu0g4pChumhBVMRRq1CECqFWaNXB5NIvaNKQpLg4Cq4FBz8Wqw4uzro6uAqC4AeIm5uToouU+L+k0CLWg+N+vLv3uHsHCPUy06yucUDTbTOViIuZ7KoYeEUvwgghgFGZWcacJCXRcXzdw8fXuxjP6nzuzxFScxYDfCLxLDNMm3iDeHrTNjjvE0dYUVaJz4nHTLog8SPXFY/fOBdcFnhmxEyn5okjxGKhjZU2ZkVTI54ijqqaTvlCxmOV8xZnrVxlzXvyFwZz+soy12kOIYFFLEGCCAVVlFCGjRitOikWUrQf7+AfdP0SuRRylcDIsYAKNMiuH/wPfndr5ScnvKRgHOh+cZyPYSCwCzRqjvN97DiNE8D/DFzpLX+lDsx8kl5radEjoH8buLhuacoecLkDDDwZsim7kp+mkM8D72f0TVkgfAv0rXm9Nfdx+gCkqavkDXBwCIwUKHu9w7t72nv790yzvx9QEXKZwXQv9wAAAAZiS0dEADIANAAxUB4d7wAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+UJEw0JHX/9/lIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12Ng+M+gBgADKAEm2Ka93QAAAABJRU5ErkJggg=='; + } + /** + * alt - The alt attribute of this image + */ + if (typeof options.alt === 'undefined') { + options.alt = '15% opaque 1x1 green pixel'; + } /** * fileName - Name of the image under which it is stored */ @@ -238,37 +259,43 @@ class ComponentImage extends ComponentGraphics { * extension - Extension of the file name including the '.' (ex. '.jpg') */ if (typeof options.extension === 'undefined') { - options.extension = '.unknown'; + options.extension = '.png'; } /** - * path - Path on the server to the file, excluding filename + * external_path - Path to the image relative to the project defined API URL */ - if (typeof options.path === 'undefined') { - options.path = '/'; + if (typeof options.external_path === 'undefined') { + options.external_path = '/images/' + options.id + '.png'; + } + /** + * internal_path - Server side path on the server to the file, excluding filename + */ + if (typeof options.internal_path === 'undefined') { + options.internal_path = '/tmp/' + options.id + '.png'; } /** * contentType - Content type of the file (based on the extension, ex. 'image/jpeg') */ if (typeof options.contentType === 'undefined') { - options.contentType = 'application/octet-stream'; + options.contentType = 'image/png'; } /** * size - Size of the file in bytes */ if (typeof options.size === 'undefined') { - options.size = 0; + options.size = 565; } /** * width - Width of the image in pixels */ if (typeof options.width === 'undefined') { - options.width = 0; + options.width = 1; } /** * height - height of the image in pixels */ if (typeof options.height === 'undefined') { - options.height = 0; + options.height = 1; } /** * orientation - The orientation of the image, one of 'square', 'landscape', 'portrait' @@ -336,6 +363,62 @@ class ComponentImage extends ComponentGraphics { this.emit(Event.UPDATE_INSTANCE_BEFORE, this); //GENERATED_UPDATE_INSTANCE_OPTIONS_START + if (property === 'src') { + this.instance.src = this.src; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'src', + instanceProperty : 'src' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'alt') { + this.instance.alt = this.alt; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'alt', + instanceProperty : 'alt' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'external_path') { + this.instance.external_path = this.external_path; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'external_path', + instanceProperty : 'external_path' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'internal_path') { + this.instance.internal_path = this.internal_path; + this.emit( + Event.UPDATE_INSTANCE_PROPERTY, + { + component : this, + property : 'internal_path', + instanceProperty : 'internal_path' + } + ); + if (property !== 'all') { + return; + } + } if (property === 'size') { this.instance.size = this.size; this.emit( @@ -416,6 +499,62 @@ class ComponentImage extends ComponentGraphics { this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this); //GENERATED_UPDATE_FROM_INSTANCE_OPTIONS_START + if (property === 'src' || property === 'all') { + this.src = this.instance.src; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'src', + instanceProperty : 'src' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'alt' || property === 'all') { + this.alt = this.instance.alt; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'alt', + instanceProperty : 'alt' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'external_path' || property === 'all') { + this.external_path = this.instance.external_path; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'external_path', + instanceProperty : 'external_path' + } + ); + if (property !== 'all') { + return; + } + } + if (property === 'internal_path' || property === 'all') { + this.internal_path = this.instance.internal_path; + this.emit( + Event.UPDATE_PROPERTY_FROM_INSTANCE, + { + component : this, + property : 'internal_path', + instanceProperty : 'internal_path' + } + ); + if (property !== 'all') { + return; + } + } if (property === 'size' || property === 'all') { this.size = this.instance.size; this.emit( @@ -496,19 +635,27 @@ class ComponentImage extends ComponentGraphics { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.IMAGE_COMPONENT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.GRAPHICS_COMPONENT_INITIALIZED, this); - Event.Emit(Event.IMAGE_COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } diff --git a/src/r3/r3-component/r3-component-input.js b/src/r3/r3-component/r3-component-input.js index 6693981..8dd705d 100644 --- a/src/r3/r3-component/r3-component-input.js +++ b/src/r3/r3-component/r3-component-input.js @@ -270,18 +270,27 @@ class ComponentInput extends Component { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.INPUT_COMPONENT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); - Event.Emit(Event.INPUT_COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } diff --git a/src/r3/r3-component/r3-component.js b/src/r3/r3-component/r3-component.js index 1d6637a..66f6b40 100644 --- a/src/r3/r3-component/r3-component.js +++ b/src/r3/r3-component/r3-component.js @@ -176,17 +176,27 @@ class Component extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.COMPONENT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } @@ -198,13 +208,21 @@ class Component extends R3Object { createInstance() { //GENERATED_CREATE_INSTANCE_METHOD_START - this.emit(Event.CREATE_INSTANCE_BEFORE, this); + this.emit( + Event.CREATE_INSTANCE_BEFORE, + this, + function(delayInstance) { + if (delayInstance === true) { + console.log('Instance creation delayed for ' + this.name); + } else { + this.setRuntime(); + this.instance = this.runtime.buildInstance(this); + this.emit(Event.INSTANCE_CREATED, this); + } + } + ); - this.setRuntime(); - this.instance = this.runtime.buildInstance(this); - - this.emit(Event.INSTANCE_CREATED, this); //GENERATED_CREATE_INSTANCE_METHOD_END //CUSTOM_CREATE_INSTANCE_METHOD_START diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js index 0e77f65..b0dbf35 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -165,11 +165,22 @@ class Entity extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END diff --git a/src/r3/r3-event.js b/src/r3/r3-event.js index 1b59ce9..2ae39ac 100644 --- a/src/r3/r3-event.js +++ b/src/r3/r3-event.js @@ -336,87 +336,89 @@ class Event { //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START //GENERATED_EVENTS_START -Event.COMPONENT_CREATED = 0x1; -Event.COMPONENT_INITIALIZED = 0x2; -Event.CREATE_INSTANCE_BEFORE = 0x3; -Event.DISPOSE_INSTANCE = 0x4; -Event.DISPOSE_OBJECT = 0x5; -Event.DOM_COMPONENT_INITIALIZED = 0x6; -Event.ENTITY_CREATED = 0x7; -Event.ENTITY_INITIALIZED = 0x8; -Event.GET_RUNTIME = 0x9; -Event.GET_WINDOW_SIZE = 0xa; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0xb; -Event.IMAGE_COMPONENT_INITIALIZED = 0xc; -Event.IMAGE_INITIALIZED = 0xd; -Event.INPUT_COMPONENT_INITIALIZED = 0xe; -Event.INSTANCE_CREATED = 0xf; -Event.INSTANCE_DISPOSED = 0x10; -Event.KEYBOARD_DOWN = 0x11; -Event.KEYBOARD_UP = 0x12; -Event.MOUSE_DOWN = 0x13; -Event.MOUSE_MOVE = 0x14; -Event.MOUSE_UP = 0x15; -Event.MOUSE_WHEEL = 0x16; -Event.OBJECT_CREATED = 0x17; -Event.OBJECT_INITIALIZED = 0x18; -Event.PAUSE = 0x19; -Event.PROJECT_INITIALIZED = 0x1a; -Event.RESTART = 0x1b; -Event.START = 0x1c; -Event.TOUCH_CANCEL = 0x1d; -Event.TOUCH_END = 0x1e; -Event.TOUCH_MOVE = 0x1f; -Event.TOUCH_START = 0x20; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x21; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x22; -Event.UPDATE_INSTANCE_AFTER = 0x23; -Event.UPDATE_INSTANCE_BEFORE = 0x24; -Event.UPDATE_INSTANCE_PROPERTY = 0x25; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x26; -Event.MAX_EVENTS = 0x27; +Event.BEFORE_RENDER = 0x1; +Event.COMPONENT_CREATED = 0x2; +Event.COMPONENT_INITIALIZED = 0x3; +Event.CREATE_INSTANCE_BEFORE = 0x4; +Event.DISPOSE_INSTANCE = 0x5; +Event.DISPOSE_OBJECT = 0x6; +Event.DOM_COMPONENT_INITIALIZED = 0x7; +Event.ENTITY_CREATED = 0x8; +Event.ENTITY_INITIALIZED = 0x9; +Event.GET_RUNTIME = 0xa; +Event.GET_WINDOW_SIZE = 0xb; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0xc; +Event.IMAGE_COMPONENT_INITIALIZED = 0xd; +Event.IMAGE_INITIALIZED = 0xe; +Event.INPUT_COMPONENT_INITIALIZED = 0xf; +Event.INSTANCE_CREATED = 0x10; +Event.INSTANCE_DISPOSED = 0x11; +Event.KEYBOARD_DOWN = 0x12; +Event.KEYBOARD_UP = 0x13; +Event.MOUSE_DOWN = 0x14; +Event.MOUSE_MOVE = 0x15; +Event.MOUSE_UP = 0x16; +Event.MOUSE_WHEEL = 0x17; +Event.OBJECT_CREATED = 0x18; +Event.OBJECT_INITIALIZED = 0x19; +Event.PAUSE = 0x1a; +Event.PROJECT_INITIALIZED = 0x1b; +Event.RESTART = 0x1c; +Event.START = 0x1d; +Event.TOUCH_CANCEL = 0x1e; +Event.TOUCH_END = 0x1f; +Event.TOUCH_MOVE = 0x20; +Event.TOUCH_START = 0x21; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x22; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x23; +Event.UPDATE_INSTANCE_AFTER = 0x24; +Event.UPDATE_INSTANCE_BEFORE = 0x25; +Event.UPDATE_INSTANCE_PROPERTY = 0x26; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x27; +Event.MAX_EVENTS = 0x28; Event.GetEventName = function(eventId) { switch(eventId) { - case 0x1 : return 'component_created'; - case 0x2 : return 'component_initialized'; - case 0x3 : return 'create_instance_before'; - case 0x4 : return 'dispose_instance'; - case 0x5 : return 'dispose_object'; - case 0x6 : return 'dom_component_initialized'; - case 0x7 : return 'entity_created'; - case 0x8 : return 'entity_initialized'; - case 0x9 : return 'get_runtime'; - case 0xa : return 'get_window_size'; - case 0xb : return 'graphics_component_initialized'; - case 0xc : return 'image_component_initialized'; - case 0xd : return 'image_initialized'; - case 0xe : return 'input_component_initialized'; - case 0xf : return 'instance_created'; - case 0x10 : return 'instance_disposed'; - case 0x11 : return 'keyboard_down'; - case 0x12 : return 'keyboard_up'; - case 0x13 : return 'mouse_down'; - case 0x14 : return 'mouse_move'; - case 0x15 : return 'mouse_up'; - case 0x16 : return 'mouse_wheel'; - case 0x17 : return 'object_created'; - case 0x18 : return 'object_initialized'; - case 0x19 : return 'pause'; - case 0x1a : return 'project_initialized'; - case 0x1b : return 'restart'; - case 0x1c : return 'start'; - case 0x1d : return 'touch_cancel'; - case 0x1e : return 'touch_end'; - case 0x1f : return 'touch_move'; - case 0x20 : return 'touch_start'; - case 0x21 : return 'update_from_instance_after'; - case 0x22 : return 'update_from_instance_before'; - case 0x23 : return 'update_instance_after'; - case 0x24 : return 'update_instance_before'; - case 0x25 : return 'update_instance_property'; - case 0x26 : return 'update_property_from_instance'; + case 0x1 : return 'before_render'; + case 0x2 : return 'component_created'; + case 0x3 : return 'component_initialized'; + case 0x4 : return 'create_instance_before'; + case 0x5 : return 'dispose_instance'; + case 0x6 : return 'dispose_object'; + case 0x7 : return 'dom_component_initialized'; + case 0x8 : return 'entity_created'; + case 0x9 : return 'entity_initialized'; + case 0xa : return 'get_runtime'; + case 0xb : return 'get_window_size'; + case 0xc : return 'graphics_component_initialized'; + case 0xd : return 'image_component_initialized'; + case 0xe : return 'image_initialized'; + case 0xf : return 'input_component_initialized'; + case 0x10 : return 'instance_created'; + case 0x11 : return 'instance_disposed'; + case 0x12 : return 'keyboard_down'; + case 0x13 : return 'keyboard_up'; + case 0x14 : return 'mouse_down'; + case 0x15 : return 'mouse_move'; + case 0x16 : return 'mouse_up'; + case 0x17 : return 'mouse_wheel'; + case 0x18 : return 'object_created'; + case 0x19 : return 'object_initialized'; + case 0x1a : return 'pause'; + case 0x1b : return 'project_initialized'; + case 0x1c : return 'restart'; + case 0x1d : return 'start'; + case 0x1e : return 'touch_cancel'; + case 0x1f : return 'touch_end'; + case 0x20 : return 'touch_move'; + case 0x21 : return 'touch_start'; + case 0x22 : return 'update_from_instance_after'; + case 0x23 : return 'update_from_instance_before'; + case 0x24 : return 'update_instance_after'; + case 0x25 : return 'update_instance_before'; + case 0x26 : return 'update_instance_property'; + case 0x27 : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } diff --git a/src/r3/r3-project.js b/src/r3/r3-project.js index 2577b66..c6019ca 100644 --- a/src/r3/r3-project.js +++ b/src/r3/r3-project.js @@ -171,11 +171,22 @@ class Project extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END diff --git a/src/r3/r3-r3-object.js b/src/r3/r3-r3-object.js index dfd7eff..abef446 100644 --- a/src/r3/r3-r3-object.js +++ b/src/r3/r3-r3-object.js @@ -173,16 +173,27 @@ class R3Object extends Event { initialize() { //GENERATED_INITIALIZE_METHOD_START - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + Event.Emit(Event.OBJECT_INITIALIZED, this); + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END } diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index 75afc83..ddb230a 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '2.0.758'; - static compileDate = '2021 Sep 18 - 11:04:13 am'; + static version = '2.0.784'; + static compileDate = '2021 Sep 19 - 21:28:13 pm'; } //GENERATED_IMPORTS_START diff --git a/src/r3/r3-runtime/r3-runtime-bullet.js b/src/r3/r3-runtime/r3-runtime-bullet.js index 6cc1b30..324a63f 100644 --- a/src/r3/r3-runtime/r3-runtime-bullet.js +++ b/src/r3/r3-runtime/r3-runtime-bullet.js @@ -76,7 +76,7 @@ const RuntimePhysics = require('./r3-runtime-physics.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeBullet extends RuntimePhysics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-code-mirror.js b/src/r3/r3-runtime/r3-runtime-code-mirror.js index 7d7269e..151ece0 100644 --- a/src/r3/r3-runtime/r3-runtime-code-mirror.js +++ b/src/r3/r3-runtime/r3-runtime-code-mirror.js @@ -76,7 +76,7 @@ const RuntimeCoder = require('./r3-runtime-coder.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeCodeMirror extends RuntimeCoder { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-control-kit.js b/src/r3/r3-runtime/r3-runtime-control-kit.js index b688f0b..9073019 100644 --- a/src/r3/r3-runtime/r3-runtime-control-kit.js +++ b/src/r3/r3-runtime/r3-runtime-control-kit.js @@ -76,7 +76,7 @@ const RuntimeGUI = require('./r3-runtime-g-u-i.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeControlKit extends RuntimeGUI { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-d-o-m.js b/src/r3/r3-runtime/r3-runtime-d-o-m.js index 4f3fe5d..bafdc12 100644 --- a/src/r3/r3-runtime/r3-runtime-d-o-m.js +++ b/src/r3/r3-runtime/r3-runtime-d-o-m.js @@ -74,7 +74,6 @@ class RuntimeDOM extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.DOCUMENT = 0x9; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-document.js b/src/r3/r3-runtime/r3-runtime-document.js index 55a91fa..d598857 100644 --- a/src/r3/r3-runtime/r3-runtime-document.js +++ b/src/r3/r3-runtime/r3-runtime-document.js @@ -76,7 +76,7 @@ const RuntimeDOM = require('./r3-runtime-d-o-m.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeDocument extends RuntimeDOM { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-g-u-i.js b/src/r3/r3-runtime/r3-runtime-g-u-i.js index 20301df..94cfb8e 100644 --- a/src/r3/r3-runtime/r3-runtime-g-u-i.js +++ b/src/r3/r3-runtime/r3-runtime-g-u-i.js @@ -74,7 +74,6 @@ class RuntimeGUI extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.CONTROL_KIT = 0xa; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-graphics.js b/src/r3/r3-runtime/r3-runtime-graphics.js index 747248c..cca8516 100644 --- a/src/r3/r3-runtime/r3-runtime-graphics.js +++ b/src/r3/r3-runtime/r3-runtime-graphics.js @@ -74,7 +74,6 @@ class RuntimeGraphics extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.THREE = 0xb; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-image.js b/src/r3/r3-runtime/r3-runtime-image.js index 5cba6e9..48e9f91 100644 --- a/src/r3/r3-runtime/r3-runtime-image.js +++ b/src/r3/r3-runtime/r3-runtime-image.js @@ -74,8 +74,6 @@ class RuntimeImage extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.NODE_JS_IMAGE = 0xc; -Runtime.WEB_IMAGE = 0xd; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-node-j-s-image.js b/src/r3/r3-runtime/r3-runtime-node-j-s-image.js index cd81a69..14f3927 100644 --- a/src/r3/r3-runtime/r3-runtime-node-j-s-image.js +++ b/src/r3/r3-runtime/r3-runtime-node-j-s-image.js @@ -76,7 +76,7 @@ const RuntimeImage = require('./r3-runtime-image.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeNodeJSImage extends RuntimeImage { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-physics.js b/src/r3/r3-runtime/r3-runtime-physics.js index fba919f..a688b82 100644 --- a/src/r3/r3-runtime/r3-runtime-physics.js +++ b/src/r3/r3-runtime/r3-runtime-physics.js @@ -74,7 +74,6 @@ class RuntimePhysics extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.BULLET = 0xe; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-statistics.js b/src/r3/r3-runtime/r3-runtime-statistics.js index 7136758..cfc917b 100644 --- a/src/r3/r3-runtime/r3-runtime-statistics.js +++ b/src/r3/r3-runtime/r3-runtime-statistics.js @@ -74,7 +74,6 @@ class RuntimeStatistics extends Runtime { //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START -Runtime.STATS = 0xf; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-runtime/r3-runtime-stats.js b/src/r3/r3-runtime/r3-runtime-stats.js index 60e5d58..559578a 100644 --- a/src/r3/r3-runtime/r3-runtime-stats.js +++ b/src/r3/r3-runtime/r3-runtime-stats.js @@ -76,7 +76,7 @@ const RuntimeStatistics = require('./r3-runtime-statistics.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeStats extends RuntimeStatistics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-three.js b/src/r3/r3-runtime/r3-runtime-three.js index cd9ee3a..50783c9 100644 --- a/src/r3/r3-runtime/r3-runtime-three.js +++ b/src/r3/r3-runtime/r3-runtime-three.js @@ -76,7 +76,7 @@ const RuntimeGraphics = require('./r3-runtime-graphics.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeThree extends RuntimeGraphics { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { diff --git a/src/r3/r3-runtime/r3-runtime-web-image.js b/src/r3/r3-runtime/r3-runtime-web-image.js index 4c7151e..210a351 100644 --- a/src/r3/r3-runtime/r3-runtime-web-image.js +++ b/src/r3/r3-runtime/r3-runtime-web-image.js @@ -76,7 +76,7 @@ const RuntimeImage = require('./r3-runtime-image.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -116,7 +116,7 @@ class RuntimeWebImage extends RuntimeImage { /** * buildInstance() - * - Creates an instance of R3.Component based on this Runtime. + * - Creates a runtime instance object based on the R3.Component representing it. * @param component */ buildInstance(component) { @@ -125,6 +125,12 @@ class RuntimeWebImage extends RuntimeImage { //GENERATED_BUILD_INSTANCE_METHOD_END //CUSTOM_BUILD_INSTANCE_METHOD_START + if (component instanceof R3.Component.Graphics.Image) { + let image = document.createElement('img'); + image.setAttribute('src', component.src); + image.setAttribute('alt', component.alt); + return image; + } //CUSTOM_BUILD_INSTANCE_METHOD_END } diff --git a/src/r3/r3-system/r3-system-d-o-m.js b/src/r3/r3-system/r3-system-d-o-m.js index 038c0d3..8e7e419 100644 --- a/src/r3/r3-system/r3-system-d-o-m.js +++ b/src/r3/r3-system/r3-system-d-o-m.js @@ -198,7 +198,6 @@ class SystemDOM extends System { //GENERATED_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD_END //CUSTOM_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD_START - object.createInstance(); //CUSTOM_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD_END } diff --git a/src/r3/r3-system/r3-system-linking.js b/src/r3/r3-system/r3-system-linking.js index 2db13c1..921783b 100644 --- a/src/r3/r3-system/r3-system-linking.js +++ b/src/r3/r3-system/r3-system-linking.js @@ -33,7 +33,8 @@ const System = require('.././r3-system.js'); Static Properties: - + - BlacklistedComponents (Default value [] - A list of component constructors which should not be + permitted to create instances immediately) Methods: @@ -57,6 +58,7 @@ const System = require('.././r3-system.js'); TEMPLATE_STATIC_OPTIONS_END CUSTOM_STATIC_OPTIONS_START + BlacklistedComponents=[] - A list of component constructors which should not be permitted to create instances immediately CUSTOM_STATIC_OPTIONS_END CUSTOM_EVENT_LISTENERS_START @@ -66,6 +68,7 @@ const System = require('.././r3-system.js'); Event.OBJECT_CREATED Event.OBJECT_INITIALIZED 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) CUSTOM_STATIC_EVENT_LISTENERS_END TEMPLATE_METHODS_START @@ -144,6 +147,11 @@ class SystemLinking extends System { SystemLinking.OnInstanceCreated ); + SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'] = Event.Subscribe( + Event.CREATE_INSTANCE_BEFORE, + SystemLinking.OnCreateInstanceBefore + ); + //GENERATED_STATIC_EVENT_LISTENERS_START_END //CUSTOM_BEFORE_STATIC_SYSTEM_START_START @@ -179,6 +187,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['INSTANCE_CREATED'].remove(); delete SystemLinking.Subscriptions['INSTANCE_CREATED']; + SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'].remove(); + delete SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE']; + //GENERATED_STATIC_EVENT_LISTENERS_STOP_END //CUSTOM_BEFORE_STATIC_SYSTEM_STOP_START @@ -206,9 +217,9 @@ class SystemLinking extends System { /** * OnObjectCreated() - * - Listens to events of type Event.OBJECT_CREATED and executes this function. + * - Listens to events of type OBJECT_CREATED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnObjectCreated(object) { @@ -216,16 +227,16 @@ class SystemLinking extends System { //GENERATED_STATIC_ON_OBJECT_CREATED_METHOD_END //CUSTOM_STATIC_ON_OBJECT_CREATED_METHOD_START - console.log('Object Created'); + console.log('object created'); //CUSTOM_STATIC_ON_OBJECT_CREATED_METHOD_END } /** * OnObjectInitialized() - * - Listens to events of type Event.OBJECT_INITIALIZED and executes this function. + * - Listens to events of type OBJECT_INITIALIZED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnObjectInitialized(object) { @@ -233,16 +244,16 @@ class SystemLinking extends System { //GENERATED_STATIC_ON_OBJECT_INITIALIZED_METHOD_END //CUSTOM_STATIC_ON_OBJECT_INITIALIZED_METHOD_START - console.log('Object Initialized : ' + object.constructor.name); + console.log('object initialized'); //CUSTOM_STATIC_ON_OBJECT_INITIALIZED_METHOD_END } /** * OnInstanceCreated() - * - Listens to events of type Event.INSTANCE_CREATED and executes this function. + * - Listens to events of type INSTANCE_CREATED and executes this function. * @param object (The event data passed as argument - typically an R3Object) - * @return null + * @return */ static OnInstanceCreated(object) { @@ -250,8 +261,33 @@ class SystemLinking extends System { //GENERATED_STATIC_ON_INSTANCE_CREATED_METHOD_END //CUSTOM_STATIC_ON_INSTANCE_CREATED_METHOD_START + console.log('instance created'); //CUSTOM_STATIC_ON_INSTANCE_CREATED_METHOD_END + } + + /** + * OnCreateInstanceBefore() + * - Listens to events of type CREATE_INSTANCE_BEFORE and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return boolean delayInstance which indicates whether or not instance creation is delayed (handled) by + * another system. (i.e. where instance creation order is of importance) + */ + static OnCreateInstanceBefore(object) { + + //GENERATED_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD_START + //GENERATED_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD_END + + //CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD_START + for (let i = 0; i < SystemLinking.BlacklistedComponents.length; i++) { + if (object instanceof SystemLinking.BlacklistedComponents) { + return true; + } + } + + return false; + //CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD_END + } //GENERATED_STATIC_EVENT_LISTENER_METHODS_END @@ -274,6 +310,11 @@ SystemLinking.Subscriptions = {}; //GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_END //GENERATED_STATIC_OPTIONS_INIT_START +/** + * static BlacklistedComponents - A list of component constructors which should not be permitted to create instances immediately + */ +SystemLinking.BlacklistedComponents = []; + //GENERATED_STATIC_OPTIONS_INIT_END //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-system/r3-system-render.js b/src/r3/r3-system/r3-system-render.js index cbc0e47..37c0f7f 100644 --- a/src/r3/r3-system/r3-system-render.js +++ b/src/r3/r3-system/r3-system-render.js @@ -203,6 +203,13 @@ class SystemRender extends System { document.body.appendChild(object.instance); } } + + if (object instanceof R3.Component.Graphics.Image) { + if (object.runtime instanceof R3.Runtime.Image.WebImage) { + document.body.appendChild(object.instance); + } + } + //CUSTOM_STATIC_ON_INSTANCE_CREATED_METHOD_END } diff --git a/src/r3/r3-system/r3-system-storage.js b/src/r3/r3-system/r3-system-storage.js index 8b5ae52..4c81fa0 100644 --- a/src/r3/r3-system/r3-system-storage.js +++ b/src/r3/r3-system/r3-system-storage.js @@ -198,7 +198,6 @@ class SystemStorage extends System { //GENERATED_STATIC_ON_IMAGE_COMPONENT_INITIALIZED_METHOD_END //CUSTOM_STATIC_ON_IMAGE_COMPONENT_INITIALIZED_METHOD_START - object.createInstance(); //CUSTOM_STATIC_ON_IMAGE_COMPONENT_INITIALIZED_METHOD_END } diff --git a/src/templates/create_instance.template b/src/templates/create_instance.template index 94bf420..c264ce9 100644 --- a/src/templates/create_instance.template +++ b/src/templates/create_instance.template @@ -1,7 +1,24 @@ - this.emit(Event.CREATE_INSTANCE_BEFORE, this); + this.emit( + Event.CREATE_INSTANCE_BEFORE, + this, + function(delayInstance) { + if (delayInstance === true) { + console.log('Instance creation delayed for ' + this.name); + } else { + /** + * Set the runtime + */ + this.setRuntime(); - this.setRuntime(); + /** + * Let the runtime build the instance + */ + this.instance = this.runtime.buildInstance(this); - this.instance = this.runtime.buildInstance(this); - - this.emit(Event.INSTANCE_CREATED, this); \ No newline at end of file + /** + * Notify anyone who might be interested + */ + this.emit(Event.INSTANCE_CREATED, this); + } + } + ); \ No newline at end of file diff --git a/src/templates/initialize.template b/src/templates/initialize.template index bcea3ae..5270302 100644 --- a/src/templates/initialize.template +++ b/src/templates/initialize.template @@ -1,6 +1,17 @@ - if (this.initialized) { - console.warn('Multiple calls to initialize() - check your callstack'); - } else { + try { + super.initialize(); + } catch (err) { + + if (!(err instanceof TypeError)) { + //Another unexpected error occurred - and we are not inside a base class + throw err; + } + delete this.callDepth; this.initialized = true; + + //CUSTOM_BEFORE_CREATE_INSTANCE_START + //CUSTOM_BEFORE_CREATE_INSTANCE_END + + this.createInstance(); } \ No newline at end of file diff --git a/src/templates/runtime_extends.template b/src/templates/runtime_extends.template index afec412..ec645c5 100644 --- a/src/templates/runtime_extends.template +++ b/src/templates/runtime_extends.template @@ -21,7 +21,7 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START - buildInstance(component) - Creates an instance of R3.Component based on this Runtime. + buildInstance(component) - Creates a runtime instance object based on the R3.Component representing it. TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/token.db b/src/templates/token.db index cbe3384..0b35307 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -27,6 +27,7 @@ GENERATED_STATIC_EVENT_LISTENERS_START GENERATED_STATIC_EVENT_LISTENERS_STOP GENERATED_STATIC_METHOD_NAME_UPPERCASE_METHOD GENERATED_STATIC_METHODS +GENERATED_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD GENERATED_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD GENERATED_STATIC_ON_GET_RUNTIME_METHOD GENERATED_STATIC_ON_IMAGE_COMPONENT_INITIALIZED_METHOD @@ -61,6 +62,7 @@ GENERATED_UPDATE_INSTANCE_METHOD GENERATED_UPDATE_INSTANCE_OPTIONS CUSTOM_AFTER_INIT CUSTOM_ASYNC_METHOD +CUSTOM_BEFORE_CREATE_INSTANCE CUSTOM_BEFORE_INIT CUSTOM_BEFORE_STATIC_SYSTEM_START CUSTOM_BEFORE_STATIC_SYSTEM_STOP @@ -88,6 +90,7 @@ CUSTOM_STATIC_EMIT_METHOD CUSTOM_STATIC_EVENT_LISTENERS CUSTOM_STATIC_METHOD_NAME_UPPERCASE_METHOD CUSTOM_STATIC_METHODS +CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD CUSTOM_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD CUSTOM_STATIC_ON_GET_RUNTIME_METHOD CUSTOM_STATIC_ON_IMAGE_COMPONENT_INITIALIZED_METHOD diff --git a/version b/version index d1affd4..edf1cd1 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.758 \ No newline at end of file +2.0.784 \ No newline at end of file