Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// getDescription.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Asset.prototype;
  /**
   * Get a description, such as "look in book", where
   * "in" has been defined as a key at
   * asset.descriptions.in.
   * "look" is always the default description.
   * @memberOf adventurejs.Asset
   * @method adventurejs.Asset#getDescription
   * @param {String} description
   * @return {String}
   */
  p.getDescription = function Asset_getDescription(description) {
    description = description || "look";
    if (!this.descriptions[description]) description = "look";
    if (this.descriptions[description]) {
      if (
        Array.isArray(this.descriptions[description]) ||
        "string" === typeof this.descriptions[description] ||
        "function" === typeof this.descriptions[description]
      ) {
        return A.getSAF.call(this.game, this.descriptions[description]);
      }

      if (
        "object" === typeof this.descriptions[description] &&
        this.descriptions[description].default
      ) {
        return A.getSAF.call(this.game, this.descriptions[description].default);
      }
    }

    return `${this.Articlename} is undescribed. `;
  };
})();