Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// getListableContents.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Tangible.prototype;
  /**
   * Get an array of assets within this asset that are listable in
   * this asset's description, for example when player examines this.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getListableContents
   * @returns {Array}
   */
  p.getListableContents = function Tangible_getListableContents() {
    var masterlist = [];
    for (var aspect in this.aspects) {
      if (!this.hasAspectAt(aspect)) {
        continue;
      }
      if (
        this.aspects[aspect].list_in_room &&
        this.aspects[aspect].contents.length > 0
      ) {
        if ("in" === aspect && this.is.closed) {
          continue;
        }
        // TODO transparent containers

        var list = this.aspects[aspect].contents;
        for (var i = 0; i < list.length; i++) {
          if (this.game.getAsset(list[i]).is.listed_in_parent) {
            masterlist.push(list[i]);
            // recurse
            masterlist = masterlist.concat(
              this.game.getAsset(list[i]).getListableContents()
            );
          }
        }
      }
    }
    return masterlist;
  };
})();