<commit_before>(function() {
	'use strict';
	var DIR_FORWARD = 1;
	var DIR_BACKWARD = 2;
	var DIR_LEFT = 3;
	var DIR_RIGHT = 4;
	var DIR_STOP = 0;
	var socket = null;
	var keyIsDown = false;

	var _movementState = DIR_STOP;


  var hasGP = false;
  var repGP;

  function canGame() {
    return "getGamepads" in navigator;
  }

  function reportOnGamepad() {
    var gp = navigator.getGamepads()[0];
    var html = "";
    html += "id: "+gp.id+"<br/>";

    for(var i=0;i<gp.buttons.length;i++) {
      html+= "Button "+(i+1)+": ";
      if(gp.buttons[i].pressed) html+= " pressed";
      html+= "<br/>";
    }

    for(var i=0;i<gp.axes.length; i+=2) {
      html+= "Stick "+(Math.ceil(i/2)+1)+": "+gp.axes[i]+","+gp.axes[i+1]+"<br/>";
    }

    if(gp.axes[1] == -1) {
    	sendForward()
		} else if(gp.axes[1] == 1) {
      sendBackward()
		}

    if(gp.axes[0] == -1) {
      sendLeft()
    }else if(gp.axes[0] == 1) {
      sendRight()
    }

    if(gp.axes[0] != -1 && gp.axes[0] != 1 && gp.axes[1] != -1 && gp.axes[1] != 1 ) {
      if (_movementState != DIR_STOP) {
    	  sendStop();
      }
		}

    $("#gamepadDisplay").html(html);
  }


  function init() {
    var savedIp = localStorage.getItem('ip');
    document.getElementById('serverip').value = savedIp;
    document.getElementById('connect').addEventListener('click', function() {
      localStorage.setItem('ip', document.getElementById('serverip').value);
      socket = io.connect('http://' + document.getElementById('serverip').value);
      initSocketEvents(socket);

      initKeyEvents();

      initGamepad();
    });
  }

	function initKeyEvents() {
    document.addEventListener('keydown', (event) => {
      // Don't repeat
      if (keyIsDown) {
        return;
      }
      const keyName = event.key;

      keyIsDown = true;
      console.log('KEYDOWN');
      switch (keyName) {
        case 'z':
        case 'w':
          sendForward();
          break;
        case 's':
          sendBackward();
          break;
        case 'q':
        case 'a':
          sendLeft();
          break;
        case 'd':
          sendRight();
          break;
        default:
          sendStop();
          break;
      }
    }, false);

    document.addEventListener('keyup', (event) => {
      // Don't repeat
      if (!keyIsDown) {
        return;
      }
      const keyName = event.key;

      keyIsDown = false;
      console.log('KEYUP');
      switch (keyName) {
        default:
          sendStop();
          break;
      }
    }, false);

    $('#forward').bind("touchstart", ()=> {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendForward();

    }, false);

    $('#backward').bind("touchstart", ()=> {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendBackward();

    }, false);

    $('#left').bind("touchstart", ()=> {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendLeft();

    }, false);

    $('#right').bind("touchstart", ()=> {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;


      sendRight();

    }, false);

    $('#right, #backward, #left, #forward').bind('touchend', (event) => {
      // Don't repeat
      if (!keyIsDown) {
        return;
      }

      keyIsDown = false;


      sendStop();
<commit_msg>Normal function ( mobile browser )<commit_after>(function() {
	'use strict';
	var DIR_FORWARD = 1;
	var DIR_BACKWARD = 2;
	var DIR_LEFT = 3;
	var DIR_RIGHT = 4;
	var DIR_STOP = 0;
	var socket = null;
	var keyIsDown = false;

	var _movementState = DIR_STOP;


  var hasGP = false;
  var repGP;

  function canGame() {
    return "getGamepads" in navigator;
  }

  function reportOnGamepad() {
    var gp = navigator.getGamepads()[0];
    var html = "";
    html += "id: "+gp.id+"<br/>";

    for(var i=0;i<gp.buttons.length;i++) {
      html+= "Button "+(i+1)+": ";
      if(gp.buttons[i].pressed) html+= " pressed";
      html+= "<br/>";
    }

    for(var i=0;i<gp.axes.length; i+=2) {
      html+= "Stick "+(Math.ceil(i/2)+1)+": "+gp.axes[i]+","+gp.axes[i+1]+"<br/>";
    }

    if(gp.axes[1] == -1) {
    	sendForward()
		} else if(gp.axes[1] == 1) {
      sendBackward()
		}

    if(gp.axes[0] == -1) {
      sendLeft()
    }else if(gp.axes[0] == 1) {
      sendRight()
    }

    if(gp.axes[0] != -1 && gp.axes[0] != 1 && gp.axes[1] != -1 && gp.axes[1] != 1 ) {
      if (_movementState != DIR_STOP) {
    	  sendStop();
      }
		}

    $("#gamepadDisplay").html(html);
  }


  function init() {
    var savedIp = localStorage.getItem('ip');
    document.getElementById('serverip').value = savedIp;
    document.getElementById('connect').addEventListener('click', function() {
      localStorage.setItem('ip', document.getElementById('serverip').value);
      socket = io.connect('http://' + document.getElementById('serverip').value);
      initSocketEvents(socket);

      initKeyEvents();

      initGamepad();
    });
  }

	function initKeyEvents() {
    document.addEventListener('keydown', (event) => {
      // Don't repeat
      if (keyIsDown) {
        return;
      }
      const keyName = event.key;

      keyIsDown = true;
      console.log('KEYDOWN');
      switch (keyName) {
        case 'z':
        case 'w':
          sendForward();
          break;
        case 's':
          sendBackward();
          break;
        case 'q':
        case 'a':
          sendLeft();
          break;
        case 'd':
          sendRight();
          break;
        default:
          sendStop();
          break;
      }
    }, false);

    document.addEventListener('keyup', (event) => {
      // Don't repeat
      if (!keyIsDown) {
        return;
      }
      const keyName = event.key;

      keyIsDown = false;
      console.log('KEYUP');
      switch (keyName) {
        default:
          sendStop();
          break;
      }
    }, false);

    $('#forward').bind("touchstart", function(event) {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendForward();

    }, false);

    $('#backward').bind("touchstart", function(event) {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendBackward();

    }, false);

    $('#left').bind("touchstart", function(event) {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;
      console.log('KEYDOWN');

      sendLeft();

    }, false);

    $('#right').bind("touchstart", function(event) {
      // Don't repeat
      if (keyIsDown) {
        return;
      }

      keyIsDown = true;


      sendRight();

    }, false);

    $('#right, #backward, #left, #forward').bind('touchend', function(event) {
      // Don't repeat
      if (!keyIsDown) {
        return;
      }

      keyIsDown = false;

      sendStop();

{'fraction_non_alphanumeric': 0.17765284609978918, 'fraction_numerical': 0.008151791988756148, 'mean_word_length': 1.9576059850374066, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 18, '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': '3339377', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2365, 'n_words': 458}