<commit_before>'use strict';

var mode = angular.module('sos.modes');
mode.factory('modeSkeletalFun', function($log, skeletalService, protonEmitterService) {

  var mode = new Mode("modeSkeletalFun", "Skeletal Fun!");
  mode.rendererType = "PIXI";

  mode.TRACKINGID_PREFIX = "skel-";

  mode.trackedSkeletons = {};
  mode.trackedEmitters = {};
  mode.spineBoy = {};
  mode.rope = null;
  mode.ropePoints = [];
  mode.container = null;
  mode.socket = null;

  mode.kinect = {
    renderer: null,
    rendererID: null
  };

  mode.debug = {
    id: mode.id,
    title: mode.title,
    skeletonsTracked: 0,
    bodiesOnScreen: 0,
    bodiesOffScreen: 0,
    containerChildren: 0
  };

  mode.init = function(parentScope) {

    console.log("initializing kinect overlay");
    mode.setParentScope(parentScope);

    mode.kinect.renderer = PIXI.autoDetectRenderer(mode.parentScope.canvasDim.width, mode.parentScope.canvasDim.height, {antialias: true, transparent: true});
    var overlayDiv = document.getElementById("kinect-overlay");
    overlayDiv.appendChild(mode.kinect.renderer.view);

    mode.container = new PIXI.Container();

    // initialize socket w/ socket.io skeletal data
    mode.initSocket();
    mode.parentScope.$on('kinectBodiesUpdate', function(events, bodies) {
      mode.trackedSkeletons = bodies;
    });

    mode.parentScope.$on('kinectNewSkeleton', function(events, skel) {

      skel.init(mode.container, Color.random());
      // create emitter
      // var proton = protonEmitterService.createProton3(mode.kinect.renderer.view);
      // skel.proton = proton;
      // var renderer = new Proton.Renderer('other', proton, mode.kinect.renderer.view);
      // renderer.onProtonUpdate = function() {
      //   // no-op
      // };
      // renderer.onParticleCreated = function(particle) {
      //   var particleSprite = new PIXI.Sprite(particle.target);
      //   particle.sprite = particleSprite;
      //   //mode.container.addChild(particle.sprite);
      // };
      // renderer.start();
    });

    // assign renderid from animation frame (for future deinit call)
    mode.renderID = requestAnimationFrame(mode.update);
  };

  mode.initSocket = function() {

    mode.socket = skeletalService.createSocket();

    mode.socket.on('disconnect', function(err) {
      $log.warn('disconnect error', err);
      // set bodies array to empty.
      mode.trackedSkeletons.length = 0;
    });

    mode.drawHitBoxes();

    //mode.drawTestAngledPolygon(new PIXI.Point(10,10), new PIXI.Point(50,50), -10);
  };

  mode.drawTestAngledPolygon = function(p1, p2, degrees) {

    var ap = new PIXI.Graphics();
    mode.ap = ap;

    ap.lineStyle(2, 0xFFFFFF);
    ap.moveTo(p1.x, p1.y);
    ap.lineTo(p2.x, p2.y);
    mode.container.addChild(ap);
  };

  mode.drawTestAngledPolygon2 = function(p1, p2, degrees) {

    var ap = new PIXI.Graphics();
    ap.lineStyle(2, 0xFFFFFF);
    ap.beginFill(0xDEDEDE);
    ap.drawRect(10,10,10,50);

    ap.boundsPadding = 0;
    var texture = ap.generateTexture();

    mode.container.addChild(texture);
  };

  mode.drawSkeletons = function() {

    angular.forEach(mode.trackedSkeletons, function(skel, key) {

      if(skel.getActiveStatus()) {

	skel.drawToStage();

	// if(skel.proton) {
	//   skel.proton.update();
	// }

	// get hand pointer
	var hp = skel.getHandPointerPoint();
	// apply offset to correct x
	hp = new PIXI.Point(hp.x - 150, hp.y);
	if(mode.topHitBox.containsPoint(hp)) {
	  mode.parentScope.postDebugInfo("topHitBox active", "true");
	} else {
	  mode.parentScope.postDebugInfo("topHitBox active", "false");
	}

      } else {
	//console.log("removing self from container");
	skel.removeSelfFromContainer();
	delete mode.trackedSkeletons[key];
      }
    });
  };

  mode.drawHitBoxes = function() {

    // place hitbox at top center
    var width = mode.parentScope.canvasDim.width * 0.5;
    var height = 80;

    mode.topHitBox = new PIXI.Graphics();
    mode.topHitBox.lineStyle(2, 0xFFFFFF);
    mode.topHitBox.beginFill(0xFFFFFF);<commit_msg>Disable hit box for now.<commit_after>'use strict';

var mode = angular.module('sos.modes');
mode.factory('modeSkeletalFun', function($log, skeletalService, protonEmitterService) {

  var mode = new Mode("modeSkeletalFun", "Skeletal Fun!");
  mode.rendererType = "PIXI";

  mode.TRACKINGID_PREFIX = "skel-";

  mode.trackedSkeletons = {};
  mode.trackedEmitters = {};
  mode.spineBoy = {};
  mode.rope = null;
  mode.ropePoints = [];
  mode.container = null;
  mode.socket = null;

  mode.kinect = {
    renderer: null,
    rendererID: null
  };

  mode.debug = {
    id: mode.id,
    title: mode.title,
    skeletonsTracked: 0,
    bodiesOnScreen: 0,
    bodiesOffScreen: 0,
    containerChildren: 0
  };

  mode.init = function(parentScope) {

    console.log("initializing kinect overlay");
    mode.setParentScope(parentScope);

    mode.kinect.renderer = PIXI.autoDetectRenderer(mode.parentScope.canvasDim.width, mode.parentScope.canvasDim.height, {antialias: true, transparent: true});
    var overlayDiv = document.getElementById("kinect-overlay");
    overlayDiv.appendChild(mode.kinect.renderer.view);

    mode.container = new PIXI.Container();

    // initialize socket w/ socket.io skeletal data
    mode.initSocket();
    mode.parentScope.$on('kinectBodiesUpdate', function(events, bodies) {
      mode.trackedSkeletons = bodies;
    });

    mode.parentScope.$on('kinectNewSkeleton', function(events, skel) {

      skel.init(mode.container, Color.random());
      // create emitter
      // var proton = protonEmitterService.createProton3(mode.kinect.renderer.view);
      // skel.proton = proton;
      // var renderer = new Proton.Renderer('other', proton, mode.kinect.renderer.view);
      // renderer.onProtonUpdate = function() {
      //   // no-op
      // };
      // renderer.onParticleCreated = function(particle) {
      //   var particleSprite = new PIXI.Sprite(particle.target);
      //   particle.sprite = particleSprite;
      //   //mode.container.addChild(particle.sprite);
      // };
      // renderer.start();
    });

    // assign renderid from animation frame (for future deinit call)
    mode.renderID = requestAnimationFrame(mode.update);
  };

  mode.initSocket = function() {

    mode.socket = skeletalService.createSocket();

    mode.socket.on('disconnect', function(err) {
      $log.warn('disconnect error', err);
      // set bodies array to empty.
      mode.trackedSkeletons.length = 0;
    });

    //mode.drawHitBoxes();

    //mode.drawTestAngledPolygon(new PIXI.Point(10,10), new PIXI.Point(50,50), -10);
  };

  mode.drawTestAngledPolygon = function(p1, p2, degrees) {

    var ap = new PIXI.Graphics();
    mode.ap = ap;

    ap.lineStyle(2, 0xFFFFFF);
    ap.moveTo(p1.x, p1.y);
    ap.lineTo(p2.x, p2.y);
    mode.container.addChild(ap);
  };

  mode.drawTestAngledPolygon2 = function(p1, p2, degrees) {

    var ap = new PIXI.Graphics();
    ap.lineStyle(2, 0xFFFFFF);
    ap.beginFill(0xDEDEDE);
    ap.drawRect(10,10,10,50);

    ap.boundsPadding = 0;
    var texture = ap.generateTexture();

    mode.container.addChild(texture);
  };

  mode.drawSkeletons = function() {

    angular.forEach(mode.trackedSkeletons, function(skel, key) {

      if(skel.getActiveStatus()) {

	skel.drawToStage();

	// if(skel.proton) {
	//   skel.proton.update();
	// }

	// get hand pointer
	// var hp = skel.getHandPointerPoint();
	// apply offset to correct x
	// hp = new PIXI.Point(hp.x - 150, hp.y);
	// if(mode.topHitBox.containsPoint(hp)) {
	//   mode.parentScope.postDebugInfo("topHitBox active", "true");
	// } else {
	//   mode.parentScope.postDebugInfo("topHitBox active", "false");
	// }

      } else {
	//console.log("removing self from container");
	skel.removeSelfFromContainer();
	delete mode.trackedSkeletons[key];
      }
    });
  };

  mode.drawHitBoxes = function() {

    // place hitbox at top center
    var width = mode.parentScope.canvasDim.width * 0.5;
    var height = 80;

    mode.topHitBox = new PIXI.Graphics();
    mode.topHitBox.lineStyle(2, 0xFFFFFF);
    mode.topHitBox.beginFill(0xFFFFFF);
{'fraction_non_alphanumeric': 0.14826226275573084, 'fraction_numerical': 0.012077890066551638, 'mean_word_length': 3.1171993911719937, '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': '943502', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2749, 'n_words': 481}