// getRoomDescription.js
(function () {
/* global adventurejs A */
var p = adventurejs.Game.prototype;
/**
* Get room description to print to game display.
* Includes input, room name, and room description.
* Defaults to current room, but can accept a room param.
* Calling the function with params.verbose set to true
* will override global verbosity settings and try to
* print a verbose description.
* <br><br>
* For example:
* <pre class="code">getRoomDescription( { verbose: true } )</pre>
* @method adventurejs.Game#getRoomDescription
* @memberOf adventurejs.Game
* @param {Object} params
* @todo Formalize handling for description/brief/verbose descriptions
*/
p.getRoomDescription = function Game_printRoom(params = {}) {
this.game.log(
"L1584",
"log",
1,
`[getRoomDescription.js] get ${this.world._room} description`,
"Game"
);
const { verbose = false, room = this.world[this.world._room] } = params;
var player = this.game.getPlayer();
var desc = "description";
var v = this.settings.verbosity;
var output = "";
// first get room name
if (room.is.dark && this.game.settings.name_for_dark_rooms) {
output =
output +
`<span class="ajs-p ajs-room-name ajs-dark-room">${this.game.settings.name_for_dark_rooms}</span>`;
} else {
output = output + `<span class="ajs-p ajs-room-name">${room.name}</span>`;
}
// first visit or params.verbose=true used by look / examine
if (
params.verbose ||
(!player.hasSeen(room) &&
this.settings.print_verbose_room_descriptions_on_first_visit)
) {
v = 1;
}
// try to choose a description based on verbosity setting
// ensure that author has written something
if (1 === v && !room.descriptions.verbose) v = 0;
if (-2 === v && !room.descriptions.briefer) v = -1;
if (-1 === v && !room.descriptions.brief) v = 0;
switch (v) {
case -2:
desc = "briefer";
break;
case -1:
desc = "brief";
break;
case 1:
desc = "verbose";
break;
default:
desc = "look";
break;
}
if (params.first && room.hasDescription("firstlook")) desc = "firstlook";
if (room.is.dark) {
desc = "dark";
}
if ("undefined" === typeof room.descriptions[desc]) desc = "look";
output +=
this.game.getModifiedDescription({
asset: room,
identifier: desc,
find_modifiers: true,
fallback_base: false,
}) || this.game.getDescription({ asset: room, identifier: desc });
return output;
};
})();