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