awesomer gui system

beta.r3js.org
Theunis J. Botha 2017-06-29 15:23:50 +02:00
parent 52ae5ae597
commit 6901c08c5f
9 changed files with 307 additions and 238 deletions

View File

@ -15,35 +15,41 @@ GameLib.Event.OnceSubscriptions = {};
/** /**
* Events we can subscribe to and publish * Events we can subscribe to and publish
*/ */
GameLib.Event.WINDOW_RESIZE = 0x1; GameLib.Event.WINDOW_RESIZE = 0x1;
GameLib.Event.PARENT_SCENE_CHANGE = 0x2; GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3; GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
GameLib.Event.IMAGE_INSTANCE_CREATED = 0x4; GameLib.Event.IMAGE_INSTANCE_CREATED = 0x4;
GameLib.Event.LOAD_IMAGE = 0x5; GameLib.Event.LOAD_IMAGE = 0x5;
GameLib.Event.NEW_ENTITY = 0x7; GameLib.Event.NEW_ENTITY = 0x7;
GameLib.Event.MATERIAL_TYPE_CHANGED = 0x8; GameLib.Event.MATERIAL_TYPE_CHANGED = 0x8;
GameLib.Event.SAVE_COMPONENT = 0x9; GameLib.Event.SAVE_COMPONENT = 0x9;
GameLib.Event.SAVE_COMPONENT_ERROR = 0xa; GameLib.Event.SAVE_COMPONENT_ERROR = 0xa;
GameLib.Event.COMPONENT_SAVED = 0xb; GameLib.Event.COMPONENT_SAVED = 0xb;
GameLib.Event.LOAD_COMPONENT = 0xc; GameLib.Event.LOAD_COMPONENT = 0xc;
GameLib.Event.LOAD_COMPONENT_ERROR = 0xd; GameLib.Event.LOAD_COMPONENT_ERROR = 0xd;
GameLib.Event.LOGGED_IN = 0xf; GameLib.Event.LOGGED_IN = 0xf;
GameLib.Event.COMPONENT_CREATED = 0x10; GameLib.Event.COMPONENT_CREATED = 0x10;
GameLib.Event.SCENE_INSTANCE_CREATED = 0x11; GameLib.Event.SCENE_INSTANCE_CREATED = 0x11;
GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x12; GameLib.Event.SCENE_OBJECT_INSTANCE_CREATED = 0x12;
GameLib.Event.WORLD_INSTANCE_CREATED = 0x13; GameLib.Event.WORLD_INSTANCE_CREATED = 0x13;
GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x14; GameLib.Event.RIGID_BODY_INSTANCE_CREATED = 0x14;
GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x15; GameLib.Event.TEXTURE_INSTANCE_CREATED = 0x15;
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x16; GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x16;
GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x17; GameLib.Event.MATERIAL_INSTANCE_CREATED = 0x17;
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x18; GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x18;
GameLib.Event.MESH_INSTANCE_CREATED = 0x19; GameLib.Event.MESH_INSTANCE_CREATED = 0x19;
GameLib.Event.MESH_INSTANCE_UPDATED = 0x1a; GameLib.Event.MESH_INSTANCE_UPDATED = 0x1a;
GameLib.Event.LIGHT_INSTANCE_CREATED = 0x1b; GameLib.Event.LIGHT_INSTANCE_CREATED = 0x1b;
GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c; GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1c;
GameLib.Event.DELETE_COMPONENT = 0x1d; GameLib.Event.DELETE_COMPONENT = 0x1d;
GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e; GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1e;
GameLib.Event.COMPONENTS_LINKED = 0x1f; 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 * Subscribe to some events
@ -54,28 +60,7 @@ GameLib.Event.prototype.subscribe = function(
eventName, eventName,
callback callback
) { ) {
return GameLib.Event.Subscribe(eventName, callback.bind(this));
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
);
}
}
}; };
GameLib.Event.EmitInstanceEvents = function(component) { GameLib.Event.EmitInstanceEvents = function(component) {
@ -147,39 +132,39 @@ GameLib.Event.EmitInstanceEvents = function(component) {
} }
}; };
/** // /**
* Stop listening for this event after the callback returns true // * Stop listening for this event after the callback returns true
* @param eventName // * @param eventName
* @param callback // * @param callback
* @returns {{fn, remove: remove}} // * @returns {{fn, remove: remove}}
*/ // */
GameLib.Event.prototype.subscribeOnce = function( // GameLib.Event.prototype.subscribeOnce = function(
eventName, // eventName,
callback // callback
) { // ) {
throw new Error('implement first properly'); // throw new Error('implement first properly');
// var fn = callback.bind(this); // // var fn = callback.bind(this);
// // //
// if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) { // // if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) {
// GameLib.Event.OnceSubscriptions[eventName].push(fn); // // GameLib.Event.OnceSubscriptions[eventName].push(fn);
// } else { // // } else {
// GameLib.Event.OnceSubscriptions[eventName] = []; // // GameLib.Event.OnceSubscriptions[eventName] = [];
// GameLib.Event.OnceSubscriptions[eventName].push(fn); // // GameLib.Event.OnceSubscriptions[eventName].push(fn);
// } // // }
// // //
// /** // // /**
// * Return a handle to the caller to allow us to unsubscribe to this event // // * Return a handle to the caller to allow us to unsubscribe to this event
// */ // // */
// return { // // return {
// fn : fn, // // fn : fn,
// remove : function() { // // remove : function() {
// GameLib.Event.Subscriptions[eventName].splice( // // GameLib.Event.Subscriptions[eventName].splice(
// GameLib.Event.Subscriptions[eventName].indexOf(fn), // // GameLib.Event.Subscriptions[eventName].indexOf(fn),
// 1 // // 1
// ); // // );
// } // // }
// } // // }
}; // };
/** /**
* *
@ -223,3 +208,29 @@ GameLib.Event.Emit = function(eventName, data) {
return count; 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
);
}
}
};

View File

@ -3,14 +3,10 @@
* @constructor * @constructor
* @param componentType * @param componentType
* @param linkedObjects * @param linkedObjects
* @param parentEntity
* @param traverse
*/ */
GameLib.Component = function( GameLib.Component = function(
componentType, componentType,
linkedObjects, linkedObjects
parentEntity,
traverse
) { ) {
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) { if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
linkedObjects = {}; linkedObjects = {};
@ -21,7 +17,7 @@ GameLib.Component = function(
GameLib.API.Component.call( GameLib.API.Component.call(
this, this,
componentType, componentType,
parentEntity this.parentEntity
); );
this.idToObject = {}; this.idToObject = {};
@ -32,11 +28,6 @@ GameLib.Component = function(
this.loaded = false; this.loaded = false;
if (GameLib.Utils.UndefinedOrNull(traverse)) {
traverse = true;
}
this.traverse = traverse;
this.dependencies = this.getDependencies(); this.dependencies = this.getDependencies();
if (this.dependencies.length === 0) { if (this.dependencies.length === 0) {
@ -46,9 +37,17 @@ GameLib.Component = function(
if (this.instance) { if (this.instance) {
this.loaded = true; this.loaded = true;
this.buildIdToObject();
GameLib.Event.EmitInstanceEvents(this); GameLib.Event.EmitInstanceEvents(this);
} }
} }
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
component : this
}
);
}; };
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype); GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
@ -66,7 +65,7 @@ GameLib.Component.prototype.getDependencies = function() {
if ( if (
this.linkedObjects.hasOwnProperty(property) && this.linkedObjects.hasOwnProperty(property) &&
property !== 'parentMesh' && property !== 'parentMesh' &&
property !== 'parentScene' && property !== 'parentScene' &&
property !== 'parentEntity' && property !== 'parentEntity' &&
property !== 'parentEntityManager' && property !== 'parentEntityManager' &&
@ -214,10 +213,6 @@ GameLib.Component.prototype.toApiObject = function() {
*/ */
GameLib.Component.prototype.buildIdToObject = function() { GameLib.Component.prototype.buildIdToObject = function() {
if (!this.traverse) {
return;
}
if (this.built) { if (this.built) {
return; return;
} }

View File

@ -5,7 +5,6 @@
* @param path * @param path
* @param contentType * @param contentType
* @param size * @param size
* @param data
* @param parentEntity GameLib.Entity * @param parentEntity GameLib.Entity
* @constructor * @constructor
*/ */
@ -15,7 +14,6 @@ GameLib.D3.API.Image = function(
path, path,
contentType, contentType,
size, size,
data,
parentEntity parentEntity
) { ) {
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
@ -56,11 +54,6 @@ GameLib.D3.API.Image = function(
} }
this.size = size; this.size = size;
if (GameLib.Utils.UndefinedOrNull(data)) {
data = null;
}
this.data = data;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null; parentEntity = null;
} }
@ -82,7 +75,6 @@ GameLib.D3.API.Image.FromObject = function(objectImage) {
objectImage.path, objectImage.path,
objectImage.contentType, objectImage.contentType,
objectImage.size, objectImage.size,
objectImage.data,
objectImage.parentEntity objectImage.parentEntity
); );
}; };

View File

@ -128,22 +128,19 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
if (event.code === 'Delete') { if (event.code === 'Delete') {
var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
var guis = GameLib.EntityManager.Instance.queryComponents([GameLib.GUI]);
var deletedMeshes = [];
meshes.map( meshes.map(
function(mesh) { function(mesh) {
if (mesh.selected) { if (mesh.selected) {
var parentEntity = mesh.parentEntity; deletedMeshes.push(mesh);
parentEntity.removeHelper(mesh, entity); this.removeHelper(mesh, entity);
entity.removeComponent(mesh); entity.removeComponent(mesh);
entity.buildIdToObject(); entity.buildIdToObject();
guis.map(function(gui) {
gui.removeObject(mesh);
});
var scene = mesh.parentScene; var scene = mesh.parentScene;
scene.removeObject(mesh); scene.removeObject(mesh);
scene.buildIdToObject(); scene.buildIdToObject();
@ -151,11 +148,13 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
}.bind(this) }.bind(this)
); );
GameLib.Event.Emit(
GameLib.Event.MESH_DELETED,
{
meshes : deletedMeshes
}
);
guis.map(function(gui) {
gui.build(entityManager);
});
} }
if (event.code === 'ControlLeft') { if (event.code === 'ControlLeft') {
@ -364,8 +363,6 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
return; return;
} }
var gui = entity.getFirstComponent(GameLib.GUI);
if (mesh.selected) { if (mesh.selected) {
helper = new GameLib.D3.Helper( helper = new GameLib.D3.Helper(
@ -387,16 +384,24 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
scene.instance.add(helper.instance); scene.instance.add(helper.instance);
gui.addObject(mesh); GameLib.Event.Emit(
GameLib.Event.MESH_SELECTED,
{
mesh : mesh
}
)
} else { } else {
gui.removeObject(mesh); GameLib.Event.Emit(
GameLib.Event.MESH_DESELECTED,
{
mesh : mesh
}
);
this.removeHelper(mesh, entity); this.removeHelper(mesh, entity);
} }
gui.build(entityManager);
} }
} }
} }

View File

@ -15,8 +15,7 @@ GameLib.EntityManager = function() {
GameLib.Component.COMPONENT_ENTITY_MANAGER, GameLib.Component.COMPONENT_ENTITY_MANAGER,
{ {
'entities' : [GameLib.Entity] 'entities' : [GameLib.Entity]
}, }
null
); );
}; };
@ -197,13 +196,17 @@ GameLib.EntityManager.prototype.queryComponents = function(constructors) {
constructors.map( constructors.map(
function(constructor) { function(constructor) {
if (component instanceof constructor) { if (component instanceof constructor) {
result.push(component); if (result.indexOf(component) === -1) {
result.push(component);
}
} }
} }
); );
} else { } else {
if (component instanceof constructors) { if (component instanceof constructors) {
result.push(component); if (result.indexOf(component) === -1) {
result.push(component);
}
} }
} }
} }

View File

@ -270,7 +270,9 @@ GameLib.GUI.prototype.buildControl = function(folder, object, property, entityMa
'gui' : GameLib.System.SYSTEM_TYPE_GUI, 'gui' : GameLib.System.SYSTEM_TYPE_GUI,
'input' : GameLib.System.SYSTEM_TYPE_INPUT, 'input' : GameLib.System.SYSTEM_TYPE_INPUT,
'render' : GameLib.System.SYSTEM_TYPE_RENDER, '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() ).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); var objects = entityManager.queryComponents(constructor);
@ -892,15 +894,11 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en
object.updateInstance(); object.updateInstance();
} }
/**
* Properties changed - rebuild the object list in the parent
*/
console.log('parentObject.buildIdToObject();');
/** /**
* Properties changed - rebuild GUI * Properties changed - rebuild GUI
*/ */
gui.build(entityManager); //gui.build(entityManager);
}; };
@ -1037,42 +1035,45 @@ GameLib.GUI.prototype.build = function(entityManager) {
this.instance.removeAllFolders(); 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) { this.objects.map(
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(
function(object) { function(object) {
@ -1114,7 +1115,6 @@ GameLib.GUI.prototype.build = function(entityManager) {
entityManager entityManager
) )
} else if (object.linkedObjects[property] instanceof Array) { } else if (object.linkedObjects[property] instanceof Array) {
console.log('ignored array : ' + property);
this.buildArrayManager( this.buildArrayManager(
folder, folder,
object, object,
@ -1123,7 +1123,7 @@ GameLib.GUI.prototype.build = function(entityManager) {
entityManager entityManager
) )
} else { } 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') { } else if (typeof (object[property]) === 'object') {

View File

@ -10,6 +10,19 @@ GameLib.System.GUI = function(
this, this,
apiSystem 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); 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() { 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); 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() { GameLib.System.GUI.prototype.stop = function() {
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); this.guis.map(function(gui){
guis.map(function(gui){
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); 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 = [];
}; };

View File

@ -48,6 +48,13 @@ GameLib.System.Linking.prototype.start = function() {
this.register = GameLib.EntityManager.Instance.queryComponents([GameLib.Component]); this.register = GameLib.EntityManager.Instance.queryComponents([GameLib.Component]);
GameLib.Event.Emit(
GameLib.Event.REGISTER_UPDATE,
{
register : this.register
}
);
this.componentCreatedSubscription = this.subscribe( this.componentCreatedSubscription = this.subscribe(
GameLib.Event.COMPONENT_CREATED, GameLib.Event.COMPONENT_CREATED,
this.componentCreated.bind(this) this.componentCreated.bind(this)
@ -170,7 +177,7 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
if (parentComponent.instance) { if (parentComponent.instance) {
parentComponent.loaded = true; parentComponent.loaded = true;
parentComponent.buildIdToObject();
if (this.resolved.indexOf(parentComponent) === -1) { if (this.resolved.indexOf(parentComponent) === -1) {
this.resolved.push(parentComponent); this.resolved.push(parentComponent);
} }
@ -184,6 +191,13 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
delete this.dependencies[component.id]; delete this.dependencies[component.id];
GameLib.Event.Emit(
GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE,
{
dependencies : this.dependencies
}
);
if (GameLib.Utils.IsEmpty(this.dependencies)) { if (GameLib.Utils.IsEmpty(this.dependencies)) {
GameLib.Event.Emit( GameLib.Event.Emit(
@ -210,6 +224,13 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
*/ */
this.register.push(component); this.register.push(component);
GameLib.Event.Emit(
GameLib.Event.REGISTER_UPDATE,
{
register : this.register
}
);
/** /**
* We only care about components with unloaded dependencies - * We only care about components with unloaded dependencies -
* other components will have already had their instance objects created * 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)) { if (this.dependencies[id].indexOf(component === -1)) {
this.dependencies[id].push(component); 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(); component.instance = component.createInstance();
if (component.instance) { if (component.instance) {
component.loaded = true; component.loaded = true;
component.buildIdToObject();
GameLib.Event.EmitInstanceEvents(component); 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 * 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 (helper) {
if (data.originalScene && data.originalScene.instance) { if (data.originalScene && data.originalScene.instance) {
@ -411,58 +439,6 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) {
data.originalScene.removeObject(data.object); data.originalScene.removeObject(data.object);
} }
data.newScene.addObject(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() { GameLib.System.Linking.prototype.stop = function() {
this.register = []; this.register = [];
GameLib.Event.Emit(
GameLib.Event.REGISTER_UPDATE,
{
register : this.register
}
);
this.componentCreatedSubscription.remove(); this.componentCreatedSubscription.remove();
this.parentSceneChangeSubscription.remove(); this.parentSceneChangeSubscription.remove();
this.parentEntityChangeSubscription.remove(); this.parentEntityChangeSubscription.remove();

View File

@ -220,14 +220,12 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
if (object.result !== 'success') { if (object.result !== 'success') {
if (onComponentError) { if (onComponentError) {
onComponentError(error); onComponentError(id, object);
} }
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.LOAD_COMPONENT_ERROR, GameLib.Event.LOAD_COMPONENT_ERROR,
{ {error : object}
error: error
}
); );
return; return;