<commit_before>/**
 * The rendering class is responsible for drawing everything at the canvas.
 * It works using a buffer of sprites, so you can use it alone, adding sprites to it.
 * Sprites are arranged into layers, so to speed up the rendering process.
 * You can have as much layers as you wish, although remember that, the more layers you have, the slower the rendering will be.
 * Animations are also handled by the class.
 *
 * @class Render
*/
(function(J) {
  'use strict';

  // TODO: find a better way to reference renderer instance.
  // What will happen when we have two canvas rendering at the same time? (like a mini-map?)
  var renderer = null;

  /**
   * Initializes the renderer.
   *
   * @method constructor
   * @option [context] {Object} 2d canvas context to be used on the rendering.
   */
  var Render = function(options) {
    renderer = this;
    this.context = options.canvas;
    this.context.imageSmoothingEnabled = false;
    this.context.mozImageSmoothingEnabled = false;
    this.context.oImageSmoothingEnabled = false;
    this.context.webkitImageSmoothingEnabled = false;
    this.spriteBuffer = {};
    this.onEnterFrame();
  };

  /**
   * Adds a sprite to the rendering buffer.
   *
   * @method AddToBuffer
   * @param sprite {Object} The sprite to be added.
   * @param sprite.asset {Object} An Image object containing the sprite.
   * @param sprite.x {Number} The horizontal position.
   * @param sprite.y {Number} The vertical position.
   * @param [layer] {Number} The layer where the sprite will be rendered. If none is specified, then the top layer is used.
   */
  Render.prototype.addToBuffer = function(sprite, layer){
    layer = typeof layer == 'undefined' ? this.spriteBuffer.length - 1 : layer;
    var l = this.spriteBuffer[layer];

    if (typeof this.spriteBuffer[layer] == 'undefined') {
      this.spriteBuffer[layer] = [];
    }

    this.spriteBuffer[layer].push(sprite);
  };

  Render.prototype.removeFromBuffer = function() {
    // TODO
  };

  /**
   * Clears the entire screen.
   *
   * @method clear
   */
  Render.prototype.clear = function () {
    this.context.clearRect(0, 0, 320, 240);
  };

  /**
   * Renders everything in the buffer to the screen.
   *
   * @method render
   */
  Render.prototype.render = function () {
    this.clear();

    for (var layer in this.spriteBuffer) {
      for (var sprite in this.spriteBuffer[layer]) {
        // TODO: check for visibility/position and render only what is needed.
        this.renderSprite(this.spriteBuffer[layer][sprite]);
      }
    }
  };

  /**
   * Renders a single sprite.
   *
   * @method renderSprite
   * @param sprite {Object} The sprite object.
   */
  Render.prototype.renderSprite = function (sprite) {
    this.context.drawImage(sprite.asset, sprite.x, sprite.y, sprite.asset.width, sprite.asset.height);
  };<commit_msg>Fixed clear() to use the canvas' width and height.<commit_after>/**
 * The rendering class is responsible for drawing everything at the canvas.
 * It works using a buffer of sprites, so you can use it alone, adding sprites to it.
 * Sprites are arranged into layers, so to speed up the rendering process.
 * You can have as much layers as you wish, although remember that, the more layers you have, the slower the rendering will be.
 * Animations are also handled by the class.
 *
 * @class Render
*/
(function(J) {
  'use strict';

  // TODO: find a better way to reference renderer instance.
  // What will happen when we have two canvas rendering at the same time? (like a mini-map?)
  var renderer = null;

  /**
   * Initializes the renderer.
   *
   * @method constructor
   * @option [context] {Object} 2d canvas context to be used on the rendering.
   */
  var Render = function(options) {
    renderer = this;
    this.context = options.canvas;
    this.context.imageSmoothingEnabled = false;
    this.context.mozImageSmoothingEnabled = false;
    this.context.oImageSmoothingEnabled = false;
    this.context.webkitImageSmoothingEnabled = false;
    this.spriteBuffer = {};
    this.onEnterFrame();
  };

  /**
   * Adds a sprite to the rendering buffer.
   *
   * @method AddToBuffer
   * @param sprite {Object} The sprite to be added.
   * @param sprite.asset {Object} An Image object containing the sprite.
   * @param sprite.x {Number} The horizontal position.
   * @param sprite.y {Number} The vertical position.
   * @param [layer] {Number} The layer where the sprite will be rendered. If none is specified, then the top layer is used.
   */
  Render.prototype.addToBuffer = function(sprite, layer){
    layer = typeof layer == 'undefined' ? this.spriteBuffer.length - 1 : layer;
    var l = this.spriteBuffer[layer];

    if (typeof this.spriteBuffer[layer] == 'undefined') {
      this.spriteBuffer[layer] = [];
    }

    this.spriteBuffer[layer].push(sprite);
  };

  Render.prototype.removeFromBuffer = function() {
    // TODO
  };

  /**
   * Clears the entire screen.
   *
   * @method clear
   */
  Render.prototype.clear = function () {
    this.context.clearRect(0, 0, this.context.canvas.width, this.context.canvas.height);
  };

  /**
   * Renders everything in the buffer to the screen.
   *
   * @method render
   */
  Render.prototype.render = function () {
    this.clear();

    for (var layer in this.spriteBuffer) {
      for (var sprite in this.spriteBuffer[layer]) {
        // TODO: check for visibility/position and render only what is needed.
        this.renderSprite(this.spriteBuffer[layer][sprite]);
      }
    }
  };

  /**
   * Renders a single sprite.
   *
   * @method renderSprite
   * @param sprite {Object} The sprite object.
   */
  Render.prototype.renderSprite = function (sprite) {
    this.context.drawImage(sprite.asset, sprite.x, sprite.y, sprite.asset.width, sprite.asset.height);
  };
{'fraction_non_alphanumeric': 0.11049913941480206, 'fraction_numerical': 0.0024096385542168677, 'mean_word_length': 3.0298196948682388, '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': '3173066', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1708, 'n_words': 578}