<commit_before>/*
p5.play
by <NAME>/molleindustria, 2015
http://molleindustria.org/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

(function (root, factory) {
if (typeof define === 'function' && define.amd)
define('p5.play', ['p5'], function (p5) { (factory(p5));});
else if (typeof exports === 'object')
factory(require('../p5'));
else
factory(root['p5']);
}
(this, function (p5) {
/**
 * p5.play is a library for p5.js to facilitate the creation of games and gamelike
 * projects. 
 *
 * It provides a flexible Sprite class to manage visual objects in 2D space
 * and features such as animation support, basic collision detection 
 * and resolution, mouse and keyboard interactions, and a virtual camera.
 *  
 * p5.play is not a box2D-derived physics engine, it doesn't use events, and it's 
 * designed to be understood and possibly modified by intermediate programmers.
 *
 * See the examples folder for more info on how to use this library.
 * 
 * @module p5.play
 * @submodule p5.play
 * @for p5.play
 * @main
 */

// =============================================================================
//                         p5 additions
// =============================================================================

/** 
* A Group containing all the sprites in the sketch.
*
* @property allSprites
* @type {Group}
*/
p5.prototype.allSprites = new Group();

/**
   * A Sprite is the main building block of p5.play:
   * an element able to store images or animations with a set of
   * properties such as position and visibility.
   * A Sprite can have a collider that defines the active area to detect
   * collisions or overlappings with other sprites and mouse interactions.
   * 
   * @method createSprite
   * @param {Number} x Initial x coordinate
   * @param {Number} y Initial y coordinate
   * @param {Number} width Width of the placeholder rectangle and of the
   *                       collider until an image or new collider are set
   * @param {Number} height Height of the placeholder rectangle and of the
   *                       collider until an image or new collider are set
   * @return {Object} The new sprite instance
   */

p5.prototype.createSprite = function(x, y, width, height) {
  var s = new Sprite(x, y, width, height);
  s.depth = allSprites.maxDepth()+1;
  allSprites.add(s);
  return s;
}


/**
   * Removes a Sprite from the sketch. 
   * The removed Sprite won't be drawn or updated anymore.
   * Equivalent to Sprite.remove()
   *
   * @method removeSprite
   * @param {Object} sprite Sprite to be removed
*/
p5.prototype.removeSprite = function(sprite) {
  sprite.remove();
}

/** 
* Updates all the sprites in the sketch (position, animation...)
* it's called automatically at every draw().
* It can be paused by passing a parameter true or false;
* Note: it does not render the sprites.
*
* @method updateSprites
* @param {Boolean} updating false to pause the update, true to resume 
*/
p5.prototype.updateSprites = function(upd) {
  
  if(upd==false)
    spriteUpdate = false;
  if(upd==true)
    spriteUpdate = true;
  
  if(spriteUpdate)
  for(var i = 0; i<allSprites.size(); i++)
  {
    allSprites.get(i).update();
  }
}

p5.prototype.spriteUpdate = true;

/** 
* Returns all the sprites in the sketch as an array
*
* @method getSprites
* @return {Array} Array of Sprites
*/
p5.prototype.getSprites = function() {

  //draw everything
  if(arguments.length===0)
  {
    return allSprites.toArray();
  }
  else
  {
    var arr = [];
    //for every tag
    for(var j=0; j<arguments.length; j++)
    {
      for(var i = 0; i<allSprites.size(); i++)
      {
        if(allSprites.get(i).isTagged(arguments[j]))
          arr.push(allSprites.get(i));
      }
    }

    return arr;
  }

}

/** 
* Displays a Group of sprites.
* If no parameter is specified, draws all sprites in the
* sketch.
* The drawing order is determined by the Sprite property "depth"
*
* @methid drawSprites
* @param {Group} [group] Group of Sprites to be displayed
*/
p5.prototype.drawSprites = function(group) {

  //draw everything
  if(arguments.length===0)
  {
    //sort by depth
    allSprites.sort(function(a,b) { 
      return a.depth - b.depth;
    });

    for(var i = 0; i<allSprites.size(); i++)
    {
      allSprites.get(i).display();
    }
  }
  else if(arguments.length===1)
  {
    if(arguments[0] instanceof Array == false)
      throw("Error: with drawSprites you can only draw all sprites or a group");
    else
    {
      arguments[0].draw();
    }

  }
}

/** 
* Displays a Sprite.
* To be typically used in the main draw function.
* 
* @method drawSprite
* @param {Sprite} sprite Sprite to be displayed
*/
p5.prototype.drawSprite = function(sprite) {
  sprite.display();
}

/** 
* Loads an animation.
* To be typically used in the preload() function of the sketch.
* 
* @method loadAnimation
* @param {Sprite} sprite Sprite to be displayed
*/
p5.prototype.loadAnimation = function() {
  return construct(Animation, arguments);
}

/** 
* Displays an animation.
* 
* @method animation
* @param {Animation} anim Animation to be displayed
* @param {Number} x X coordinate<commit_msg>safety check on draw sprite<commit_after>/*
p5.play
by <NAME>/molleindustria, 2015
http://molleindustria.org/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

(function (root, factory) {
if (typeof define === 'function' && define.amd)
define('p5.play', ['p5'], function (p5) { (factory(p5));});
else if (typeof exports === 'object')
factory(require('../p5'));
else
factory(root['p5']);
}
(this, function (p5) {
/**
 * p5.play is a library for p5.js to facilitate the creation of games and gamelike
 * projects. 
 *
 * It provides a flexible Sprite class to manage visual objects in 2D space
 * and features such as animation support, basic collision detection 
 * and resolution, mouse and keyboard interactions, and a virtual camera.
 *  
 * p5.play is not a box2D-derived physics engine, it doesn't use events, and it's 
 * designed to be understood and possibly modified by intermediate programmers.
 *
 * See the examples folder for more info on how to use this library.
 * 
 * @module p5.play
 * @submodule p5.play
 * @for p5.play
 * @main
 */

// =============================================================================
//                         p5 additions
// =============================================================================

/** 
* A Group containing all the sprites in the sketch.
*
* @property allSprites
* @type {Group}
*/
p5.prototype.allSprites = new Group();

/**
   * A Sprite is the main building block of p5.play:
   * an element able to store images or animations with a set of
   * properties such as position and visibility.
   * A Sprite can have a collider that defines the active area to detect
   * collisions or overlappings with other sprites and mouse interactions.
   * 
   * @method createSprite
   * @param {Number} x Initial x coordinate
   * @param {Number} y Initial y coordinate
   * @param {Number} width Width of the placeholder rectangle and of the
   *                       collider until an image or new collider are set
   * @param {Number} height Height of the placeholder rectangle and of the
   *                       collider until an image or new collider are set
   * @return {Object} The new sprite instance
   */

p5.prototype.createSprite = function(x, y, width, height) {
  var s = new Sprite(x, y, width, height);
  s.depth = allSprites.maxDepth()+1;
  allSprites.add(s);
  return s;
}


/**
   * Removes a Sprite from the sketch. 
   * The removed Sprite won't be drawn or updated anymore.
   * Equivalent to Sprite.remove()
   *
   * @method removeSprite
   * @param {Object} sprite Sprite to be removed
*/
p5.prototype.removeSprite = function(sprite) {
  sprite.remove();
}

/** 
* Updates all the sprites in the sketch (position, animation...)
* it's called automatically at every draw().
* It can be paused by passing a parameter true or false;
* Note: it does not render the sprites.
*
* @method updateSprites
* @param {Boolean} updating false to pause the update, true to resume 
*/
p5.prototype.updateSprites = function(upd) {
  
  if(upd==false)
    spriteUpdate = false;
  if(upd==true)
    spriteUpdate = true;
  
  if(spriteUpdate)
  for(var i = 0; i<allSprites.size(); i++)
  {
    allSprites.get(i).update();
  }
}

p5.prototype.spriteUpdate = true;

/** 
* Returns all the sprites in the sketch as an array
*
* @method getSprites
* @return {Array} Array of Sprites
*/
p5.prototype.getSprites = function() {

  //draw everything
  if(arguments.length===0)
  {
    return allSprites.toArray();
  }
  else
  {
    var arr = [];
    //for every tag
    for(var j=0; j<arguments.length; j++)
    {
      for(var i = 0; i<allSprites.size(); i++)
      {
        if(allSprites.get(i).isTagged(arguments[j]))
          arr.push(allSprites.get(i));
      }
    }

    return arr;
  }

}

/** 
* Displays a Group of sprites.
* If no parameter is specified, draws all sprites in the
* sketch.
* The drawing order is determined by the Sprite property "depth"
*
* @methid drawSprites
* @param {Group} [group] Group of Sprites to be displayed
*/
p5.prototype.drawSprites = function(group) {

  //draw everything
  if(arguments.length===0)
  {
    //sort by depth
    allSprites.sort(function(a,b) { 
      return a.depth - b.depth;
    });

    for(var i = 0; i<allSprites.size(); i++)
    {
      allSprites.get(i).display();
    }
  }
  else if(arguments.length===1)
  {
    if(arguments[0] instanceof Array == false)
      throw("Error: with drawSprites you can only draw all sprites or a group");
    else
    {
      arguments[0].draw();
    }

  }
}

/** 
* Displays a Sprite.
* To be typically used in the main draw function.
* 
* @method drawSprite
* @param {Sprite} sprite Sprite to be displayed
*/
p5.prototype.drawSprite = function(sprite) {
  if(sprite!=null)
  sprite.display();
}

/** 
* Loads an animation.
* To be typically used in the preload() function of the sketch.
* 
* @method loadAnimation
* @param {Sprite} sprite Sprite to be displayed
*/
p5.prototype.loadAnimation = function() {
  return construct(Animation, arguments);
}

/** 
* Displays an animation.
* 
* @method animation
* @param {Animation} anim Animation to be displayed
* @param {Number} x X coordinate
{'fraction_non_alphanumeric': 0.1338934103439223, 'fraction_numerical': 0.0073510107639800475, 'mean_word_length': 3.2962406015037593, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6667637', 'n_tokens_mistral': 3559, 'n_tokens_neox': 3398, 'n_words': 1290}