process component for buildId
parent
543b68046f
commit
b042b797d0
|
@ -30,6 +30,8 @@ GameLib.Component = function(
|
||||||
|
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
|
|
||||||
|
this.linked = false;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(delayed)) {
|
if (GameLib.Utils.UndefinedOrNull(delayed)) {
|
||||||
delayed = false;
|
delayed = false;
|
||||||
}
|
}
|
||||||
|
@ -286,6 +288,36 @@ GameLib.Component.prototype.toApiObject = function() {
|
||||||
return this.id;
|
return this.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.Component.prototype.processComponent = function(object) {
|
||||||
|
if (object instanceof GameLib.Component) {
|
||||||
|
|
||||||
|
object.buildIdToObject();
|
||||||
|
|
||||||
|
if (!object.linked) {
|
||||||
|
this.linked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var idToObject = object.idToObject;
|
||||||
|
|
||||||
|
for (var objectProperty in idToObject) {
|
||||||
|
if (idToObject.hasOwnProperty(objectProperty)) {
|
||||||
|
this.idToObject[objectProperty] = idToObject[objectProperty];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object.id) {
|
||||||
|
this.idToObject[object.id] = object;
|
||||||
|
} else {
|
||||||
|
console.warn('Object with no ID passed: ' + object)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (typeof object === 'string') {
|
||||||
|
this.linked = false;
|
||||||
|
} else {
|
||||||
|
console.warn('Unhandled type of object: ', object);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function - builds an 'id to object' object - which contains the ids which point directly
|
* This function - builds an 'id to object' object - which contains the ids which point directly
|
||||||
* to its corresponding object, for all the objects contained inside this object
|
* to its corresponding object, for all the objects contained inside this object
|
||||||
|
@ -296,19 +328,26 @@ GameLib.Component.prototype.buildIdToObject = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this component 'building' flag is true - it is in the process of building idToObject up the callstack and the
|
||||||
|
* caller should know to not try to build idToObject again (prevent infinite recursion)
|
||||||
|
*/
|
||||||
this.building = true;
|
this.building = true;
|
||||||
|
|
||||||
this.idToObject = {};
|
/**
|
||||||
|
* If any child component is not fully linked, this component will show as not linked
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.linked = true;
|
||||||
|
|
||||||
var loaded = true;
|
this.idToObject = {};
|
||||||
|
|
||||||
for (var property in this.linkedObjects) {
|
for (var property in this.linkedObjects) {
|
||||||
if (
|
if (
|
||||||
this.linkedObjects.hasOwnProperty(property) &&
|
this.linkedObjects.hasOwnProperty(property) &&
|
||||||
this.hasOwnProperty(property) &&
|
this.hasOwnProperty(property) &&
|
||||||
this[property] &&
|
this[property] &&
|
||||||
property.indexOf('parent') !== 0 &&
|
property.indexOf('parent') !== 0
|
||||||
loaded
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (this.linkedObjects[property] instanceof Array) {
|
if (this.linkedObjects[property] instanceof Array) {
|
||||||
|
@ -317,7 +356,7 @@ GameLib.Component.prototype.buildIdToObject = function() {
|
||||||
* Remove null objects (can happen)
|
* Remove null objects (can happen)
|
||||||
*/
|
*/
|
||||||
this[property] = this[property].filter(
|
this[property] = this[property].filter(
|
||||||
function(object) {
|
function (object) {
|
||||||
if (object === null) {
|
if (object === null) {
|
||||||
console.log('null object found and removed');
|
console.log('null object found and removed');
|
||||||
return false;
|
return false;
|
||||||
|
@ -327,86 +366,16 @@ GameLib.Component.prototype.buildIdToObject = function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
this[property].map(
|
this[property].map(
|
||||||
|
function (object) {
|
||||||
function(object) {
|
this.processComponent(object);
|
||||||
|
|
||||||
if (object instanceof Object) {
|
|
||||||
|
|
||||||
if (object.buildIdToObject) {
|
|
||||||
|
|
||||||
object.buildIdToObject();
|
|
||||||
|
|
||||||
if (object.loaded === false) {
|
|
||||||
loaded = false;
|
|
||||||
/**
|
|
||||||
* Don't continue processing
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
var _idToObject = object.idToObject;
|
|
||||||
|
|
||||||
for (var property in _idToObject) {
|
|
||||||
if (_idToObject.hasOwnProperty(property)) {
|
|
||||||
this.idToObject[property] = _idToObject[property];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object.id) {
|
|
||||||
this.idToObject[object.id] = object;
|
|
||||||
} else {
|
|
||||||
console.warn('Object with no ID passed: ' + object)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (typeof object === 'string') {
|
|
||||||
loaded = false;
|
|
||||||
} else {
|
|
||||||
console.warn('Unhandled type of object: ', object);
|
|
||||||
}
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
this.processComponent(this[property]);
|
||||||
var object = this[property];
|
|
||||||
|
|
||||||
if (object instanceof Object) {
|
|
||||||
|
|
||||||
if (object.buildIdToObject) {
|
|
||||||
|
|
||||||
object.buildIdToObject();
|
|
||||||
|
|
||||||
if (object.loaded === false) {
|
|
||||||
loaded = false;
|
|
||||||
} else {
|
|
||||||
var _idToObject = object.idToObject;
|
|
||||||
|
|
||||||
for (var objectProperty in _idToObject) {
|
|
||||||
if (_idToObject.hasOwnProperty(objectProperty)) {
|
|
||||||
this.idToObject[objectProperty] = _idToObject[objectProperty];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (object.id) {
|
|
||||||
this.idToObject[object.id] = object;
|
|
||||||
} else {
|
|
||||||
console.warn('Object with no ID passed: ' + object)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (typeof object === 'string') {
|
|
||||||
|
|
||||||
loaded = false;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.warn('Unhandled type of object: ', object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loaded = loaded;
|
|
||||||
|
|
||||||
this.idToObject[this.id] = this;
|
this.idToObject[this.id] = this;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue