Pre-release
AdventureJS Docs Downloads Bundler Devlog Score: 0 Moves: 0
// isIn.js
(function () {
  /* global AdventureJS A */
  var p = AdventureJS.Assets.Entity.prototype;

  /**
   * <strong>isIn</strong> tests whether
   * one asset is specifically in the <code>in</code> aspect of another asset.
   * <pre class="display"><code class="language-javascript">if( MyGame.$('rabbit').isIn('hat') ){ // do stuff }
   * </code></pre>
   * @memberOf AdventureJS.Assets.Entity
   * @method AdventureJS.Assets.Entity#isIn
   * @param {Object|String} asset Can be string or object.
   * @returns {boolean}
   */
  p.isIn = function Entity_isIn(asset) {
    if ("undefined" === typeof asset) {
      return this.getNestOrPlaceAspect() === "in";
    }
    if ("string" === typeof asset) asset = this.game.getAsset(asset);
    if (!asset || !asset.id || !asset.hasClass("Entity")) return false;

    if (this.getNestOrPlaceAsset().id !== asset.id) return false;

    // if asset.quirks.in_means_on we'll allow "isIn" to mean "isOn"
    const allow_on = asset.quirks.in_means_on;
    const preposition = this.getNestOrPlacePreposition();
    if (preposition === "on" && allow_on) {
      return true;
    } else if (preposition !== "in") return false;

    return true;
  };
})();