Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getAnyPartContainingAnySubstance.js
(function () {
  /* global adventurejs A */
  var p = adventurejs.Tangible.prototype;
  /**
   * Get any registered part of this asset that
   * contains any substance.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getAnyPartContainingAnySubstance
   * @returns {object|null}
   */
  p.getAnyPartContainingAnySubstance =
    function Tangible_getAnyPartContainingAnySubstance() {
      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.containsAnySubstance()) 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.containsAnySubstance()) return asset;
          }
        }
      }

      return null;
    }; // getAnyPartContainingAnySubstance.js
})();