Commits

Anonymous committed 30dd76e

added last command in the controller

  • Participants
  • Parent commits 439f255

Comments (0)

Files changed (3)

File coffee/app.coffee

                 for $facet in $facets
                     $facet.querySelector('div').style.backgroundColor = @colors[facet]
 
+    straightturn: (mov) =>
+        @model.combination(mov)
+        @renderColors()
+
     turn: (mov, callback) ->
         @movcallback = callback
         @ismoving = true
 
     view: undefined
 
+    model: undefined
+
     turnlist: ["R2", "U", "R", "U", "R'", "U'", "R'", "U'", "R'", "U", "R'"]
 
     constructor:(cubeview) ->
         @view = cubeview
+        @model = cubeview.model
 
         # add the text movements
         @view.$container.insertAdjacentHTML "beforeend", '<div class="movtext">' + @turnlist.join(' ') + '</div><div class="movbuttons"><a class="first" href="#">|◀</a><a class="previous" href="#">◀|</a><a class="previous-play" href="#">◀</a><a class="stop" href="#">◼</a><a class="next-play" href="#">▶</a><a class="next" href="#">|▶</a><a class="last" href="#">▶|</a></div>'
             @next()
         @view.$container.querySelector('.stop').addEventListener 'click', =>
             @stop()
+        @view.$container.querySelector('.last').addEventListener 'click', =>
+            @last()
 
     end_callback: =>
         if @mode is 'play'
                 @mode = 'stop'
                 @next_play()
             else
-                console.log 'end'
                 @mode = 'stop'
                 @current = -1
         else if @mode is 'play_stop'
                 @mode = 'stop'
                 @end_callback()
 
+    last : =>
+        window.setTimeout =>
+            if @mode is 'stop'
+                @current = 0 if @current is -1
+                remaining_turnlist = @turnlist[@current..@turnlist.length-1]
+                @view.straightturn(remaining_turnlist.join(''))
+                @current = @turnlist.length
+
 document.addEventListener 'DOMContentLoaded', ->
 
     for $container in document.querySelectorAll '.cubeofcoffee'

File css/style.css

     }
 
     .cube.transitioned {
-        -moz-transition: -moz-transform 0.2s;
+        -moz-transition: -moz-transform 1s;
         -moz-transition-timing-function: ease-in;
         -webkit-transition: -webkit-transform 1s;
         -o-transition: -o-transform 1s;
     function CubeView($container) {
       this.transitionend = __bind(this.transitionend, this);
 
+      this.straightturn = __bind(this.straightturn, this);
+
       this.renderColors = __bind(this.renderColors, this);
 
       var $cubeofcoffee, $viewer, eventtype, face, facet, height, hideclass, htmlstring, i, j, minlength, mov, offsetX, offsetY, perspective, remaining_spaceX, remaining_spaceY, transforms, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
       return _results;
     };
 
+    CubeView.prototype.straightturn = function(mov) {
+      this.model.combination(mov);
+      return this.renderColors();
+    };
+
     CubeView.prototype.turn = function(mov, callback) {
       var $cube, movclass, _i, _len, _ref, _results;
       this.movcallback = callback;
 
     CubeController.prototype.view = void 0;
 
+    CubeController.prototype.model = void 0;
+
     CubeController.prototype.turnlist = ["R2", "U", "R", "U", "R'", "U'", "R'", "U'", "R'", "U", "R'"];
 
     function CubeController(cubeview) {
+      this.last = __bind(this.last, this);
+
       this.stop = __bind(this.stop, this);
 
       this.next_play = __bind(this.next_play, this);
 
       var _this = this;
       this.view = cubeview;
+      this.model = cubeview.model;
       this.view.$container.insertAdjacentHTML("beforeend", '<div class="movtext">' + this.turnlist.join(' ') + '</div><div class="movbuttons"><a class="first" href="#">|◀</a><a class="previous" href="#">◀|</a><a class="previous-play" href="#">◀</a><a class="stop" href="#">◼</a><a class="next-play" href="#">▶</a><a class="next" href="#">|▶</a><a class="last" href="#">▶|</a></div>');
       this.view.$container.querySelector('.next-play').addEventListener('click', function() {
         return _this.next_play();
       this.view.$container.querySelector('.stop').addEventListener('click', function() {
         return _this.stop();
       });
+      this.view.$container.querySelector('.last').addEventListener('click', function() {
+        return _this.last();
+      });
     }
 
     CubeController.prototype.end_callback = function() {
           this.mode = 'stop';
           return this.next_play();
         } else {
-          console.log('end');
           this.mode = 'stop';
           return this.current = -1;
         }
       });
     };
 
+    CubeController.prototype.last = function() {
+      var _this = this;
+      return window.setTimeout(function() {
+        var remaining_turnlist;
+        if (_this.mode === 'stop') {
+          if (_this.current === -1) {
+            _this.current = 0;
+          }
+          remaining_turnlist = _this.turnlist.slice(_this.current, (_this.turnlist.length - 1) + 1 || 9e9);
+          _this.view.straightturn(remaining_turnlist.join(''));
+          return _this.current = _this.turnlist.length;
+        }
+      });
+    };
+
     return CubeController;
 
   })();