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.
- package/dist/index.d.ts +37 -8
- package/dist/isaacscript-common.lua +6695 -6631
- 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 +9 -70
- package/dist/src/functions/log.d.ts.map +1 -1
- package/dist/src/functions/log.lua +18 -504
- 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/dist/src/indexLua.d.ts +185 -0
- package/dist/src/indexLua.d.ts.map +1 -0
- package/dist/src/indexLua.lua +1314 -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 +50 -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 +24 -455
- package/src/functions/logMisc.ts +441 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"main": "dist/src/index",
|
|
23
23
|
"types": "dist/src/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"isaac-typescript-definitions": "^7.2.
|
|
25
|
+
"isaac-typescript-definitions": "^7.2.9"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -16,7 +16,8 @@ import { runNextGameFrame } from "../features/runInNFrames";
|
|
|
16
16
|
import { saveDataManager } from "../features/saveDataManager/exports";
|
|
17
17
|
import { removeCollectibleFromItemTracker } from "../functions/collectibles";
|
|
18
18
|
import { removeAllFamiliars } from "../functions/entitiesSpecific";
|
|
19
|
-
import { log
|
|
19
|
+
import { log } from "../functions/log";
|
|
20
|
+
import { logError } from "../functions/logMisc";
|
|
20
21
|
import { getPlayerFromIndex, getPlayerIndex } from "../functions/playerIndex";
|
|
21
22
|
import { isCharacter } from "../functions/players";
|
|
22
23
|
import { PlayerIndex } from "../types/PlayerIndex";
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getTopLeftWallGridIndex,
|
|
9
9
|
spawnGridEntity,
|
|
10
10
|
} from "../functions/gridEntities";
|
|
11
|
-
import { logError } from "../functions/
|
|
11
|
+
import { logError } from "../functions/logMisc";
|
|
12
12
|
import {
|
|
13
13
|
postNewRoomEarlyFire,
|
|
14
14
|
postNewRoomEarlyHasSubscriptions,
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
2
|
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
3
|
+
import { getTime } from "../functions/benchmark";
|
|
4
|
+
import { getParentFunctionDescription } from "../functions/log";
|
|
3
5
|
import { AddCallbackParameterCustom } from "../interfaces/private/AddCallbackParameterCustom";
|
|
4
6
|
import { CALLBACK_REGISTER_FUNCTIONS } from "../objects/callbackRegisterFunctions";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* `isaacscript-common` has many custom callbacks that you can use in your mods. Instead of
|
|
8
10
|
* hijacking the vanilla `Mod` object, we provide a `ModUpgraded` object for you to use, which
|
|
9
|
-
* extends the base class and adds a new method of `AddCallbackCustom`.
|
|
11
|
+
* extends the base class and adds a new method of `AddCallbackCustom`. (There is no corresponding
|
|
12
|
+
* `RemoveCallbackCustom`.)
|
|
10
13
|
*
|
|
11
14
|
* To upgrade your mod, use the `upgradeMod` helper function.
|
|
12
15
|
*/
|
|
@@ -28,10 +31,14 @@ export class ModUpgraded implements Mod {
|
|
|
28
31
|
/** We store a copy of the original mod object so that we can re-implement its functions. */
|
|
29
32
|
Mod: Mod;
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
Debug: boolean;
|
|
35
|
+
TimeThreshold: float | undefined;
|
|
33
36
|
|
|
37
|
+
constructor(mod: Mod, debug: boolean, timeThreshold?: float) {
|
|
38
|
+
this.Name = mod.Name;
|
|
34
39
|
this.Mod = mod;
|
|
40
|
+
this.Debug = debug;
|
|
41
|
+
this.TimeThreshold = timeThreshold;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
// ---------------
|
|
@@ -42,7 +49,46 @@ export class ModUpgraded implements Mod {
|
|
|
42
49
|
modCallback: T,
|
|
43
50
|
...args: AddCallbackParameter[T]
|
|
44
51
|
): void {
|
|
45
|
-
this.
|
|
52
|
+
if (this.Debug) {
|
|
53
|
+
const callback = args[0];
|
|
54
|
+
const optionalArg = args[1];
|
|
55
|
+
|
|
56
|
+
const parentFunctionDescription = getParentFunctionDescription();
|
|
57
|
+
const callbackName = `ModCallback.${ModCallback[modCallback]}`;
|
|
58
|
+
const signature =
|
|
59
|
+
parentFunctionDescription === undefined
|
|
60
|
+
? callbackName
|
|
61
|
+
: `${parentFunctionDescription} - ${callbackName}`;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* We don't use the "log" helper function since it will always show the same "unknown" prefix.
|
|
65
|
+
*/
|
|
66
|
+
const callbackWithLogger = (...callbackArgs: unknown[]) => {
|
|
67
|
+
const startTime = getTime();
|
|
68
|
+
Isaac.DebugString(`${signature} - START`);
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
callback(...callbackArgs);
|
|
73
|
+
|
|
74
|
+
const endTime = getTime();
|
|
75
|
+
const elapsedTime = endTime - startTime;
|
|
76
|
+
if (
|
|
77
|
+
this.TimeThreshold === undefined ||
|
|
78
|
+
this.TimeThreshold >= elapsedTime
|
|
79
|
+
) {
|
|
80
|
+
Isaac.DebugString(`${signature} - END - time: ${elapsedTime}`);
|
|
81
|
+
} else {
|
|
82
|
+
Isaac.DebugString(`${signature} - END`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
this.Mod.AddCallback(modCallback, callbackWithLogger, optionalArg);
|
|
89
|
+
} else {
|
|
90
|
+
this.Mod.AddCallback(modCallback, ...args);
|
|
91
|
+
}
|
|
46
92
|
}
|
|
47
93
|
|
|
48
94
|
HasData(): boolean {
|
package/src/core/upgradeMod.ts
CHANGED
|
@@ -28,10 +28,18 @@ import { loadShaderCrashFix } from "../shaderCrashFix";
|
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* @param modVanilla The mod object returned by the `RegisterMod` function.
|
|
31
|
+
* @param debug Optional. Whether to log additional output when a callback is fired. Default is
|
|
32
|
+
* false.
|
|
33
|
+
* @param timeThreshold Optional. If provided, will only log callbacks that take longer than the
|
|
34
|
+
* specified number of seconds.
|
|
31
35
|
* @returns The upgraded mod object.
|
|
32
36
|
*/
|
|
33
|
-
export function upgradeMod(
|
|
34
|
-
|
|
37
|
+
export function upgradeMod(
|
|
38
|
+
modVanilla: Mod,
|
|
39
|
+
debug = false,
|
|
40
|
+
timeThreshold?: float,
|
|
41
|
+
): ModUpgraded {
|
|
42
|
+
const mod = new ModUpgraded(modVanilla, debug, timeThreshold);
|
|
35
43
|
|
|
36
44
|
if (!areFeaturesInitialized()) {
|
|
37
45
|
setFeaturesInitialized();
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import { reorderedCallbacksSetStageInternal } from "../../callbacks/reorderedCallbacks";
|
|
17
17
|
import { game } from "../../core/cachedClasses";
|
|
18
18
|
import { doorSlotFlagsToDoorSlots } from "../../functions/doors";
|
|
19
|
-
import { logError } from "../../functions/
|
|
19
|
+
import { logError } from "../../functions/logMisc";
|
|
20
20
|
import { newRNG } from "../../functions/rng";
|
|
21
21
|
import {
|
|
22
22
|
getRoomDataForTypeVariant,
|
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