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

    if (!indirect_aspect || !indirect_asset) {
      return this.getDescription(direct_aspect);
    }

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

    if (
      this.descriptions[direct_aspect] &&
      this.descriptions[direct_aspect][target]
    ) {
      return A.getSAF.call(this.game, this.descriptions[direct_aspect][target]);
    }

    return this.getDescription(direct_aspect);
  };
})();