<commit_before>class window.TileView extends Backbone.View

  WIDTH: 73,
  HEIGHT: 67,

  el: no
  template: _.template("<div class=\"tile tile_<%= type %>\"><%= label %></div>")
  events:
    'touchstart' : 'dragTileStart'
    'touchmove'  : 'dragTileMove'
    'touchend'   : 'dragTileEnd'

  initialize: ->
    @listenTo @model, 'change', @render
    @listenTo @model, 'remove', @remove
    @model.view = @

  render: =>
    tileData = @model.toJSON()
    @$el.html @template(tileData)

    left = (tileData.position % game.board.getSize()) * @WIDTH
    top = (Math.ceil((tileData.position + 1) / game.board.getSize()) - 1) * @HEIGHT

    @$el
      .css
        'z-index': tileData.position
      .animate
        translate3d: "#{left}px, #{top}px, 0"
      ,
        duration: 150
        easing: "ease-out"

    @

  remove: ->
    @$el.remove()

  play: ->
    return if not @tilesToPlay = @getTilesToPlay() if not @tilesToPlay

    # Swtich each tile positions
    for i in [@tilesToPlay.length-1...0]
      tile1 = @tilesToPlay[i]
      tile2 = @tilesToPlay[i-1]
      @tilesToPlay[i] = tile2
      @tilesToPlay[i-1] = tile1
      game.board.switchTiles tile1, tile2

    game.set('moves', game.get('moves') + 1)

  getTilesToPlay: ->
    @positions = @model.getRelativePositioning()
    # Check if the clicked tile is on same column or row with empty tile
    if @positions.delta % @positions.boardSize is 0 # Empty tile and our tile are on a same column
      (game.board.getTileWithPosition pos for pos in [@positions.tilePos..@positions.emptyPos] when (pos - @positions.emptyPos) % @positions.boardSize is 0)
    else if (@positions.delta < @positions.boardSize) and parseInt(@positions.tilePos / @positions.boardSize) is parseInt(@positions.emptyPos / @positions.boardSize) # or they are on the same row
      (game.board.getTileWithPosition pos for pos in [@positions.tilePos..@positions.emptyPos]) if @positions.delta < @positions.boardSize

  dragTileStart: (e) ->
    return if not @tilesToPlay = @getTilesToPlay()

    @touch =
      x1: e.touches[0].pageX
      y1: e.touches[0].pageY
    @horizontal = (@positions.delta < @positions.boardSize)<commit_msg>Added tile destroy animation<commit_after>class window.TileView extends Backbone.View

  WIDTH: 73,
  HEIGHT: 67,

  el: no
  template: _.template("<div class=\"tile tile_<%= type %>\"><%= label %></div>")
  events:
    'touchstart' : 'dragTileStart'
    'touchmove'  : 'dragTileMove'
    'touchend'   : 'dragTileEnd'

  initialize: ->
    @listenTo @model, 'change', @render
    @listenTo @model, 'remove', @remove
    @model.view = @

  render: =>
    tileData = @model.toJSON()
    @$el.html @template(tileData)

    @left = (tileData.position % game.board.getSize()) * @WIDTH
    @top = (Math.ceil((tileData.position + 1) / game.board.getSize()) - 1) * @HEIGHT

    @$el
      .css
        'z-index': tileData.position
      .animate
        translate3d: "#{@left}px, #{@top}px, 0"
      ,
        duration: 150
        easing: "ease-out"

    @

  remove: ->
    @$el.animate
      translate3d: "#{@left}px, #{@top + 150}px, 0"
      opacity: 0
    ,
      complete: -> @remove()

  play: ->
    return if not @tilesToPlay = @getTilesToPlay() if not @tilesToPlay

    # Swtich each tile positions
    for i in [@tilesToPlay.length-1...0]
      tile1 = @tilesToPlay[i]
      tile2 = @tilesToPlay[i-1]
      @tilesToPlay[i] = tile2
      @tilesToPlay[i-1] = tile1
      game.board.switchTiles tile1, tile2

    game.set('moves', game.get('moves') + 1)

  getTilesToPlay: ->
    @positions = @model.getRelativePositioning()
    # Check if the clicked tile is on same column or row with empty tile
    if @positions.delta % @positions.boardSize is 0 # Empty tile and our tile are on a same column
      (game.board.getTileWithPosition pos for pos in [@positions.tilePos..@positions.emptyPos] when (pos - @positions.emptyPos) % @positions.boardSize is 0)
    else if (@positions.delta < @positions.boardSize) and parseInt(@positions.tilePos / @positions.boardSize) is parseInt(@positions.emptyPos / @positions.boardSize) # or they are on the same row
      (game.board.getTileWithPosition pos for pos in [@positions.tilePos..@positions.emptyPos]) if @positions.delta < @positions.boardSize

  dragTileStart: (e) ->
    return if not @tilesToPlay = @getTilesToPlay()

    @touch =
      x1: e.touches[0].pageX
      y1: e.touches[0].pageY
    @horizontal = (@positions.delta < @positions.boardSize)
{'fraction_non_alphanumeric': 0.14311270125223613, 'fraction_numerical': 0.013864042933810376, 'mean_word_length': 3.018867924528302, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305054', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1500, 'n_words': 371}