Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// getExtendedExitName.js

(function () {
  /*global adventurejs A*/

  var p = adventurejs.Game.prototype;

  /**
   *
   * @method adventurejs.Game#getExtendedExitName
   * @memberOf adventurejs.Game
   * @param {Object} exit
   * @param {Object} destination
   * @returns {String}
   */
  p.getExtendedExitName = function Game_getExtendedExitName(exit, destination) {
    // add the direction
    var output = `<span class="exit-direction">${exit.direction}</span>`;
    var player = this.game.getPlayer();

    var preposition = " to ";
    var definite_article = destination.definite_article;
    var destName = destination.name; //destination.name;
    var addDest = true;
    var currentRoom = this.game.getCurrentRoom();
    var settings = this.settings;

    // test conditions that may prevent printing destination

    if (
      false === settings.show_room_names_in_exit_descriptions ||
      false === currentRoom.show_room_names_in_exit_descriptions
    ) {
      addDest = false;
    }

    if (
      !player.knowsAbout(destination) &&
      (settings.show_room_names_in_exit_descriptions_only_when_room_is_known ||
        currentRoom.show_room_names_in_exit_descriptions_only_when_room_is_known)
    ) {
      addDest = false;
    }

    if (
      !exit.is.used &&
      (settings.show_room_names_in_exit_descriptions_only_after_exit_has_been_used ||
        currentRoom.show_room_names_in_exit_descriptions_only_after_exit_has_been_used)
    ) {
      addDest = false;
    }

    if (addDest) {
      output += `${preposition} ${definite_article ? definite_article + " " : ""} 
        <span class="exit-destination">${destName}</span>`;
    }

    return output;
  };
})();