isaacscript-common 14.1.1 → 14.1.3
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 -22
- package/dist/isaacscript-common.lua +135 -64
- package/dist/src/callbacks.d.ts +1 -1
- package/dist/src/callbacks.d.ts.map +1 -1
- package/dist/src/callbacks.lua +7 -16
- package/dist/src/classes/ModFeature.d.ts +16 -4
- package/dist/src/classes/ModFeature.d.ts.map +1 -1
- package/dist/src/classes/ModFeature.lua +46 -4
- package/dist/src/classes/ModUpgraded.d.ts +2 -7
- package/dist/src/classes/ModUpgraded.d.ts.map +1 -1
- package/dist/src/classes/ModUpgraded.lua +28 -6
- package/dist/src/classes/private/Feature.d.ts +0 -1
- package/dist/src/classes/private/Feature.d.ts.map +1 -1
- package/dist/src/classes/private/Feature.lua +0 -1
- package/dist/src/core/upgradeMod.d.ts +2 -5
- package/dist/src/core/upgradeMod.d.ts.map +1 -1
- package/dist/src/core/upgradeMod.lua +2 -2
- package/dist/src/decorators.d.ts +2 -1
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.lua +8 -1
- package/dist/src/functions/decorators.d.ts +7 -6
- package/dist/src/functions/decorators.d.ts.map +1 -1
- package/dist/src/functions/decorators.lua +24 -5
- package/dist/src/functions/logMisc.d.ts +9 -2
- package/dist/src/functions/logMisc.d.ts.map +1 -1
- package/dist/src/functions/logMisc.lua +32 -2
- package/dist/src/functions/tstlClass.d.ts +0 -2
- package/dist/src/functions/tstlClass.d.ts.map +1 -1
- package/dist/src/functions/tstlClass.lua +0 -19
- package/dist/src/interfaces/TSTLClassMetatable.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/callbacks.ts +9 -9
- package/src/classes/ModFeature.ts +66 -6
- package/src/classes/ModUpgraded.ts +51 -12
- package/src/classes/private/Feature.ts +0 -2
- package/src/core/upgradeMod.ts +6 -11
- package/src/decorators.ts +20 -2
- package/src/functions/decorators.ts +61 -12
- package/src/functions/logMisc.ts +28 -2
- package/src/functions/tstlClass.ts +0 -15
- package/src/interfaces/TSTLClassMetatable.ts +1 -0
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
|
-
import { ISCFeature } from "../enums/ISCFeature";
|
|
3
2
|
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
4
3
|
import { ModCallbackCustom2 } from "../enums/ModCallbackCustom2";
|
|
5
4
|
import { AddCallbackParametersCustom } from "../interfaces/private/AddCallbackParametersCustom";
|
|
6
5
|
import { AddCallbackParametersCustom2 } from "../interfaces/private/AddCallbackParametersCustom2";
|
|
7
|
-
import { FunctionTuple } from "../types/FunctionTuple";
|
|
8
6
|
/**
|
|
9
7
|
* `isaacscript-common` has many custom callbacks that you can use in your mods. Instead of
|
|
10
8
|
* hijacking the vanilla `Mod` object, we provide a `ModUpgraded` object for you to use, which
|
|
@@ -65,13 +63,10 @@ export declare class ModUpgraded implements Mod {
|
|
|
65
63
|
* conditions of how you registered the callback, it will be removed.
|
|
66
64
|
*/
|
|
67
65
|
RemoveCallbackCustom<T extends ModCallbackCustom2>(modCallbackCustom: T, callback: AddCallbackParametersCustom2[T][0]): void;
|
|
68
|
-
/**
|
|
69
|
-
* This method should only be used by the `upgradeMod` function. Returns the class methods from
|
|
70
|
-
* the features that were added.
|
|
71
|
-
*/
|
|
72
|
-
initOptionalFeature(feature: ISCFeature): FunctionTuple[];
|
|
73
66
|
/** This is used to initialize both custom callbacks and "extra features". */
|
|
74
67
|
private initFeature;
|
|
75
68
|
private uninitFeature;
|
|
69
|
+
/** Returns the names of the exported class methods from the features that were added. */
|
|
70
|
+
private initOptionalFeature;
|
|
76
71
|
}
|
|
77
72
|
//# sourceMappingURL=ModUpgraded.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModUpgraded.d.ts","sourceRoot":"","sources":["../../../src/classes/ModUpgraded.ts"],"names":[],"mappings":"AAAA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SAAS,iBAAiB,EAClD,iBAAiB,EAAE,CAAC,EACpB,GAAG,IAAI,EAAE,2BAA2B,CAAC,CAAC,CAAC,GACtC,IAAI;IAMP,wFAAwF;IACjF,kBAAkB,CAAC,CAAC,SAAS,kBAAkB,EACpD,iBAAiB,EAAE,CAAC,EACpB,GAAG,IAAI,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACvC,IAAI;IAOP;;;;;OAKG;IACI,oBAAoB,CAAC,CAAC,SAAS,kBAAkB,EACtD,iBAAiB,EAAE,CAAC,EACpB,QAAQ,EAAE,4BAA4B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC3C,IAAI;IAaP,6EAA6E;IAC7E,OAAO,CAAC,WAAW;IAoCnB,OAAO,CAAC,aAAa;IAsCrB,yFAAyF;IACzF,OAAO,CAAC,mBAAmB;CAM5B"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
3
|
local __TS__Spread = ____lualib.__TS__Spread
|
|
4
|
+
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
|
|
4
5
|
local ____exports = {}
|
|
6
|
+
local getExportedMethodsFromFeature
|
|
5
7
|
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
6
8
|
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
|
|
7
9
|
local ____callbacks = require("src.callbacks")
|
|
8
10
|
local getCallbacks = ____callbacks.getCallbacks
|
|
11
|
+
local ____decorators = require("src.decorators")
|
|
12
|
+
local EXPORTED_METHOD_NAMES_KEY = ____decorators.EXPORTED_METHOD_NAMES_KEY
|
|
9
13
|
local ____features = require("src.features")
|
|
10
14
|
local getFeatures = ____features.getFeatures
|
|
11
15
|
local ____exports = require("src.features.saveDataManager.exports")
|
|
@@ -16,10 +20,28 @@ local getTime = ____debugFunctions.getTime
|
|
|
16
20
|
local ____log = require("src.functions.log")
|
|
17
21
|
local getParentFunctionDescription = ____log.getParentFunctionDescription
|
|
18
22
|
local ____tstlClass = require("src.functions.tstlClass")
|
|
19
|
-
local
|
|
23
|
+
local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
|
|
20
24
|
local getTSTLClassName = ____tstlClass.getTSTLClassName
|
|
21
25
|
local ____callbackRegisterFunctions = require("src.objects.callbackRegisterFunctions")
|
|
22
26
|
local CALLBACK_REGISTER_FUNCTIONS = ____callbackRegisterFunctions.CALLBACK_REGISTER_FUNCTIONS
|
|
27
|
+
function getExportedMethodsFromFeature(self, featureClass)
|
|
28
|
+
local constructor = getTSTLClassConstructor(nil, featureClass)
|
|
29
|
+
local exportedMethodNames = constructor[EXPORTED_METHOD_NAMES_KEY]
|
|
30
|
+
return __TS__ArrayMap(
|
|
31
|
+
exportedMethodNames,
|
|
32
|
+
function(____, name)
|
|
33
|
+
local featureClassRecord = featureClass
|
|
34
|
+
local method = featureClassRecord[name]
|
|
35
|
+
if method == nil then
|
|
36
|
+
error("Failed to find a decorated exported method: " .. name)
|
|
37
|
+
end
|
|
38
|
+
local function wrappedMethod(____, ...)
|
|
39
|
+
return featureClassRecord[name](featureClassRecord, ...)
|
|
40
|
+
end
|
|
41
|
+
return {name, wrappedMethod}
|
|
42
|
+
end
|
|
43
|
+
)
|
|
44
|
+
end
|
|
23
45
|
--- `isaacscript-common` has many custom callbacks that you can use in your mods. Instead of
|
|
24
46
|
-- hijacking the vanilla `Mod` object, we provide a `ModUpgraded` object for you to use, which
|
|
25
47
|
-- extends the base class and adds a new method of `AddCallbackCustom`.
|
|
@@ -102,11 +124,6 @@ function ModUpgraded.prototype.RemoveCallbackCustom(self, modCallbackCustom, cal
|
|
|
102
124
|
self:uninitFeature(callbackClass)
|
|
103
125
|
end
|
|
104
126
|
end
|
|
105
|
-
function ModUpgraded.prototype.initOptionalFeature(self, feature)
|
|
106
|
-
local featureClass = self.features[feature]
|
|
107
|
-
self:initFeature(featureClass)
|
|
108
|
-
return getTSTLClassMethods(nil, featureClass)
|
|
109
|
-
end
|
|
110
127
|
function ModUpgraded.prototype.initFeature(self, feature)
|
|
111
128
|
if feature.initialized then
|
|
112
129
|
return
|
|
@@ -177,4 +194,9 @@ function ModUpgraded.prototype.uninitFeature(self, feature)
|
|
|
177
194
|
saveDataManagerRemove(nil, className)
|
|
178
195
|
end
|
|
179
196
|
end
|
|
197
|
+
function ModUpgraded.prototype.initOptionalFeature(self, feature)
|
|
198
|
+
local featureClass = self.features[feature]
|
|
199
|
+
self:initFeature(featureClass)
|
|
200
|
+
return getExportedMethodsFromFeature(nil, featureClass)
|
|
201
|
+
end
|
|
180
202
|
return ____exports
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../../../../src/classes/private/Feature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,aAAa,EACb,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;GAMG;AACH,qBAAa,OAAO;IACX,WAAW,UAAS;IAEpB,CAAC,CAAC,EAAE,QAAQ,CAAC;IACb,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,mBAAmB,CAAC,EAAE,mBAAmB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../../../../src/classes/private/Feature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,aAAa,EACb,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;GAMG;AACH,qBAAa,OAAO;IACX,WAAW,UAAS;IAEpB,CAAC,CAAC,EAAE,QAAQ,CAAC;IACb,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,mBAAmB,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACpD"}
|
|
@@ -4,17 +4,14 @@ import { ModUpgraded } from "../classes/ModUpgraded";
|
|
|
4
4
|
import { Feature } from "../classes/private/Feature";
|
|
5
5
|
import { ISCFeature } from "../enums/ISCFeature";
|
|
6
6
|
import { ISCFeatureToClass } from "../features";
|
|
7
|
-
import { LowercaseKeys } from "../types/LowercaseKeys";
|
|
8
7
|
import { UnionToIntersection } from "../types/UnionToIntersection";
|
|
9
8
|
/**
|
|
10
9
|
* By specifying one or more optional features, end-users will get a version of `ModUpgraded` that
|
|
11
10
|
* has extra methods corresponding to the features.
|
|
12
11
|
*
|
|
13
|
-
* We have to explicitly account for the empty array case, since `never` will
|
|
14
|
-
* union.
|
|
12
|
+
* We have to explicitly account for the empty array case, since the `never` will mess up the union.
|
|
15
13
|
*/
|
|
16
|
-
declare type ModUpgradedWithFeatures<T extends ISCFeature> = [T] extends [never] ? ModUpgraded :
|
|
17
|
-
declare type KeysToScrubFromModClass = keyof Feature | LowercaseKeys<ModUpgraded>;
|
|
14
|
+
declare type ModUpgradedWithFeatures<T extends ISCFeature> = [T] extends [never] ? ModUpgraded : ModUpgraded & Omit<UnionToIntersection<ISCFeatureToClass[T]>, keyof Feature>;
|
|
18
15
|
/**
|
|
19
16
|
* Use this function to enable the custom callbacks and other optional features provided by
|
|
20
17
|
* `isaacscript-common`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgradeMod.d.ts","sourceRoot":"","sources":["../../../src/core/upgradeMod.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAchD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"upgradeMod.d.ts","sourceRoot":"","sources":["../../../src/core/upgradeMod.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAchD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;;;;GAKG;AACH,aAAK,uBAAuB,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpE,WAAW,GACX,WAAW,GACT,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,GAAG,KAAK,EACrD,UAAU,EAAE,GAAG,EACf,QAAQ,GAAE,CAAC,EAAO,EAClB,KAAK,UAAQ,EACb,aAAa,CAAC,EAAE,KAAK,GACpB,uBAAuB,CAAC,CAAC,CAAC,CA+B5B"}
|
|
@@ -82,9 +82,9 @@ function ____exports.upgradeMod(self, modVanilla, features, ____debug, timeThres
|
|
|
82
82
|
loadShaderCrashFix(nil, modVanilla)
|
|
83
83
|
legacyInit(nil, mod)
|
|
84
84
|
for ____, feature in ipairs(features) do
|
|
85
|
-
local
|
|
85
|
+
local exportedMethodTuples = mod:initOptionalFeature(feature)
|
|
86
86
|
local modRecord = mod
|
|
87
|
-
for ____, ____value in ipairs(
|
|
87
|
+
for ____, ____value in ipairs(exportedMethodTuples) do
|
|
88
88
|
local funcName = ____value[1]
|
|
89
89
|
local func = ____value[2]
|
|
90
90
|
modRecord[funcName] = func
|
package/dist/src/decorators.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Feature } from "./classes/private/Feature";
|
|
2
|
+
export declare const EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
|
|
2
3
|
/**
|
|
3
4
|
* A decorator function that signifies that the decorated class method should be added to the
|
|
4
5
|
* `ModUpgraded` object.
|
|
5
6
|
*
|
|
6
7
|
* This is only meant to be used internally.
|
|
7
8
|
*/
|
|
8
|
-
export declare function Exported(): <
|
|
9
|
+
export declare function Exported(): <Class extends Feature>(target: Class, propertyKey: keyof Class) => void;
|
|
9
10
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,QAAQ,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,QAAQ,wEAInB,IAAI,CAgBR"}
|
package/dist/src/decorators.lua
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
local ____exports = {}
|
|
2
|
+
____exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames"
|
|
2
3
|
--- A decorator function that signifies that the decorated class method should be added to the
|
|
3
4
|
-- `ModUpgraded` object.
|
|
4
5
|
--
|
|
5
6
|
-- This is only meant to be used internally.
|
|
6
7
|
function ____exports.Exported(self)
|
|
7
|
-
return function(____,
|
|
8
|
+
return function(____, target, propertyKey)
|
|
9
|
+
local constructor = target.constructor
|
|
10
|
+
if not (constructor[____exports.EXPORTED_METHOD_NAMES_KEY] ~= nil) then
|
|
11
|
+
constructor[____exports.EXPORTED_METHOD_NAMES_KEY] = {}
|
|
12
|
+
end
|
|
13
|
+
local exportedMethodNames = constructor[____exports.EXPORTED_METHOD_NAMES_KEY]
|
|
14
|
+
exportedMethodNames[#exportedMethodNames + 1] = propertyKey
|
|
8
15
|
end
|
|
9
16
|
end
|
|
10
17
|
return ____exports
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
2
|
import { ModFeature } from "../classes/ModFeature";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { AddCallbackParametersCustom2 } from "../interfaces/private/AddCallbackParametersCustom2";
|
|
3
|
+
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
4
|
+
import { AddCallbackParametersCustom } from "../interfaces/private/AddCallbackParametersCustom";
|
|
6
5
|
import { AllButFirst } from "../types/AllButFirst";
|
|
7
6
|
/**
|
|
8
7
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
9
8
|
* registered with `Mod.AddCallback`.
|
|
9
|
+
*
|
|
10
|
+
* @ignore
|
|
10
11
|
*/
|
|
11
12
|
export declare function Callback<T extends ModCallback>(modCallback: T, ...optionalArgs: AllButFirst<AddCallbackParameters[T]>): <Class extends ModFeature, Fn extends AddCallbackParameters[T][0]>(target: Class, propertyKey: string, _descriptor: TypedPropertyDescriptor<Fn>) => void;
|
|
12
13
|
/**
|
|
13
14
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
14
15
|
* registered with `ModUpgraded.AddCallbackCustom`.
|
|
16
|
+
*
|
|
17
|
+
* @ignore
|
|
15
18
|
*/
|
|
16
|
-
export declare function CallbackCustom<T extends
|
|
17
|
-
mod: ModUpgraded;
|
|
18
|
-
}>(target: Class, propertyKey: string) => void;
|
|
19
|
+
export declare function CallbackCustom<T extends ModCallbackCustom>(modCallbackCustom: T, ...optionalArgs: AllButFirst<AddCallbackParametersCustom[T]>): <Class extends ModFeature, Fn extends AddCallbackParametersCustom[T][0]>(target: Class, propertyKey: string, _descriptor: TypedPropertyDescriptor<Fn>) => void;
|
|
19
20
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/functions/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/functions/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAGL,UAAU,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,EAC5C,WAAW,EAAE,CAAC,EACd,GAAG,YAAY,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,kGAIvC,MAAM,+CAElB,IAAI,CAwBR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,iBAAiB,EACxD,iBAAiB,EAAE,CAAC,EACpB,GAAG,YAAY,EAAE,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,wGAO7C,MAAM,+CAElB,IAAI,CA0BR"}
|
|
@@ -1,32 +1,51 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Spread = ____lualib.__TS__Spread
|
|
3
3
|
local ____exports = {}
|
|
4
|
+
local ____ModFeature = require("src.classes.ModFeature")
|
|
5
|
+
local ADD_CALLBACK_ARGS_KEY = ____ModFeature.ADD_CALLBACK_ARGS_KEY
|
|
6
|
+
local ADD_CALLBACK_CUSTOM_ARGS_KEY = ____ModFeature.ADD_CALLBACK_CUSTOM_ARGS_KEY
|
|
4
7
|
--- A decorator function that signifies that the decorated class method should be automatically
|
|
5
8
|
-- registered with `Mod.AddCallback`.
|
|
9
|
+
--
|
|
10
|
+
-- @ignore
|
|
6
11
|
function ____exports.Callback(self, modCallback, ...)
|
|
7
12
|
local optionalArgs = {...}
|
|
8
13
|
return function(____, target, propertyKey, _descriptor)
|
|
9
14
|
local methodName = propertyKey
|
|
10
15
|
local method = target[methodName]
|
|
11
|
-
|
|
16
|
+
local addCallbackArgs = {
|
|
12
17
|
modCallback,
|
|
13
18
|
method,
|
|
14
19
|
__TS__Spread(optionalArgs)
|
|
15
|
-
|
|
20
|
+
}
|
|
21
|
+
local constructor = target.constructor
|
|
22
|
+
if not (constructor[ADD_CALLBACK_ARGS_KEY] ~= nil) then
|
|
23
|
+
constructor[ADD_CALLBACK_ARGS_KEY] = {}
|
|
24
|
+
end
|
|
25
|
+
local callbackTuples = constructor[ADD_CALLBACK_ARGS_KEY]
|
|
26
|
+
callbackTuples[#callbackTuples + 1] = addCallbackArgs
|
|
16
27
|
end
|
|
17
28
|
end
|
|
18
29
|
--- A decorator function that signifies that the decorated class method should be automatically
|
|
19
30
|
-- registered with `ModUpgraded.AddCallbackCustom`.
|
|
31
|
+
--
|
|
32
|
+
-- @ignore
|
|
20
33
|
function ____exports.CallbackCustom(self, modCallbackCustom, ...)
|
|
21
34
|
local optionalArgs = {...}
|
|
22
|
-
return function(____, target, propertyKey)
|
|
35
|
+
return function(____, target, propertyKey, _descriptor)
|
|
23
36
|
local methodName = propertyKey
|
|
24
37
|
local method = target[methodName]
|
|
25
|
-
|
|
38
|
+
local addCallbackArgs = {
|
|
26
39
|
modCallbackCustom,
|
|
27
40
|
method,
|
|
28
41
|
__TS__Spread(optionalArgs)
|
|
29
|
-
|
|
42
|
+
}
|
|
43
|
+
local constructor = target.constructor
|
|
44
|
+
if not (constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] ~= nil) then
|
|
45
|
+
constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] = {}
|
|
46
|
+
end
|
|
47
|
+
local callbackTuples = constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY]
|
|
48
|
+
callbackTuples[#callbackTuples + 1] = addCallbackArgs
|
|
30
49
|
end
|
|
31
50
|
end
|
|
32
51
|
return ____exports
|
|
@@ -44,8 +44,8 @@ export declare function logSet(set: Set<AnyNotNil> | ReadonlySet<AnyNotNil>): vo
|
|
|
44
44
|
/** Helper function for logging every sound effect that is currently playing. */
|
|
45
45
|
export declare function logSounds(): void;
|
|
46
46
|
/**
|
|
47
|
-
* Helper function for logging every key and value of a table. This is a deep log; the function
|
|
48
|
-
* recursively call itself if it counters a table within a table.
|
|
47
|
+
* Helper function for logging every key and value of a Lua table. This is a deep log; the function
|
|
48
|
+
* will recursively call itself if it counters a table within a table.
|
|
49
49
|
*
|
|
50
50
|
* This function will only work on tables that have string keys (because it logs the keys in order,
|
|
51
51
|
* instead of randomly). It will throw a run-time error if it encounters a non-string key.
|
|
@@ -56,6 +56,13 @@ export declare function logTable(luaTable: unknown, parentTables?: number): void
|
|
|
56
56
|
* will only do a shallow comparison.
|
|
57
57
|
*/
|
|
58
58
|
export declare function logTableDifferences<K extends AnyNotNil, V>(table1: LuaMap<K, V>, table2: LuaMap<K, V>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Helper function to log the keys of a Lua table. This is not a deep log; only the keys of the
|
|
61
|
+
* top-most table will be logged.
|
|
62
|
+
*
|
|
63
|
+
* This function is useful for tables that have recursive references.
|
|
64
|
+
*/
|
|
65
|
+
export declare function logTableKeys(luaTable: unknown): void;
|
|
59
66
|
/** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
|
|
60
67
|
export declare function logTearFlags(flags: TearFlag | BitFlags<TearFlag>): void;
|
|
61
68
|
/** Helper function for printing out every use flag that is turned on. Useful when debugging. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logMisc.d.ts","sourceRoot":"","sources":["../../../src/functions/logMisc.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,eAAe,EACf,UAAU,EACV,UAAU,EAKV,cAAc,EAGd,QAAQ,EACR,OAAO,EACR,MAAM,8BAA8B,CAAC;AAmBtC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,CAG3D;AAED,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,eAAe,EAAE,GAAG,IAAI,CAS7E;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAI3C;AAED,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAE7E;AAED,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAE7E;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAGhD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAED,4FAA4F;AAC5F,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EACrD,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAC3B,WAAW,SAAK,GACf,IAAI,CAmBN;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAiBxC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAI9C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAA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G;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAoBnD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI,CAG7D"}
|
|
@@ -374,8 +374,8 @@ function ____exports.logSounds(self)
|
|
|
374
374
|
end
|
|
375
375
|
end
|
|
376
376
|
end
|
|
377
|
-
--- Helper function for logging every key and value of a table. This is a deep log; the function
|
|
378
|
-
-- recursively call itself if it counters a table within a table.
|
|
377
|
+
--- Helper function for logging every key and value of a Lua table. This is a deep log; the function
|
|
378
|
+
-- will recursively call itself if it counters a table within a table.
|
|
379
379
|
--
|
|
380
380
|
-- This function will only work on tables that have string keys (because it logs the keys in order,
|
|
381
381
|
-- instead of randomly). It will throw a run-time error if it encounters a non-string key.
|
|
@@ -460,6 +460,36 @@ function ____exports.logTableDifferences(self, table1, table2)
|
|
|
460
460
|
end
|
|
461
461
|
end
|
|
462
462
|
end
|
|
463
|
+
--- Helper function to log the keys of a Lua table. This is not a deep log; only the keys of the
|
|
464
|
+
-- top-most table will be logged.
|
|
465
|
+
--
|
|
466
|
+
-- This function is useful for tables that have recursive references.
|
|
467
|
+
function ____exports.logTableKeys(self, luaTable)
|
|
468
|
+
log(nil, "Printing out the keys of a Lua table:")
|
|
469
|
+
if not isTable(nil, luaTable) then
|
|
470
|
+
log(
|
|
471
|
+
nil,
|
|
472
|
+
(" n/a (encountered a variable of type \"" .. __TS__TypeOf(luaTable)) .. "\" instead of a table)"
|
|
473
|
+
)
|
|
474
|
+
return
|
|
475
|
+
end
|
|
476
|
+
local numElements = 0
|
|
477
|
+
iterateTableInOrder(
|
|
478
|
+
nil,
|
|
479
|
+
luaTable,
|
|
480
|
+
function(____, key)
|
|
481
|
+
log(
|
|
482
|
+
nil,
|
|
483
|
+
tostring(key)
|
|
484
|
+
)
|
|
485
|
+
numElements = numElements + 1
|
|
486
|
+
end
|
|
487
|
+
)
|
|
488
|
+
log(
|
|
489
|
+
nil,
|
|
490
|
+
" The size of the table was: " .. tostring(numElements)
|
|
491
|
+
)
|
|
492
|
+
end
|
|
463
493
|
--- Helper function for printing out every tear flag that is turned on. Useful when debugging.
|
|
464
494
|
function ____exports.logTearFlags(self, flags)
|
|
465
495
|
____exports.logFlags(nil, flags, TearFlag, "tear")
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
2
|
import { DefaultMap } from "../classes/DefaultMap";
|
|
3
3
|
import { TSTLClassMetatable } from "../interfaces/TSTLClassMetatable";
|
|
4
|
-
import { FunctionTuple } from "../types/FunctionTuple";
|
|
5
4
|
import { TSTLClass } from "../types/TSTLClass";
|
|
6
5
|
/**
|
|
7
6
|
* Helper function to get the constructor from an instantiated TypeScriptToLua class, which is
|
|
@@ -10,7 +9,6 @@ import { TSTLClass } from "../types/TSTLClass";
|
|
|
10
9
|
* Returns undefined if passed a non-table or if the provided table does not have a metatable.
|
|
11
10
|
*/
|
|
12
11
|
export declare function getTSTLClassConstructor(object: unknown): TSTLClassMetatable["constructor"] | undefined;
|
|
13
|
-
export declare function getTSTLClassMethods(object: unknown): FunctionTuple[];
|
|
14
12
|
/**
|
|
15
13
|
* Helper function to get the name of a TypeScriptToLua class from the instantiated class object.
|
|
16
14
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tstlClass.d.ts","sourceRoot":"","sources":["../../../src/functions/tstlClass.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"tstlClass.d.ts","sourceRoot":"","sources":["../../../src/functions/tstlClass.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAW/C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,OAAO,GACd,kBAAkB,CAAC,aAAa,CAAC,GAAG,SAAS,CAW/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOpE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAG1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAG5E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,CAGnE;AAED,kGAAkG;AAClG,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,SAAS,CA4B3E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAO3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAiB3D"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local Set = ____lualib.Set
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
|
-
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
|
|
5
|
-
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
6
4
|
local ____exports = {}
|
|
7
5
|
local VANILLA_TSTL_CLASSES
|
|
8
6
|
local ____types = require("src.functions.types")
|
|
@@ -48,23 +46,6 @@ function ____exports.isVanillaTSTLClass(self, object)
|
|
|
48
46
|
end
|
|
49
47
|
VANILLA_TSTL_CLASSES = __TS__New(Set, {"Map", "Set", "WeakMap", "WeakSet"})
|
|
50
48
|
local TSTL_CLASS_METATABLE_KEYS = __TS__New(Set, {"____constructor", "__index", "constructor"})
|
|
51
|
-
function ____exports.getTSTLClassMethods(self, object)
|
|
52
|
-
local constructor = ____exports.getTSTLClassConstructor(nil, object)
|
|
53
|
-
if constructor == nil then
|
|
54
|
-
return {}
|
|
55
|
-
end
|
|
56
|
-
local classEntries = __TS__ObjectEntries(constructor.prototype)
|
|
57
|
-
return __TS__ArrayFilter(
|
|
58
|
-
classEntries,
|
|
59
|
-
function(____, ____bindingPattern0)
|
|
60
|
-
local value
|
|
61
|
-
local key
|
|
62
|
-
key = ____bindingPattern0[1]
|
|
63
|
-
value = ____bindingPattern0[2]
|
|
64
|
-
return not TSTL_CLASS_METATABLE_KEYS:has(key) and type(value) == "function"
|
|
65
|
-
end
|
|
66
|
-
)
|
|
67
|
-
end
|
|
68
49
|
--- Helper function to determine if a given object is a TypeScriptToLua `Map`.
|
|
69
50
|
--
|
|
70
51
|
-- It is not reliable to use the `instanceof` operator to determine this because each Lua module has
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TSTLClassMetatable.d.ts","sourceRoot":"","sources":["../../../src/interfaces/TSTLClassMetatable.ts"],"names":[],"mappings":";;;;AAAA,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"TSTLClassMetatable.d.ts","sourceRoot":"","sources":["../../../src/interfaces/TSTLClassMetatable.ts"],"names":[],"mappings":";;;;AAAA,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;KAErD,CAAC;CACH"}
|
package/package.json
CHANGED
package/src/callbacks.ts
CHANGED
|
@@ -48,6 +48,7 @@ import { PostSpikesRender } from "./classes/callbacks/PostSpikesRender";
|
|
|
48
48
|
import { PreBerserkDeath } from "./classes/callbacks/PreBerserkDeath";
|
|
49
49
|
import { PreCustomRevive } from "./classes/callbacks/PreCustomRevive";
|
|
50
50
|
import { ModCallbackCustom2 } from "./enums/ModCallbackCustom2";
|
|
51
|
+
import { getEnumValues } from "./functions/enums";
|
|
51
52
|
import { newObjectWithEnumKeys } from "./functions/utils";
|
|
52
53
|
|
|
53
54
|
const MOD_CALLBACK_CUSTOM_TO_CLASS = newObjectWithEnumKeys(ModCallbackCustom2, {
|
|
@@ -116,19 +117,18 @@ const MOD_CALLBACK_CUSTOM_TO_CLASS = newObjectWithEnumKeys(ModCallbackCustom2, {
|
|
|
116
117
|
} as const);
|
|
117
118
|
|
|
118
119
|
export type ModCallbackCustomToClass = {
|
|
119
|
-
[
|
|
120
|
-
typeof MOD_CALLBACK_CUSTOM_TO_CLASS[
|
|
120
|
+
readonly [key in keyof typeof MOD_CALLBACK_CUSTOM_TO_CLASS]: InstanceType<
|
|
121
|
+
typeof MOD_CALLBACK_CUSTOM_TO_CLASS[key]
|
|
121
122
|
>;
|
|
122
123
|
};
|
|
123
124
|
|
|
124
125
|
export function getCallbacks(): ModCallbackCustomToClass {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
);
|
|
126
|
+
const instantiatedClasses: Record<number, unknown> = {};
|
|
127
|
+
|
|
128
|
+
for (const modCallbackCustom of getEnumValues(ModCallbackCustom2)) {
|
|
129
|
+
const constructor = MOD_CALLBACK_CUSTOM_TO_CLASS[modCallbackCustom];
|
|
130
|
+
instantiatedClasses[modCallbackCustom] = new constructor();
|
|
131
|
+
}
|
|
132
132
|
|
|
133
133
|
return instantiatedClasses as unknown as ModCallbackCustomToClass;
|
|
134
134
|
}
|
|
@@ -1,14 +1,74 @@
|
|
|
1
|
+
import { getTSTLClassConstructor } from "../functions/tstlClass";
|
|
2
|
+
import { TSTLClassMetatable } from "../interfaces/TSTLClassMetatable";
|
|
1
3
|
import { ModUpgraded } from "./ModUpgraded";
|
|
2
4
|
|
|
5
|
+
export const ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs";
|
|
6
|
+
export const ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs";
|
|
7
|
+
|
|
8
|
+
type ModFeatureConstructor = TSTLClassMetatable["constructor"] & {
|
|
9
|
+
[ADD_CALLBACK_ARGS_KEY]: unknown[] | undefined;
|
|
10
|
+
[ADD_CALLBACK_CUSTOM_ARGS_KEY]: unknown[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
3
13
|
/**
|
|
4
|
-
* A helper class for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
14
|
+
* A helper class for mods that wants to represent their individual features as classes. Extend your
|
|
15
|
+
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
16
|
+
* that automatically subscribe to callbacks.
|
|
17
|
+
*
|
|
18
|
+
* For example:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* export class MyFeature extends ModFeature {
|
|
22
|
+
* @Callback(ModCallback.POST_GAME_STARTED)
|
|
23
|
+
* postGameStarted(isContinued: boolean): void {
|
|
24
|
+
* Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
7
28
|
*/
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
8
30
|
export class ModFeature {
|
|
9
|
-
private mod: ModUpgraded;
|
|
10
|
-
|
|
11
31
|
constructor(mod: ModUpgraded) {
|
|
12
|
-
|
|
32
|
+
const constructor = getTSTLClassConstructor(this);
|
|
33
|
+
if (constructor === undefined) {
|
|
34
|
+
error("Failed to get the TSTL class constructor for a mod feature.");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const modFeatureConstructor = constructor as ModFeatureConstructor;
|
|
38
|
+
addDecoratedCallbacks(mod, modFeatureConstructor);
|
|
39
|
+
addDecoratedCallbacksCustom(mod, modFeatureConstructor);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function addDecoratedCallbacks(
|
|
44
|
+
mod: ModUpgraded,
|
|
45
|
+
modFeatureConstructor: ModFeatureConstructor,
|
|
46
|
+
) {
|
|
47
|
+
const addCallbackArgs = modFeatureConstructor[ADD_CALLBACK_ARGS_KEY];
|
|
48
|
+
if (addCallbackArgs === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const args of addCallbackArgs) {
|
|
53
|
+
// @ts-expect-error The compiler does not know that the arguments match the method.
|
|
54
|
+
// eslint-disable-next-line isaacscript/strict-enums
|
|
55
|
+
mod.AddCallback(...args);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function addDecoratedCallbacksCustom(
|
|
60
|
+
mod: ModUpgraded,
|
|
61
|
+
modFeatureConstructor: ModFeatureConstructor,
|
|
62
|
+
) {
|
|
63
|
+
const addCallbackCustomArgs =
|
|
64
|
+
modFeatureConstructor[ADD_CALLBACK_CUSTOM_ARGS_KEY];
|
|
65
|
+
if (addCallbackCustomArgs === undefined) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const args of addCallbackCustomArgs) {
|
|
70
|
+
// @ts-expect-error The compiler does not know that the arguments match the method.
|
|
71
|
+
// eslint-disable-next-line isaacscript/strict-enums
|
|
72
|
+
mod.AddCallbackCustom(...args);
|
|
13
73
|
}
|
|
14
74
|
}
|