// debug.js
(function () {
/* global adventurejs A */
var p = adventurejs.Game.prototype;
/**
* Prep the supplied string for printing to the display.
* @method adventurejs.Game#debug
* @memberOf adventurejs.Game
* @param {String} token
*/
p.debug = function Game_print(msg) {
if (!msg) return;
let token_array = msg.split("|").map((token) => token.trim());
let code = token_array[0];
let keyword = token_array[1];
let content = token_array[2];
let hook = ["verbaction", "verbreaction", "verbphase"].includes(
keyword.toLowerCase()
);
if (!hook) keyword = "general";
if (
!this.game.settings.debug_keywords[keyword.toLowerCase()] &&
!this.game.settings.debug_keywords.all
) {
return;
}
let type = hook ? "hook" : "debug";
if (token_array.length > 1) {
msg = `<span class="ajs-${type} ajs-${keyword.toLowerCase()}">`;
for (var i = 0; i < token_array.length; i++) {
if (i === 1 && !this.game.settings.include_filename_in_debug) continue;
msg += `<span class="_${i}">${i === 0 && hook ? keyword : token_array[i]}</span> `;
}
msg += "</span>";
}
if (msg) {
// print to display
this.display.print(msg, "ajs-debug");
}
};
})();