Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// isNested.js
(function () {
  /*global adventurejs A*/
  var p = adventurejs.Character.prototype;
  /**
   * Determine whether character asset has a nest. Can be used
   * to test against specific aspects and parent assets.
   * For example, player.isNested( 'in', 'bed' )
   * @memberOf adventurejs.Character
   * @method adventurejs.Character#isNested
   * @return {Boolean}
   */
  p.isNested = p.$nested = function Character_isNested(prep, prop) {
    if ("undefined" === typeof this.nest) return false;

    var prepkey = Object.keys(this.nest)[0];
    var propvalue = this.nest[prepkey];

    if (prep && "undefined" === typeof prepkey) return false;
    if (prep && prep !== prepkey) return false;

    if (prop && "undefined" === typeof propvalue) return false;
    if (prop && prop !== propvalue) return false;

    // received isNested()
    if ("undefined" === typeof prep && "undefined" === typeof prop) {
      if (propvalue) return true;
      else return false;
    }

    return true;
  };
})();