// isIn.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Tangible.prototype;
/**
* <strong>isIn</strong> tests whether
* one asset is in (any aspect of) another asset.
* <pre class="display"><code class="language-javascript">if( MyGame.$('jewel').$isIn('crown') ){ // do stuff }
* </code></pre>
* @memberOf adventurejs.Tangible
* @method adventurejs.Tangible#isIn
* @param {Object|String} asset Can be string or object.
*/
p.isIn = p.$isIn = function Tangible_isIn( asset )
{
if("string" === typeof asset) asset = this.game.getAsset(asset);
if(!asset) return false;
var parent_id;
var nextlevel;
// get parent of this
if( this.place ) nextlevel = this.getPlaceAsset();
// this has no parent
if( !nextlevel ) return false;
while ( nextlevel )
{
if( nextlevel.id === asset.id )
{
return true;
}
else
{
if( !nextlevel.place ) return false;
nextlevel = nextlevel.getPlaceAsset();
if( !nextlevel ) return false;
}
}
return false;
}
}());