isaacscript-common 14.1.2 → 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 -19
- package/dist/isaacscript-common.lua +91 -20
- 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 +5 -5
- package/dist/src/core/upgradeMod.d.ts +2 -5
- package/dist/src/core/upgradeMod.d.ts.map +1 -1
- package/dist/src/decorators.d.ts +1 -1
- package/dist/src/decorators.d.ts.map +1 -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/package.json +1 -1
- package/src/classes/ModFeature.ts +66 -6
- package/src/classes/ModUpgraded.ts +8 -11
- package/src/core/upgradeMod.ts +4 -9
- package/src/decorators.ts +4 -1
- package/src/functions/decorators.ts +61 -12
- package/src/functions/logMisc.ts +28 -2
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,10 @@ import { TrapdoorVariant } from 'isaac-typescript-definitions';
|
|
|
79
79
|
import { TrinketType } from 'isaac-typescript-definitions';
|
|
80
80
|
import { UseFlag } from 'isaac-typescript-definitions';
|
|
81
81
|
|
|
82
|
+
export declare const ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs";
|
|
83
|
+
|
|
84
|
+
export declare const ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs";
|
|
85
|
+
|
|
82
86
|
declare interface AddCallbackParametersCustom {
|
|
83
87
|
[ModCallbackCustom.POST_AMBUSH_FINISHED]: PostAmbushFinishedRegisterParameters;
|
|
84
88
|
[ModCallbackCustom.POST_AMBUSH_STARTED]: PostAmbushStartedRegisterParameters;
|
|
@@ -827,16 +831,18 @@ export declare function calculateStageTypeRepentance(stage: LevelStage): StageTy
|
|
|
827
831
|
/**
|
|
828
832
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
829
833
|
* registered with `Mod.AddCallback`.
|
|
834
|
+
*
|
|
835
|
+
* @ignore
|
|
830
836
|
*/
|
|
831
837
|
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;
|
|
832
838
|
|
|
833
839
|
/**
|
|
834
840
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
835
841
|
* registered with `ModUpgraded.AddCallbackCustom`.
|
|
842
|
+
*
|
|
843
|
+
* @ignore
|
|
836
844
|
*/
|
|
837
|
-
export declare function CallbackCustom<T extends
|
|
838
|
-
mod: ModUpgraded;
|
|
839
|
-
}>(target: Class, propertyKey: string) => void;
|
|
845
|
+
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;
|
|
840
846
|
|
|
841
847
|
declare type CallbackSignatureGridEntity = ((gridEntity: GridEntity) => void) | ((gridEntity: GridEntity, oldState: int, newState: int) => void);
|
|
842
848
|
|
|
@@ -7519,8 +7525,6 @@ export declare function kColorEquals(kColor1: KColor, kColor2: KColor): boolean;
|
|
|
7519
7525
|
*/
|
|
7520
7526
|
export declare function keyboardToString(keyboard: Keyboard, uppercase: boolean): string | undefined;
|
|
7521
7527
|
|
|
7522
|
-
declare type KeysToScrubFromModClass = keyof Feature | LowercaseKeys<ModUpgraded>;
|
|
7523
|
-
|
|
7524
7528
|
/**
|
|
7525
7529
|
* For `EntityType.EFFECT` (1000), `EffectVariant.LADDER` (8).
|
|
7526
7530
|
*
|
|
@@ -7710,8 +7714,8 @@ export declare function logSet(set: Set<AnyNotNil> | ReadonlySet<AnyNotNil>): vo
|
|
|
7710
7714
|
export declare function logSounds(): void;
|
|
7711
7715
|
|
|
7712
7716
|
/**
|
|
7713
|
-
* Helper function for logging every key and value of a table. This is a deep log; the function
|
|
7714
|
-
* recursively call itself if it counters a table within a table.
|
|
7717
|
+
* Helper function for logging every key and value of a Lua table. This is a deep log; the function
|
|
7718
|
+
* will recursively call itself if it counters a table within a table.
|
|
7715
7719
|
*
|
|
7716
7720
|
* This function will only work on tables that have string keys (because it logs the keys in order,
|
|
7717
7721
|
* instead of randomly). It will throw a run-time error if it encounters a non-string key.
|
|
@@ -7724,6 +7728,14 @@ export declare function logTable(luaTable: unknown, parentTables?: number): void
|
|
|
7724
7728
|
*/
|
|
7725
7729
|
export declare function logTableDifferences<K extends AnyNotNil, V>(table1: LuaMap<K, V>, table2: LuaMap<K, V>): void;
|
|
7726
7730
|
|
|
7731
|
+
/**
|
|
7732
|
+
* Helper function to log the keys of a Lua table. This is not a deep log; only the keys of the
|
|
7733
|
+
* top-most table will be logged.
|
|
7734
|
+
*
|
|
7735
|
+
* This function is useful for tables that have recursive references.
|
|
7736
|
+
*/
|
|
7737
|
+
export declare function logTableKeys(luaTable: unknown): void;
|
|
7738
|
+
|
|
7727
7739
|
/** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
|
|
7728
7740
|
export declare function logTearFlags(flags: TearFlag | BitFlags<TearFlag>): void;
|
|
7729
7741
|
|
|
@@ -9447,12 +9459,22 @@ declare type ModCallbackCustomPlayer = MatchingCallbackCustom<CallbackSignatureP
|
|
|
9447
9459
|
declare type ModCallbackCustomRevive = MatchingCallbackCustom<CallbackSignatureRevive>;
|
|
9448
9460
|
|
|
9449
9461
|
/**
|
|
9450
|
-
* A helper class for
|
|
9451
|
-
*
|
|
9452
|
-
*
|
|
9462
|
+
* A helper class for mods that wants to represent their individual features as classes. Extend your
|
|
9463
|
+
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
9464
|
+
* that automatically subscribe to callbacks.
|
|
9465
|
+
*
|
|
9466
|
+
* For example:
|
|
9467
|
+
*
|
|
9468
|
+
* ```ts
|
|
9469
|
+
* export class MyFeature extends ModFeature {
|
|
9470
|
+
* @Callback(ModCallback.POST_GAME_STARTED)
|
|
9471
|
+
* postGameStarted(isContinued: boolean): void {
|
|
9472
|
+
* Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
|
|
9473
|
+
* }
|
|
9474
|
+
* }
|
|
9475
|
+
* ```
|
|
9453
9476
|
*/
|
|
9454
9477
|
export declare class ModFeature {
|
|
9455
|
-
private mod;
|
|
9456
9478
|
constructor(mod: ModUpgraded);
|
|
9457
9479
|
}
|
|
9458
9480
|
|
|
@@ -9516,24 +9538,20 @@ export declare class ModUpgraded implements Mod {
|
|
|
9516
9538
|
* conditions of how you registered the callback, it will be removed.
|
|
9517
9539
|
*/
|
|
9518
9540
|
RemoveCallbackCustom<T extends ModCallbackCustom2>(modCallbackCustom: T, callback: AddCallbackParametersCustom2[T][0]): void;
|
|
9519
|
-
/**
|
|
9520
|
-
* This method should only be used by the `upgradeMod` function. Returns the names of the exported
|
|
9521
|
-
* class methods from the features that were added.
|
|
9522
|
-
*/
|
|
9523
|
-
initOptionalFeature(feature: ISCFeature): FunctionTuple[];
|
|
9524
9541
|
/** This is used to initialize both custom callbacks and "extra features". */
|
|
9525
9542
|
private initFeature;
|
|
9526
9543
|
private uninitFeature;
|
|
9544
|
+
/** Returns the names of the exported class methods from the features that were added. */
|
|
9545
|
+
private initOptionalFeature;
|
|
9527
9546
|
}
|
|
9528
9547
|
|
|
9529
9548
|
/**
|
|
9530
9549
|
* By specifying one or more optional features, end-users will get a version of `ModUpgraded` that
|
|
9531
9550
|
* has extra methods corresponding to the features.
|
|
9532
9551
|
*
|
|
9533
|
-
* We have to explicitly account for the empty array case, since `never` will
|
|
9534
|
-
* union.
|
|
9552
|
+
* We have to explicitly account for the empty array case, since the `never` will mess up the union.
|
|
9535
9553
|
*/
|
|
9536
|
-
declare type ModUpgradedWithFeatures<T extends ISCFeature> = [T] extends [never] ? ModUpgraded :
|
|
9554
|
+
declare type ModUpgradedWithFeatures<T extends ISCFeature> = [T] extends [never] ? ModUpgraded : ModUpgraded & Omit<UnionToIntersection<ISCFeatureToClass[T]>, keyof Feature>;
|
|
9537
9555
|
|
|
9538
9556
|
/**
|
|
9539
9557
|
* Helper function to move all of the players to where they would normally go when arriving at a new
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 14.1.
|
|
3
|
+
isaacscript-common 14.1.3
|
|
4
4
|
|
|
5
5
|
This is the "isaacscript-common" library, which was created with the IsaacScript tool.
|
|
6
6
|
|
|
@@ -24483,6 +24483,32 @@ function ____exports.logTableDifferences(self, table1, table2)
|
|
|
24483
24483
|
end
|
|
24484
24484
|
end
|
|
24485
24485
|
end
|
|
24486
|
+
function ____exports.logTableKeys(self, luaTable)
|
|
24487
|
+
log(nil, "Printing out the keys of a Lua table:")
|
|
24488
|
+
if not isTable(nil, luaTable) then
|
|
24489
|
+
log(
|
|
24490
|
+
nil,
|
|
24491
|
+
(" n/a (encountered a variable of type \"" .. __TS__TypeOf(luaTable)) .. "\" instead of a table)"
|
|
24492
|
+
)
|
|
24493
|
+
return
|
|
24494
|
+
end
|
|
24495
|
+
local numElements = 0
|
|
24496
|
+
iterateTableInOrder(
|
|
24497
|
+
nil,
|
|
24498
|
+
luaTable,
|
|
24499
|
+
function(____, key)
|
|
24500
|
+
log(
|
|
24501
|
+
nil,
|
|
24502
|
+
tostring(key)
|
|
24503
|
+
)
|
|
24504
|
+
numElements = numElements + 1
|
|
24505
|
+
end
|
|
24506
|
+
)
|
|
24507
|
+
log(
|
|
24508
|
+
nil,
|
|
24509
|
+
" The size of the table was: " .. tostring(numElements)
|
|
24510
|
+
)
|
|
24511
|
+
end
|
|
24486
24512
|
function ____exports.logTearFlags(self, flags)
|
|
24487
24513
|
____exports.logFlags(nil, flags, TearFlag, "tear")
|
|
24488
24514
|
end
|
|
@@ -34947,11 +34973,6 @@ function ModUpgraded.prototype.RemoveCallbackCustom(self, modCallbackCustom, cal
|
|
|
34947
34973
|
self:uninitFeature(callbackClass)
|
|
34948
34974
|
end
|
|
34949
34975
|
end
|
|
34950
|
-
function ModUpgraded.prototype.initOptionalFeature(self, feature)
|
|
34951
|
-
local featureClass = self.features[feature]
|
|
34952
|
-
self:initFeature(featureClass)
|
|
34953
|
-
return getExportedMethodsFromFeature(nil, featureClass)
|
|
34954
|
-
end
|
|
34955
34976
|
function ModUpgraded.prototype.initFeature(self, feature)
|
|
34956
34977
|
if feature.initialized then
|
|
34957
34978
|
return
|
|
@@ -35022,17 +35043,52 @@ function ModUpgraded.prototype.uninitFeature(self, feature)
|
|
|
35022
35043
|
saveDataManagerRemove(nil, className)
|
|
35023
35044
|
end
|
|
35024
35045
|
end
|
|
35046
|
+
function ModUpgraded.prototype.initOptionalFeature(self, feature)
|
|
35047
|
+
local featureClass = self.features[feature]
|
|
35048
|
+
self:initFeature(featureClass)
|
|
35049
|
+
return getExportedMethodsFromFeature(nil, featureClass)
|
|
35050
|
+
end
|
|
35025
35051
|
return ____exports
|
|
35026
35052
|
end,
|
|
35027
35053
|
["src.classes.ModFeature"] = function(...)
|
|
35028
35054
|
local ____lualib = require("lualib_bundle")
|
|
35029
35055
|
local __TS__Class = ____lualib.__TS__Class
|
|
35056
|
+
local __TS__Spread = ____lualib.__TS__Spread
|
|
35030
35057
|
local ____exports = {}
|
|
35058
|
+
local addDecoratedCallbacks, addDecoratedCallbacksCustom
|
|
35059
|
+
local ____tstlClass = require("src.functions.tstlClass")
|
|
35060
|
+
local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
|
|
35061
|
+
function addDecoratedCallbacks(self, mod, modFeatureConstructor)
|
|
35062
|
+
local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
|
|
35063
|
+
if addCallbackArgs == nil then
|
|
35064
|
+
return
|
|
35065
|
+
end
|
|
35066
|
+
for ____, args in ipairs(addCallbackArgs) do
|
|
35067
|
+
mod:AddCallback(__TS__Spread(args))
|
|
35068
|
+
end
|
|
35069
|
+
end
|
|
35070
|
+
function addDecoratedCallbacksCustom(self, mod, modFeatureConstructor)
|
|
35071
|
+
local addCallbackCustomArgs = modFeatureConstructor[____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY]
|
|
35072
|
+
if addCallbackCustomArgs == nil then
|
|
35073
|
+
return
|
|
35074
|
+
end
|
|
35075
|
+
for ____, args in ipairs(addCallbackCustomArgs) do
|
|
35076
|
+
mod:AddCallbackCustom(__TS__Spread(args))
|
|
35077
|
+
end
|
|
35078
|
+
end
|
|
35079
|
+
____exports.ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs"
|
|
35080
|
+
____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs"
|
|
35031
35081
|
____exports.ModFeature = __TS__Class()
|
|
35032
35082
|
local ModFeature = ____exports.ModFeature
|
|
35033
35083
|
ModFeature.name = "ModFeature"
|
|
35034
35084
|
function ModFeature.prototype.____constructor(self, mod)
|
|
35035
|
-
|
|
35085
|
+
local constructor = getTSTLClassConstructor(nil, self)
|
|
35086
|
+
if constructor == nil then
|
|
35087
|
+
error("Failed to get the TSTL class constructor for a mod feature.")
|
|
35088
|
+
end
|
|
35089
|
+
local modFeatureConstructor = constructor
|
|
35090
|
+
addDecoratedCallbacks(nil, mod, modFeatureConstructor)
|
|
35091
|
+
addDecoratedCallbacksCustom(nil, mod, modFeatureConstructor)
|
|
35036
35092
|
end
|
|
35037
35093
|
return ____exports
|
|
35038
35094
|
end,
|
|
@@ -46641,14 +46697,6 @@ end
|
|
|
46641
46697
|
function ____exports.loadShaderCrashFix(self, mod)
|
|
46642
46698
|
mod:AddCallback(ModCallback.POST_PLAYER_INIT, postPlayerInit)
|
|
46643
46699
|
end
|
|
46644
|
-
return ____exports
|
|
46645
|
-
end,
|
|
46646
|
-
["src.types.StartsWithLowercase"] = function(...)
|
|
46647
|
-
local ____exports = {}
|
|
46648
|
-
return ____exports
|
|
46649
|
-
end,
|
|
46650
|
-
["src.types.LowercaseKeys"] = function(...)
|
|
46651
|
-
local ____exports = {}
|
|
46652
46700
|
return ____exports
|
|
46653
46701
|
end,
|
|
46654
46702
|
["src.types.UnionToIntersection"] = function(...)
|
|
@@ -51839,28 +51887,43 @@ return ____exports
|
|
|
51839
51887
|
local ____lualib = require("lualib_bundle")
|
|
51840
51888
|
local __TS__Spread = ____lualib.__TS__Spread
|
|
51841
51889
|
local ____exports = {}
|
|
51890
|
+
local ____ModFeature = require("src.classes.ModFeature")
|
|
51891
|
+
local ADD_CALLBACK_ARGS_KEY = ____ModFeature.ADD_CALLBACK_ARGS_KEY
|
|
51892
|
+
local ADD_CALLBACK_CUSTOM_ARGS_KEY = ____ModFeature.ADD_CALLBACK_CUSTOM_ARGS_KEY
|
|
51842
51893
|
function ____exports.Callback(self, modCallback, ...)
|
|
51843
51894
|
local optionalArgs = {...}
|
|
51844
51895
|
return function(____, target, propertyKey, _descriptor)
|
|
51845
51896
|
local methodName = propertyKey
|
|
51846
51897
|
local method = target[methodName]
|
|
51847
|
-
|
|
51898
|
+
local addCallbackArgs = {
|
|
51848
51899
|
modCallback,
|
|
51849
51900
|
method,
|
|
51850
51901
|
__TS__Spread(optionalArgs)
|
|
51851
|
-
|
|
51902
|
+
}
|
|
51903
|
+
local constructor = target.constructor
|
|
51904
|
+
if not (constructor[ADD_CALLBACK_ARGS_KEY] ~= nil) then
|
|
51905
|
+
constructor[ADD_CALLBACK_ARGS_KEY] = {}
|
|
51906
|
+
end
|
|
51907
|
+
local callbackTuples = constructor[ADD_CALLBACK_ARGS_KEY]
|
|
51908
|
+
callbackTuples[#callbackTuples + 1] = addCallbackArgs
|
|
51852
51909
|
end
|
|
51853
51910
|
end
|
|
51854
51911
|
function ____exports.CallbackCustom(self, modCallbackCustom, ...)
|
|
51855
51912
|
local optionalArgs = {...}
|
|
51856
|
-
return function(____, target, propertyKey)
|
|
51913
|
+
return function(____, target, propertyKey, _descriptor)
|
|
51857
51914
|
local methodName = propertyKey
|
|
51858
51915
|
local method = target[methodName]
|
|
51859
|
-
|
|
51916
|
+
local addCallbackArgs = {
|
|
51860
51917
|
modCallbackCustom,
|
|
51861
51918
|
method,
|
|
51862
51919
|
__TS__Spread(optionalArgs)
|
|
51863
|
-
|
|
51920
|
+
}
|
|
51921
|
+
local constructor = target.constructor
|
|
51922
|
+
if not (constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] ~= nil) then
|
|
51923
|
+
constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] = {}
|
|
51924
|
+
end
|
|
51925
|
+
local callbackTuples = constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY]
|
|
51926
|
+
callbackTuples[#callbackTuples + 1] = addCallbackArgs
|
|
51864
51927
|
end
|
|
51865
51928
|
end
|
|
51866
51929
|
return ____exports
|
|
@@ -53583,6 +53646,14 @@ return ____exports
|
|
|
53583
53646
|
end,
|
|
53584
53647
|
["src.types.HasAllEnumKeys"] = function(...)
|
|
53585
53648
|
local ____exports = {}
|
|
53649
|
+
return ____exports
|
|
53650
|
+
end,
|
|
53651
|
+
["src.types.StartsWithLowercase"] = function(...)
|
|
53652
|
+
local ____exports = {}
|
|
53653
|
+
return ____exports
|
|
53654
|
+
end,
|
|
53655
|
+
["src.types.LowercaseKeys"] = function(...)
|
|
53656
|
+
local ____exports = {}
|
|
53586
53657
|
return ____exports
|
|
53587
53658
|
end,
|
|
53588
53659
|
["src.types.StartsWithUppercase"] = function(...)
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { ModUpgraded } from "./ModUpgraded";
|
|
2
|
+
export declare const ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs";
|
|
3
|
+
export declare const ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs";
|
|
2
4
|
/**
|
|
3
|
-
* A helper class for
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* A helper class for mods that wants to represent their individual features as classes. Extend your
|
|
6
|
+
* mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
7
|
+
* that automatically subscribe to callbacks.
|
|
8
|
+
*
|
|
9
|
+
* For example:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* export class MyFeature extends ModFeature {
|
|
13
|
+
* @Callback(ModCallback.POST_GAME_STARTED)
|
|
14
|
+
* postGameStarted(isContinued: boolean): void {
|
|
15
|
+
* Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
6
19
|
*/
|
|
7
20
|
export declare class ModFeature {
|
|
8
|
-
private mod;
|
|
9
21
|
constructor(mod: ModUpgraded);
|
|
10
22
|
}
|
|
11
23
|
//# sourceMappingURL=ModFeature.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAOtE;;;;;;;;;;;;;;;GAeG;AAEH,qBAAa,UAAU;gBACT,GAAG,EAAE,WAAW;CAU7B"}
|
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__Spread = ____lualib.__TS__Spread
|
|
3
4
|
local ____exports = {}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
local addDecoratedCallbacks, addDecoratedCallbacksCustom
|
|
6
|
+
local ____tstlClass = require("src.functions.tstlClass")
|
|
7
|
+
local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
|
|
8
|
+
function addDecoratedCallbacks(self, mod, modFeatureConstructor)
|
|
9
|
+
local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
|
|
10
|
+
if addCallbackArgs == nil then
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
for ____, args in ipairs(addCallbackArgs) do
|
|
14
|
+
mod:AddCallback(__TS__Spread(args))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
function addDecoratedCallbacksCustom(self, mod, modFeatureConstructor)
|
|
18
|
+
local addCallbackCustomArgs = modFeatureConstructor[____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY]
|
|
19
|
+
if addCallbackCustomArgs == nil then
|
|
20
|
+
return
|
|
21
|
+
end
|
|
22
|
+
for ____, args in ipairs(addCallbackCustomArgs) do
|
|
23
|
+
mod:AddCallbackCustom(__TS__Spread(args))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
____exports.ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs"
|
|
27
|
+
____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs"
|
|
28
|
+
--- A helper class for mods that wants to represent their individual features as classes. Extend your
|
|
29
|
+
-- mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
|
|
30
|
+
-- that automatically subscribe to callbacks.
|
|
31
|
+
--
|
|
32
|
+
-- For example:
|
|
33
|
+
--
|
|
34
|
+
-- ```ts
|
|
35
|
+
-- export class MyFeature extends ModFeature {
|
|
36
|
+
--
|
|
37
|
+
-- @Callback (ModCallback.POST_GAME_STARTED)
|
|
38
|
+
-- postGameStarted(isContinued: boolean): void {
|
|
39
|
+
-- Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
|
|
40
|
+
-- }
|
|
41
|
+
-- }
|
|
42
|
+
-- ```
|
|
7
43
|
____exports.ModFeature = __TS__Class()
|
|
8
44
|
local ModFeature = ____exports.ModFeature
|
|
9
45
|
ModFeature.name = "ModFeature"
|
|
10
46
|
function ModFeature.prototype.____constructor(self, mod)
|
|
11
|
-
|
|
47
|
+
local constructor = getTSTLClassConstructor(nil, self)
|
|
48
|
+
if constructor == nil then
|
|
49
|
+
error("Failed to get the TSTL class constructor for a mod feature.")
|
|
50
|
+
end
|
|
51
|
+
local modFeatureConstructor = constructor
|
|
52
|
+
addDecoratedCallbacks(nil, mod, modFeatureConstructor)
|
|
53
|
+
addDecoratedCallbacksCustom(nil, mod, modFeatureConstructor)
|
|
12
54
|
end
|
|
13
55
|
return ____exports
|
|
@@ -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 names of the exported
|
|
70
|
-
* class methods from 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,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"ModUpgraded.d.ts","sourceRoot":"","sources":["../../../src/classes/ModUpgraded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAI3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAYjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAKlG;;;;;;GAMG;AACH,qBAAa,WAAY,YAAW,GAAG;IAKrC;;;OAGG;IACI,IAAI,EAAE,MAAM,CAAC;IAMpB,4FAA4F;IAC5F,OAAO,CAAC,GAAG,CAAM;IAEjB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,aAAa,CAAoB;IAEzC,OAAO,CAAC,SAAS,CAAC;gBAUN,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,KAAK;IAa3D;;;;OAIG;IACI,WAAW,CAAC,CAAC,SAAS,WAAW,EACtC,WAAW,EAAE,CAAC,EACd,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,IAAI;IAkDP,0FAA0F;IACnF,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;;OAKG;IACI,cAAc,CAAC,CAAC,SAAS,WAAW,EACzC,WAAW,EAAE,CAAC,EACd,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACpC,IAAI;IAIP,6EAA6E;IACtE,UAAU,IAAI,IAAI;IAIzB;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQnC;;;;OAIG;IAEI,iBAAiB,CAAC,CAAC,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"}
|
|
@@ -124,11 +124,6 @@ function ModUpgraded.prototype.RemoveCallbackCustom(self, modCallbackCustom, cal
|
|
|
124
124
|
self:uninitFeature(callbackClass)
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
|
-
function ModUpgraded.prototype.initOptionalFeature(self, feature)
|
|
128
|
-
local featureClass = self.features[feature]
|
|
129
|
-
self:initFeature(featureClass)
|
|
130
|
-
return getExportedMethodsFromFeature(nil, featureClass)
|
|
131
|
-
end
|
|
132
127
|
function ModUpgraded.prototype.initFeature(self, feature)
|
|
133
128
|
if feature.initialized then
|
|
134
129
|
return
|
|
@@ -199,4 +194,9 @@ function ModUpgraded.prototype.uninitFeature(self, feature)
|
|
|
199
194
|
saveDataManagerRemove(nil, className)
|
|
200
195
|
end
|
|
201
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
|
|
202
202
|
return ____exports
|
|
@@ -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"}
|
package/dist/src/decorators.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare const EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
|
|
|
6
6
|
*
|
|
7
7
|
* This is only meant to be used internally.
|
|
8
8
|
*/
|
|
9
|
-
export declare function Exported(): <
|
|
9
|
+
export declare function Exported(): <Class extends Feature>(target: Class, propertyKey: keyof Class) => void;
|
|
10
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,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAEjE;;;;;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"}
|
|
@@ -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":"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"}
|
|
1
|
+
{"version":3,"file":"logMisc.d.ts","sourceRoot":"","sources":["../../../src/functions/logMisc.ts"],"names":[],"mappings":"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"}
|
|
@@ -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")
|
package/package.json
CHANGED
|
@@ -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
|
}
|
|
@@ -216,17 +216,6 @@ export class ModUpgraded implements Mod {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
/**
|
|
220
|
-
* This method should only be used by the `upgradeMod` function. Returns the names of the exported
|
|
221
|
-
* class methods from the features that were added.
|
|
222
|
-
*/
|
|
223
|
-
public initOptionalFeature(feature: ISCFeature): FunctionTuple[] {
|
|
224
|
-
const featureClass = this.features[feature];
|
|
225
|
-
this.initFeature(featureClass);
|
|
226
|
-
|
|
227
|
-
return getExportedMethodsFromFeature(featureClass);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
219
|
// ----------------------
|
|
231
220
|
// Custom private methods
|
|
232
221
|
// ----------------------
|
|
@@ -305,6 +294,14 @@ export class ModUpgraded implements Mod {
|
|
|
305
294
|
saveDataManagerRemove(className);
|
|
306
295
|
}
|
|
307
296
|
}
|
|
297
|
+
|
|
298
|
+
/** Returns the names of the exported class methods from the features that were added. */
|
|
299
|
+
private initOptionalFeature(feature: ISCFeature): FunctionTuple[] {
|
|
300
|
+
const featureClass = this.features[feature];
|
|
301
|
+
this.initFeature(featureClass);
|
|
302
|
+
|
|
303
|
+
return getExportedMethodsFromFeature(featureClass);
|
|
304
|
+
}
|
|
308
305
|
}
|
|
309
306
|
|
|
310
307
|
/**
|
package/src/core/upgradeMod.ts
CHANGED
|
@@ -16,24 +16,18 @@ import { initCustomCallbacks } from "../initCustomCallbacks";
|
|
|
16
16
|
import { initFeatures } from "../initFeatures";
|
|
17
17
|
import { patchErrorFunction } from "../patchErrorFunctions";
|
|
18
18
|
import { loadShaderCrashFix } from "../shaderCrashFix";
|
|
19
|
-
import { LowercaseKeys } from "../types/LowercaseKeys";
|
|
20
19
|
import { UnionToIntersection } from "../types/UnionToIntersection";
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* By specifying one or more optional features, end-users will get a version of `ModUpgraded` that
|
|
24
23
|
* has extra methods corresponding to the features.
|
|
25
24
|
*
|
|
26
|
-
* We have to explicitly account for the empty array case, since `never` will
|
|
27
|
-
* union.
|
|
25
|
+
* We have to explicitly account for the empty array case, since the `never` will mess up the union.
|
|
28
26
|
*/
|
|
29
27
|
type ModUpgradedWithFeatures<T extends ISCFeature> = [T] extends [never]
|
|
30
28
|
? ModUpgraded
|
|
31
|
-
:
|
|
32
|
-
|
|
33
|
-
KeysToScrubFromModClass
|
|
34
|
-
>;
|
|
35
|
-
|
|
36
|
-
type KeysToScrubFromModClass = keyof Feature | LowercaseKeys<ModUpgraded>;
|
|
29
|
+
: ModUpgraded &
|
|
30
|
+
Omit<UnionToIntersection<ISCFeatureToClass[T]>, keyof Feature>;
|
|
37
31
|
|
|
38
32
|
/**
|
|
39
33
|
* Use this function to enable the custom callbacks and other optional features provided by
|
|
@@ -83,6 +77,7 @@ export function upgradeMod<T extends ISCFeature = never>(
|
|
|
83
77
|
legacyInit(mod); // TODO: remove
|
|
84
78
|
|
|
85
79
|
for (const feature of features) {
|
|
80
|
+
// @ts-expect-error We intentionally access the private function here.
|
|
86
81
|
const exportedMethodTuples = mod.initOptionalFeature(feature);
|
|
87
82
|
|
|
88
83
|
// If the optional feature provides helper functions, attach them to the base mod object. (This
|
package/src/decorators.ts
CHANGED
|
@@ -9,7 +9,10 @@ export const EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
|
|
|
9
9
|
* This is only meant to be used internally.
|
|
10
10
|
*/
|
|
11
11
|
export function Exported() {
|
|
12
|
-
return <
|
|
12
|
+
return <Class extends Feature>(
|
|
13
|
+
target: Class,
|
|
14
|
+
propertyKey: keyof Class,
|
|
15
|
+
): void => {
|
|
13
16
|
// Since the decorator runs prior to instantiation, we only have access to get and set static
|
|
14
17
|
// properties, which are located on the "constructor" table.
|
|
15
18
|
const constructor = target.constructor as unknown as LuaTable<
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { ModCallback } from "isaac-typescript-definitions";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import {
|
|
3
|
+
ADD_CALLBACK_ARGS_KEY,
|
|
4
|
+
ADD_CALLBACK_CUSTOM_ARGS_KEY,
|
|
5
|
+
ModFeature,
|
|
6
|
+
} from "../classes/ModFeature";
|
|
7
|
+
import { ModCallbackCustom } from "../enums/ModCallbackCustom";
|
|
8
|
+
import { AddCallbackParametersCustom } from "../interfaces/private/AddCallbackParametersCustom";
|
|
6
9
|
import { AllButFirst } from "../types/AllButFirst";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
10
13
|
* registered with `Mod.AddCallback`.
|
|
14
|
+
*
|
|
15
|
+
* @ignore
|
|
11
16
|
*/
|
|
12
17
|
export function Callback<T extends ModCallback>(
|
|
13
18
|
modCallback: T,
|
|
@@ -18,28 +23,72 @@ export function Callback<T extends ModCallback>(
|
|
|
18
23
|
propertyKey: string,
|
|
19
24
|
_descriptor: TypedPropertyDescriptor<Fn>,
|
|
20
25
|
): void => {
|
|
26
|
+
// First, prepare the arguments for the `Mod.AddCallback` method.
|
|
21
27
|
const methodName = propertyKey as keyof Class;
|
|
22
28
|
const method = target[methodName] as AddCallbackParameters[T][0];
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
const addCallbackArgs = [
|
|
30
|
+
modCallback,
|
|
31
|
+
method,
|
|
32
|
+
...optionalArgs,
|
|
33
|
+
] as unknown as AddCallbackParameters[T];
|
|
34
|
+
|
|
35
|
+
// Since the decorator runs prior to instantiation, we only have access to get and set static
|
|
36
|
+
// properties, which are located on the "constructor" table. Thus, we store the callback
|
|
37
|
+
// arguments for later.
|
|
38
|
+
const constructor = target.constructor as unknown as LuaTable<
|
|
39
|
+
AnyNotNil,
|
|
40
|
+
unknown
|
|
41
|
+
>;
|
|
42
|
+
if (!constructor.has(ADD_CALLBACK_ARGS_KEY)) {
|
|
43
|
+
constructor.set(ADD_CALLBACK_ARGS_KEY, []);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const callbackTuples = constructor.get(ADD_CALLBACK_ARGS_KEY) as unknown[];
|
|
47
|
+
callbackTuples.push(addCallbackArgs);
|
|
25
48
|
};
|
|
26
49
|
}
|
|
27
50
|
|
|
28
51
|
/**
|
|
29
52
|
* A decorator function that signifies that the decorated class method should be automatically
|
|
30
53
|
* registered with `ModUpgraded.AddCallbackCustom`.
|
|
54
|
+
*
|
|
55
|
+
* @ignore
|
|
31
56
|
*/
|
|
32
|
-
export function CallbackCustom<T extends
|
|
57
|
+
export function CallbackCustom<T extends ModCallbackCustom>(
|
|
33
58
|
modCallbackCustom: T,
|
|
34
|
-
...optionalArgs: AllButFirst<
|
|
59
|
+
...optionalArgs: AllButFirst<AddCallbackParametersCustom[T]>
|
|
35
60
|
) {
|
|
36
|
-
return <
|
|
61
|
+
return <
|
|
62
|
+
Class extends ModFeature,
|
|
63
|
+
Fn extends AddCallbackParametersCustom[T][0],
|
|
64
|
+
>(
|
|
37
65
|
target: Class,
|
|
38
66
|
propertyKey: string,
|
|
67
|
+
_descriptor: TypedPropertyDescriptor<Fn>,
|
|
39
68
|
): void => {
|
|
69
|
+
// First, prepare the arguments for the `Mod.AddCallbackCustom` method.
|
|
40
70
|
const methodName = propertyKey as keyof Class;
|
|
41
|
-
const method = target[methodName] as
|
|
42
|
-
|
|
43
|
-
|
|
71
|
+
const method = target[methodName] as AddCallbackParametersCustom[T][0];
|
|
72
|
+
const addCallbackArgs = [
|
|
73
|
+
modCallbackCustom,
|
|
74
|
+
method,
|
|
75
|
+
...optionalArgs,
|
|
76
|
+
] as unknown as AddCallbackParametersCustom[T];
|
|
77
|
+
|
|
78
|
+
// Since the decorator runs prior to instantiation, we only have access to get and set static
|
|
79
|
+
// properties, which are located on the "constructor" table. Thus, we store the callback
|
|
80
|
+
// arguments for later.
|
|
81
|
+
const constructor = target.constructor as unknown as LuaTable<
|
|
82
|
+
AnyNotNil,
|
|
83
|
+
unknown
|
|
84
|
+
>;
|
|
85
|
+
if (!constructor.has(ADD_CALLBACK_CUSTOM_ARGS_KEY)) {
|
|
86
|
+
constructor.set(ADD_CALLBACK_CUSTOM_ARGS_KEY, []);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const callbackTuples = constructor.get(
|
|
90
|
+
ADD_CALLBACK_CUSTOM_ARGS_KEY,
|
|
91
|
+
) as unknown[];
|
|
92
|
+
callbackTuples.push(addCallbackArgs);
|
|
44
93
|
};
|
|
45
94
|
}
|
package/src/functions/logMisc.ts
CHANGED
|
@@ -307,8 +307,8 @@ export function logSounds(): void {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
/**
|
|
310
|
-
* Helper function for logging every key and value of a table. This is a deep log; the function
|
|
311
|
-
* recursively call itself if it counters a table within a table.
|
|
310
|
+
* Helper function for logging every key and value of a Lua table. This is a deep log; the function
|
|
311
|
+
* will recursively call itself if it counters a table within a table.
|
|
312
312
|
*
|
|
313
313
|
* This function will only work on tables that have string keys (because it logs the keys in order,
|
|
314
314
|
* instead of randomly). It will throw a run-time error if it encounters a non-string key.
|
|
@@ -399,6 +399,32 @@ export function logTableDifferences<K extends AnyNotNil, V>(
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
+
/**
|
|
403
|
+
* Helper function to log the keys of a Lua table. This is not a deep log; only the keys of the
|
|
404
|
+
* top-most table will be logged.
|
|
405
|
+
*
|
|
406
|
+
* This function is useful for tables that have recursive references.
|
|
407
|
+
*/
|
|
408
|
+
export function logTableKeys(luaTable: unknown): void {
|
|
409
|
+
log("Printing out the keys of a Lua table:");
|
|
410
|
+
|
|
411
|
+
if (!isTable(luaTable)) {
|
|
412
|
+
log(
|
|
413
|
+
` n/a (encountered a variable of type "${typeof luaTable}" instead of a table)`,
|
|
414
|
+
);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
let numElements = 0;
|
|
419
|
+
iterateTableInOrder(luaTable, (key) => {
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
421
|
+
log(`${key}`);
|
|
422
|
+
numElements++;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
log(` The size of the table was: ${numElements}`);
|
|
426
|
+
}
|
|
427
|
+
|
|
402
428
|
/** Helper function for printing out every tear flag that is turned on. Useful when debugging. */
|
|
403
429
|
export function logTearFlags(flags: TearFlag | BitFlags<TearFlag>): void {
|
|
404
430
|
logFlags(flags, TearFlag, "tear");
|