// addWordsToLookup.js
(function () {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Asset.prototype;
/**
* <strong>addWordsToLookup()</strong> takes words associated with
* this asset and adds them to the global lookup table.
* @method adventurejs.Asset#addWordsToLookup
* @memberOf adventurejs.Asset
* @param {Array} words
* @param {String} type
*/
p.addWordsToLookup = function Asset_addWOrdsToLookup(words, type) {
if (!words.length) return;
while (words.length > 0) {
if (!words[0] || "string" !== typeof words[0] || " " === words[0]) {
words.shift();
continue;
}
words[0] = words[0].trim();
// is this word not in our lookup yet?
if (false === words[0] in this.game.world_lookup) {
this.game.world_lookup[words[0]] = {};
this.game.world_lookup[words[0]].IDs = [];
if (type) {
this.game.world_lookup[words[0]].type = type;
}
}
// is current object represented by this word yet?
if (-1 === this.game.world_lookup[words[0]].IDs.indexOf(this.id)) {
this.game.world_lookup[words[0]].IDs.push(this.id);
}
words.shift();
}
return;
};
})();