From 184a6ab1c6c6f7753f91eded203511abfe34a871 Mon Sep 17 00:00:00 2001 From: cybafelo Date: Wed, 16 Oct 2019 21:02:53 +0200 Subject: [PATCH] mobile --- src/build_component_lists.php | 5 +- src/build_events.php | 4 + src/r3-a-1-component-info.js | 2 +- src/r3-a-2-event-1.js | 224 +++++++++++++++++----------------- src/r3-a-3-utils.js | 6 +- src/r3-a-4-component.js | 33 ++++- src/r3-api-customCode.js | 2 +- src/r3-api-project-0.js | 70 +++++++++++ src/r3-canvas.js | 34 ++++-- src/r3-entity.js | 197 ++---------------------------- src/r3-project-0.js | 1 + 11 files changed, 266 insertions(+), 312 deletions(-) diff --git a/src/build_component_lists.php b/src/build_component_lists.php index 4d92269..1189c3b 100755 --- a/src/build_component_lists.php +++ b/src/build_component_lists.php @@ -29,7 +29,7 @@ foreach ($files as $file) { !preg_match('/r3\-z\./', $file) && !preg_match('/^r3\-a\-.*/', $file) && !preg_match('/^\.$/', $file) && - !preg_match('/^\.$/', $file) && + !preg_match('/^\.\.$/', $file) && preg_match('/.*\.js$/', $file) ) { @@ -57,7 +57,6 @@ foreach ($files as $file) { $file = join('.', $parts); - $componentType = strtoupper($file); $componentType = str_replace('R3.', '', $componentType); $componentType = str_replace('API.', '', $componentType); @@ -146,7 +145,7 @@ foreach ($componentTypes as $componentType) { $runtime = 'R3.Runtime.DEFAULT'; - if (preg_match('/Bone|Camera|Canvas|Clock|Color|Composer|Controls|Curve|Effect|Fog|Geometry|Graphics|Image|Light|Material|Mesh|Mouse|Object|Particle|Pass|Raycaster|Render|Scene|Shader|Shadow|Skeleton|Text|Video|Viewport/', $name)) { + if (preg_match('/Bone|Box|Camera|Canvas|Clock|Color|Composer|Controls|Curve|Effect|Fog|Geometry|Graphics|Image|Light|Material|Mesh|Mouse|Object|Particle|Pass|Raycaster|Render|Scene|Shader|Shadow|Skeleton|Text|Video|Viewport/', $name)) { $runtime = 'R3.Runtime.GRAPHICS'; } diff --git a/src/build_events.php b/src/build_events.php index 51203d7..25b88ee 100755 --- a/src/build_events.php +++ b/src/build_events.php @@ -51,6 +51,10 @@ foreach ($files as $file) { } +array_push($events, 'R3.Event.START'); +array_push($events, 'R3.Event.PAUSE'); +array_push($events, 'R3.Event.RESTART'); + sort($events); $i = 1; diff --git a/src/r3-a-1-component-info.js b/src/r3-a-1-component-info.js index bc694fa..a582e72 100644 --- a/src/r3-a-1-component-info.js +++ b/src/r3-a-1-component-info.js @@ -2996,7 +2996,7 @@ R3.GetComponentInfo = function(componentType) { name : 'R3.Box3', constructor : R3.Box3, apiConstructor : R3.API.Box3, - runtime: R3.Runtime.DEFAULT + runtime: R3.Runtime.GRAPHICS }; default : throw new Error('Invalid component type: ' + componentType); diff --git a/src/r3-a-2-event-1.js b/src/r3-a-2-event-1.js index 5cb87e3..671a6cc 100644 --- a/src/r3-a-2-event-1.js +++ b/src/r3-a-2-event-1.js @@ -52,61 +52,64 @@ R3.Event.IMAGE_UPLOAD_COMPLETE = 0x33; R3.Event.INSTANCE_CLONED = 0x34; R3.Event.INSTANCE_CREATED = 0x35; R3.Event.INSTANCE_DISPOSAL = 0x36; -R3.Event.KEY_DOWN = 0x37; -R3.Event.KEY_UP = 0x38; -R3.Event.LOAD_COMPONENT = 0x39; -R3.Event.LOAD_COMPONENT_ERROR = 0x3a; -R3.Event.LOAD_FONT = 0x3b; -R3.Event.LOAD_IMAGE = 0x3c; -R3.Event.LOAD_PROGRESS = 0x3d; -R3.Event.MATERIAL_TEXTURES_UPDATED = 0x3e; -R3.Event.MATERIAL_TYPE_CHANGED = 0x3f; -R3.Event.MAXIMUM_PROJECTS = 0x40; -R3.Event.MESH_DESELECTED = 0x41; -R3.Event.MESH_FACE_DESELECTED = 0x42; -R3.Event.MESH_FACE_SELECTED = 0x43; -R3.Event.MESH_SELECTED = 0x44; -R3.Event.MOUSE_DOWN = 0x45; -R3.Event.MOUSE_MOVE = 0x46; -R3.Event.MOUSE_UP = 0x47; -R3.Event.MOUSE_WHEEL = 0x48; -R3.Event.MUTE_AUDIO = 0x49; -R3.Event.NAME_UPDATE = 0x4a; -R3.Event.PARENT_SCENE_CHANGE = 0x4b; -R3.Event.PARENT_WORLD_CHANGE = 0x4c; -R3.Event.PAUSE_ALL_AUDIO = 0x4d; -R3.Event.PLAY_AUDIO = 0x4e; -R3.Event.PROJECT_LOADED = 0x4f; -R3.Event.QUERY_PARSED = 0x50; -R3.Event.RECEIVE_DESTINATION_CHANGED = 0x51; -R3.Event.REGISTER_DEPENDENCIES = 0x52; -R3.Event.REGISTER_UPDATE = 0x53; -R3.Event.REMOVE_COMPONENT = 0x54; -R3.Event.REMOVE_MESH = 0x55; -R3.Event.REMOVE_PARTICLE_ENGINE = 0x56; -R3.Event.RENDERER_SIZE_CHANGE = 0x57; -R3.Event.REPLACE_COMPONENT = 0x58; -R3.Event.RESOLVE_DEPENDENCIES = 0x59; -R3.Event.SAVE_COMPONENT = 0x5a; -R3.Event.SAVE_COMPONENT_ERROR = 0x5b; -R3.Event.SAVING = 0x5c; -R3.Event.SELECTION_MODE_CHANGE = 0x5d; -R3.Event.SET_APPLICATION_MODE = 0x5e; -R3.Event.SIGN_IN = 0x5f; -R3.Event.SIGN_OUT = 0x60; -R3.Event.STOP_ALL_AUDIO = 0x61; -R3.Event.STOP_AUDIO = 0x62; -R3.Event.STOP_VISUALIZE = 0x63; -R3.Event.TEXTURE_ANIMATED_CHANGE = 0x64; -R3.Event.TEXTURE_INSTANCE_UPDATED = 0x65; -R3.Event.TOUCH_CANCEL = 0x66; -R3.Event.TOUCH_END = 0x67; -R3.Event.TOUCH_MOVE = 0x68; -R3.Event.TOUCH_START = 0x69; -R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x6a; -R3.Event.VISUALIZE = 0x6b; -R3.Event.WINDOW_RESIZE = 0x6c; -R3.Event.MAX_EVENTS = 0x6d; +R3.Event.INSTANCE_LOADED = 0x37; +R3.Event.KEY_DOWN = 0x38; +R3.Event.KEY_UP = 0x39; +R3.Event.LOAD_COMPONENT = 0x3a; +R3.Event.LOAD_COMPONENT_ERROR = 0x3b; +R3.Event.LOAD_FONT = 0x3c; +R3.Event.LOAD_IMAGE = 0x3d; +R3.Event.LOAD_PROGRESS = 0x3e; +R3.Event.MATERIAL_TEXTURES_UPDATED = 0x3f; +R3.Event.MATERIAL_TYPE_CHANGED = 0x40; +R3.Event.MAXIMUM_PROJECTS = 0x41; +R3.Event.MESH_DESELECTED = 0x42; +R3.Event.MESH_FACE_DESELECTED = 0x43; +R3.Event.MESH_FACE_SELECTED = 0x44; +R3.Event.MESH_SELECTED = 0x45; +R3.Event.MOUSE_DOWN = 0x46; +R3.Event.MOUSE_MOVE = 0x47; +R3.Event.MOUSE_UP = 0x48; +R3.Event.MOUSE_WHEEL = 0x49; +R3.Event.MUTE_AUDIO = 0x4a; +R3.Event.NAME_UPDATE = 0x4b; +R3.Event.PARENT_SCENE_CHANGE = 0x4c; +R3.Event.PARENT_WORLD_CHANGE = 0x4d; +R3.Event.PAUSE = 0x4e; +R3.Event.PAUSE_ALL_AUDIO = 0x4f; +R3.Event.PLAY_AUDIO = 0x50; +R3.Event.PROJECT_LOADED = 0x51; +R3.Event.QUERY_PARSED = 0x52; +R3.Event.RECEIVE_DESTINATION_CHANGED = 0x53; +R3.Event.REGISTER_DEPENDENCIES = 0x54; +R3.Event.REGISTER_UPDATE = 0x55; +R3.Event.REMOVE_COMPONENT = 0x56; +R3.Event.REMOVE_MESH = 0x57; +R3.Event.REMOVE_PARTICLE_ENGINE = 0x58; +R3.Event.RENDERER_SIZE_CHANGE = 0x59; +R3.Event.REPLACE_COMPONENT = 0x5a; +R3.Event.RESOLVE_DEPENDENCIES = 0x5b; +R3.Event.RESTART = 0x5c; +R3.Event.SAVE_COMPONENT = 0x5d; +R3.Event.SAVE_COMPONENT_ERROR = 0x5e; +R3.Event.SAVING = 0x5f; +R3.Event.SELECTION_MODE_CHANGE = 0x60; +R3.Event.SIGN_IN = 0x61; +R3.Event.SIGN_OUT = 0x62; +R3.Event.START = 0x63; +R3.Event.STOP_ALL_AUDIO = 0x64; +R3.Event.STOP_AUDIO = 0x65; +R3.Event.STOP_VISUALIZE = 0x66; +R3.Event.TEXTURE_ANIMATED_CHANGE = 0x67; +R3.Event.TEXTURE_INSTANCE_UPDATED = 0x68; +R3.Event.TOUCH_CANCEL = 0x69; +R3.Event.TOUCH_END = 0x6a; +R3.Event.TOUCH_MOVE = 0x6b; +R3.Event.TOUCH_START = 0x6c; +R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x6d; +R3.Event.VISUALIZE = 0x6e; +R3.Event.WINDOW_RESIZE = 0x6f; +R3.Event.MAX_EVENTS = 0x70; /** * R3.Event.GetEventName @@ -171,60 +174,63 @@ R3.Event.GetEventName = function(eventId) { case 0x34 : return 'instance_cloned'; case 0x35 : return 'instance_created'; case 0x36 : return 'instance_disposal'; - case 0x37 : return 'key_down'; - case 0x38 : return 'key_up'; - case 0x39 : return 'load_component'; - case 0x3a : return 'load_component_error'; - case 0x3b : return 'load_font'; - case 0x3c : return 'load_image'; - case 0x3d : return 'load_progress'; - case 0x3e : return 'material_textures_updated'; - case 0x3f : return 'material_type_changed'; - case 0x40 : return 'maximum_projects'; - case 0x41 : return 'mesh_deselected'; - case 0x42 : return 'mesh_face_deselected'; - case 0x43 : return 'mesh_face_selected'; - case 0x44 : return 'mesh_selected'; - case 0x45 : return 'mouse_down'; - case 0x46 : return 'mouse_move'; - case 0x47 : return 'mouse_up'; - case 0x48 : return 'mouse_wheel'; - case 0x49 : return 'mute_audio'; - case 0x4a : return 'name_update'; - case 0x4b : return 'parent_scene_change'; - case 0x4c : return 'parent_world_change'; - case 0x4d : return 'pause_all_audio'; - case 0x4e : return 'play_audio'; - case 0x4f : return 'project_loaded'; - case 0x50 : return 'query_parsed'; - case 0x51 : return 'receive_destination_changed'; - case 0x52 : return 'register_dependencies'; - case 0x53 : return 'register_update'; - case 0x54 : return 'remove_component'; - case 0x55 : return 'remove_mesh'; - case 0x56 : return 'remove_particle_engine'; - case 0x57 : return 'renderer_size_change'; - case 0x58 : return 'replace_component'; - case 0x59 : return 'resolve_dependencies'; - case 0x5a : return 'save_component'; - case 0x5b : return 'save_component_error'; - case 0x5c : return 'saving'; - case 0x5d : return 'selection_mode_change'; - case 0x5e : return 'set_application_mode'; - case 0x5f : return 'sign_in'; - case 0x60 : return 'sign_out'; - case 0x61 : return 'stop_all_audio'; - case 0x62 : return 'stop_audio'; - case 0x63 : return 'stop_visualize'; - case 0x64 : return 'texture_animated_change'; - case 0x65 : return 'texture_instance_updated'; - case 0x66 : return 'touch_cancel'; - case 0x67 : return 'touch_end'; - case 0x68 : return 'touch_move'; - case 0x69 : return 'touch_start'; - case 0x6a : return 'unresolved_dependencies_update'; - case 0x6b : return 'visualize'; - case 0x6c : return 'window_resize'; + case 0x37 : return 'instance_loaded'; + case 0x38 : return 'key_down'; + case 0x39 : return 'key_up'; + case 0x3a : return 'load_component'; + case 0x3b : return 'load_component_error'; + case 0x3c : return 'load_font'; + case 0x3d : return 'load_image'; + case 0x3e : return 'load_progress'; + case 0x3f : return 'material_textures_updated'; + case 0x40 : return 'material_type_changed'; + case 0x41 : return 'maximum_projects'; + case 0x42 : return 'mesh_deselected'; + case 0x43 : return 'mesh_face_deselected'; + case 0x44 : return 'mesh_face_selected'; + case 0x45 : return 'mesh_selected'; + case 0x46 : return 'mouse_down'; + case 0x47 : return 'mouse_move'; + case 0x48 : return 'mouse_up'; + case 0x49 : return 'mouse_wheel'; + case 0x4a : return 'mute_audio'; + case 0x4b : return 'name_update'; + case 0x4c : return 'parent_scene_change'; + case 0x4d : return 'parent_world_change'; + case 0x4e : return 'pause'; + case 0x4f : return 'pause_all_audio'; + case 0x50 : return 'play_audio'; + case 0x51 : return 'project_loaded'; + case 0x52 : return 'query_parsed'; + case 0x53 : return 'receive_destination_changed'; + case 0x54 : return 'register_dependencies'; + case 0x55 : return 'register_update'; + case 0x56 : return 'remove_component'; + case 0x57 : return 'remove_mesh'; + case 0x58 : return 'remove_particle_engine'; + case 0x59 : return 'renderer_size_change'; + case 0x5a : return 'replace_component'; + case 0x5b : return 'resolve_dependencies'; + case 0x5c : return 'restart'; + case 0x5d : return 'save_component'; + case 0x5e : return 'save_component_error'; + case 0x5f : return 'saving'; + case 0x60 : return 'selection_mode_change'; + case 0x61 : return 'sign_in'; + case 0x62 : return 'sign_out'; + case 0x63 : return 'start'; + case 0x64 : return 'stop_all_audio'; + case 0x65 : return 'stop_audio'; + case 0x66 : return 'stop_visualize'; + case 0x67 : return 'texture_animated_change'; + case 0x68 : return 'texture_instance_updated'; + case 0x69 : return 'touch_cancel'; + case 0x6a : return 'touch_end'; + case 0x6b : return 'touch_move'; + case 0x6c : return 'touch_start'; + case 0x6d : return 'unresolved_dependencies_update'; + case 0x6e : return 'visualize'; + case 0x6f : return 'window_resize'; default : throw new Error('Event type not defined : ' + eventId); } diff --git a/src/r3-a-3-utils.js b/src/r3-a-3-utils.js index 7e67f95..e40d918 100644 --- a/src/r3-a-3-utils.js +++ b/src/r3-a-3-utils.js @@ -88,7 +88,8 @@ R3.Utils.RemoveFromSelect = function(select, id) { * * @param select * @param id - * @returns {null|number} + * @returns boolean true if successful + * * @constructor */ R3.Utils.SetSelectIndex = function(select, id) { @@ -98,9 +99,10 @@ R3.Utils.SetSelectIndex = function(select, id) { for (i = 0; i < select.options.length; i++) { if (select.options[i].value === id) { select.selectedIndex = i; + return true; } } - return null; + return false; }; R3.Utils.SortSelect = function(select) { diff --git a/src/r3-a-4-component.js b/src/r3-a-4-component.js index f18509f..2ad89a8 100644 --- a/src/r3-a-4-component.js +++ b/src/r3-a-4-component.js @@ -575,8 +575,6 @@ R3.Component.prototype.createInstance = function() { throw new Error(R3.GetComponentName(this) + ' has no instance at time of createInstance'); } - this.loaded = true; - R3.Event.Emit( R3.Event.INSTANCE_CREATED, { @@ -584,6 +582,19 @@ R3.Component.prototype.createInstance = function() { } ); + this.loaded = true; + + /** + * Use this event to know that the object has now loaded and all 'INSTANCE_CREATED' events have been handled. + * The idToObject property of this component can now be trusted. + */ + R3.Event.Emit( + R3.Event.INSTANCE_LOADED, + { + component: this + } + ); + if (this instanceof R3.Project) { R3.Event.Emit( R3.Event.PROJECT_LOADED, @@ -802,6 +813,24 @@ R3.Component.prototype.getPropertyValue = function(item) { return item; }; +/** + * Returns all components of type 'constructor' - slower than queryComponents + * @param constructor + */ +R3.Component.prototype.findComponentsByConstructor = function(constructor) { + + return Object.keys(this.idToObject).reduce( + function(result, id) { + if (this.idToObject[id] instanceof constructor) { + result.push(this.idToObject[id]); + } + return result; + }.bind(this), + [] + ); + +}; + /** * Components are linked at runtime - for storing, we just store the ID * @returns {*} diff --git a/src/r3-api-customCode.js b/src/r3-api-customCode.js index d8b8dec..7f06e61 100644 --- a/src/r3-api-customCode.js +++ b/src/r3-api-customCode.js @@ -15,7 +15,7 @@ R3.API.CustomCode = function( this.eventId = apiComponent.eventId; if (R3.Utils.UndefinedOrNull(apiComponent.code)) { - apiComponent.code = "return null;\n//@ sourceURL=" + this.name + ".js"; + apiComponent.code = "console.log(this.name);return null;\n//@ sourceURL=" + R3.Event.GetEventName(this.eventId)+ ".js"; } this.code = apiComponent.code; }; diff --git a/src/r3-api-project-0.js b/src/r3-api-project-0.js index 9f86b12..2457ffb 100644 --- a/src/r3-api-project-0.js +++ b/src/r3-api-project-0.js @@ -7,6 +7,7 @@ * @property entities * @property controls * @property images + * @property code * @property applicationMode * * @constructor @@ -37,6 +38,75 @@ R3.API.Project = function( } this.images = apiComponent.images; + if (R3.Utils.UndefinedOrNull(apiComponent.code)) { + apiComponent.code = [ + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Project Loaded', + eventId : R3.Event.PROJECT_LOADED + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Before Render', + eventId : R3.Event.BEFORE_RENDER + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Key Up', + eventId : R3.Event.KEY_UP + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Key Down', + eventId : R3.Event.KEY_DOWN + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Mouse Up', + eventId : R3.Event.MOUSE_UP + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Mouse Down', + eventId : R3.Event.MOUSE_DOWN + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Mouse Move', + eventId : R3.Event.MOUSE_MOVE + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Touch Start', + eventId : R3.Event.TOUCH_START + } + ), + new R3.API.CustomCode( + { + parent : this, + name : this.name + ' - Code - Touch End', + eventId : R3.Event.TOUCH_END + } + ) + ] + } + this.code = apiComponent.code; + if (R3.Utils.UndefinedOrNull(apiComponent.applicationMode)) { apiComponent.applicationMode = R3.API.Project.APPLICATION_MODE_EDIT; } diff --git a/src/r3-canvas.js b/src/r3-canvas.js index 730a6e6..17f5bf7 100644 --- a/src/r3-canvas.js +++ b/src/r3-canvas.js @@ -54,11 +54,26 @@ R3.Canvas.prototype.updateInstance = function(property) { return; } - if ( - property === 'autoUpdateSize' || - property === 'width' || - property === 'height' - ) { + if (property === 'width') { + this.instance.setAttribute('width', this.width); + this.instance.setAttribute('style', 'left: ' + this.offset.x + 'px;top: ' + this.offset.y + 'px;width:' + this.width + 'px;height:' + this.height + 'px'); + return; + } + + if (property === 'height') { + this.instance.setAttribute('height', this.height); + this.instance.setAttribute('style', 'left: ' + this.offset.x + 'px;top: ' + this.offset.y + 'px;width:' + this.width + 'px;height:' + this.height + 'px'); + return; + } + + + if (property === 'autoUpdateSize') { + /** + * TODO : whatever - can't remember what the purpose of this stupid property was... + */ + console.log('whatever'); + return; + /** * We cannot control everything about the canvas - this is dependent on where the canvas lives and its * dimensions can also be controlled via CSS - @@ -72,16 +87,15 @@ R3.Canvas.prototype.updateInstance = function(property) { /** * Update from our canvas size */ - this.width = this.instance.width; - this.height = this.instance.height; - + this.width = this.instance.getAttribute('width'); + this.height = this.instance.getAttribute('height'); } else { /** * Command our canvas to take a size - this is not guaranteed however - CSS wins */ - this.instance.width = this.width; - this.instance.height = this.height; + this.instance.setAttribute('width', this.width); + this.instance.setAttribute('height', this.height); } return; } diff --git a/src/r3-entity.js b/src/r3-entity.js index 36ca9ea..1967464 100644 --- a/src/r3-entity.js +++ b/src/r3-entity.js @@ -8,18 +8,8 @@ R3.Entity = function( ) { __RUNTIME_COMPONENT__; - // - // this.instanceCreatedEventSubscription = this.subscribe( - // R3.Event.INSTANCE_CREATED, - // this.instanceCreatedEvent - // ); - // - // this.removeComponentSubscription = this.subscribe( - // R3.Event.REMOVE_COMPONENT, - // this.removeComponentEvent - // ); - // this.idRegister = {}; + this.linkedComponents = [R3.Component]; __UPGRADE_TO_RUNTIME__; }; @@ -29,22 +19,6 @@ R3.Entity.prototype.constructor = R3.Entity; R3.Entity.prototype.createInstance = function() { - // this.components.map( - // function(component) { - // component.parent = this; - // - // Object.keys(component.idToObject).map( - // function(componentId) { - // R3.Utils.PushUnique(this.components, component.idToObject[componentId]); - // component.idToObject[componentId].parent = this; - // }.bind(this) - // ); - // - // }.bind(this) - // ); - // - // this.buildIdRegister(); - // this.instance = true; __CREATE_INSTANCE__; @@ -55,7 +29,6 @@ R3.Entity.prototype.updateInstance = function(property) { if (property === 'components') { console.log('todo: entity components change'); - // this.buildIdRegister(); return; } @@ -64,164 +37,20 @@ R3.Entity.prototype.updateInstance = function(property) { }; -// /** -// * Links a component to its parent entity -// */ -// R3.Entity.prototype.instanceCreatedEvent = function(data) { -// -// if (data.component === this) { -// /** -// * do nothing -// */ -// return; -// } -// -// -// if (data.component.parent === this.id) { -// this.addComponent(data.component); -// } -// }; -// -// R3.Entity.prototype.removeComponentEvent = function(data) { -// -// if (data.component === this) { -// /** -// * do nothing -// */ -// return; -// } -// -// if (data.component.parent === this) { -// this.removeComponent(data.component); -// } -// }; - -/** - * Adds a component to this entity through the instance (should notify the entity manager instance) - * @param component - */ -// R3.Entity.prototype.addComponent = function(component) { -// -// component.parent = this; -// -// /** -// * Could be that this entity is not loaded and needs to be linked still -// */ -// if (this.components.indexOf(component.id) !== -1) { -// console.log('the entity still has to load'); -// return; -// } -// -// R3.Utils.PushUnique(this.components, component); -// -// if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { -// this.idRegister[component.componentType] = []; -// } -// -// R3.Utils.PushUnique(this.idRegister[component.componentType], component); -// -// component.buildIdToObject(); -// -// Object.keys(component.idToObject).map( -// function(componentId) { -// -// if (component.id !== componentId) { -// this.addComponent(component.idToObject[componentId]); -// } -// -// }.bind(this) -// ); -// }; - -// R3.Entity.prototype.removeComponent = function(component) { -// -// component.parent = null; -// -// var index = this.components.indexOf(component); -// -// if (index === -1) { -// console.warn('component not found in entity'); -// } else { -// this.components.splice(index, 1); -// } -// -// if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { -// console.warn('component type not found in entity register'); -// } else { -// -// index = this.idRegister[component.componentType].indexOf(component); -// -// if (index === -1) { -// console.warn('component ' + component.name + ' not found in id register of entity ' + this.name); -// } else { -// this.idRegister[component.componentType].splice(index, 1); -// } -// -// /** -// * Remove the hash completely if it was the last one -// */ -// if (this.idRegister[component.componentType].length === 0) { -// delete this.idRegister[component.componentType]; -// } -// -// } -// }; - /** * Returns all components of type 'constructor' - slower than queryComponents * @param constructor */ -// R3.Entity.prototype.findComponentsByConstructor = function(constructor) { -// -// var components = this.components.reduce( -// function(result, component) { -// if (component instanceof constructor) { -// result.push(component); -// } -// return result; -// }, -// [] -// ); -// -// return components; -// }; +R3.Entity.prototype.findComponentsByConstructor = function(constructor) { -/** - * Returns all child components of this entity by component type (via hash reference - very fast) - * @param componentType - * @returns {*} - */ -// R3.Entity.prototype.queryComponents = function(componentType) { -// return this.idRegister[componentType] || []; -// }; -// -// R3.Entity.prototype.buildIdRegister = function() { -// console.log('updating id register for entity : ' + this.name); -// -// this.idRegister = {}; -// -// this.components.map( -// function(component) { -// -// if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { -// this.idRegister[component.componentType] = []; -// } -// -// this.idRegister[component.componentType].push(component); -// -// }.bind(this) -// ); -// -// console.log('done updating idRegister'); -// }; -// -// /** -// * Cleanup our subscriptions first -// */ -// R3.Entity.prototype.remove = function() { -// -// this.instanceCreatedEventSubscription.remove(); -// this.removeComponentSubscription.remove(); -// -// R3.Component.prototype.remove.call(this); -// }; + return this.components.reduce( + function(result, component) { + if (component instanceof constructor) { + result.push(component); + } + return result; + }, + [] + ); + +}; diff --git a/src/r3-project-0.js b/src/r3-project-0.js index f38b1b5..00f9b76 100644 --- a/src/r3-project-0.js +++ b/src/r3-project-0.js @@ -12,6 +12,7 @@ R3.Project = function( this.linkedComponents.entities = [R3.Entity]; this.linkedComponents.controls = [R3.Controls]; this.linkedComponents.images = [R3.Image]; + this.linkedComponents.code = [R3.CustomCode]; __UPGRADE_TO_RUNTIME__; };