From 880e1ca630958fdbecd7d32b254504bbdb4653bf Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Tue, 4 Jun 2013 10:26:50 -1000 Subject: [PATCH] animation work --- build/bundle.js | 68 ++++++++++++-------- spec/animation.spec.js | 9 +++ src/js/git/index.js | 12 ++-- src/js/visuals/animation/animationFactory.js | 34 +++++++--- src/js/visuals/animation/index.js | 6 +- 5 files changed, 82 insertions(+), 47 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index 28b017db..12fd172e 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -7318,7 +7318,7 @@ GitEngine.prototype.makeOrigin = function(treeString) { // TODO handle the case where the master target on origin is not present // locally, so we have to go up the chain. for now we assume the master on - // origin is at least present + // origin is at least present. var originTree = JSON.parse(unescape(treeString)); var originMasterTarget = originTree.branches.master.target; var originMaster = this.makeBranch( @@ -7676,20 +7676,16 @@ GitEngine.prototype.revert = function(whichCommits) { _.each(toRebase, function(oldCommit) { var newId = this.rebaseAltID(oldCommit.get('id')); - var commitMessage = intl.str( - 'git-revert-msg', - { - oldCommit: this.resolveName(oldCommit), - oldMsg: oldCommit.get('commitMessage') - } - ); + var commitMessage = intl.str('git-revert-msg', { + oldCommit: this.resolveName(oldCommit), + oldMsg: oldCommit.get('commitMessage') + }); var newCommit = this.makeCommit([base], newId, { commitMessage: commitMessage }); base = newCommit; - // animation stuff afterSnapshot = this.gitVisuals.genSnapshot(); animationResponse.rebaseSteps.push({ @@ -9190,6 +9186,18 @@ var makeCommitBirthAnimation = function(gitVisuals, visNode) { }; }; +var makeHighlightAnimation = function(visNode, visBranch) { + var fullTime = GRAPHICS.defaultAnimationTime * 0.66; + var slowTime = fullTime * 2.0; + + return { + animation: function() { + visNode.highlightTo(visBranch, slowTime, 'easeInOut'); + }, + duration: fullTime * 1.5 + }; +}; + AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { if (!animationQueue) { throw new Error("Need animation queue to add closure to!"); @@ -9306,13 +9314,11 @@ AnimationFactory.prototype.rebaseHighlightPart = function(animationQueue, rebase _.each(oldCommits, function(oldCommit) { var visNode = oldCommit.get('visNode'); + var anPack = makeHighlightAnimation(visNode, visBranch); animationQueue.add(new Animation({ - closure: function() { - visNode.highlightTo(visBranch, slowTime, 'easeInOut'); - }, - duration: fullTime * 1.5 + closure: anPack.animation, + duration: anPack.duration })); - }, this); this.delay(animationQueue, fullTime * 2); @@ -23248,7 +23254,7 @@ GitEngine.prototype.makeOrigin = function(treeString) { // TODO handle the case where the master target on origin is not present // locally, so we have to go up the chain. for now we assume the master on - // origin is at least present + // origin is at least present. var originTree = JSON.parse(unescape(treeString)); var originMasterTarget = originTree.branches.master.target; var originMaster = this.makeBranch( @@ -23606,20 +23612,16 @@ GitEngine.prototype.revert = function(whichCommits) { _.each(toRebase, function(oldCommit) { var newId = this.rebaseAltID(oldCommit.get('id')); - var commitMessage = intl.str( - 'git-revert-msg', - { - oldCommit: this.resolveName(oldCommit), - oldMsg: oldCommit.get('commitMessage') - } - ); + var commitMessage = intl.str('git-revert-msg', { + oldCommit: this.resolveName(oldCommit), + oldMsg: oldCommit.get('commitMessage') + }); var newCommit = this.makeCommit([base], newId, { commitMessage: commitMessage }); base = newCommit; - // animation stuff afterSnapshot = this.gitVisuals.genSnapshot(); animationResponse.rebaseSteps.push({ @@ -31323,6 +31325,18 @@ var makeCommitBirthAnimation = function(gitVisuals, visNode) { }; }; +var makeHighlightAnimation = function(visNode, visBranch) { + var fullTime = GRAPHICS.defaultAnimationTime * 0.66; + var slowTime = fullTime * 2.0; + + return { + animation: function() { + visNode.highlightTo(visBranch, slowTime, 'easeInOut'); + }, + duration: fullTime * 1.5 + }; +}; + AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { if (!animationQueue) { throw new Error("Need animation queue to add closure to!"); @@ -31439,13 +31453,11 @@ AnimationFactory.prototype.rebaseHighlightPart = function(animationQueue, rebase _.each(oldCommits, function(oldCommit) { var visNode = oldCommit.get('visNode'); + var anPack = makeHighlightAnimation(visNode, visBranch); animationQueue.add(new Animation({ - closure: function() { - visNode.highlightTo(visBranch, slowTime, 'easeInOut'); - }, - duration: fullTime * 1.5 + closure: anPack.animation, + duration: anPack.duration })); - }, this); this.delay(animationQueue, fullTime * 2); diff --git a/spec/animation.spec.js b/spec/animation.spec.js index 116e4ef0..65b9ab66 100644 --- a/spec/animation.spec.js +++ b/spec/animation.spec.js @@ -18,6 +18,15 @@ describe('Promise animation', function() { expect(value).toBe(1); }); + it('also takes animation packs', function() { + var value = 0; + var animation = new PromiseAnimation({ + animation: function() { value++; } + }); + animation.play(); + expect(value).toBe(1); + }); + it('Will resolve a deferred', function() { var value = 0; var closure = function() { diff --git a/src/js/git/index.js b/src/js/git/index.js index bef392cc..144b01a8 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -623,20 +623,16 @@ GitEngine.prototype.revert = function(whichCommits) { _.each(toRebase, function(oldCommit) { var newId = this.rebaseAltID(oldCommit.get('id')); - var commitMessage = intl.str( - 'git-revert-msg', - { - oldCommit: this.resolveName(oldCommit), - oldMsg: oldCommit.get('commitMessage') - } - ); + var commitMessage = intl.str('git-revert-msg', { + oldCommit: this.resolveName(oldCommit), + oldMsg: oldCommit.get('commitMessage') + }); var newCommit = this.makeCommit([base], newId, { commitMessage: commitMessage }); base = newCommit; - // animation stuff afterSnapshot = this.gitVisuals.genSnapshot(); animationResponse.rebaseSteps.push({ diff --git a/src/js/visuals/animation/animationFactory.js b/src/js/visuals/animation/animationFactory.js index c1999e17..2ee074b7 100644 --- a/src/js/visuals/animation/animationFactory.js +++ b/src/js/visuals/animation/animationFactory.js @@ -41,6 +41,18 @@ var makeCommitBirthAnimation = function(gitVisuals, visNode) { }; }; +var makeHighlightAnimation = function(visNode, visBranch) { + var fullTime = GRAPHICS.defaultAnimationTime * 0.66; + var slowTime = fullTime * 2.0; + + return { + animation: function() { + visNode.highlightTo(visBranch, slowTime, 'easeInOut'); + }, + duration: fullTime * 1.5 + }; +}; + AnimationFactory.prototype.genCommitBirthAnimation = function(animationQueue, commit, gitVisuals) { if (!animationQueue) { throw new Error("Need animation queue to add closure to!"); @@ -143,9 +155,6 @@ AnimationFactory.prototype.rebaseAnimation = function(animationQueue, rebaseResp }; AnimationFactory.prototype.rebaseHighlightPart = function(animationQueue, rebaseResponse, gitEngine) { - var fullTime = GRAPHICS.defaultAnimationTime * 0.66; - var slowTime = fullTime * 2.0; - // we want to highlight all the old commits var oldCommits = rebaseResponse.toRebaseArray; // we are either highlighting to a visBranch or a visNode @@ -157,18 +166,27 @@ AnimationFactory.prototype.rebaseHighlightPart = function(animationQueue, rebase _.each(oldCommits, function(oldCommit) { var visNode = oldCommit.get('visNode'); + var anPack = makeHighlightAnimation(visNode, visBranch); animationQueue.add(new Animation({ - closure: function() { - visNode.highlightTo(visBranch, slowTime, 'easeInOut'); - }, - duration: fullTime * 1.5 + closure: anPack.animation, + duration: anPack.duration })); - }, this); this.delay(animationQueue, fullTime * 2); }; +AnimationFactory.prototype.genHighlightPromiseAnmation = function(commit, destBranch) { + var visBranch = destBranch.get('visBranch'); + var visNode = commit.get('visNode'); + + var anPack = makeHighlightAnimation(visNode, visBranch); + return new PromiseAnimation({ + closure: anPack.animation, + duration: anPack.duration + }); +}; + AnimationFactory.prototype.rebaseBirthPart = function(animationQueue, rebaseResponse, gitEngine, gitVisuals) { var rebaseSteps = rebaseResponse.rebaseSteps; diff --git a/src/js/visuals/animation/index.js b/src/js/visuals/animation/index.js index 76bad8c2..34f27f9c 100644 --- a/src/js/visuals/animation/index.js +++ b/src/js/visuals/animation/index.js @@ -103,10 +103,10 @@ var PromiseAnimation = Backbone.Model.extend({ }, initialize: function(options) { - if (!options.closure) { - throw new Error('need closure'); + if (!options.closure && !options.animation) { + throw new Error('need closure or animation'); } - // TODO needed? + this.set('closure', options.closure || options.animation); this.set('deferred', options.deferred || Q.defer()); },