animation system update

beta.r3js.org
-=yb4f310 2017-09-14 10:50:09 +02:00
parent 74ef87c6aa
commit 85b65a2672
2 changed files with 51 additions and 10 deletions

View File

@ -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) {

View File

@ -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)
)
};