// getDirection.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Dictionary.prototype;
/**
*
* @memberOf adventurejs.Dictionary
* @method adventurejs.Dictionary#getDirection
* @param {String} word A direction name.
* Directions can have aliases,
* for example 'ne' as a shortcut for 'northeast'.
* When player inputs an alias, we want to lookup the primary name,
* which we need to get the direction object.
* @returns {String} The primary direction name.
*/
p.getDirection = function Dictionary_getDirection( word )
{
if(typeof this.directionLookup[word] !== "undefined" )
{
return(word);
}
for (var prop in this.directionLookup)
{
if("undefined" === typeof this.directionLookup[prop].synonyms)
{
continue;
}
var synonyms = this.directionLookup[prop].synonyms;
for(var i = 0; i < synonyms.length;i++)
{
if(word===synonyms[i]) {
// found a synonym, return the base word
return prop;
}
}
}
return false;
}
}());