send resolved
parent
3ee447bf4d
commit
52ae5ae597
|
@ -43,6 +43,7 @@ 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;
|
||||
|
||||
/**
|
||||
* Subscribe to some events
|
||||
|
|
|
@ -628,4 +628,14 @@ GameLib.Utils.Difference = function (a, b) {
|
|||
return c.indexOf(e) === i;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether or not the object is empty
|
||||
* @param obj
|
||||
* @returns {boolean}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.Utils.IsEmpty = function(obj) {
|
||||
return (Object.keys(obj).length === 0 && obj.constructor === Object);
|
||||
};
|
|
@ -127,17 +127,22 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
|||
|
||||
if (event.code === 'Delete') {
|
||||
|
||||
var meshes = entity.getComponents(GameLib.D3.Mesh);
|
||||
var gui = entity.getFirstComponent(GameLib.GUI);
|
||||
var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
|
||||
var guis = GameLib.EntityManager.Instance.queryComponents([GameLib.GUI]);
|
||||
|
||||
meshes.map(
|
||||
function(mesh) {
|
||||
if (mesh.selected) {
|
||||
this.removeHelper(mesh, entity);
|
||||
|
||||
var parentEntity = mesh.parentEntity;
|
||||
|
||||
parentEntity.removeHelper(mesh, entity);
|
||||
entity.removeComponent(mesh);
|
||||
entity.buildIdToObject();
|
||||
|
||||
gui.removeObject(mesh);
|
||||
guis.map(function(gui) {
|
||||
gui.removeObject(mesh);
|
||||
});
|
||||
|
||||
var scene = mesh.parentScene;
|
||||
scene.removeObject(mesh);
|
||||
|
@ -148,7 +153,9 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
|||
|
||||
|
||||
|
||||
gui.build(entityManager);
|
||||
guis.map(function(gui) {
|
||||
gui.build(entityManager);
|
||||
});
|
||||
}
|
||||
|
||||
if (event.code === 'ControlLeft') {
|
||||
|
|
|
@ -28,6 +28,8 @@ GameLib.System.Linking = function(
|
|||
*/
|
||||
this.register = [];
|
||||
|
||||
this.resolved = [];
|
||||
|
||||
this.componentCreatedSubscription = null;
|
||||
this.parentSceneChangeSubscription = null;
|
||||
this.parentEntityChangeSubscription = null;
|
||||
|
@ -136,13 +138,17 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
|||
} else {
|
||||
|
||||
parentComponents.map(
|
||||
function(parentComponent) {
|
||||
function (parentComponent) {
|
||||
|
||||
/**
|
||||
* Link the parent component to this component
|
||||
*/
|
||||
this.link(parentComponent, {component: component});
|
||||
|
||||
if (this.resolved.indexOf(component) === -1) {
|
||||
this.resolved.push(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the actual dependency
|
||||
*/
|
||||
|
@ -164,6 +170,11 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
|||
|
||||
if (parentComponent.instance) {
|
||||
parentComponent.loaded = true;
|
||||
|
||||
if (this.resolved.indexOf(parentComponent) === -1) {
|
||||
this.resolved.push(parentComponent);
|
||||
}
|
||||
|
||||
GameLib.Event.EmitInstanceEvents(parentComponent);
|
||||
}
|
||||
}
|
||||
|
@ -172,7 +183,24 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
|||
);
|
||||
|
||||
delete this.dependencies[component.id];
|
||||
|
||||
if (GameLib.Utils.IsEmpty(this.dependencies)) {
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.COMPONENTS_LINKED,
|
||||
{
|
||||
components: this.resolved.map(
|
||||
function(component) {
|
||||
return component;
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
this.resolved = [];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
||||
|
@ -212,6 +240,10 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
|
|||
*/
|
||||
this.link(component, {component: processedComponent});
|
||||
|
||||
if (this.resolved.indexOf(processedComponent) === -1) {
|
||||
this.resolved.push(processedComponent);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
|
@ -314,34 +346,6 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
|
|||
|
||||
this.resolveDependencies(data.scene);
|
||||
|
||||
// var scene = data.scene;
|
||||
//
|
||||
// scene.images.map(
|
||||
// function(image){
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.LOAD_IMAGE,
|
||||
// {
|
||||
// onLoaded : function(image) {
|
||||
// if (this.onImageLoaded) {
|
||||
// this.onImageLoaded(image);
|
||||
// }
|
||||
// },
|
||||
// onProgress : function(image, progress) {
|
||||
// if (this.onImageProgress) {
|
||||
// this.onImageProgress(image, progress);
|
||||
// }
|
||||
// },
|
||||
// onError : function(image, error) {
|
||||
// if (this.onImageError) {
|
||||
// this.onImageError(image, error);
|
||||
// }
|
||||
// },
|
||||
// image : image
|
||||
// }
|
||||
// );
|
||||
// }.bind(this)
|
||||
// );
|
||||
|
||||
/**
|
||||
* Add all meshes and lights
|
||||
*/
|
||||
|
@ -366,232 +370,15 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
|
|||
};
|
||||
|
||||
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
||||
|
||||
this.resolveDependencies(data.image);
|
||||
|
||||
// var textures = this.queryRegister(GameLib.D3.Texture);
|
||||
//
|
||||
// textures.map(
|
||||
//
|
||||
// function(texture) {
|
||||
// /**
|
||||
// * Only work with images that belong to this texture
|
||||
// */
|
||||
// if (
|
||||
// texture.image === data.image
|
||||
// ) {
|
||||
// /**
|
||||
// * Update instance, if already an instance
|
||||
// */
|
||||
// if (texture.instance) {
|
||||
// texture.updateInstance();
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.TEXTURE_INSTANCE_UPDATED,
|
||||
// {
|
||||
// texture : texture
|
||||
// }
|
||||
// )
|
||||
// } else {
|
||||
// /**
|
||||
// * Create a new instance
|
||||
// */
|
||||
// texture.instance = texture.createInstance();
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.TEXTURE_INSTANCE_CREATED,
|
||||
// {
|
||||
// texture : texture
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.textureInstanceCreated = function(data) {
|
||||
|
||||
this.resolveDependencies(data.texture);
|
||||
|
||||
// var materials = this.queryRegister(GameLib.D3.Material);
|
||||
//
|
||||
// materials.map(
|
||||
//
|
||||
// function(material) {
|
||||
//
|
||||
// if (!material.loaded) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!data.texture.loaded || !data.texture.instance) {
|
||||
// console.warn('texture indicated it is loaded however it is not');
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// console.log('texture instance created');
|
||||
|
||||
// var modified = false;
|
||||
|
||||
// /**
|
||||
// * We also need to check if the image of the texture is assigned -
|
||||
// * if not we should disable the map
|
||||
// */
|
||||
// if (material.alphaMap === data.texture) {
|
||||
// if (material.instance.alphaMap !== data.texture.instance) {
|
||||
// material.instance.alphaMap = data.texture.instance;
|
||||
// }
|
||||
// modified = true;
|
||||
// } else {
|
||||
// if (material.instance.alphaMap)
|
||||
// material.instance.alphaMap = null;
|
||||
// }
|
||||
//
|
||||
// if (material.aoMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.aoMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.aoMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.bumpMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.bumpMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.bumpMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.diffuseMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.map = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.map = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.displacementMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.displacementMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.displacementMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.emissiveMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.emissiveMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.emissiveMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.environmentMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.envMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.envMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.lightMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.lightMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.lightMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.metalnessMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.metalnessMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.metalnessMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.normalMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.normalMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.normalMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.roughnessMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.roughnessMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.roughnessMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
// if (material.specularMap === data.texture) {
|
||||
//
|
||||
// if (data.texture.image) {
|
||||
// material.instance.specularMap = data.texture.instance;
|
||||
// } else {
|
||||
// material.instance.specularMap = null;
|
||||
// }
|
||||
// modified = true;
|
||||
// }
|
||||
//
|
||||
// if (modified) {
|
||||
// material.updateInstance();
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.MATERIAL_INSTANCE_UPDATED,
|
||||
// {
|
||||
// material : material
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.materialInstanceCreated = function(data) {
|
||||
|
||||
this.resolveDependencies(data.material);
|
||||
|
||||
// var meshes = this.queryRegister(GameLib.D3.Mesh);
|
||||
//
|
||||
// meshes.map(function(mesh){
|
||||
//
|
||||
// if (!mesh.instance) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Only work with materials assigned to us
|
||||
// */
|
||||
// if (mesh.materials[0] !== data.material) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (mesh.instance.material === data.material.instance) {
|
||||
// //mesh.instance.geometry.uvsNeedUpdate = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (mesh.materials[0] === data.material) {
|
||||
//
|
||||
// if (mesh.instance.material !== data.material.instance) {
|
||||
// mesh.instance.material = data.material.instance;
|
||||
// }
|
||||
//
|
||||
// //mesh.instance.geometry.uvsNeedUpdate = true;
|
||||
// }
|
||||
// });
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -263,7 +263,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
|
|||
)
|
||||
}
|
||||
|
||||
loaded.push(runtimeComponent.id);
|
||||
loaded.push(runtimeComponent);
|
||||
|
||||
if (includeDependencies) {
|
||||
/**
|
||||
|
@ -310,8 +310,8 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
|
|||
function (result, dependency) {
|
||||
|
||||
var found = loaded.reduce(
|
||||
function (result, id) {
|
||||
if (id === dependency) {
|
||||
function (result, component) {
|
||||
if (component.id === dependency) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
@ -365,7 +365,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
|
|||
}
|
||||
);
|
||||
|
||||
var toProcess = GameLib.Utils.Difference(loaded, loading);
|
||||
var toProcess = GameLib.Utils.Difference(loaded.map(function(component){return component.id}), loading);
|
||||
|
||||
if (toProcess.length === 0) {
|
||||
GameLib.Event.Emit(
|
||||
|
|
Loading…
Reference in New Issue