// 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 { verbose = false, room = this.world[this.world._room] } = params;
var player = this.game.getPlayer();
var desc = "description";
var v = this.settings.verbosity;
var msg = "";
// first print room name
if (room.is.dark && this.game.settings.name_for_dark_rooms) {
this.print(
this.game.settings.name_for_dark_rooms,
"ajs-dark-room ajs-room-name"
);
} else {
this.print(room.name, "ajs-room-name");
}
// 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 (room.is.dark) {
desc = "dark";
}
if ("undefined" === typeof room.descriptions[desc]) desc = "look";
msg +=
this.game.getModifiedDescription({
asset: room,
identifier: desc,
find_modifiers: true,
fallback_base: false,
}) || this.game.getDescription({ asset: room, identifier: desc });
let description = "";
description = this.print(
msg,
`${room.is.dark ? "ajs-dark-room" : ""} ajs-room-description`
);
console.warn({ description });
let dockmsg = `<div class="ajs-room-description-container">${description}</div>`;
let exits = "";
if (this.game.settings.print_room_exits && !room.is.dark) {
exits = this.printRoomExits();
}
if (exits)
dockmsg = dockmsg + `<div class="ajs-exits-container">${exits}</div>`;
let contents = "";
if (this.game.settings.print_room_contents && !room.is.dark) {
contents = this.printRoomContents();
}
if (contents)
dockmsg =
dockmsg + `<div class="ajs-contents-container">${contents}</div>`;
dockmsg = `<div class="ajs-roomdock-output ajs-output">${dockmsg}</div>`;
for (let item in this.display.roomdocks) {
let dock = this.display.roomdocks[item];
console.warn({ dock });
dock.innerHTML = dockmsg;
}
return this;
};
})();