Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getRoomId.js
(function () {
  /*global adventurejs A*/
  var p = adventurejs.Tangible.prototype;
  /**
   * Get the ID of the room this asset is in.
   * @memberOf adventurejs.Tangible
   * @method adventurejs.Tangible#getRoomId
   * @returns {String}
   */
  p.getRoomId = function Tangible_getRoomId() {
    var room = null;
    var child = this;
    while (null === room) {
      if ("undefined" === typeof child.place) {
        // if it doesn't have a place property, it's not Tangible
        break;
      }
      var parent = child.getPlaceAsset();
      if (!parent) {
        break;
      }
      if (parent instanceof adventurejs.Room) {
        room = parent.id;
      } else {
        child = parent;
      }
    }
    return room;
  };
})();