<commit_before>/**
 * Handles mouse/keyboard input and transforms camera position accordingly
 */
var FlyControls = require('three.fly');
var eventify = require('ngraph.events');
var appEvents = require('../events');

module.exports = createUserInputController;

function createUserInputController(camera, domElement) {
  var clock = new THREE.Clock();

  var controls = new FlyControls(camera, domElement);
  domElement.tabIndex = 0;
  domElement.focus();
  controls.movementSpeed = 800;
  controls.rollSpeed = 1;
  controls.autoForward = false;
  controls.dragToLook = true;

  // we want to listen on document level, since focus can be anywhere
  window.document.addEventListener('keydown', keydown, false);

  var touchControls;
  var controller = {
    update: update,
    pause: pause,
    resume: resume
  };

  eventify(controller);

  if (window.orientation !== undefined) {
    touchControls = require('three.orientation')(camera);
    controller.update = updateTochToo;
  }

  return controller;

  function update() {
    controls.update(clock.getDelta());
  }

  function updateTochToo() {
    controls.update(clock.getDelta());
    touchControls.update();
  }

  function keydown(e) {
    if (e.which === 27) { // ESC
      appEvents.fire('focusScene');
    }

    if (shouldSkipKeyboardEvent(e)) return;

    if (e.which === 32) { // spacebar
      changeSteeringMode();
    } else if (e.which === 76) { // l
      controller.fire('toggleLinks');
    } else if (e.which === 191) { // `/` key
      // need to do this in next iteration to prevent search field from entering
      // actual character
      setTimeout(function() {
        appEvents.fire('focusSearch');
      }, 0);
    }
  }

  function shouldSkipKeyboardEvent(e) {
    var target = e.target || e.srcElement;
    var name = target && target.tagName;
    return name && name.match(/input/i); // We should ignore input boxes
  }

  function changeSteeringMode() {
    controls.dragToLook = !controls.dragToLook;

    controls.moveState.yawLeft = 0;
    controls.moveState.pitchDown = 0;
    controls.updateRotationVector();
    controller.fire('steeringModeChanged', controls.dragToLook);
  }

  function pause() {
    if (touchControls) touchControls.disconnect();
  }

  function resume () {
    if (touchControls) touchControls.connect();
  }
}<commit_msg>Renamed controls to wasdControls<commit_after>/**
 * Handles mouse/keyboard input and transforms camera position accordingly
 */
var FlyControls = require('three.fly');
var eventify = require('ngraph.events');
var appEvents = require('../events');

module.exports = createUserInputController;

function createUserInputController(camera, domElement) {
  var clock = new THREE.Clock();

  var wasdControls = new FlyControls(camera, domElement);
  domElement.tabIndex = 0;
  domElement.focus();
  wasdControls.movementSpeed = 800;
  wasdControls.rollSpeed = 1;
  wasdControls.autoForward = false;
  wasdControls.dragToLook = true;

  // we want to listen on document level, since focus can be anywhere
  window.document.addEventListener('keydown', keydown, false);

  var touchControls;
  var controller = {
    update: update,
    pause: pause,
    resume: resume
  };

  eventify(controller);

  if (window.orientation !== undefined) {
    touchControls = require('three.orientation')(camera);
    controller.update = updateTochToo;
  }

  return controller;

  function update() {
    wasdControls.update(clock.getDelta());
  }

  function updateTochToo() {
    wasdControls.update(clock.getDelta());
    touchControls.update();
  }

  function keydown(e) {
    if (e.which === 27) { // ESC
      appEvents.fire('focusScene');
    }

    if (shouldSkipKeyboardEvent(e)) return;

    if (e.which === 32) { // spacebar
      changeSteeringMode();
    } else if (e.which === 76) { // l
      controller.fire('toggleLinks');
    } else if (e.which === 191) { // `/` key
      // need to do this in next iteration to prevent search field from entering
      // actual character
      setTimeout(function() {
        appEvents.fire('focusSearch');
      }, 0);
    }
  }

  function shouldSkipKeyboardEvent(e) {
    var target = e.target || e.srcElement;
    var name = target && target.tagName;
    return name && name.match(/input/i); // We should ignore input boxes
  }

  function changeSteeringMode() {
    wasdControls.dragToLook = !wasdControls.dragToLook;

    wasdControls.moveState.yawLeft = 0;
    wasdControls.moveState.pitchDown = 0;
    wasdControls.updateRotationVector();
    controller.fire('steeringModeChanged', wasdControls.dragToLook);
  }

  function pause() {
    if (touchControls) touchControls.disconnect();
  }

  function resume () {
    if (touchControls) touchControls.connect();
  }
}
{'fraction_non_alphanumeric': 0.1268169370128502, 'fraction_numerical': 0.007162418369496524, 'mean_word_length': 3.4208566108007448, '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': '3078876', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1375, 'n_words': 339}