// getAncestorId.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Assets.Entity.prototype;
/**
* Get the ID of this asset's topmost parent, excluding {@link AdventureJS.Assets.Room|Room}.
* @memberOf AdventureJS.Assets.Entity
* @method AdventureJS.Assets.Entity#getAncestorId
* @returns {String}
*/
p.getAncestorId = function Entity_getAncestorId() {
var child = this;
var parent_asset = this.getPlaceAsset();
// child has no parent, so it's not accessible
if (!parent_asset) {
return "";
}
// child parent is room
if (parent_asset instanceof AdventureJS.Assets.Room) {
return "";
}
while (parent_asset) {
child = parent_asset;
if (!parent_asset.getPlaceAsset()) {
return "";
}
parent_asset = parent_asset.getPlaceAsset();
if (parent_asset instanceof AdventureJS.Assets.Room) {
return child.id;
}
}
return "";
};
})();