Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// canBePut.js
(function () {
  /*global adventurejs A*/
  "use strict";
  var p = adventurejs.Tangible.prototype;
  /**
   * Check whether this asset can be placed within
   * the specified aspect of the specified asset.
   * This takes into account the
   * <code>with_assets</code> and
   * <code>with_classes</code> properties.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#canBePut
   * @param {String} aspect
   * @param {Object} asset
   * @returns {Boolean}
   */
  p.canBePut = function Tangible_canBePut(aspect, asset) {
    if (!asset.hasAspectAt(aspect)) return false;
    if (!asset.getAspectAt(aspect).player_can_add_assets_to_contents)
      return false;

    var can = true;

    var with_classes = asset.aspects[aspect].with_classes;
    if (with_classes.length > 0) {
      can = false;
      for (var i = 0; i < with_classes.length; i++) {
        var clas = with_classes[i];
        if (this instanceof adventurejs[clas]) {
          can = true;
          break;
        }
      }
    }

    var with_assets = asset.aspects[aspect].with_assets;
    if (with_assets.length > 0) {
      can = false;
      for (var i = 0; i < with_assets.length; i++) {
        if (this.id === with_assets[i]) {
          can = true;
          break;
        }
      }
    }

    return can;
  };
})();