Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// Dictionary.js
(function () {
  /* global adventurejs A */
  /* global adventurejs A */
  /**
   * @class adventurejs.Dictionary
   * @param {Game} game A reference to the game instance.
   * @ajsnavheading FrameworkClasses
   * @ajsinternal
   * @summary Framework class that manages verb instances and lookup tables for verbs and nouns.
   * @classdesc
   * <p>
   * <strong>Dictionary</strong> manages all {@link adventurejs.Verb|Verbs}
   * and Verb related functions. It also manages lookup tables for
   * Verbs, nouns, directions, and sentence patterns. A Dictionary
   * instance is created automatically by {@link adventurejs.Game|Game}
   * at runtime. There is no public constructor, and authors should
   * not need to make new instances.
   * </p>
   */
  class Dictionary {
    constructor(game) {
      /**
       * A reference back to the main {@link adventurejs.Game|Game} object.
       * @var {Object} adventurejs.Dictionary#game
       * @default {}
       */
      this.game = game;

      /**
       * Unused?
       * @var {Object} adventurejs.Dictionary#directions
       * @default {}
       * @todo Is this irrelevant?
       */
      this.directions = {};

      /**
       * Lookup table for direction keywords.
       * @var {Object} adventurejs.Dictionary#direction_lookup
       * @default {}
       * @ajsnode game.dictionary.direction_lookup
       */
      this.direction_lookup = {};

      /**
       * Container for all constructed instance of
       * {@link adventurejs.Verb|Verb}.
       * @var {Object} adventurejs.Dictionary#verbs
       * @default {}
       * @ajsnode game.dictionary.verbs
       */
      this.verbs = {};

      /**
       * When using <a href="#disableAllVerbsBut">disableAllVerbsBut</a>,
       * save the enabled verb IDs here.
       * @var {Array} adventurejs.Dictionary#enabled_verbs
       * @default []
       */
      this.enabled_verbs = [];

      /**
       * When using <a href="#disableVerbs">disableVerbs</a>,
       * save the disabled verb IDs here.
       * @var {Array} adventurejs.Dictionary#disabled_verbs
       * @default []
       */
      this.disabled_verbs = [];

      /**
       * Boolean used to determine if we've initialize all predefined verbs.
       * @var {Boolean} adventurejs.Dictionary#did_initialize_verbs
       * @default false
       */
      this.did_initialize_verbs = false;

      /**
       * A lookup table for verb keywords.
       * @var {Object} adventurejs.Dictionary#verb_lookup
       * @default {}
       */
      this.verb_lookup = {};

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#try_to_verbs
       * @default []
       */
      this.try_to_verbs = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#try_gerunds
       * @default []
       */
      this.try_gerunds = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_gerunds
       * @default []
       */
      this.verb_gerunds = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_noun_preps
       * @default []
       */
      this.verb_noun_preps = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_prep_nouns
       * @default []
       */
      this.verb_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_prep_prep_nouns
       * @default []
       */
      this.verb_prep_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_prep_prep_prep_nouns
       * @default []
       */
      this.verb_prep_prep_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_noun_prep_nouns
       * @default []
       */
      this.verb_noun_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_noun_prep_prep_nouns
       * @default []
       */
      this.verb_noun_prep_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_noun_prep_noun_prep_nouns
       * @default []
       */
      this.verb_noun_prep_noun_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_prep_noun_prep_nouns
       * @default []
       */
      this.verb_prep_noun_prep_nouns = [];

      /**
       * We store a variety of phrasal verb patterns,
       * which we compare against when searching player input.
       * @var {Array} adventurejs.Dictionary#verb_prep_noun_prep_noun_prep_nouns
       * @default []
       */
      this.verb_prep_noun_prep_noun_prep_nouns = [];

      /**
       * A placeholder for verbs to write their state/unstate strings to for lookup..
       * @var {Object} adventurejs.Dictionary#verb_state_lookup
       */
      this.verb_state_lookup = {};

      return this;
    } // Dictionary constructor

    /**
     * Provides a chainable shortcut method for setting a number of properties on the instance.
     * @method adventurejs.Dictionary#set
     * @param {Object} props A generic object containing properties to copy to the instance.
     * @returns {adventurejs.Dictionary} Returns the instance the method is called on (useful for chaining calls.)
     * @chainable
     */
    set(props) {
      return A.deepSet.call(this.game, props, this);
    }
  }

  adventurejs.Dictionary = Dictionary;
})();