Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// hasAnyPartContainingSubstance.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#hasAnyPartContainingSubstance
   * @param {String} id
   * @returns {boolean}
   */
  p.hasAnyPartContainingSubstance =
    function Tangible_hasAnyPartContainingSubstance(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 true;
        } 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 true;
          }
        }
      }

      return false;
    }; // hasAnyPartContainingSubstance.js
})();