Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// hasIndirectDescription.js
(function() {
	/*global adventurejs A*/ 
  "use strict";
  var p = adventurejs.Asset.prototype;	
  /**
   * Determine whether asset has an indirect description, 
   * such as "look at this through magnifying glass", where
   * "through magnifying glass" becomes a key at 
   * asset.descriptions["through magnifying glass"].
   * "look" is always the default direct object description.
   * @memberOf adventurejs.Asset
	 * @method adventurejs.Asset#hasIndirectDescription
   * @param {String} indirect_aspect
   * @param {Object} indirect_asset
   * @param {String} direct_aspect
   * @return {String|Boolean}
   */
  p.hasIndirectDescription = function Asset_hasIndirectDescription( direct_aspect, indirect_aspect, indirect_asset )
  {
    if( !indirect_aspect || !indirect_asset ) return false;
    if( direct_aspect === "at" ) direct_aspect = "look";
    direct_aspect = direct_aspect || "look";

    let target = `${indirect_aspect} ${indirect_asset.name}`;

    if( this.descriptions[ direct_aspect ]
    && this.descriptions[ direct_aspect ][ target ] )
    {
      return true;
    }

    return false;
  }
}());