// getAnyPartContainingSubstance.js
(function () {
/* global adventurejs A */
var p = adventurejs.Tangible.prototype;
/**
* Check whether this asset has a registered part that
* contains the specified substance.
* @memberOf adventurejs.Tangible
* @method adventurejs.Tangible#getAnyPartContainingSubstance
* @param {String} id
* @returns {object}
*/
p.getAnyPartContainingSubstance =
function Tangible_getAnyPartContainingSubstance(id) {
const parent = this.linked_parent
? this.game.getAsset(this.linked_parent)
: this;
for (var prop in parent.linked_components) {
if (
!Object.prototype.hasOwnProperty.call(parent.linked_components, prop)
)
continue;
if ("string" === typeof parent.linked_components[prop]) {
let asset = this.game.getAsset(parent.linked_components[prop]);
if (!asset) continue;
if (asset.containsSubstance(id)) return asset;
} else if (Array.isArray(parent.linked_components[prop])) {
for (let i = 0; i < parent.linked_components[prop].length; i++) {
let asset = this.game.getAsset(parent.linked_components[prop][i]);
if (!asset) continue;
if (asset.containsSubstance(id)) return asset;
}
}
}
return null;
}; // getAnyPartContainingSubstance.js
})();