Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
//setGlobalDescriptions.js

(function() {
  /*global adventurejs A*/ 
  "use strict";

	var p = adventurejs.Game.prototype;

  /**
   * A method to let author set default descriptions for global 
   * objects such as sun, moon, sky, floor, walls.
   * @memberOf adventurejs.Game
   * @method adventurejs.Game#setGlobalDescriptions
   * @kind function
   * @param {Object} globals A list of globle Scenery Assets.
   */
   p.setGlobalDescriptions = function Game_setGlobalDescriptions( globals )
  {
    //console.warn( globals );

    var globalsKeys = Object.keys( globals );
    for( var i = 0; i < globalsKeys.length; i++ ) 
    {
      var id = globalsKeys[i];
      var global_precursor = globals[ id ];
      var global_asset = this.game.world[ id ];

      if( "undefined" === typeof global_asset )
      {
        var see = "See adventurejs.Game#setGlobalDescriptions for info about setting global descriptions. ";
        var msg = "setGlobalDescriptions received an id for which there is no global object. ";
        this.game.log("warn","critical",msg + see, 'Game' );
        continue; // @todo make new global?
      }

      var description;
      if( global_precursor.descriptions
      && global_precursor.descriptions.look )
      {
        description = global_precursor.descriptions.look;
      }
      else if ( global_precursor.description )
      {
        description = global_precursor.description;
      }
      else
      {
        description = "";
      }

      var enabled = global_precursor.enabled;

      //id = "global_" + id;

      if( "undefined" !== typeof global_asset )
      {
        global_asset.descriptions.look = description;
        global_asset.enabled = enabled;
      }
    }

    return this;
  }
    
}());