Pre-release
AdventureJS Docs Downloads Bundler Devlog
Score: 0 Moves: 0
// canContainAssetAt.js
(function () {
  /* global AdventureJS A */
  var p = AdventureJS.Assets.Entity.prototype;
  /**
   * Check whether this asset can be attached to specified
   * other asset.
   * @memberOf AdventureJS.Assets.Entity
   * @method AdventureJS.Assets.Entity#canContainAssetAt
   * @param {Object} object
   * @returns {Boolean}
   */
  p.canContainAssetAt = function Entity_canContainAssetAt(asset, preposition) {
    var aspect = this.aspects[preposition];
    if (!aspect || !aspect.class) return false;

    if (
      aspect.capacity.width > -1 &&
      asset.dimensions.width > aspect.capacity.width
    ) {
      return false;
    }

    if (
      aspect.capacity.height > -1 &&
      asset.dimensions.height > aspect.capacity.height
    ) {
      return false;
    }

    if (
      aspect.capacity.depth > -1 &&
      asset.dimensions.depth > aspect.capacity.depth
    ) {
      return false;
    }

    if (
      aspect.capacity.weight > -1 &&
      asset.dimensions.weight > aspect.capacity.weight
    ) {
      return false;
    }

    if (
      aspect.capacity.count > -1 &&
      aspect.contents.length >= aspect.capacity.count
    ) {
      return false;
    }

    return true;
  };
})();