<commit_before>/**
 * @namespace Lyria
 * Lyria namespace decleration
 */
;(function(window, document, Lyria, $, undefined) {
  'use strict';

  /**
   * The scene director is the manager for all scenes
   *  
   */
  Lyria.SceneDirector = (function() {
    
    function SceneDirector(container, parent) {
      
      if (container instanceof Lyria.Viewport) {
        this.viewport = container;
      } else {
        this.viewport = new Lyria.Viewport(container, parent);
      }
      
      this.sceneList = {};
      this.currentScene = null;
      this.onSceneChange = function(scene) {};
      
    }
    
    // Properties
    SceneDirector.prototype.sceneClassName = 'scene';
    
    // Methods
    SceneDirector.prototype.add = function(scene, options) {
      
      if (!(scene instanceof Lyria.Scene)) {
        if (Lyria.Scenes[scene]) {
          scene = Lyria.Scenes[scene];          
        } else {
          throw 'No valid scene found.';
        }        
      }
      
      scene.parent = this;
      this.sceneList[scene.name] = scene;
      
      if (this.viewport.$container) {
        if ($('#' + scene.name).length === 0) { 
          this.viewport.$container.prepend($(document.createElement('div'))
                       .attr('id', scene.name)
                       .attr('class', SceneDirector.prototype.sceneClassName));
                       
          if (scene.content) {
            $('#' + scene.name).html(scene.content);
          }
        }
      }
      
      return this;
    };
    
    SceneDirector.prototype.show = function(scene, options, callback) {
      
      if (this.onSceneChange) {
        this.onSceneChange(scene);
      }
      
      // More than one scene visible at the same time
      if ($('.' + SceneDirector.prototype.sceneClassName + ':visible')) {
        $('.' + SceneDirector.prototype.sceneClassName).hide();
      }

      if (this.currentScene) {
        if (this.currentScene.transition && this.currentScene.length) {
          $('#' + this.currentScene).hide(this.currentScene.transition.length, function() {
            $('.' + SceneDirector.prototype.sceneClassName).hide();
          });
        } else {
          $('.' + SceneDirector.prototype.sceneClassName).hide();
        }

        if (this.currentScene.onDeactivated) {
          this.currentScene.onDeactivated(options);
        }

      }

      $.each(this.sceneList, function(key, value) {
        if (key === scene) {

          if (scene.transition && scene.transition.length) {
            $('#' + scene).show(scene.transition.length);
          } else {
            $('#' + scene).show();
          }
          this.currentScene = value;
          if (this.currentScene.onActive) {
            this.currentScene.onActive(options);
          }
          
          if (callback)
            callback(scene);
          
          return false;
        }
      });
    };
    
    SceneDirector.prototype.render = function() {
      if (!this.currentScene.render) {
        return;
      }
      this.currentScene.render();
    };
    
    SceneDirector.prototype.update = function(dt) {
      if (!this.currentScene.update) {
        return;
      }
      this.currentScene.update(dt);
    };
    
    return SceneDirector;
    
  })();<commit_msg>SceneDirector handles event binding when adding a scene<commit_after>/**
 * @namespace Lyria
 * Lyria namespace decleration
 */
;(function(window, document, Lyria, $, undefined) {'use strict';

  /**
   * The scene director is the manager for all scenes
   *
   */
  Lyria.SceneDirector = (function() {

    function SceneDirector(container, parent) {

      if ( container instanceof Lyria.Viewport) {
        this.viewport = container;
      } else {
        this.viewport = new Lyria.Viewport(container, parent);
      }

      this.sceneList = {};
      this.currentScene = null;
      this.onSceneChange = function(scene) {
      };

    }

    // Properties
    SceneDirector.prototype.sceneClassName = 'scene';

    // Methods
    SceneDirector.prototype.add = function(scene, options) {

      if (!( scene instanceof Lyria.Scene)) {
        if (Lyria.Scenes[scene]) {
          scene = Lyria.Scenes[scene];
        } else {
          throw 'No valid scene found.';
        }
      }

      scene.parent = this;
      this.sceneList[scene.name] = scene;

      if (this.viewport.$container) {
        if ($('#' + scene.name).length === 0) {
          this.viewport.$container.prepend($(document.createElement('div')).attr('id', scene.name).attr('class', SceneDirector.prototype.sceneClassName));

          if (scene.content) {
            $('#' + scene.name).html(scene.content);
          }

          // Bind events
          if (scene.events && !$.isEmptyObject(scene.events)) {
            $.each(scene.events, function(key, value) {
              if (( typeof value === 'object') && (key !== 'delegate')) {
                $(scene.events.delegate).on(value, key, {
                  scene: scene
                });
              }
            });
          }
        }
      }

      return this;
    };

    SceneDirector.prototype.show = function(scene, options, callback) {

      if (this.onSceneChange) {
        this.onSceneChange(scene);
      }

      // More than one scene visible at the same time
      if ($('.' + SceneDirector.prototype.sceneClassName + ':visible')) {
        $('.' + SceneDirector.prototype.sceneClassName).hide();
      }

      if (this.currentScene) {
        if (this.currentScene.transition && this.currentScene.length) {
          $('#' + this.currentScene).hide(this.currentScene.transition.length, function() {
            $('.' + SceneDirector.prototype.sceneClassName).hide();
          });
        } else {
          $('.' + SceneDirector.prototype.sceneClassName).hide();
        }

        if (this.currentScene.onDeactivated) {
          this.currentScene.onDeactivated(options);
        }

      }

      $.each(this.sceneList, function(key, value) {
        if (key === scene) {

          if (scene.transition && scene.transition.length) {
            $('#' + scene).show(scene.transition.length);
          } else {
            $('#' + scene).show();
          }
          this.currentScene = value;
          if (this.currentScene.onActive) {
            this.currentScene.onActive(options);
          }

          if (callback)
            callback(scene);

          return false;
        }
      });
    };

    SceneDirector.prototype.render = function() {
      if (!this.currentScene.render) {
        return;
      }
      this.currentScene.render();
    };

    SceneDirector.prototype.update = function(dt) {
      if (!this.currentScene.update) {
        return;
      }
      this.currentScene.update(dt);
    };

    return SceneDirector;

  })();
{'fraction_non_alphanumeric': 0.13992673992673993, 'fraction_numerical': 0.00029304029304029304, 'mean_word_length': 1.8194960760016523, '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': '87399', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1863, 'n_words': 325}