diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index b3fbcee..0cf46ed 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -15,35 +15,41 @@ GameLib.Event.OnceSubscriptions = {}; /** * Events we can subscribe to and publish */ -GameLib.Event.WINDOW_RESIZE = 0x1; -GameLib.Event.PARENT_SCENE_CHANGE = 0x2; -GameLib.Event.PARENT_ENTITY_CHANGE = 0x3; -GameLib.Event.IMAGE_INSTANCE_CREATED = 0x4; -GameLib.Event.LOAD_IMAGE = 0x5; -GameLib.Event.NEW_ENTITY = 0x7; -GameLib.Event.MATERIAL_TYPE_CHANGED = 0x8; -GameLib.Event.SAVE_COMPONENT = 0x9; -GameLib.Event.SAVE_COMPONENT_ERROR = 0xa; -GameLib.Event.COMPONENT_SAVED = 0xb; -GameLib.Event.LOAD_COMPONENT = 0xc; -GameLib.Event.LOAD_COMPONENT_ERROR = 0xd; -GameLib.Event.LOGGED_IN = 0xf; -GameLib.Event.COMPONENT_CREATED = 0x10; -GameLib.Event.SCENE_INSTANCE_CREATED = 0x11; -GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x12; -GameLib.Event.WORLD_INSTANCE_CREATED = 0x13; -GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x14; -GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x15; -GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x16; -GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x17; -GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x18; -GameLib.Event.MESH_INSTANCE_CREATED = 0x19; -GameLib.Event.MESH_INSTANCE_UPDATED = 0x1a; -GameLib.Event.LIGHT_INSTANCE_CREATED = 0x1b; -GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c; -GameLib.Event.DELETE_COMPONENT = 0x1d; -GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e; -GameLib.Event.COMPONENTS_LINKED = 0x1f; +GameLib.Event.WINDOW_RESIZE = 0x1; +GameLib.Event.PARENT_SCENE_CHANGE = 0x2; +GameLib.Event.PARENT_ENTITY_CHANGE = 0x3; +GameLib.Event.IMAGE_INSTANCE_CREATED = 0x4; +GameLib.Event.LOAD_IMAGE = 0x5; +GameLib.Event.NEW_ENTITY = 0x7; +GameLib.Event.MATERIAL_TYPE_CHANGED = 0x8; +GameLib.Event.SAVE_COMPONENT = 0x9; +GameLib.Event.SAVE_COMPONENT_ERROR = 0xa; +GameLib.Event.COMPONENT_SAVED = 0xb; +GameLib.Event.LOAD_COMPONENT = 0xc; +GameLib.Event.LOAD_COMPONENT_ERROR = 0xd; +GameLib.Event.LOGGED_IN = 0xf; +GameLib.Event.COMPONENT_CREATED = 0x10; +GameLib.Event.SCENE_INSTANCE_CREATED = 0x11; +GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x12; +GameLib.Event.WORLD_INSTANCE_CREATED = 0x13; +GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x14; +GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x15; +GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x16; +GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x17; +GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x18; +GameLib.Event.MESH_INSTANCE_CREATED = 0x19; +GameLib.Event.MESH_INSTANCE_UPDATED = 0x1a; +GameLib.Event.LIGHT_INSTANCE_CREATED = 0x1b; +GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c; +GameLib.Event.DELETE_COMPONENT = 0x1d; +GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e; +GameLib.Event.COMPONENTS_LINKED = 0x1f; +GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x20; +GameLib.Event.REGISTER_UPDATE = 0x21; +GameLib.Event.BUILD_GUI = 0x22; +GameLib.Event.MESH_DELETED = 0x23; +GameLib.Event.MESH_SELECTED = 0x24; +GameLib.Event.MESH_DESELECTED = 0x25; /** * Subscribe to some events @@ -54,28 +60,7 @@ GameLib.Event.prototype.subscribe = function( eventName, callback ) { - - var fn = callback.bind(this); - - if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) { - GameLib.Event.Subscriptions[eventName].push(fn); - } else { - GameLib.Event.Subscriptions[eventName] = []; - GameLib.Event.Subscriptions[eventName].push(fn); - } - - /** - * Return a handle to the caller to allow us to unsubscribe to this event - */ - return { - fn : fn, - remove : function() { - GameLib.Event.Subscriptions[eventName].splice( - GameLib.Event.Subscriptions[eventName].indexOf(fn), - 1 - ); - } - } + return GameLib.Event.Subscribe(eventName, callback.bind(this)); }; GameLib.Event.EmitInstanceEvents = function(component) { @@ -147,39 +132,39 @@ GameLib.Event.EmitInstanceEvents = function(component) { } }; -/** - * Stop listening for this event after the callback returns true - * @param eventName - * @param callback - * @returns {{fn, remove: remove}} - */ -GameLib.Event.prototype.subscribeOnce = function( - eventName, - callback -) { - throw new Error('implement first properly'); - // var fn = callback.bind(this); - // - // if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) { - // GameLib.Event.OnceSubscriptions[eventName].push(fn); - // } else { - // GameLib.Event.OnceSubscriptions[eventName] = []; - // GameLib.Event.OnceSubscriptions[eventName].push(fn); - // } - // - // /** - // * Return a handle to the caller to allow us to unsubscribe to this event - // */ - // return { - // fn : fn, - // remove : function() { - // GameLib.Event.Subscriptions[eventName].splice( - // GameLib.Event.Subscriptions[eventName].indexOf(fn), - // 1 - // ); - // } - // } -}; +// /** +// * Stop listening for this event after the callback returns true +// * @param eventName +// * @param callback +// * @returns {{fn, remove: remove}} +// */ +// GameLib.Event.prototype.subscribeOnce = function( +// eventName, +// callback +// ) { +// throw new Error('implement first properly'); +// // var fn = callback.bind(this); +// // +// // if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) { +// // GameLib.Event.OnceSubscriptions[eventName].push(fn); +// // } else { +// // GameLib.Event.OnceSubscriptions[eventName] = []; +// // GameLib.Event.OnceSubscriptions[eventName].push(fn); +// // } +// // +// // /** +// // * Return a handle to the caller to allow us to unsubscribe to this event +// // */ +// // return { +// // fn : fn, +// // remove : function() { +// // GameLib.Event.Subscriptions[eventName].splice( +// // GameLib.Event.Subscriptions[eventName].indexOf(fn), +// // 1 +// // ); +// // } +// // } +// }; /** * @@ -222,4 +207,30 @@ GameLib.Event.Emit = function(eventName, data) { } return count; +}; + +GameLib.Event.Subscribe = function( + eventName, + fn +) { + + if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) { + GameLib.Event.Subscriptions[eventName].push(fn); + } else { + GameLib.Event.Subscriptions[eventName] = []; + GameLib.Event.Subscriptions[eventName].push(fn); + } + + /** + * Return a handle to the caller to allow us to unsubscribe to this event + */ + return { + fn : fn, + remove : function() { + GameLib.Event.Subscriptions[eventName].splice( + GameLib.Event.Subscriptions[eventName].indexOf(fn), + 1 + ); + } + } }; \ No newline at end of file diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 91c601a..e44ce3c 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -3,14 +3,10 @@ * @constructor * @param componentType * @param linkedObjects - * @param parentEntity - * @param traverse */ GameLib.Component = function( componentType, - linkedObjects, - parentEntity, - traverse + linkedObjects ) { if (GameLib.Utils.UndefinedOrNull(linkedObjects)) { linkedObjects = {}; @@ -21,7 +17,7 @@ GameLib.Component = function( GameLib.API.Component.call( this, componentType, - parentEntity + this.parentEntity ); this.idToObject = {}; @@ -32,11 +28,6 @@ GameLib.Component = function( this.loaded = false; - if (GameLib.Utils.UndefinedOrNull(traverse)) { - traverse = true; - } - this.traverse = traverse; - this.dependencies = this.getDependencies(); if (this.dependencies.length === 0) { @@ -46,9 +37,17 @@ GameLib.Component = function( if (this.instance) { this.loaded = true; + this.buildIdToObject(); GameLib.Event.EmitInstanceEvents(this); } } + + GameLib.Event.Emit( + GameLib.Event.COMPONENT_CREATED, + { + component : this + } + ); }; GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype); @@ -66,7 +65,7 @@ GameLib.Component.prototype.getDependencies = function() { if ( this.linkedObjects.hasOwnProperty(property) && - property !== 'parentMesh' && + property !== 'parentMesh' && property !== 'parentScene' && property !== 'parentEntity' && property !== 'parentEntityManager' && @@ -214,10 +213,6 @@ GameLib.Component.prototype.toApiObject = function() { */ GameLib.Component.prototype.buildIdToObject = function() { - if (!this.traverse) { - return; - } - if (this.built) { return; } diff --git a/src/game-lib-d3-api-image.js b/src/game-lib-d3-api-image.js index 08055a0..7a17122 100644 --- a/src/game-lib-d3-api-image.js +++ b/src/game-lib-d3-api-image.js @@ -5,7 +5,6 @@ * @param path * @param contentType * @param size - * @param data * @param parentEntity GameLib.Entity * @constructor */ @@ -15,7 +14,6 @@ GameLib.D3.API.Image = function( path, contentType, size, - data, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -56,11 +54,6 @@ GameLib.D3.API.Image = function( } this.size = size; - if (GameLib.Utils.UndefinedOrNull(data)) { - data = null; - } - this.data = data; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } @@ -82,7 +75,6 @@ GameLib.D3.API.Image.FromObject = function(objectImage) { objectImage.path, objectImage.contentType, objectImage.size, - objectImage.data, objectImage.parentEntity ); }; diff --git a/src/game-lib-d3-input-editor.js b/src/game-lib-d3-input-editor.js index 28586c9..cc82575 100644 --- a/src/game-lib-d3-input-editor.js +++ b/src/game-lib-d3-input-editor.js @@ -128,22 +128,19 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) { if (event.code === 'Delete') { var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); - var guis = GameLib.EntityManager.Instance.queryComponents([GameLib.GUI]); + + var deletedMeshes = []; meshes.map( function(mesh) { if (mesh.selected) { - var parentEntity = mesh.parentEntity; + deletedMeshes.push(mesh); - parentEntity.removeHelper(mesh, entity); + this.removeHelper(mesh, entity); entity.removeComponent(mesh); entity.buildIdToObject(); - guis.map(function(gui) { - gui.removeObject(mesh); - }); - var scene = mesh.parentScene; scene.removeObject(mesh); scene.buildIdToObject(); @@ -151,11 +148,13 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) { }.bind(this) ); + GameLib.Event.Emit( + GameLib.Event.MESH_DELETED, + { + meshes : deletedMeshes + } + ); - - guis.map(function(gui) { - gui.build(entityManager); - }); } if (event.code === 'ControlLeft') { @@ -364,8 +363,6 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager) return; } - var gui = entity.getFirstComponent(GameLib.GUI); - if (mesh.selected) { helper = new GameLib.D3.Helper( @@ -387,16 +384,24 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager) scene.instance.add(helper.instance); - gui.addObject(mesh); + GameLib.Event.Emit( + GameLib.Event.MESH_SELECTED, + { + mesh : mesh + } + ) } else { - gui.removeObject(mesh); + GameLib.Event.Emit( + GameLib.Event.MESH_DESELECTED, + { + mesh : mesh + } + ); this.removeHelper(mesh, entity); } - - gui.build(entityManager); } } } diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 2efa9eb..11df13f 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -15,8 +15,7 @@ GameLib.EntityManager = function() { GameLib.Component.COMPONENT_ENTITY_MANAGER, { 'entities' : [GameLib.Entity] - }, - null + } ); }; @@ -197,13 +196,17 @@ GameLib.EntityManager.prototype.queryComponents = function(constructors) { constructors.map( function(constructor) { if (component instanceof constructor) { - result.push(component); + if (result.indexOf(component) === -1) { + result.push(component); + } } } ); } else { if (component instanceof constructors) { - result.push(component); + if (result.indexOf(component) === -1) { + result.push(component); + } } } } diff --git a/src/game-lib-gui.js b/src/game-lib-gui.js index 5444351..68a5e36 100644 --- a/src/game-lib-gui.js +++ b/src/game-lib-gui.js @@ -270,7 +270,9 @@ GameLib.GUI.prototype.buildControl = function(folder, object, property, entityMa 'gui' : GameLib.System.SYSTEM_TYPE_GUI, 'input' : GameLib.System.SYSTEM_TYPE_INPUT, 'render' : GameLib.System.SYSTEM_TYPE_RENDER, - 'storage' : GameLib.System.SYSTEM_TYPE_STORAGE + 'storage' : GameLib.System.SYSTEM_TYPE_STORAGE, + 'linking' : GameLib.System.SYSTEM_TYPE_LINKING, + 'physics' : GameLib.System.SYSTEM_TYPE_PHYSICS } ).name(property).listen() ); @@ -837,7 +839,7 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di } }; -GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, entityManager, constructor, parentObject) { +GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, entityManager, constructor) { var objects = entityManager.queryComponents(constructor); @@ -892,15 +894,11 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en object.updateInstance(); } - /** - * Properties changed - rebuild the object list in the parent - */ - console.log('parentObject.buildIdToObject();'); /** * Properties changed - rebuild GUI */ - gui.build(entityManager); + //gui.build(entityManager); }; @@ -1037,42 +1035,45 @@ GameLib.GUI.prototype.build = function(entityManager) { this.instance.removeAllFolders(); - var discoveredObjects = []; + this.objects.sort( + function(a, b) { + if (a.name > b.name) { + return 1; + } - var parentObject = this.objects[0]; + if (a.name < b.name) { + return -1; + } - this.objects.map( + return 0; + } + ); + // + // var discoveredObjects = []; + // + // var parentObject = this.objects[0]; + // + // this.objects.map( + // + // function(object) { + // + // if (object.idToObject) { + // for (var property in object.idToObject) { + // if (object.idToObject.hasOwnProperty(property)) { + // if (discoveredObjects.indexOf(object.idToObject[property]) === -1) { + // discoveredObjects.push(object.idToObject[property]); + // } + // } + // } + // } + // + // }.bind(this) + // ); + // + // discoveredObjects + // ); - function(object) { - - if (object.idToObject) { - for (var property in object.idToObject) { - if (object.idToObject.hasOwnProperty(property)) { - if (discoveredObjects.indexOf(object.idToObject[property]) === -1) { - discoveredObjects.push(object.idToObject[property]); - } - } - } - } - - }.bind(this) - ); - - discoveredObjects.sort( - function(a, b) { - if (a.name > b.name) { - return 1; - } - - if (a.name < b.name) { - return -1; - } - - return 0; - } - ); - - discoveredObjects.map( + this.objects.map( function(object) { @@ -1114,7 +1115,6 @@ GameLib.GUI.prototype.build = function(entityManager) { entityManager ) } else if (object.linkedObjects[property] instanceof Array) { - console.log('ignored array : ' + property); this.buildArrayManager( folder, object, @@ -1123,7 +1123,7 @@ GameLib.GUI.prototype.build = function(entityManager) { entityManager ) } else { - this.buildSelectControl(folder, object, property, entityManager, object.linkedObjects[property], parentObject); + this.buildSelectControl(folder, object, property, entityManager, object.linkedObjects[property]); } } else if (typeof (object[property]) === 'object') { diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index 5df975e..a503fc8 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -10,6 +10,19 @@ GameLib.System.GUI = function( this, apiSystem ); + + this.guis = []; + + this.buildGUISubscription = null; + + this.meshDeletedSubscription = null; + + this.meshSelectedSubscription = null; + + this.meshDeselectedSubscription = null; + + this.newEntitySubscription = null; + }; GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype); @@ -17,19 +30,89 @@ GameLib.System.GUI.prototype.constructor = GameLib.System.GUI; GameLib.System.GUI.prototype.start = function() { - var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); + this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); - guis.map(function(gui){ + this.guis.map(function(gui){ gui.domElement.instance.parentElement.appendChild(gui.instance.domElement); - }) + }); + + this.buildGUISubscription = this.subscribe( + GameLib.Event.BUILD_GUI, + this.buildGUI + ); + + this.meshDeletedSubscription = this.subscribe( + GameLib.Event.MESH_DELETED, + this.meshDeleted + ); + + this.meshSelectedSubscription = this.subscribe( + GameLib.Event.MESH_SELECTED, + this.meshSelected + ); + + this.meshDeselectedSubscription = this.subscribe( + GameLib.Event.MESH_DESELECTED, + this.meshDeslected + ); + + this.newEntitySubscription = this.subscribe( + GameLib.Event.NEW_ENTITY, + this.newEntity + ) +}; + +GameLib.System.GUI.prototype.buildGUI = function(data) { + + + + this.guis.map(function(gui){ + gui.objects = []; + + if ( + data.components && + data.components.length > 0 + ) { + gui.objects = data.components; + } + + gui.build(GameLib.EntityManager.Instance); + }); + +}; + +GameLib.System.GUI.prototype.meshDeleted = function(data) { + +}; + +GameLib.System.GUI.prototype.meshSelected = function(data) { + +}; + +GameLib.System.GUI.prototype.meshDeslected = function(data) { + +}; + +GameLib.System.GUI.prototype.newEntity = function(data) { + }; GameLib.System.GUI.prototype.stop = function() { - var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); - - guis.map(function(gui){ + this.guis.map(function(gui){ gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); - }) + }); + + this.buildGUISubscription.remove(); + + this.meshDeletedSubscription.remove(); + + this.meshSelectedSubscription.remove(); + + this.meshDeselectedSubscription.remove(); + + this.newEntitySubscription.remove(); + + this.guis = []; }; diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index 7a21bad..9961b24 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -47,7 +47,14 @@ GameLib.System.Linking.prototype.constructor = GameLib.System.Linking; GameLib.System.Linking.prototype.start = function() { this.register = GameLib.EntityManager.Instance.queryComponents([GameLib.Component]); - + + GameLib.Event.Emit( + GameLib.Event.REGISTER_UPDATE, + { + register : this.register + } + ); + this.componentCreatedSubscription = this.subscribe( GameLib.Event.COMPONENT_CREATED, this.componentCreated.bind(this) @@ -170,11 +177,11 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) { if (parentComponent.instance) { parentComponent.loaded = true; - + parentComponent.buildIdToObject(); if (this.resolved.indexOf(parentComponent) === -1) { this.resolved.push(parentComponent); } - + GameLib.Event.EmitInstanceEvents(parentComponent); } } @@ -184,6 +191,13 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) { delete this.dependencies[component.id]; + GameLib.Event.Emit( + GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE, + { + dependencies : this.dependencies + } + ); + if (GameLib.Utils.IsEmpty(this.dependencies)) { GameLib.Event.Emit( @@ -210,6 +224,13 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { */ this.register.push(component); + GameLib.Event.Emit( + GameLib.Event.REGISTER_UPDATE, + { + register : this.register + } + ); + /** * We only care about components with unloaded dependencies - * other components will have already had their instance objects created @@ -258,6 +279,12 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { */ if (this.dependencies[id].indexOf(component === -1)) { this.dependencies[id].push(component); + GameLib.Event.Emit( + GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE, + { + dependencies : this.dependencies + } + ); } /** @@ -278,6 +305,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { component.instance = component.createInstance(); if (component.instance) { component.loaded = true; + component.buildIdToObject(); GameLib.Event.EmitInstanceEvents(component); } } @@ -395,7 +423,7 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) { /** * We remove the helper (if any) from the old scene and add it to the new scene */ - var helper = this.findHelperByObject(data.object); + var helper = GameLib.EntityManager.Instance.findHelperByObject(data.object); if (helper) { if (data.originalScene && data.originalScene.instance) { @@ -411,58 +439,6 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) { data.originalScene.removeObject(data.object); } data.newScene.addObject(data.object); - - /** - * We inherit the parent entity of this new scene - */ - var originalEntity = null; - var newEntity = null; - - if (data.object.hasOwnProperty('parentEntity')) { - originalEntity = data.object.parentEntity - } - - if (data.newScene.hasOwnProperty('parentEntity')) { - newEntity = data.newScene.parentEntity; - } - - var gui = null; - - if (originalEntity) { - - if (originalEntity.removeComponent) { - if (helper) { - originalEntity.removeComponent(helper); - } - originalEntity.removeComponent(data.object); - } - - if (originalEntity.getFirstComponent) { - gui = originalEntity.getFirstComponent(GameLib.GUI); - if (gui) { - gui.removeObject(data.object); - gui.build(this); - } - } - } - - if (newEntity) { - - if (newEntity.addComponent) { - if (helper) { - newEntity.addComponent(helper); - } - newEntity.addComponent(data.object); - } - - if (newEntity.getFirstComponent) { - gui = newEntity.getFirstComponent(GameLib.GUI); - if (gui) { - gui.addObject(data.object); - gui.build(this); - } - } - } } }; @@ -496,6 +472,12 @@ GameLib.System.Linking.prototype.onParentEntityChange = function(data) { GameLib.System.Linking.prototype.stop = function() { this.register = []; + GameLib.Event.Emit( + GameLib.Event.REGISTER_UPDATE, + { + register : this.register + } + ); this.componentCreatedSubscription.remove(); this.parentSceneChangeSubscription.remove(); this.parentEntityChangeSubscription.remove(); diff --git a/src/game-lib-system-storage.js b/src/game-lib-system-storage.js index 3e2617d..f3c548a 100644 --- a/src/game-lib-system-storage.js +++ b/src/game-lib-system-storage.js @@ -220,14 +220,12 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe if (object.result !== 'success') { if (onComponentError) { - onComponentError(error); + onComponentError(id, object); } GameLib.Event.Emit( GameLib.Event.LOAD_COMPONENT_ERROR, - { - error: error - } + {error : object} ); return;