Commits

Christophe Thiriot  committed 439f255

added next command

  • Participants
  • Parent commits 6a49d99

Comments (0)

Files changed (2)

File coffee/app.coffee

         # buttons clicks
         @view.$container.querySelector('.next-play').addEventListener 'click', =>
             @next_play()
+        @view.$container.querySelector('.next').addEventListener 'click', =>
+            @next()
         @view.$container.querySelector('.stop').addEventListener 'click', =>
             @stop()
 
     end_callback: =>
         if @mode is 'play'
             if @current < @turnlist.length - 1
+                @mode = 'stop'
                 @next_play()
             else
+                console.log 'end'
                 @mode = 'stop'
                 @current = -1
         else if @mode is 'play_stop'
             @mode = 'stop'
 
+    next: =>
+        window.setTimeout =>
+            if @mode is 'stop'
+                @mode = 'play_stop'
+                @current++
+                @view.turn @turnlist[@current], @end_callback
+
 
     next_play: =>
         window.setTimeout =>
-            @mode = 'play'
-            @current++
-            @view.turn @turnlist[@current], @end_callback
+            if @mode is 'stop'
+                @mode = 'play'
+                @current++
+                @view.turn @turnlist[@current], @end_callback
 
     stop: =>
         window.setTimeout =>
-            @mode = 'stop'
-            @end_callback()
+            if @mode isnt 'stop'
+                @mode = 'stop'
+                @end_callback()
 
 document.addEventListener 'DOMContentLoaded', ->
 
 
       this.next_play = __bind(this.next_play, this);
 
+      this.next = __bind(this.next, this);
+
       this.end_callback = __bind(this.end_callback, this);
 
       var _this = this;
       this.view.$container.querySelector('.next-play').addEventListener('click', function() {
         return _this.next_play();
       });
+      this.view.$container.querySelector('.next').addEventListener('click', function() {
+        return _this.next();
+      });
       this.view.$container.querySelector('.stop').addEventListener('click', function() {
         return _this.stop();
       });
     CubeController.prototype.end_callback = function() {
       if (this.mode === 'play') {
         if (this.current < this.turnlist.length - 1) {
+          this.mode = 'stop';
           return this.next_play();
         } else {
+          console.log('end');
           this.mode = 'stop';
           return this.current = -1;
         }
       }
     };
 
+    CubeController.prototype.next = function() {
+      var _this = this;
+      return window.setTimeout(function() {
+        if (_this.mode === 'stop') {
+          _this.mode = 'play_stop';
+          _this.current++;
+          return _this.view.turn(_this.turnlist[_this.current], _this.end_callback);
+        }
+      });
+    };
+
     CubeController.prototype.next_play = function() {
       var _this = this;
       return window.setTimeout(function() {
-        _this.mode = 'play';
-        _this.current++;
-        return _this.view.turn(_this.turnlist[_this.current], _this.end_callback);
+        if (_this.mode === 'stop') {
+          _this.mode = 'play';
+          _this.current++;
+          return _this.view.turn(_this.turnlist[_this.current], _this.end_callback);
+        }
       });
     };
 
     CubeController.prototype.stop = function() {
       var _this = this;
       return window.setTimeout(function() {
-        _this.mode = 'stop';
-        return _this.end_callback();
+        if (_this.mode !== 'stop') {
+          _this.mode = 'stop';
+          return _this.end_callback();
+        }
       });
     };