Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// Collection.js
(function () {
  /*global adventurejs A*/

  /**
   * @ajspath adventurejs.Atom.Asset.Matter.Tangible.Scenery.Collection
   * @augments adventurejs.Scenery
   * @class adventurejs.Collection
   * @ajsconstruct MyGame.createAsset({ "class":"Collection", "name":"foo", [...] })
   * @ajsconstructedby adventurejs.Game#createAsset
   * @ajsnavheading SceneryClasses
   * @param {String} game_name The name of the top level game object.
   * @param {String} name A name for the object, to be serialized and used as ID.
   * @summary An Asset that provides a way to refer to a group of Assets together.
   * @tutorial Tangibles_Collections
   * @classdesc
   * <p>
   * <strong>Collection</strong> provides a way to perform some verbs
   * on a specific group of related objects. In the example below,
   * a {@link adventurejs.Desk|Desk} has three
   * {@link adventurejs.Drawer|Drawers}. Each drawer can be open or
   * closed. A player might input something like
   * <code class="property">examine drawers</code>.
   * Normally, that would lead to a
   * <a href="/doc/NextSteps_Disambiguation.html">disambiguation</a>
   * prompt such as <code class="property">Which did $(we) mean?
   * 1. The top drawer, 2. the middle drawer, or
   * 3. the bottom drawer?</code>
   * Here, we've made a collection for the three drawers lets players
   * refer to the three drawers as one object.
   * </p>
   * <pre class="display"><code class="language-javascript">MyGame.createAsset({
   *   class: "Desk",
   *   name: "desk",
   *   place: { in: "Office" },
   *   descriptions: {
   *     look: function()
   *     {
   *       return "It's a heavy wooden desk. It has three drawers
   *       stacked vertically. The top drawer is $( top drawer is| open or| closed ),
   *       the middle drawer is $( middle drawer is| open or| closed ),
   *       and the bottom drawer is $( bottom drawer is| open or| closed )."
   *     },
   *   },
   *   adjectives: "wooden, heavy",
   * });
   * MyGame.createAsset({
   *   class: "Drawer",
   *   name: "top drawer",
   *   synonyms: "top desk drawer, top drawer lock, lock",
   *   descriptions: { look: "The top drawer is $( top drawer is| open or| closed ). ", },
   *   adjectives: "desk",
   *   place: { attached: "desk" },
   *   dov: {
   *     unlock: { with_assets: ['tiny brass key'], },
   *   },
   *   is: { locked: true, listed_in_parent: false },
   * });
   * MyGame.createAsset({
   *   class: "Drawer",
   *   name: "middle drawer",
   *   synonyms: "middle desk drawer",
   *   descriptions: { look: "The middle drawer is $( middle drawer is| open or| closed ). ", },
   *   adjectives: "desk",
   *   place: { attached: "desk" },
   *   is: { listed_in_parent: false },
   * });
   * MyGame.createAsset({
   *   class: "Drawer",
   *   name: "bottom drawer",
   *   synonyms: "bottom desk drawer",
   *   descriptions: { look: "The bottom drawer is $( bottom drawer is| open or| closed ). ", },
   *   adjectives: "desk",
   *   place: { attached: "desk" },
   *   is: { listed_in_parent: false },
   * });
   * MyGame.createAsset({
   *   class: "Collection",
   *   name: "desk drawers",
   *   place: { attached: "desk" },
   *   collection: "top drawer, middle drawer, bottom drawer",
   *   synonyms: [ "drawers", "three drawers" ],
   *   is: { listed_in_parent: false },
   *   descriptions: {
   *     look: function()
   *     {
   *       var openCount = [];
   *       var closedCount = [];
   *       var complicatedMsg = "The desk has three drawers stacked vertically. ";   *
   *       MyGame.$("top drawer").is.closed ?
   *         closedCount.push( "top drawer" ) : openCount.push( "top drawer" );
   *       MyGame.$("middle drawer").is.closed ?
   *         closedCount.push( "middle drawer" ) : openCount.push( "middle drawer" );
   *       MyGame.$("bottom drawer").is.closed ?
   *         closedCount.push( "bottom drawer" ) : openCount.push( "bottom drawer" );
   *
   *       if( 0 === openCount.length )
   *       {
   *         complicatedMsg += "All three are closed.";
   *       }
   *       else if( 0 === closedCount.length )
   *       {
   *         complicatedMsg += "All three are open.";
   *       }
   *       else if ( 2 == openCount.length )
   *       {
   *         complicatedMsg += "The "
   *         + openCount[ 0 ]
   *         + " and the "
   *         + openCount[ 1 ]
   *         + " are open. The "
   *         + closedCount[ 0 ]
   *         + " is closed. ";
   *       }
   *       else if ( 2 == closedCount.length )
   *       {
   *         complicatedMsg += "The "
   *         + closedCount[ 0 ]
   *         + " and the "
   *         + closedCount[ 1 ]
   *         + " are closed. The "
   *         + openCount[ 0 ]
   *         + " is open. ";
   *       }
   *       return complicatedMsg
   *     },
   *   },
   * });
   * </code></pre>
   * <p>In the "desk drawers" Collection,
   * take special note of these lines:</p>
   * <pre class="display"><code class="language-javascript">name: "desk drawers",
   *   synonyms: [ "drawers", "three drawers" ],
   *   collection: "top drawer, middle drawer, bottom drawer",
   *   place: { attached: "desk" },
   *   is: { listed_in_parent: false },
   * </code></pre>
   * <li>
   * <code class="property">collection</code> is set to a list of the items that
   * the Collection represents. This is important, because some
   * {@link adventurejs.Verb|Verb} actions will be forwarded to
   * the items in the list. In this example,
   * <code class="property">open drawers</code>
   * will try to open each drawer in turn as if the player had input
   * <code class="property">open top drawer then open middle drawer
   * then open bottom drawer</code>.
   * </li>
   * <li><code class="property">name</code> and
   * <code class="property">synonyms</code> have been set
   * to plural words that players are likely to use.</li>
   * <li>
   * <code class="property">thing_this_is_attached</code>
   * is set to <code class="property">desk</code>,
   * the same as the drawers, and
   * <code class="property">is.listed_in_parent</code>
   * is set to <code class="property">desk</code> so that
   * the Collection doesn't show up in the
   * {@link adventurejs.Room|Room} description.
   * </li>
   **/
  class Collection extends adventurejs.Scenery {
    constructor(name, game_name) {
      super(name, game_name);
      this.class = "Collection";

      this.is.collection = true;
      this.is.listed_in_room = false;
    }
  }

  adventurejs.Collection = Collection;
})();