process component for buildId
parent
543b68046f
commit
b042b797d0
|
@ -30,6 +30,8 @@ GameLib.Component = function(
|
|||
|
||||
this.loaded = false;
|
||||
|
||||
this.linked = false;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(delayed)) {
|
||||
delayed = false;
|
||||
}
|
||||
|
@ -286,131 +288,98 @@ GameLib.Component.prototype.toApiObject = function() {
|
|||
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
|
||||
* to its corresponding object, for all the objects contained inside this object
|
||||
*/
|
||||
GameLib.Component.prototype.buildIdToObject = function() {
|
||||
|
||||
if (this.building) {
|
||||
return;
|
||||
}
|
||||
if (this.building) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.building = true;
|
||||
/**
|
||||
* 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.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) {
|
||||
if (
|
||||
this.linkedObjects.hasOwnProperty(property) &&
|
||||
this.hasOwnProperty(property) &&
|
||||
this[property] &&
|
||||
property.indexOf('parent') !== 0 &&
|
||||
loaded
|
||||
) {
|
||||
for (var property in this.linkedObjects) {
|
||||
if (
|
||||
this.linkedObjects.hasOwnProperty(property) &&
|
||||
this.hasOwnProperty(property) &&
|
||||
this[property] &&
|
||||
property.indexOf('parent') !== 0
|
||||
) {
|
||||
|
||||
if (this.linkedObjects[property] instanceof Array) {
|
||||
if (this.linkedObjects[property] instanceof Array) {
|
||||
|
||||
/**
|
||||
* Remove null objects (can happen)
|
||||
*/
|
||||
this[property] = this[property].filter(
|
||||
function(object) {
|
||||
if (object === null) {
|
||||
console.log('null object found and removed');
|
||||
return false;
|
||||
this[property] = this[property].filter(
|
||||
function (object) {
|
||||
if (object === null) {
|
||||
console.log('null object found and removed');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
this[property].map(
|
||||
|
||||
function(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);
|
||||
}
|
||||
function (object) {
|
||||
this.processComponent(object);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
this.processComponent(this[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var object = this[property];
|
||||
this.idToObject[this.id] = this;
|
||||
|
||||
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.building = false;
|
||||
this.building = false;
|
||||
};
|
||||
|
||||
GameLib.Component.prototype.generateNewIds = function() {
|
||||
|
|
Loading…
Reference in New Issue