async storage

beta.r3js.org
-=yb4f310 2017-11-14 12:18:21 +01:00
parent 7990601fe7
commit 627eb60a2a
1 changed files with 43 additions and 30 deletions

View File

@ -460,9 +460,9 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
}.bind(this)
);
this.loading = this.loading.reduce(
toProcess.map(
function(result, id) {
function(id) {
var xhr = new XMLHttpRequest();
@ -477,6 +477,26 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
return;
}
if (
runtimeComponent.parentEntity &&
typeof runtimeComponent.parentEntity === 'string'
) {
GameLib.EntityManager.Instance.queryComponents(GameLib.Entity).map(
function (entity) {
if (runtimeComponent.parentEntity === entity.id) {
runtimeComponent.parentEntity = entity;
}
}
);
}
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
component: runtimeComponent
}
);
__system.loaded.push(runtimeComponent.id);
if (includeDependencies) {
@ -494,8 +514,8 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
var index = dependencies.indexOf(id);
if (index === -1) {
dependencies.splice();
if (index !== -1) {
dependencies.splice(index, 1);
}
}
);
@ -551,12 +571,12 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
dependencies = dependencies.reduce(
function (result, dependency) {
if (this.loaded.indexOf(dependency) === -1) {
if (__system.loaded.indexOf(dependency) === -1) {
result.push(dependency);
}
return result;
}.bind(__system),
},
[]
);
@ -565,20 +585,11 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
*/
dependencies.map(
function (dependency) {
GameLib.Utils.PushUnique(this.loading, dependency);
}.bind(__system)
GameLib.Utils.PushUnique(__system.loading, dependency);
}
);
if (__system.onComponentLoaded) {
__system.onComponentLoaded(runtimeComponent);
}
GameLib.Event.Emit(
GameLib.Event.COMPONENT_CREATED,
{
component: runtimeComponent
}
);
__system.loadComponent(apiUrl, dependencies, includeDependencies, clientCallback, clientErrorCallback);
GameLib.Event.Emit(
GameLib.Event.LOAD_PROGRESS,
@ -587,16 +598,19 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
toProcess : dependencies.length
}
);
__system.loadComponent(apiUrl, dependencies,includeDependencies, clientCallback, clientErrorCallback);
// GameLib.Event.Emit(
// GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE,
// {
// loaded: __system.loaded
// }
// )
}
// GameLib.Event.Emit(
// GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE,
// {
// loaded: __system.loaded
// }
// );
if (__system.onComponentLoaded) {
__system.onComponentLoaded(runtimeComponent);
}
}
}(this);
@ -639,9 +653,8 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
xhr.send();
return result;
}.bind(this),
[]
}.bind(this)
);