// 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) {
if ("string" === typeof exit) {
exit = this.game.getAsset(exit);
}
if ("string" === typeof destination) {
destination = this.game.getAsset(destination);
}
if (!destination) {
destination = this.game.getAsset(exit.destination);
}
if (!exit || !destination) return "";
const player = this.game.getPlayer();
const preposition = " to ";
const definite_article = destination.definite_article;
const input = this.game.getInput();
const subject = input.getSubject();
const room = subject.getRoom();
const settings = this.settings;
let direction = exit.direction;
let destination_name = destination.name;
let output = "";
// named exits are very simple because they
// already are the destination name
if (exit.is.named) {
// add <a>?
if (this.game.settings.print_exits_links) {
// destination_name = `<a href="#"
// onclick="event.preventDefault(); window.${this.game.game_name}.sendToParser('${destination_name}')"
// >${destination_name}</a>`;
destination_name = `
<a href="#"
class="ajs-exit-link"
data-destination = "${destination_name}"
>${destination_name}</a>`;
}
output += `
<span class="ajs-exit-preposition">${preposition}</span>
${definite_article ? definite_article + " " : ""}
<span class="ajs-exit-destination">${destination_name}</span>
`;
}
// otherwise we have a directional name
else {
// add <a>?
if (this.game.settings.print_exits_links) {
// direction = `<a href="#"
// onclick="window.${this.game.game_name}.sendToParser('${direction}')"
// >${direction}</a>`;
direction = `
<a href="#"
class="ajs-exit-link"
data-destination = "${direction}"
>${direction}</a>`;
}
output = `<span class="ajs-exit-direction">${direction}</span>`;
// decide whether to reveal the destination
let add_destination = true;
// get settings that may prevent printing destination
let print_exits_room_names =
room.print_exits_room_names === true ||
(room.print_exits_room_names !== false &&
settings.print_exits_room_names === true);
let print_exits_room_names_if_known =
room.print_exits_room_names_if_known === true ||
(room.print_exits_room_names_if_known !== false &&
settings.print_exits_room_names_if_known === true);
let print_exits_room_names_if_used =
room.print_exits_room_names_if_used === true ||
(room.print_exits_room_names_if_used !== false &&
settings.print_exits_room_names_if_used === true);
// test settings against current conditions
if (!print_exits_room_names) {
add_destination = false;
}
if (!player.knowsAbout(destination) && print_exits_room_names_if_known) {
add_destination = false;
}
if (!exit.is.used && print_exits_room_names_if_used) {
add_destination = false;
}
if (add_destination) {
output += `
<span class="ajs-exit-preposition">${preposition}</span>
${definite_article ? definite_article + " " : ""}
<span class="ajs-exit-destination">${destination_name}</span>
`;
}
}
return output.trim();
};
})();