isaacscript-common 13.2.0 → 13.3.1

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