<commit_before>import { util, drag } from 'chessground-mobile';
import gameApi from '../../../lichess/game';

export default function(ctrl, e) {
  if (e.button !== undefined && e.button !== 0) return; // only touch or left click
  if (ctrl.replaying() || !gameApi.isPlayerPlaying(ctrl.data)) return;
  const cgData = ctrl.chessground.data;
  const role = e.target.getAttribute('data-role'),
    color = e.target.getAttribute('data-color'),
    number = e.target.getAttribute('data-nb');
  if (!role || !color || number === '0') return;
  e.stopPropagation();
  e.preventDefault();
  var key;
  for (var i in util.allKeys) {
    if (!cgData.pieces[util.allKeys[i]]) {
      key = util.allKeys[i];
      break;
    }
  }
  if (!key) return;<commit_msg>Prevent drag of opponent color<commit_after>import { util, drag } from 'chessground-mobile';
import gameApi from '../../../lichess/game';

function isDraggable(data, color) {
  return data.movable.color === color && (
    data.turnColor === color || data.predroppable.enabled
  );
}

export default function(ctrl, e) {
  if (e.button !== undefined && e.button !== 0) return; // only touch or left click
  if (ctrl.replaying() || !gameApi.isPlayerPlaying(ctrl.data)) return;
  const cgData = ctrl.chessground.data;
  const role = e.target.getAttribute('data-role'),
    color = e.target.getAttribute('data-color'),
    number = e.target.getAttribute('data-nb');
  if (!role || !color || number === '0') return;
  if (!isDraggable(ctrl.chessground.data, color)) return;
  e.stopPropagation();
  e.preventDefault();
  var key;
  for (var i in util.allKeys) {
    if (!cgData.pieces[util.allKeys[i]]) {
      key = util.allKeys[i];
      break;
    }
  }
  if (!key) return;
{'fraction_non_alphanumeric': 0.1755813953488372, 'fraction_numerical': 0.002325581395348837, 'mean_word_length': 3.577127659574468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '3214006', 'n_tokens_mistral': 573, 'n_tokens_neox': 577, 'n_words': 138}