// hasIndirectDescription.js
(function () {
/*global adventurejs A*/
var p = adventurejs.Asset.prototype;
/**
* Determine whether asset has an indirect description,
* such as "look at this through magnifying glass", where
* "through magnifying glass" becomes a key at
* asset.descriptions["through magnifying glass"].
* "look" is always the default direct object description.
* @memberOf adventurejs.Asset
* @method adventurejs.Asset#hasIndirectDescription
* @param {String} indirect_aspect
* @param {Object} indirect_asset
* @param {String} direct_aspect
* @return {String|Boolean}
* @deprecated
* @todo delete
*/
p.hasIndirectDescription = function Asset_hasIndirectDescription(
direct_aspect,
indirect_aspect,
indirect_asset
) {
if (!indirect_aspect || !indirect_asset) return false;
if (direct_aspect === "at") direct_aspect = "look";
direct_aspect = direct_aspect || "look";
// account for equivalencies
let indirect_aspects = [indirect_aspect];
// in the case of glasses, binoculars, etc player might say
// "look at x with binoculars" while author has coded for
// "look at x through binoculars" and we'll allow it
if (indirect_aspect === "with") indirect_aspects.push("through");
// "look in chair" may be equivalent to "look on chair"
if (indirect_aspect === "in" && indirect_asset.hasQuirk("in_means_on"))
indirect_aspects.push("on");
for (let i = 0; i < indirect_aspects.length; i++) {
let target = `${indirect_aspects[i]} ${indirect_asset.name}`;
if (this.descriptions[direct_aspect]) {
// look for a single item description like "through microscope"
if (this.descriptions[direct_aspect][target]) {
return true;
}
let keys = Object.keys(this.descriptions[direct_aspect]);
if (keys.length) {
// look for a multiple item description like
// "through microscope, with blacklight"
for (let d = 0; d < keys.length; d++) {
let key = keys[d];
let modifiers = key.split(",").map((item) => item.trim());
if (
Array.isArray(modifiers) &&
modifiers.includes(`${indirect_aspect} ${indirect_asset.name}`)
) {
return true;
}
}
}
}
}
return false;
};
})();