From 0e1967595bc1a9e06103e3925553f8314b7a18a6 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 9 Oct 2017 12:45:29 +0200 Subject: [PATCH] remove coder and physics deps --- src/game-lib-d3-api-z-animation.js | 18 ++++--- src/game-lib-d3-custom-code.js | 20 +++---- src/game-lib-system-storage.js | 85 +++++++++++++++++++++--------- 3 files changed, 82 insertions(+), 41 deletions(-) diff --git a/src/game-lib-d3-api-z-animation.js b/src/game-lib-d3-api-z-animation.js index d589f0f..7921205 100644 --- a/src/game-lib-d3-api-z-animation.js +++ b/src/game-lib-d3-api-z-animation.js @@ -1,17 +1,12 @@ /** * Creates a Animation object - * @param coder * @param apiAnimation GameLib.D3.API.Animation * @constructor */ GameLib.D3.Animation = function( - coder, apiAnimation ) { - this.coder = coder; - this.coder.isNotCodeMirrorThrow(); - if (GameLib.Utils.UndefinedOrNull(apiAnimation)) { apiAnimation = {}; } @@ -182,21 +177,28 @@ GameLib.D3.Animation.prototype.toApiObject = function() { /** * Converts from an Object Animation to a GameLib.D3.Animation - * @param coder GameLib.D3.Coder * @param objectAnimation Object * @returns {GameLib.D3.Animation} * @constructor */ -GameLib.D3.Animation.FromObject = function(coder, objectAnimation) { +GameLib.D3.Animation.FromObject = function(objectAnimation) { var apiAnimation = GameLib.D3.API.Animation.FromObject(objectAnimation); return new GameLib.D3.Animation( - coder, apiAnimation ); }; GameLib.D3.Animation.prototype.launchEditor = function(){ + GameLib.Event.Emit( + GameLib.Event.GET_CODER_IMPLEMENTATION, + null, + function(coder) { + this.coder = coder; + this.coder.isNotCodeMirrorThrow(); + }.bind(this) + ); + var property = null; if (this.functionType === GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION) { diff --git a/src/game-lib-d3-custom-code.js b/src/game-lib-d3-custom-code.js index 8cc6025..2ccbb0d 100644 --- a/src/game-lib-d3-custom-code.js +++ b/src/game-lib-d3-custom-code.js @@ -1,17 +1,12 @@ /** * Creates a CustomCode object - * @param coder * @param apiCustomCode GameLib.D3.API.CustomCode * @constructor */ GameLib.D3.CustomCode = function( - coder, apiCustomCode ) { - this.coder = coder; - this.coder.isNotCodeMirrorThrow(); - if (GameLib.Utils.UndefinedOrNull(apiCustomCode)) { apiCustomCode = {}; } @@ -93,22 +88,29 @@ GameLib.D3.CustomCode.prototype.toApiObject = function() { /** * Converts from an Object CustomCode to a GameLib.D3.CustomCode - * @param coder GameLib.D3.Coder * @param objectCustomCode Object * @returns {GameLib.D3.CustomCode} * @constructor */ -GameLib.D3.CustomCode.FromObject = function(coder, objectCustomCode) { +GameLib.D3.CustomCode.FromObject = function(objectCustomCode) { var apiCustomCode = GameLib.D3.API.CustomCode.FromObject(objectCustomCode); return new GameLib.D3.CustomCode( - coder, apiCustomCode ); }; GameLib.D3.CustomCode.prototype.launchEditor = function(){ - this.editor = this.coder.instance( + GameLib.Event.Emit( + GameLib.Event.GET_CODER_IMPLEMENTATION, + null, + function(coder) { + this.coder = coder; + this.coder.isNotCodeMirrorThrow(); + }.bind(this) + ); + + this.editor = this.coder.instance( document.body, { value : this.code, diff --git a/src/game-lib-system-storage.js b/src/game-lib-system-storage.js index dbb1596..92678d2 100644 --- a/src/game-lib-system-storage.js +++ b/src/game-lib-system-storage.js @@ -1,8 +1,6 @@ /** * Storage System takes care loading and linking components and dependencies * @param graphics - * @param physics - * @param coder * @param apiSystem GameLib.API.System * @param token * @param apiUploadUrl @@ -16,8 +14,6 @@ */ GameLib.System.Storage = function( graphics, - physics, - coder, apiSystem, token, apiUploadUrl, @@ -28,15 +24,6 @@ GameLib.System.Storage = function( onComponentProgress, onComponentError ) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - this.physics = physics; - this.physics.isNotCannonThrow(); - - this.coder = coder; - this.coder.isNotCodeMirrorThrow(); - GameLib.System.call( this, apiSystem @@ -101,7 +88,40 @@ GameLib.System.Storage.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.loginSubscription = this.subscribe( + GameLib.Event.Emit( + GameLib.Event.GET_GRAPHICS_IMPLEMENTATION, + null, + function(graphics) { + this.graphics = graphics; + }.bind(this), + function() { + this.graphics = null; + }.bind(this) + ); + + GameLib.Event.Emit( + GameLib.Event.GET_PHYSICS_IMPLEMENTATION, + null, + function(physics) { + this.physics = physics; + }.bind(this), + function() { + this.physics = null; + }.bind(this) + ); + + GameLib.Event.Emit( + GameLib.Event.GET_CODER_IMPLEMENTATION, + null, + function(coder) { + this.coder = coder; + }.bind(this), + function() { + this.coder = null; + }.bind(this) + ); + + this.loginSubscription = this.subscribe( GameLib.Event.LOGGED_IN, function(data) { this.token = data.token; @@ -400,24 +420,41 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc } else { try { + runtimeComponent = fn(component); + } catch (error) { - try { - runtimeComponent = fn(__system.coder, component); - } catch (error) { + + if (__system.coder) { + + try { + runtimeComponent = fn(__system.coder, component); + } catch (error) { + + } + + } + + if (!runtimeComponent && __system.graphics) { try { runtimeComponent = fn(__system.graphics, component); } catch (error) { - try { - runtimeComponent = fn(__system.physics, component); - } catch (error) { - /** - * ok - we don't cannot create this component - */ - } + } } + + if (!runtimeComponent && __system.physics) { + try { + runtimeComponent = fn(__system.physics, component); + } catch (error) { + /** + * ok - we don't cannot create this component + */ + } + } + } + if (!runtimeComponent) { if (clientErrorCallback) { clientErrorCallback('Could not create a runtime component: ' + component.name);