From 85b65a2672f36ea80103234cc619603a8cf4d9aa Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Thu, 14 Sep 2017 10:50:09 +0200 Subject: [PATCH] animation system update --- src/game-lib-a-1-event.js | 17 ++++++++++++ src/game-lib-system-animation.js | 44 ++++++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index 8734614..46657a1 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -371,6 +371,23 @@ GameLib.Event.Emit = function( var count = 0; if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) { + + if (GameLib.Event.Subscriptions[eventName].length === 0) { + + if (clientCallback) { + /** + * We execute the client callback immediately since there are no subscriptions to this event + */ + clientCallback(); + } + + if (clientErrorCallback) { + clientErrorCallback({ + message : 'No subscriptions for event ' + eventName + }) + } + } + GameLib.Event.Subscriptions[eventName].map( function(callback) { if (callback) { diff --git a/src/game-lib-system-animation.js b/src/game-lib-system-animation.js index bed48e0..9f856fc 100644 --- a/src/game-lib-system-animation.js +++ b/src/game-lib-system-animation.js @@ -19,23 +19,47 @@ GameLib.System.Animation.prototype.start = function() { GameLib.System.prototype.start.call(this); + this.renderSubscriptions = []; + this.animateSubscription = GameLib.Event.Subscribe( GameLib.Event.ANIMATE, - this.animate + this.animate.bind(this) ); + }; -GameLib.System.Animation.prototype.animate = function(data, clientCallback) { +GameLib.System.Animation.prototype.animate = function(animationData, clientCallback) { + + this.renderSubscriptions.push( + + new GameLib.Event.Subscribe( + + GameLib.Event.BEFORE_RENDER, + + function(subscriptionIndex) { + return function(renderData) { + + if ( + clientCallback( + { + renderData : renderData, + animationData : animationData + } + ) + ) { + + this.renderSubscriptions[subscriptionIndex].remove(); + + animationData.done(); + } + + }.bind(this); + + }.bind(this)(this.renderSubscriptions.length) + ) + ); - this.renderSubscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, - function(data) { - if (clientCallback(data)) { - this.renderSubscription.remove(); - } - }.bind(this) - ) };