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

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

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

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

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

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

    return true;
  };
})();