linker fix for dependency register, gui for clicking

beta.r3js.org
Theunis J. Botha 2017-06-30 12:06:55 +02:00
parent 943a81916f
commit 01fbf4e2ae
6 changed files with 95 additions and 9 deletions

View File

@ -630,6 +630,18 @@ GameLib.Utils.Difference = function (a, b) {
);
};
/**
* Push only if not in there already
* @param array
* @param object
* @constructor
*/
GameLib.Utils.PushUnique = function(array, object) {
if (array.indexOf(object) === -1) {
array.push(object);
}
};
/**
* Checks whether or not the object is empty
* @param obj

View File

@ -54,7 +54,7 @@ GameLib.Entity.prototype.createInstance = function() {
*/
GameLib.Entity.prototype.addComponent = function(component) {
this.components.push(component);
GameLib.Utils.PushUnique(this.components, component);
/**
* Here we will dig into this component - find all its 'parentEntity' members - and update them accordingly
@ -67,10 +67,9 @@ GameLib.Entity.prototype.addComponent = function(component) {
for (var property in component.idToObject) {
if (component.idToObject.hasOwnProperty(property) &&
component.idToObject[property] !== component &&
component.idToObject[property] instanceof GameLib.Component &&
this.components.indexOf(component.idToObject[property] === -1)
component.idToObject[property] instanceof GameLib.Component
) {
this.components.push(component.idToObject[property]);
GameLib.Utils.PushUnique(this.components, component.idToObject[property]);
component.idToObject[property].parentEntity = this;
}
}

View File

@ -783,7 +783,10 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
var step = 0.1;
if (property === 'localRotation') {
if (
property === 'localRotation' ||
property === 'localPosition'
) {
step = 0.001;
}

View File

@ -23,6 +23,8 @@ GameLib.System.GUI = function(
this.newEntitySubscription = null;
this.meshSelectionObjects = {};
};
GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype);
@ -87,10 +89,77 @@ GameLib.System.GUI.prototype.meshDeleted = function(data) {
GameLib.System.GUI.prototype.meshSelected = function(data) {
var mesh = data.mesh;
var objectsToAdd = [];
this.guis.map(
function(gui) {
if (mesh.parentEntity) {
GameLib.Utils.PushUnique(objectsToAdd, mesh.parentEntity);
}
objectsToAdd.push(mesh);
mesh.materials.map(
function(material){
GameLib.Utils.PushUnique(objectsToAdd, material);
}
);
mesh.materials.map(
function(material){
for (var property in material.linkedObjects) {
if (
material.linkedObjects.hasOwnProperty(property) &&
material.hasOwnProperty(property) &&
material[property] &&
property !== 'parentEntity'
)
{
GameLib.Utils.PushUnique(objectsToAdd, material[property]);
for (var tProperty in material[property].linkedObjects) {
if (
material[property].linkedObjects.hasOwnProperty(tProperty) &&
material[property].hasOwnProperty(tProperty) &&
material[property][tProperty] &&
tProperty !== 'parentEntity'
) {
GameLib.Utils.PushUnique(objectsToAdd, material[property][tProperty]);
}
}
}
}
}
)
}
);
this.guis.map(function(gui){
objectsToAdd.map(function(object){
gui.addObject(object);
}.bind(this));
gui.build(GameLib.EntityManager.Instance);
});
this.meshSelectionObjects[mesh.id] = objectsToAdd;
};
GameLib.System.GUI.prototype.meshDeslected = function(data) {
if (GameLib.Utils.UndefinedOrNull(this.meshSelectionObjects[data.mesh.id])) {
console.warn('selected mesh data not available');
return;
}
this.guis.map(
function(gui) {
this.meshSelectionObjects[data.mesh.id].map(function(object){
gui.removeObject(object);
}.bind(this));
gui.build(GameLib.EntityManager.Instance);
}.bind(this)
)
};
GameLib.System.GUI.prototype.newEntity = function(data) {

View File

@ -219,7 +219,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) {
*/
var processedComponent = GameLib.EntityManager.Instance.findComponentById(id);
if (processedComponent) {
if (processedComponent && processedComponent.loaded) {
/**
* Link the component

View File

@ -185,7 +185,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
}
});
return function download(id) {
return function download(id, parentEntity) {
var onComponentLoaded = this.onComponentLoaded;
@ -248,8 +248,11 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
if (component.componentType === GameLib.Component.COMPONENT_ENTITY) {
runtimeComponent = fn(component, GameLib.EntityManager.Instance);
runtimeComponent.parentEntity = parentEntity;
parentEntity = runtimeComponent;
} else {
runtimeComponent = fn(__system.graphics, component);
runtimeComponent.parentEntity = parentEntity;
}
if (runtimeComponent instanceof GameLib.D3.Image) {
@ -368,7 +371,7 @@ GameLib.System.Storage.prototype.loadComponent = function(toProcess, includeDepe
}
)
} else {
download.bind(__system)(toProcess.pop());
download.bind(__system)(toProcess.pop(), parentEntity);
}
});
};
@ -420,7 +423,7 @@ GameLib.System.Storage.prototype.load = function(data) {
}
if (data.ids && data.ids.length > 0) {
this.loadComponent(data.ids, data.includeDependencies)(data.ids[0]);
this.loadComponent(data.ids, data.includeDependencies)(data.ids[0], null);
} else {
console.log('No components selected');
}