1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
////////////////////////////////////////////////////////////////////////////////
// Debugging helpers.
////////////////////////////////////////////////////////////////////////////////
//;; ## camMarkTiles(label|labels)
//;;
//;; Mark area on the map by label(s), but only if debug mode is enabled.
//;; Otherwise, remember what to mark in case it is going to be.
//;;
//;; @param {string|string[]} label
//;; @returns {void}
//;;
function camMarkTiles(label)
{
if (camIsString(label))
{
__camMarkedTiles[label] = true;
}
else
{
for (let i = 0, l = label.length; i < l; ++i)
{
__camMarkedTiles[label[i]] = true;
}
}
// apply instantly
__camUpdateMarkedTiles();
}
//;; ## camUnmarkTiles(label|labels)
//;;
//;; No longer mark area(s) with given label(s) in debug mode.
//;;
//;; @param {string|string[]} label
//;; @returns {void}
//;;
function camUnmarkTiles(label)
{
if (camIsString(label))
{
delete __camMarkedTiles[label];
}
else
{
for (let i = 0, l = label.length; i < l; ++i)
{
delete __camMarkedTiles[label[i]];
}
}
// apply instantly
__camUpdateMarkedTiles();
}
//;; ## camDebug(...args)
//;;
//;; Pretty debug prints - a wrapper around `debug()`.
//;; Prints a function call stack and the argument message, prefixed with `DEBUG`.
//;; Only use this function to indicate actual bugs in the scenario script,
//;; because game shouldn't print things when nothing is broken.
//;; If you want to keep some prints around to make debugging easier
//;; without distracting the user, use `camTrace()`.
//;;
//;; @param {...string} args
//;; @returns {void}
//;;
function camDebug(...args)
{
__camGenericDebug("DEBUG", debugGetCallerFuncName(), args, true, __camBacktrace());
}
//;; ## camDebugOnce(...args)
//;;
//;; Same as `camDebug()`, but prints each message only once during script lifetime.
//;;
//;; @param {...string} args
//;; @returns {void}
//;;
function camDebugOnce(...args)
{
const __STR = debugGetCallerFuncName() + ": " + args.join(" ");
if (camDef(__camDebuggedOnce[__STR]))
{
return;
}
__camDebuggedOnce[__STR] = true;
__camGenericDebug("DEBUG", debugGetCallerFuncName(), args, true, __camBacktrace());
}
//;; ## camTrace(...args)
//;;
//;; Same as `camDebug()`, but only warns in cheat mode.
//;; Prefixed with `TRACE`. It's safe and natural to keep `camTrace()` calls in your code for easier debugging.
//;;
//;; @param {...string} args
//;; @returns {void}
//;;
function camTrace(...args)
{
if (!camIsCheating())
{
return;
}
__camGenericDebug("TRACE", debugGetCallerFuncName(), args);
}
//;; ## camTraceOnce(...args)
//;;
//;; Same as `camTrace()`, but prints each message only once during script lifetime.
//;;
//;; @param {...string} args
//;; @returns {void}
//;;
function camTraceOnce(...args)
{
if (!camIsCheating())
{
return;
}
const __STR = debugGetCallerFuncName() + ": " + args.join(" ");
if (camDef(__camTracedOnce[__STR]))
{
return;
}
__camTracedOnce[__STR] = true;
__camGenericDebug("TRACE", debugGetCallerFuncName(), args);
}
//;; ## camIsCheating()
//;;
//;; Check if the player is in cheat mode.
//;;
//;; @returns {boolean}
//;;
function camIsCheating()
{
return __camCheatMode;
}
//////////// privates
function __camUpdateMarkedTiles()
{
hackMarkTiles();
if (camIsCheating() && camDef(__camMarkedTiles))
{
for (const label in __camMarkedTiles)
{
hackMarkTiles(label);
}
}
}
function __camLetMeWin()
{
__camLetMeWinArtifacts();
hackMarkTiles(); // clear marked tiles, as they may actually remain
__camGameWon();
}
function __camGenericDebug(flag, functionName, args, err, backtrace)
{
if (camDef(backtrace) && backtrace)
{
for (let i = backtrace.length - 1; i >= 0; --i)
{
debug("STACK: from", [backtrace[i]]);
}
}
if (!functionName)
{
functionName = "<anonymous>";
}
const __STR = flag + ": " + functionName + ": " + Array.prototype.join.call(args, " ");
debug(__STR);
if (camDef(err) && err)
{
dump(__STR);
}
}
function __camBacktrace()
{
return debugGetBacktrace();
}
|