isaacscript-common 13.2.0 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +25 -3
- package/dist/isaacscript-common.lua +11810 -11745
- package/dist/src/callbacks/customRevive.d.ts.map +1 -1
- package/dist/src/callbacks/customRevive.lua +2 -1
- package/dist/src/callbacks/postNewRoomEarly.lua +2 -2
- package/dist/src/classes/ModUpgraded.d.ts +5 -2
- package/dist/src/classes/ModUpgraded.d.ts.map +1 -1
- package/dist/src/classes/ModUpgraded.lua +39 -3
- package/dist/src/core/upgradeMod.d.ts +6 -1
- package/dist/src/core/upgradeMod.d.ts.map +1 -1
- package/dist/src/core/upgradeMod.lua +9 -2
- package/dist/src/features/customStage/exports.lua +2 -2
- package/dist/src/features/extraConsoleCommands/listCommands.lua +5 -5
- package/dist/src/features/pause.lua +2 -2
- package/dist/src/features/saveDataManager/load.d.ts.map +1 -1
- package/dist/src/features/saveDataManager/load.lua +2 -1
- package/dist/src/features/saveDataManager/main.lua +2 -2
- package/dist/src/features/taintedLazarusPlayers.lua +2 -2
- package/dist/src/functions/benchmark.d.ts +12 -0
- package/dist/src/functions/benchmark.d.ts.map +1 -1
- package/dist/src/functions/benchmark.lua +19 -0
- package/dist/src/functions/debugFunctions.d.ts +1 -0
- package/dist/src/functions/debugFunctions.d.ts.map +1 -1
- package/dist/src/functions/debugFunctions.lua +15 -23
- package/dist/src/functions/globals.lua +1 -1
- package/dist/src/functions/hex.lua +2 -2
- package/dist/src/functions/jsonHelpers.lua +2 -2
- package/dist/src/functions/log.d.ts +0 -68
- package/dist/src/functions/log.d.ts.map +1 -1
- package/dist/src/functions/log.lua +3 -496
- package/dist/src/functions/logMisc.d.ts +69 -0
- package/dist/src/functions/logMisc.d.ts.map +1 -0
- package/dist/src/functions/logMisc.lua +498 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.lua +8 -0
- package/package.json +2 -2
- package/src/callbacks/customRevive.ts +2 -1
- package/src/callbacks/postNewRoomEarly.ts +1 -1
- package/src/classes/ModUpgraded.ts +43 -4
- package/src/core/upgradeMod.ts +10 -2
- package/src/features/customStage/exports.ts +1 -1
- package/src/features/extraConsoleCommands/listCommands.ts +1 -1
- package/src/features/pause.ts +1 -1
- package/src/features/saveDataManager/load.ts +2 -1
- package/src/features/saveDataManager/main.ts +1 -1
- package/src/features/taintedLazarusPlayers.ts +1 -1
- package/src/functions/benchmark.ts +23 -0
- package/src/functions/debugFunctions.ts +15 -25
- package/src/functions/globals.ts +1 -1
- package/src/functions/hex.ts +1 -1
- package/src/functions/jsonHelpers.ts +1 -1
- package/src/functions/log.ts +5 -443
- package/src/functions/logMisc.ts +441 -0
- package/src/index.ts +1 -0
package/src/features/pause.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
removeAllTears,
|
|
13
13
|
} from "../functions/entitiesSpecific";
|
|
14
14
|
import { isTear } from "../functions/isaacAPIClass";
|
|
15
|
-
import { logError } from "../functions/
|
|
15
|
+
import { logError } from "../functions/logMisc";
|
|
16
16
|
import { getAllPlayers } from "../functions/playerIndex";
|
|
17
17
|
import { useActiveItemTemp } from "../functions/players";
|
|
18
18
|
import { disableAllInputsExceptFor, enableAllInputs } from "./disableInputs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsonDecode } from "../../functions/jsonHelpers";
|
|
2
|
-
import { log
|
|
2
|
+
import { log } from "../../functions/log";
|
|
3
|
+
import { logError } from "../../functions/logMisc";
|
|
3
4
|
import { iterateTableInOrder } from "../../functions/table";
|
|
4
5
|
import { isString, isTable } from "../../functions/types";
|
|
5
6
|
import { SaveData } from "../../interfaces/SaveData";
|
|
@@ -5,7 +5,7 @@ import { ModCallbackCustom } from "../../enums/ModCallbackCustom";
|
|
|
5
5
|
import { SaveDataKey } from "../../enums/SaveDataKey";
|
|
6
6
|
import { SerializationType } from "../../enums/SerializationType";
|
|
7
7
|
import { deepCopy } from "../../functions/deepCopy";
|
|
8
|
-
import { logError } from "../../functions/
|
|
8
|
+
import { logError } from "../../functions/logMisc";
|
|
9
9
|
import { onFirstFloor } from "../../functions/stage";
|
|
10
10
|
import { clearTable, iterateTableInOrder } from "../../functions/table";
|
|
11
11
|
import { SaveData } from "../../interfaces/SaveData";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { ModCallback, PlayerType } from "isaac-typescript-definitions";
|
|
5
5
|
import { ModUpgraded } from "../classes/ModUpgraded";
|
|
6
6
|
import { errorIfFeaturesNotInitialized } from "../featuresInitialized";
|
|
7
|
-
import { logError } from "../functions/
|
|
7
|
+
import { logError } from "../functions/logMisc";
|
|
8
8
|
import { saveDataManager } from "./saveDataManager/exports";
|
|
9
9
|
|
|
10
10
|
const FEATURE_NAME = "taintedLazarusPlayers";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SECOND_IN_MILLISECONDS } from "../core/constants";
|
|
1
2
|
import { log } from "./log";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -39,3 +40,25 @@ export function benchmark(
|
|
|
39
40
|
|
|
40
41
|
return averages;
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Helper function to get the current time in seconds for benchmarking / profiling purposes.
|
|
46
|
+
*
|
|
47
|
+
* - If the "--luadebug" flag is enabled, then this function will use the `socket.gettime` method,
|
|
48
|
+
* which returns the epoch timestamp in seconds (e.g. "1640320492.5779"). This is preferable over
|
|
49
|
+
* the `Isaac.GetTime` method, since it has one extra decimal point of precision.
|
|
50
|
+
* - If the "--luadebug" flag is disabled, then this function will use the `Isaac.GetTime` method,
|
|
51
|
+
* which returns the number of seconds since the computer's operating system was started (e.g.
|
|
52
|
+
* "739454.963"). (The milliseconds return value of `Isaac.GetTime` is converted to seconds to
|
|
53
|
+
* align with the return value of `socket.gettime`.)
|
|
54
|
+
*/
|
|
55
|
+
export function getTime(): float {
|
|
56
|
+
const [ok, requiredSocket] = pcall(require, "socket");
|
|
57
|
+
if (ok) {
|
|
58
|
+
const socket = requiredSocket as Socket;
|
|
59
|
+
return socket.gettime();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The "--luadebug" launch option is not enabled.
|
|
63
|
+
return Isaac.GetTime() / SECOND_IN_MILLISECONDS;
|
|
64
|
+
}
|
|
@@ -6,6 +6,7 @@ import { saveDataManagerSetGlobal } from "../features/saveDataManager/exports";
|
|
|
6
6
|
import * as logExports from "./log";
|
|
7
7
|
import { log } from "./log";
|
|
8
8
|
import * as logEntitiesExports from "./logEntities";
|
|
9
|
+
import * as logMiscExports from "./logMisc";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Helper function to enable some IsaacScript features that are useful when developing a mod. They
|
|
@@ -27,6 +28,7 @@ import * as logEntitiesExports from "./logEntities";
|
|
|
27
28
|
export function enableDevFeatures(mod: ModUpgraded): void {
|
|
28
29
|
saveDataManagerSetGlobal();
|
|
29
30
|
setLogFunctionsGlobal();
|
|
31
|
+
setTracebackFunctionsGlobal();
|
|
30
32
|
enableExtraConsoleCommands(mod);
|
|
31
33
|
enableFastReset();
|
|
32
34
|
removeFadeIn();
|
|
@@ -45,8 +47,8 @@ export function getTraceback(): string {
|
|
|
45
47
|
return debug.traceback();
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
50
|
+
if (SandboxGetTraceback !== undefined) {
|
|
51
|
+
return SandboxGetTraceback();
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
return 'stack traceback:\n(the "--luadebug" flag is not enabled)';
|
|
@@ -81,13 +83,19 @@ export function isLuaDebugEnabled(): boolean {
|
|
|
81
83
|
export function setLogFunctionsGlobal(): void {
|
|
82
84
|
const globals = _G as Record<string, unknown>;
|
|
83
85
|
|
|
84
|
-
for (const [
|
|
85
|
-
|
|
86
|
+
for (const exports of [logExports, logMiscExports, logEntitiesExports]) {
|
|
87
|
+
// eslint-disable-next-line isaacscript/no-object-any
|
|
88
|
+
for (const [logFuncName, logFunc] of Object.entries(exports)) {
|
|
89
|
+
globals[logFuncName] = logFunc;
|
|
90
|
+
}
|
|
86
91
|
}
|
|
92
|
+
}
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
export function setTracebackFunctionsGlobal(): void {
|
|
95
|
+
const globals = _G as Record<string, unknown>;
|
|
96
|
+
|
|
97
|
+
globals["getTraceback"] = getTraceback;
|
|
98
|
+
globals["traceback"] = traceback;
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
/**
|
|
@@ -101,21 +109,3 @@ export function traceback(): void {
|
|
|
101
109
|
const tracebackOutput = getTraceback();
|
|
102
110
|
log(tracebackOutput);
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
// If the debug functions will provide useful output, make them global by default.
|
|
106
|
-
if (isLuaDebugEnabled() || sandboxGetTraceback !== undefined) {
|
|
107
|
-
setDebugFunctionsGlobal();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function setDebugFunctionsGlobal() {
|
|
111
|
-
// "debug" is not always defined like the Lua definitions imply.
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
113
|
-
if (_G.debug === undefined && sandboxGetTraceback === undefined) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const globals = _G as Record<string, unknown>;
|
|
118
|
-
|
|
119
|
-
globals["getTraceback"] = getTraceback;
|
|
120
|
-
globals["traceback"] = traceback;
|
|
121
|
-
}
|
package/src/functions/globals.ts
CHANGED
package/src/functions/hex.ts
CHANGED
package/src/functions/log.ts
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CollectibleType,
|
|
3
|
-
DamageFlag,
|
|
4
|
-
EntityFlag,
|
|
5
|
-
GameStateFlag,
|
|
6
|
-
GridRoom,
|
|
7
|
-
HeartSubType,
|
|
8
|
-
LevelStateFlag,
|
|
9
|
-
ProjectileFlag,
|
|
10
|
-
SeedEffect,
|
|
11
|
-
SoundEffect,
|
|
12
|
-
TearFlag,
|
|
13
|
-
UseFlag,
|
|
14
|
-
} from "isaac-typescript-definitions";
|
|
15
|
-
import { game, sfxManager } from "../core/cachedClasses";
|
|
16
|
-
import { arrayToString } from "./array";
|
|
17
|
-
import { getCollectibleName } from "./collectibles";
|
|
18
|
-
import { getEntityID } from "./entities";
|
|
19
|
-
import { getEnumEntries } from "./enums";
|
|
20
|
-
import { hasFlag } from "./flag";
|
|
21
|
-
import { getIsaacAPIClassName } from "./isaacAPIClass";
|
|
22
|
-
import { getPlayerHealth } from "./playerHealth";
|
|
23
|
-
import { getEffectsList, getPlayerName } from "./players";
|
|
24
|
-
import { getRoomData, getRoomGridIndex, getRoomListIndex } from "./roomData";
|
|
25
|
-
import { combineSets, getSortedSetValues } from "./set";
|
|
26
|
-
import { iterateTableInOrder } from "./table";
|
|
27
|
-
import { getTrinketName } from "./trinkets";
|
|
28
|
-
import { isTable, isUserdata } from "./types";
|
|
29
|
-
import { printConsole } from "./utils";
|
|
30
|
-
import { vectorToString } from "./vector";
|
|
31
|
-
|
|
32
1
|
/**
|
|
33
2
|
* Helper function to prefix the name of the function and the line number before a debug message.
|
|
34
3
|
*/
|
|
@@ -50,9 +19,12 @@ export function getDebugPrependString(
|
|
|
50
19
|
}
|
|
51
20
|
}
|
|
52
21
|
|
|
53
|
-
if (
|
|
22
|
+
if (SandboxGetParentFunctionDescription !== undefined) {
|
|
54
23
|
// The Racing+ sandbox is enabled.
|
|
55
|
-
|
|
24
|
+
const parentFunctionDescription = SandboxGetParentFunctionDescription(
|
|
25
|
+
numParentFunctions + 1,
|
|
26
|
+
);
|
|
27
|
+
return `${parentFunctionDescription} - ${msg}`;
|
|
56
28
|
}
|
|
57
29
|
|
|
58
30
|
return msg;
|
|
@@ -68,413 +40,3 @@ export function log(msg: string): void {
|
|
|
68
40
|
const debugMsg = getDebugPrependString(msg);
|
|
69
41
|
Isaac.DebugString(debugMsg);
|
|
70
42
|
}
|
|
71
|
-
|
|
72
|
-
export function logArray<T>(array: T[] | readonly T[]): void {
|
|
73
|
-
const arrayString = arrayToString(array);
|
|
74
|
-
log(`Array: ${arrayString}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function logCollectibleTypes(collectibleTypes: CollectibleType[]): void {
|
|
78
|
-
log("Collectibles:");
|
|
79
|
-
|
|
80
|
-
let i = 1;
|
|
81
|
-
for (const collectibleType of collectibleTypes) {
|
|
82
|
-
const collectibleName = getCollectibleName(collectibleType);
|
|
83
|
-
log(`${i}) ${collectibleName} (${collectibleType})`);
|
|
84
|
-
i++;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function logColor(color: Color): void {
|
|
89
|
-
log(
|
|
90
|
-
`Color: R${color.R}, G${color.G}, B${color.B}, A${color.A}, RO${color.RO}, BO${color.BO}, GO${color.GO}`,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Helper function for printing out every damage flag that is turned on. Useful when debugging. */
|
|
95
|
-
export function logDamageFlags(flags: DamageFlag | BitFlags<DamageFlag>): void {
|
|
96
|
-
logFlags(flags, DamageFlag, "damage");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Helper function for printing out every entity flag that is turned on. Useful when debugging. */
|
|
100
|
-
export function logEntityFlags(flags: EntityFlag | BitFlags<EntityFlag>): void {
|
|
101
|
-
logFlags(flags, EntityFlag, "entity");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function logEntityID(entity: Entity): void {
|
|
105
|
-
const entityID = getEntityID(entity);
|
|
106
|
-
log(`Entity: ${entityID}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Helper function to log an error message and also print it to the console for better visibility.
|
|
111
|
-
*
|
|
112
|
-
* This is useful in situations where using the `error` function would be dangerous (since it
|
|
113
|
-
* prevents all of the subsequent code in the callback from running).
|
|
114
|
-
*/
|
|
115
|
-
export function logError(msg: string): void {
|
|
116
|
-
const errorMsg = `Error: ${msg}`;
|
|
117
|
-
log(errorMsg);
|
|
118
|
-
printConsole(errorMsg);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Helper function for printing out every flag that is turned on. Useful when debugging. */
|
|
122
|
-
export function logFlags<T extends BitFlag | BitFlag128>(
|
|
123
|
-
flags: T | BitFlags<T>,
|
|
124
|
-
flagEnum: Record<string, T>,
|
|
125
|
-
description = "",
|
|
126
|
-
): void {
|
|
127
|
-
if (description !== "") {
|
|
128
|
-
description = "flag";
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
132
|
-
log(`Logging ${description} values for: ${flags}`);
|
|
133
|
-
let hasNoFlags = true;
|
|
134
|
-
for (const [key, value] of getEnumEntries(flagEnum)) {
|
|
135
|
-
if (hasFlag(flags, value)) {
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
137
|
-
log(` Has flag: ${key} (${value})`);
|
|
138
|
-
hasNoFlags = false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (hasNoFlags) {
|
|
143
|
-
log(" n/a (no flags)");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Helper function for printing out every game state flag that is turned on. Useful when debugging.
|
|
149
|
-
*/
|
|
150
|
-
export function logGameStateFlags(): void {
|
|
151
|
-
log("Logging game state flags:");
|
|
152
|
-
|
|
153
|
-
const gameStateFlagEntries = getEnumEntries(GameStateFlag);
|
|
154
|
-
|
|
155
|
-
let hasNoFlags = true;
|
|
156
|
-
for (const [key, gameStateFlag] of gameStateFlagEntries) {
|
|
157
|
-
const flagValue = game.GetStateFlag(gameStateFlag);
|
|
158
|
-
if (flagValue) {
|
|
159
|
-
log(` Has flag: ${key} (${gameStateFlag})`);
|
|
160
|
-
hasNoFlags = false;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (hasNoFlags) {
|
|
165
|
-
log(" n/a (no flags)");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function logKColor(kColor: KColor): void {
|
|
170
|
-
log(
|
|
171
|
-
`Color: R${kColor.Red}, G${kColor.Green}, B${kColor.Blue}, A${kColor.Alpha}`,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Helper function for printing out every level state flag that is turned on. Useful when debugging.
|
|
177
|
-
*/
|
|
178
|
-
export function logLevelStateFlags(): void {
|
|
179
|
-
const level = game.GetLevel();
|
|
180
|
-
|
|
181
|
-
const levelStateFlagEntries = getEnumEntries(LevelStateFlag);
|
|
182
|
-
|
|
183
|
-
log("Logging level state flags:");
|
|
184
|
-
let hasNoFlags = true;
|
|
185
|
-
for (const [key, levelStateFlag] of levelStateFlagEntries) {
|
|
186
|
-
const flagValue = level.GetStateFlag(levelStateFlag);
|
|
187
|
-
if (flagValue) {
|
|
188
|
-
log(` Has flag: ${key} (${levelStateFlag})`);
|
|
189
|
-
hasNoFlags = false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (hasNoFlags) {
|
|
194
|
-
log(" n/a (no flags)");
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function logMap(map: Map<AnyNotNil, unknown>): void {
|
|
199
|
-
log("Printing out a TSTL Map:");
|
|
200
|
-
|
|
201
|
-
const mapKeys = [...map.keys()];
|
|
202
|
-
mapKeys.sort();
|
|
203
|
-
|
|
204
|
-
for (const key of mapKeys) {
|
|
205
|
-
const value = map.get(key);
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
207
|
-
log(` ${key} --> ${value}`);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
log(` The size of the map was: ${map.size}`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export function logPlayerEffects(player: EntityPlayer): void {
|
|
214
|
-
const effects = getEffectsList(player);
|
|
215
|
-
|
|
216
|
-
log("Logging player effects:");
|
|
217
|
-
|
|
218
|
-
if (effects.length === 0) {
|
|
219
|
-
log(" n/a (no effects)");
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
effects.forEach((effect, i) => {
|
|
224
|
-
let effectDescription: string;
|
|
225
|
-
if (effect.Item.IsCollectible()) {
|
|
226
|
-
const collectibleName = getCollectibleName(effect.Item.ID);
|
|
227
|
-
effectDescription = `Collectible: ${collectibleName}`;
|
|
228
|
-
} else if (effect.Item.IsTrinket()) {
|
|
229
|
-
const trinketName = getTrinketName(effect.Item.ID);
|
|
230
|
-
effectDescription = `Trinket: ${trinketName}`;
|
|
231
|
-
} else if (effect.Item.IsNull()) {
|
|
232
|
-
effectDescription = `Null item: ${effect.Item.ID}`;
|
|
233
|
-
} else {
|
|
234
|
-
effectDescription = `Unknown type of effect: ${effect.Item.ID}`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
log(` ${i + 1}) ${effectDescription} (x${effect.Count})`);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export function logPlayerHealth(player: EntityPlayer): void {
|
|
242
|
-
const playerName = getPlayerName(player);
|
|
243
|
-
const playerHealth = getPlayerHealth(player);
|
|
244
|
-
|
|
245
|
-
log(`Player health for ${playerName}:`);
|
|
246
|
-
log(` Max hearts: ${playerHealth.maxHearts}`);
|
|
247
|
-
log(` Hearts: ${playerHealth.hearts}`);
|
|
248
|
-
log(` Eternal hearts: ${playerHealth.eternalHearts}`);
|
|
249
|
-
log(` Soul hearts: ${playerHealth.soulHearts}`);
|
|
250
|
-
log(` Bone hearts: ${playerHealth.boneHearts}`);
|
|
251
|
-
log(` Golden hearts: ${playerHealth.goldenHearts}`);
|
|
252
|
-
log(` Rotten hearts: ${playerHealth.rottenHearts}`);
|
|
253
|
-
log(` Broken hearts: ${playerHealth.brokenHearts}`);
|
|
254
|
-
log(` Soul charges: ${playerHealth.soulCharges}`);
|
|
255
|
-
log(` Blood charges: ${playerHealth.bloodCharges}`);
|
|
256
|
-
log(" Soul heart types: [");
|
|
257
|
-
for (const soulHeartType of playerHealth.soulHeartTypes) {
|
|
258
|
-
log(` HeartSubType.${HeartSubType[soulHeartType]}`);
|
|
259
|
-
}
|
|
260
|
-
log(" ]");
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Helper function for printing out every projectile flag that is turned on. Useful when debugging.
|
|
265
|
-
*/
|
|
266
|
-
export function logProjectileFlags(
|
|
267
|
-
flags: ProjectileFlag | BitFlags<ProjectileFlag>,
|
|
268
|
-
): void {
|
|
269
|
-
logFlags(flags, ProjectileFlag, "projectile");
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/** Helper function for logging information about the current room. */
|
|
273
|
-
export function logRoom(): void {
|
|
274
|
-
const room = game.GetRoom();
|
|
275
|
-
const bossID = room.GetBossID();
|
|
276
|
-
const roomGridIndex = getRoomGridIndex();
|
|
277
|
-
const roomListIndex = getRoomListIndex();
|
|
278
|
-
const roomData = getRoomData();
|
|
279
|
-
|
|
280
|
-
log("Current room information:");
|
|
281
|
-
if (roomData === undefined) {
|
|
282
|
-
log("- Room data is undefined.");
|
|
283
|
-
} else {
|
|
284
|
-
log(`- Room stage ID: ${roomData.StageID}`);
|
|
285
|
-
log(
|
|
286
|
-
`- Type/variant/sub-type: ${roomData.Type}.${roomData.Variant}.${roomData.Subtype}`,
|
|
287
|
-
);
|
|
288
|
-
log(`- Name: ${roomData.Name}`);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const roomGridIndexName = GridRoom[roomGridIndex];
|
|
292
|
-
if (roomGridIndexName === undefined) {
|
|
293
|
-
log(`- Grid index: ${roomGridIndex}`);
|
|
294
|
-
} else {
|
|
295
|
-
log(`- Grid index: GridRoom.${roomGridIndexName} (${roomGridIndex})`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
log(`- List index: ${roomListIndex}`);
|
|
299
|
-
log(`- Boss ID: ${bossID}`);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Helper function for printing out every seed effect (i.e. Easter Egg) that is turned on for the
|
|
304
|
-
* particular run.
|
|
305
|
-
*/
|
|
306
|
-
export function logSeedEffects(): void {
|
|
307
|
-
const seeds = game.GetSeeds();
|
|
308
|
-
|
|
309
|
-
const seedEffectEntries = getEnumEntries(SeedEffect);
|
|
310
|
-
|
|
311
|
-
log("Logging seed effects:");
|
|
312
|
-
let hasNoSeedEffects = true;
|
|
313
|
-
for (const [key, seedEffect] of seedEffectEntries) {
|
|
314
|
-
if (seeds.HasSeedEffect(seedEffect)) {
|
|
315
|
-
log(` ${key} (${seedEffect})`);
|
|
316
|
-
hasNoSeedEffects = false;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (hasNoSeedEffects) {
|
|
321
|
-
log(" n/a (no seed effects)");
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function logSet(set: Set<AnyNotNil> | ReadonlySet<AnyNotNil>): void {
|
|
326
|
-
log("Printing out a TSTL Set:");
|
|
327
|
-
|
|
328
|
-
const setValues = getSortedSetValues(set);
|
|
329
|
-
for (const value of setValues) {
|
|
330
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
331
|
-
log(` Value: ${value}`);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
log(` The size of the set was: ${set.size}`);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/** Helper function for logging every sound effect that is currently playing. */
|
|
338
|
-
export function logSounds(): void {
|
|
339
|
-
const soundEffects = getEnumEntries(SoundEffect);
|
|
340
|
-
|
|
341
|
-
for (const [key, soundEffect] of soundEffects) {
|
|
342
|
-
if (sfxManager.IsPlaying(soundEffect)) {
|
|
343
|
-
log(`Currently playing sound effect: ${key} (${soundEffect})`);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Helper function for logging every key and value of a table. This is a deep log; the function will
|
|
350
|
-
* recursively call itself if it counters a table within a table.
|
|
351
|
-
*
|
|
352
|
-
* This function will only work on tables that have string keys (because it logs the keys in order,
|
|
353
|
-
* instead of randomly). It will throw a run-time error if it encounters a non-string key.
|
|
354
|
-
*/
|
|
355
|
-
export function logTable(luaTable: unknown, parentTables = 0): void {
|
|
356
|
-
if (parentTables === 0) {
|
|
357
|
-
log("Printing out a Lua table:");
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const numSpaces = (parentTables + 1) * 2; // 2, 4, 6, etc.
|
|
361
|
-
const indentation = " ".repeat(numSpaces);
|
|
362
|
-
|
|
363
|
-
if (!isTable(luaTable)) {
|
|
364
|
-
// Put it in an IIFE so that it will show as "func" instead of "logTable" and align with the
|
|
365
|
-
// other text. We have to use a non-arrow function to prevent Lua language server errors with
|
|
366
|
-
// the self argument.
|
|
367
|
-
(function func() {
|
|
368
|
-
log(
|
|
369
|
-
`${indentation}n/a (encountered a variable of type "${typeof luaTable}" instead of a table)`,
|
|
370
|
-
);
|
|
371
|
-
})();
|
|
372
|
-
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
let numElements = 0;
|
|
377
|
-
iterateTableInOrder(luaTable, (key, value) => {
|
|
378
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
379
|
-
log(`${indentation}${key} --> ${value}`);
|
|
380
|
-
|
|
381
|
-
if (isTable(value)) {
|
|
382
|
-
if (key === "__class") {
|
|
383
|
-
log(
|
|
384
|
-
`${indentation} (skipping enumerating this key to avoid infinite recursion)`,
|
|
385
|
-
);
|
|
386
|
-
} else {
|
|
387
|
-
logTable(value, parentTables + 1);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
numElements++;
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
// Put it in an IIFE so that it will show as "func" instead of "logTable" and align with the other
|
|
395
|
-
// text. We have to use a non-arrow function to prevent Lua language server errors with the self
|
|
396
|
-
// argument.
|
|
397
|
-
(function func() {
|
|
398
|
-
log(`${indentation}The size of the table was: ${numElements}`);
|
|
399
|
-
})();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Helper function to print out the differences between the entries of two tables. Note that this
|
|
404
|
-
* will only do a shallow comparison.
|
|
405
|
-
*/
|
|
406
|
-
export function logTableDifferences<K extends AnyNotNil, V>(
|
|
407
|
-
table1: LuaMap<K, V>,
|
|
408
|
-
table2: LuaMap<K, V>,
|
|
409
|
-
): void {
|
|
410
|
-
log("Comparing two Lua tables:");
|
|
411
|
-
|
|
412
|
-
const table1Keys = Object.keys(table1);
|
|
413
|
-
const table1KeysSet = new Set(table1Keys);
|
|
414
|
-
|
|
415
|
-
const table2Keys = Object.keys(table2);
|
|
416
|
-
const table2KeysSet = new Set(table2Keys);
|
|
417
|
-
|
|
418
|
-
const keysSet = combineSets(table1KeysSet, table2KeysSet);
|
|
419
|
-
const keys = [...keysSet.values()];
|
|
420
|
-
keys.sort();
|
|
421
|
-
|
|
422
|
-
for (const key of keys) {
|
|
423
|
-
if (!table1KeysSet.has(key)) {
|
|
424
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
425
|
-
log(` Table 1 is missing key: ${key}`);
|
|
426
|
-
} else if (!table2KeysSet.has(key)) {
|
|
427
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
428
|
-
log(` Table 2 is missing key: ${key}`);
|
|
429
|
-
} else {
|
|
430
|
-
const value1 = table1.get(key);
|
|
431
|
-
|
|
432
|
-
const value2 = table2.get(key);
|
|
433
|
-
if (value1 !== value2) {
|
|
434
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
435
|
-
log(` ${key} --> "${value1}" versus "${value2}"`);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
|
|
442
|
-
export function logTearFlags(flags: TearFlag | BitFlags<TearFlag>): void {
|
|
443
|
-
logFlags(flags, TearFlag, "tear");
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/** Helper function for printing out every use flag that is turned on. Useful when debugging. */
|
|
447
|
-
export function logUseFlags(flags: UseFlag | BitFlags<UseFlag>): void {
|
|
448
|
-
logFlags(flags, UseFlag, "use");
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Helper function to enumerate all of the properties of a "userdata" object (i.e. an object from
|
|
453
|
-
* the Isaac API).
|
|
454
|
-
*/
|
|
455
|
-
export function logUserdata(userdata: unknown): void {
|
|
456
|
-
if (!isUserdata(userdata)) {
|
|
457
|
-
log("Userdata: [not userdata]");
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const metatable = getmetatable(userdata);
|
|
462
|
-
if (metatable === undefined) {
|
|
463
|
-
log("Userdata: [no metatable]");
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const classType = getIsaacAPIClassName(userdata);
|
|
468
|
-
if (classType === undefined) {
|
|
469
|
-
log("Userdata: [no class type]");
|
|
470
|
-
} else {
|
|
471
|
-
log(`Userdata: ${classType}`);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
logTable(metatable);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
export function logVector(vector: Vector, round = false): void {
|
|
478
|
-
const vectorString = vectorToString(vector, round);
|
|
479
|
-
log(`Vector: ${vectorString}`);
|
|
480
|
-
}
|