// printRoom.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Game.prototype;
/**
* Print room description 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">printRoom( { verbose: true } )</pre>
* @method AdventureJS.Game#printRoom
* @memberOf AdventureJS.Game
* @param {Object} params
* @todo Formalize handling for description/brief/verbose descriptions
*/
p.printRoom = function Game_printRoom(params = {}) {
this.game.log(
"L1083",
"log",
1,
`[printRoom.js] print ${this.world._room} description`,
"Game"
);
const {
first = false,
verbose = false,
room = this.game.world[this.game.world._room],
} = params;
let exits = "";
let contents = "";
let exits_and_contents = [];
// --------------------------------------------------
// Get game and room settings
// --------------------------------------------------
const print_exits =
(room.print_room_exits ||
(room.print_room_exits !== false &&
this.game.settings.print_room_exits)) &&
!room.isDark();
const print_room_contents =
(room.print_room_contents ||
(room.print_room_contents !== false &&
this.game.settings.print_room_contents)) &&
!room.isDark();
const print_contents_before_exits =
room.print_contents_before_exits ||
(room.print_contents_before_exits !== false &&
this.game.settings.print_contents_before_exits);
// --------------------------------------------------
// Print room description
// --------------------------------------------------
this.game.print(this.game.getRoomDescription(params));
// --------------------------------------------------
// Set room exits
// --------------------------------------------------
if (print_exits) {
exits = this.game.getRoomExits();
exits_and_contents.push(exits);
}
// --------------------------------------------------
// Set room contents
// --------------------------------------------------
if (print_room_contents) {
contents = this.game.getPrintableRoomContents();
if (print_contents_before_exits) {
exits_and_contents.unshift(contents);
} else {
exits_and_contents.push(contents);
}
}
// --------------------------------------------------
// Print contents and exits
// --------------------------------------------------
for (let i = 0; i < exits_and_contents.length; i++) {
this.game.print(exits_and_contents[i]);
}
return this;
};
})();