// Dictionary.js
(function () {
/*global adventurejs A*/
"use strict";
/*global adventurejs A*/
/**
* @class adventurejs.Dictionary
* @param {Game} game A reference to the game instance.
* @ajsnavheading FrameworkReference
* @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#directionLookup
* @default {}
* @ajsnode game.dictionary.directionLookup
*/
this.directionLookup = {};
/**
* 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 = {};
//this.stringLookup = {};
/**
* We store a variety of verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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 verb/noun/preposition patterns per verb,
* 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
/**
* Construct all native verbs. When complete,
* sets game.dictionary.did_initialize_verbs to true.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#initStandardVerbs
* @kind function
* @ajsinternal
*/
initStandardVerbs() {
for (var preverb in A.Preverbs) {
this.createVerb(A.Preverbs[preverb]);
}
this.did_initialize_verbs = true;
}
/**
* Determine whether string is recognized as a preposition.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#isPreposition
* @param {String} preposition
* @returns {Boolean}
*/
isPreposition(word) {
var bool = false;
if (this.prepositions.indexOf(word) > -1) bool = true;
return bool;
}
/**
* Determine whether string is recognized as a preposition
* and return the string.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#getPreposition
* @param {String} preposition
* @returns {String|Boolean}
*/
getPreposition(word) {
if (this.prepositions.indexOf(word) > -1) return word;
else return false;
}
/**
* Determine whether string is recognized as an adverb
* and return the string.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#getAdverb
* @param {String} preposition
* @returns {String|Boolean}
*/
getAdverb(word) {
if (this.adverbs.indexOf(word) > -1) return word;
else return false;
}
/**
* Determine whether string is recognized as an getAdjective
* and return the string.
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#getAdjective
* @param {String} preposition
* @returns {String|Boolean}
*/
getAdjective(word) {
if (this.adjectives.indexOf(word) > -1) return word;
else return false;
}
/**
* 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;
})();