isaacscript-common 15.2.1 → 15.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 CHANGED
@@ -3780,7 +3780,13 @@ export declare const GAME_FRAMES_PER_SECOND = 30;
3780
3780
  * It is easier to write mod code if the callbacks run in a more logical order:
3781
3781
  * - `POST_GAME_STARTED` --> `POST_NEW_LEVEL` --> `POST_NEW_ROOM`
3782
3782
  *
3783
- * Manually reorganize the callback execution so that this is the case.
3783
+ * `isaacscript-common` provides three new callbacks that change the order to this:
3784
+ * - `POST_GAME_STARTED_REORDERED`
3785
+ * - `POST_NEW_LEVEL_REORDERED`
3786
+ * - `POST_NEW_ROOM_REORDERED`
3787
+ *
3788
+ * Additionally, there are some helper functions listed below that can deal with some edge cases
3789
+ * that you may run into with these callbacks.
3784
3790
  */
3785
3791
  declare class GameReorderedCallbacks extends Feature {
3786
3792
  private currentStage;
@@ -3802,12 +3808,13 @@ declare class GameReorderedCallbacks extends Feature {
3802
3808
  * the next `POST_NEW_LEVEL`.
3803
3809
  *
3804
3810
  * If some specific cases, mods can change the current level during run initialization on the 0th
3805
- * frame. However, due to how the callback reordering works, the custom `POST_NEW_LEVEL` callback
3806
- * will never fire on the 0th frame. To get around this, call this function before changing levels
3807
- * to temporarily force the callback to fire.
3811
+ * frame. (For example, if you had a mod that made the player start the run in Caves instead of
3812
+ * Basement.) However, due to how the callback reordering works, the `POST_NEW_LEVEL_REORDERED`
3813
+ * callback will never fire on the 0th frame. To get around this, call this function before
3814
+ * changing levels to temporarily force the callback to fire.
3808
3815
  *
3809
3816
  * In order to use this function, you must upgrade your mod with
3810
- * `ISCFeature.CUSTOM_GRID_ENTITIES`.
3817
+ * `ISCFeature.GAME_REORDERED_CALLBACKS`.
3811
3818
  */
3812
3819
  forceNewLevelCallback(): void;
3813
3820
  /**
@@ -3815,23 +3822,24 @@ declare class GameReorderedCallbacks extends Feature {
3815
3822
  * the next `POST_NEW_ROOM`.
3816
3823
  *
3817
3824
  * If some specific cases, mods can change the current room during run initialization on the 0th
3818
- * frame. However, due to how the callback reordering works, the custom `POST_NEW_ROOM` callback
3819
- * will never fire on the 0th frame. To get around this, call this function before changing rooms
3820
- * to temporarily force the callback to fire.
3825
+ * frame. (For example, if you had a mod that made the player start the Treasure Room of Basement
3826
+ * 1 instead of the normal starting room.) However, due to how the callback reordering works, the
3827
+ * `POST_NEW_ROOM_REORDERED` callback will never fire on the 0th frame. To get around this, call
3828
+ * this function before changing rooms to temporarily force the callback to fire.
3821
3829
  *
3822
3830
  * In order to use this function, you must upgrade your mod with
3823
- * `ISCFeature.CUSTOM_GRID_ENTITIES`.
3831
+ * `ISCFeature.GAME_REORDERED_CALLBACKS`.
3824
3832
  */
3825
3833
  forceNewRoomCallback(): void;
3826
3834
  /**
3827
- * Helper function to manually set the variable that the reordered callback logic uses to track
3835
+ * Helper function to manually set the variables that the reordered callback logic uses to track
3828
3836
  * the current stage and stage type.
3829
3837
  *
3830
- * This is useful because if the stage is changed with the `Game.SetStage` method, the reordered
3831
- * callbacks will stop working.
3838
+ * This is useful because if the stage is changed with the `Game.SetStage` method (or the
3839
+ * `setStage` helper function), the reordered callbacks will stop working.
3832
3840
  *
3833
3841
  * In order to use this function, you must upgrade your mod with
3834
- * `ISCFeature.CUSTOM_GRID_ENTITIES`.
3842
+ * `ISCFeature.GAME_REORDERED_CALLBACKS`.
3835
3843
  */
3836
3844
  reorderedCallbacksSetStage(stage: LevelStage, stageType: StageType): void;
3837
3845
  }
@@ -8972,8 +8980,8 @@ export declare enum ModCallbackCustom {
8972
8980
  /**
8973
8981
  * Fires when a new grid entity is initialized. Specifically, this is either:
8974
8982
  *
8975
- * - in the `POST_NEW_ROOM` callback (firing every time a room is entered, even if the entity was
8976
- * previously there on a previous room entry)
8983
+ * - in the `POST_NEW_ROOM_REORDERED` callback (firing every time a room is entered, even if the
8984
+ * entity was previously there on a previous room entry)
8977
8985
  * - in the `POST_UPDATE` callback (if the entity appeared mid-way through the room, like when the
8978
8986
  * trapdoor appears after defeating It Lives!)
8979
8987
  *
@@ -9073,8 +9081,8 @@ export declare enum ModCallbackCustom {
9073
9081
  */
9074
9082
  POST_GRID_ENTITY_UPDATE = 36,
9075
9083
  /**
9076
- * Fires from the `POST_PEFFECT_UPDATE` callback when the player loses a Holy Mantle temporary
9077
- * collectible effect.
9084
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when the player loses a Holy Mantle
9085
+ * temporary collectible effect.
9078
9086
  *
9079
9087
  * This callback is useful because you might want to have code that happens when the player is hit
9080
9088
  * from an enemy. Normally, you would accomplish this via the `ENTITY_TAKE_DMG` callback, but that
@@ -9096,8 +9104,8 @@ export declare enum ModCallbackCustom {
9096
9104
  */
9097
9105
  POST_HOLY_MANTLE_REMOVED = 37,
9098
9106
  /**
9099
- * Fires from `POST_PEFFECT_UPDATE` callback when the player loses charge on their active
9100
- * collectible item, implying that the item was just used.
9107
+ * Fires from `POST_PEFFECT_UPDATE_REORDERED` callback when the player loses charge on their
9108
+ * active collectible item, implying that the item was just used.
9101
9109
  *
9102
9110
  * This callback is useful because the `USE_ITEM` callback does not fire when The Candle, Red
9103
9111
  * Candle, and Bob's Rotten Brain are discharged.
@@ -9119,9 +9127,9 @@ export declare enum ModCallbackCustom {
9119
9127
  */
9120
9128
  POST_ITEM_DISCHARGE = 38,
9121
9129
  /**
9122
- * Fires from the `POST_PEFFECT_UPDATE` callback when an item is no longer queued (i.e. when the
9123
- * animation of the player holding the item above their head is finished and the item is actually
9124
- * added to the player's inventory).
9130
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when an item is no longer queued (i.e.
9131
+ * when the animation of the player holding the item above their head is finished and the item is
9132
+ * actually added to the player's inventory).
9125
9133
  *
9126
9134
  * Note that this callback will only fire once per Forgotten/Soul pair.
9127
9135
  *
@@ -9404,8 +9412,9 @@ export declare enum ModCallbackCustom {
9404
9412
  */
9405
9413
  POST_PIT_UPDATE = 55,
9406
9414
  /**
9407
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player's health (i.e. hearts) is different
9408
- * than what it was on the previous frame. For more information, see the `PlayerHealth` enum.
9415
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player's health (i.e. hearts) is
9416
+ * different than what it was on the previous frame. For more information, see the `PlayerHealth`
9417
+ * enum.
9409
9418
  *
9410
9419
  * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
9411
9420
  * - You can provide an optional third argument that will make the callback only fire if it
@@ -9425,8 +9434,8 @@ export declare enum ModCallbackCustom {
9425
9434
  */
9426
9435
  POST_PLAYER_CHANGE_HEALTH = 56,
9427
9436
  /**
9428
- * Fires from the `POST_PEFFECT_UPDATE` callback when one of the player's stats change from what
9429
- * they were on the previous frame.
9437
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when one of the player's stats change
9438
+ * from what they were on the previous frame.
9430
9439
  *
9431
9440
  * The type of `oldValue` and `newValue` will depend on what kind of stat it is. For example,
9432
9441
  * `StatType.FLYING` will be a boolean. (You can use the "Types" helper functions to narrow the
@@ -9455,7 +9464,8 @@ export declare enum ModCallbackCustom {
9455
9464
  */
9456
9465
  POST_PLAYER_CHANGE_STAT = 57,
9457
9466
  /**
9458
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player entity changes its player type
9467
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player entity changes its player
9468
+ * type
9459
9469
  * (i.e. character) from what it was on the previous frame. For example, it will fire after using
9460
9470
  * Clicker, after dying with the Judas' Shadow collectible, etc.
9461
9471
  *
@@ -9477,9 +9487,9 @@ export declare enum ModCallbackCustom {
9477
9487
  */
9478
9488
  POST_PLAYER_CHANGE_TYPE = 58,
9479
9489
  /**
9480
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player's collectible count is higher than
9481
- * what it was on the previous frame, or when the active items change, or when the build is
9482
- * rerolled.
9490
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player's collectible count is
9491
+ * higher than what it was on the previous frame, or when the active items change, or when the
9492
+ * build is rerolled.
9483
9493
  *
9484
9494
  * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
9485
9495
  * - You can provide an optional third argument that will make the callback only fire if the
@@ -9494,9 +9504,9 @@ export declare enum ModCallbackCustom {
9494
9504
  */
9495
9505
  POST_PLAYER_COLLECTIBLE_ADDED = 59,
9496
9506
  /**
9497
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player's collectible count is lower than
9498
- * what it was on the previous frame, or when the active items change, or when the build is
9499
- * rerolled.
9507
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player's collectible count is
9508
+ * lower than what it was on the previous frame, or when the active items change, or when the
9509
+ * build is rerolled.
9500
9510
  *
9501
9511
  * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
9502
9512
  * - You can provide an optional third argument that will make the callback only fire if the
@@ -9685,8 +9695,9 @@ export declare enum ModCallbackCustom {
9685
9695
  */
9686
9696
  POST_PROJECTILE_INIT_LATE = 70,
9687
9697
  /**
9688
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player first picks up a new item. The
9689
- * pickup returned in the callback is assumed to be the first pickup that no longer exists.
9698
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player first picks up a new
9699
+ * item. The pickup returned in the callback is assumed to be the first pickup that no longer
9700
+ * exists.
9690
9701
  *
9691
9702
  * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
9692
9703
  * - You can provide an optional third argument that will make the callback only fire if it
@@ -9815,8 +9826,8 @@ export declare enum ModCallbackCustom {
9815
9826
  /**
9816
9827
  * Fires when a new slot entity is initialized. Specifically, this is either:
9817
9828
  *
9818
- * - in the `POST_NEW_ROOM` callback (firing every time a room is entered, even if the entity was
9819
- * previously there on a previous room entry)
9829
+ * - in the `POST_NEW_ROOM_REORDERED` callback (firing every time a room is entered, even if the
9830
+ * entity was previously there on a previous room entry)
9820
9831
  * - in the `POST_UPDATE` callback (if the entity appeared mid-way through the room, like when a
9821
9832
  * Wheel of Fortune card is used)
9822
9833
  *
@@ -9943,7 +9954,7 @@ export declare enum ModCallbackCustom {
9943
9954
  */
9944
9955
  POST_TNT_UPDATE = 87,
9945
9956
  /**
9946
- * Fires from the `POST_PEFFECT_UPDATE` callback when a player gains or loses a new
9957
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when a player gains or loses a new
9947
9958
  * transformation.
9948
9959
  *
9949
9960
  * Note that this callback will only fire once per Forgotten/Soul pair.
@@ -9977,9 +9988,9 @@ export declare enum ModCallbackCustom {
9977
9988
  */
9978
9989
  POST_TRINKET_BREAK = 89,
9979
9990
  /**
9980
- * Fires from the `POST_PEFFECT_UPDATE` callback on the frame before a Berserk effect ends when
9981
- * the player is predicted to die (e.g. they currently have no health left or they took damage in
9982
- * a "Lost" form).
9991
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback on the frame before a Berserk effect
9992
+ * ends when the player is predicted to die (e.g. they currently have no health left or they took
9993
+ * damage in a "Lost" form).
9983
9994
  *
9984
9995
  * When registering the callback with the `ModUpgraded.AddCallbackCustom` method:
9985
9996
  * - You can provide an optional third argument that will make the callback only fire if it
@@ -10032,8 +10043,8 @@ export declare enum ModCallbackCustom {
10032
10043
  */
10033
10044
  PRE_GET_PEDESTAL = 92,
10034
10045
  /**
10035
- * Fires from the `POST_PEFFECT_UPDATE` callback when an item becomes queued (i.e. when the player
10036
- * begins to hold the item above their head).
10046
+ * Fires from the `POST_PEFFECT_UPDATE_REORDERED` callback when an item becomes queued (i.e. when
10047
+ * the player begins to hold the item above their head).
10037
10048
  *
10038
10049
  * Note that this callback will only fire once per Forgotten/Soul pair.
10039
10050
  *
@@ -10703,9 +10714,30 @@ declare class ModdedElementSets extends Feature {
10703
10714
  * }
10704
10715
  * }
10705
10716
  * ```
10717
+ *
10718
+ * In almost all cases, you will want the callback functions to be immediately subscribed after
10719
+ * instantiating the class. However, if this is not the case, you can pass `false` as the optional
10720
+ * second argument to the constructor.
10706
10721
  */
10707
10722
  export declare class ModFeature {
10708
- constructor(mod: ModUpgradedBase);
10723
+ private mod;
10724
+ private initialized;
10725
+ constructor(mod: ModUpgradedBase, init?: boolean);
10726
+ /**
10727
+ * Runs the `Mod.AddCallback` and `ModUpgraded.AddCallbackCustom` methods for all of the decorated
10728
+ * callbacks. Additionally, subscribes the `v` object to the save data manager, if present.
10729
+ *
10730
+ * @param init Optional. Whether to initialize or uninitialize. Default is true.
10731
+ */
10732
+ init(init?: boolean): void;
10733
+ /**
10734
+ * Runs the `Mod.RemoveCallback` and `ModUpgraded.RemoveCallbackCustom` methods for all of the
10735
+ * decorated callbacks. Additionally, unsubscribes the `v` object from the save data manager, if
10736
+ * present.
10737
+ *
10738
+ * This is just an alias for `ModFeature.init(false)`.
10739
+ */
10740
+ uninit(): void;
10709
10741
  }
10710
10742
 
10711
10743
  /**
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 15.2.1
3
+ isaacscript-common 15.3.1
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -27607,8 +27607,6 @@ return ____exports
27607
27607
  local ____lualib = require("lualib_bundle")
27608
27608
  local __TS__Class = ____lualib.__TS__Class
27609
27609
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
27610
- local Set = ____lualib.Set
27611
- local __TS__New = ____lualib.__TS__New
27612
27610
  local ____exports = {}
27613
27611
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
27614
27612
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
@@ -27622,7 +27620,6 @@ PostNPCInitFilter.name = "PostNPCInitFilter"
27622
27620
  __TS__ClassExtends(PostNPCInitFilter, CustomCallback)
27623
27621
  function PostNPCInitFilter.prototype.____constructor(self)
27624
27622
  CustomCallback.prototype.____constructor(self)
27625
- self.v = {room = {firedSet = __TS__New(Set)}}
27626
27623
  self.shouldFire = shouldFireNPC
27627
27624
  self.postNPCInit = function(____, npc)
27628
27625
  self:fire(npc)
@@ -27705,8 +27702,6 @@ return ____exports
27705
27702
  local ____lualib = require("lualib_bundle")
27706
27703
  local __TS__Class = ____lualib.__TS__Class
27707
27704
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
27708
- local Set = ____lualib.Set
27709
- local __TS__New = ____lualib.__TS__New
27710
27705
  local ____exports = {}
27711
27706
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
27712
27707
  local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
@@ -27720,7 +27715,6 @@ PostNPCUpdateFilter.name = "PostNPCUpdateFilter"
27720
27715
  __TS__ClassExtends(PostNPCUpdateFilter, CustomCallback)
27721
27716
  function PostNPCUpdateFilter.prototype.____constructor(self)
27722
27717
  CustomCallback.prototype.____constructor(self)
27723
- self.v = {room = {firedSet = __TS__New(Set)}}
27724
27718
  self.shouldFire = shouldFireNPC
27725
27719
  self.postNPCUpdate = function(____, npc)
27726
27720
  self:fire(npc)
@@ -48346,66 +48340,122 @@ return ____exports
48346
48340
  ["src.classes.ModFeature"] = function(...)
48347
48341
  local ____lualib = require("lualib_bundle")
48348
48342
  local __TS__Class = ____lualib.__TS__Class
48343
+ local Map = ____lualib.Map
48344
+ local __TS__New = ____lualib.__TS__New
48349
48345
  local ____exports = {}
48350
- local checkAddDecoratedCallbacks, checkAddDecoratedCallbacksCustom, checkRegisterSaveDataManager
48346
+ local initDecoratedCallbacks, addCallback, removeCallback, initSaveDataManager, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
48347
+ local ____array = require("src.functions.array")
48348
+ local isArray = ____array.isArray
48349
+ local ____deepCopy = require("src.functions.deepCopy")
48350
+ local deepCopy = ____deepCopy.deepCopy
48351
48351
  local ____tstlClass = require("src.functions.tstlClass")
48352
48352
  local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
48353
48353
  local getTSTLClassName = ____tstlClass.getTSTLClassName
48354
48354
  local ____types = require("src.functions.types")
48355
+ local isFunction = ____types.isFunction
48356
+ local isNumber = ____types.isNumber
48355
48357
  local isTable = ____types.isTable
48356
- function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor, modFeature)
48357
- local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
48358
+ function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, vanilla, init)
48359
+ local modFeatureConstructor = constructor
48360
+ local argsKey = vanilla and ____exports.ADD_CALLBACK_ARGS_KEY or ____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY
48361
+ local addCallbackArgs = modFeatureConstructor[argsKey]
48358
48362
  if addCallbackArgs == nil then
48359
48363
  return
48360
48364
  end
48361
- local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
48365
+ if not isArray(nil, addCallbackArgs) then
48366
+ error(("Failed to initialize/uninitialize the decorated callbacks on a mod feature since the callback arguments on the key of \"" .. argsKey) .. "\" was not an array.")
48367
+ end
48362
48368
  for ____, args in ipairs(addCallbackArgs) do
48363
- local parameters = args
48369
+ if not isArray(nil, args) then
48370
+ error("Failed to initialize/uninitialize the decorated callbacks on a mod feature since one of the callback arguments was not an array.")
48371
+ end
48372
+ local parameters = deepCopy(nil, args)
48364
48373
  local modCallback = table.remove(parameters, 1)
48365
- if modCallback == nil then
48366
- error("Failed to get the ModCallback from the parameters for class: " .. tstlClassName)
48374
+ if not isNumber(nil, modCallback) then
48375
+ error("Failed to get the callback number from the parameters for class: " .. tstlClassName)
48367
48376
  end
48368
48377
  local callback = table.remove(parameters, 1)
48369
- if callback == nil then
48370
- error("Failed to get the callback from the parameters for class: " .. tstlClassName)
48378
+ if not isFunction(nil, callback) then
48379
+ error("Failed to get the callback function from the parameters for class: " .. tstlClassName)
48371
48380
  end
48372
- local function newCallback(____, ...)
48373
- callback(modFeature, ...)
48381
+ local mod = modFeature.mod
48382
+ if init then
48383
+ addCallback(
48384
+ nil,
48385
+ modFeature,
48386
+ modFeatureConstructor,
48387
+ mod,
48388
+ modCallback,
48389
+ callback,
48390
+ parameters,
48391
+ vanilla
48392
+ )
48393
+ else
48394
+ removeCallback(
48395
+ nil,
48396
+ modFeatureConstructor,
48397
+ mod,
48398
+ modCallback,
48399
+ vanilla
48400
+ )
48374
48401
  end
48375
- mod:AddCallback(
48376
- modCallback,
48377
- newCallback,
48378
- table.unpack(parameters)
48379
- )
48380
48402
  end
48381
48403
  end
48382
- function checkAddDecoratedCallbacksCustom(self, mod, modFeatureConstructor, modFeature)
48383
- local addCallbackCustomArgs = modFeatureConstructor[____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY]
48384
- if addCallbackCustomArgs == nil then
48385
- return
48404
+ function addCallback(self, modFeature, modFeatureConstructor, mod, modCallback, callback, parameters, vanilla)
48405
+ local function wrappedCallback(____, ...)
48406
+ callback(nil, modFeature, ...)
48386
48407
  end
48387
- local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
48388
- for ____, args in ipairs(addCallbackCustomArgs) do
48389
- local parameters = args
48390
- local modCallbackCustom = table.remove(parameters, 1)
48391
- if modCallbackCustom == nil then
48392
- error("Failed to get the ModCallbackCustom from the parameters for class: " .. tstlClassName)
48393
- end
48394
- local callback = table.remove(parameters, 1)
48395
- if callback == nil then
48396
- error("Failed to get the callback from the parameters for class: " .. tstlClassName)
48408
+ if vanilla then
48409
+ local modCallbackVanilla = modCallback
48410
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CALLBACK_METHODS_KEY]
48411
+ if wrappedMethodsMap == nil then
48412
+ wrappedMethodsMap = __TS__New(Map)
48413
+ modFeatureConstructor[WRAPPED_CALLBACK_METHODS_KEY] = wrappedMethodsMap
48397
48414
  end
48398
- local function newCallback(____, ...)
48399
- callback(modFeature, ...)
48415
+ wrappedMethodsMap:set(modCallbackVanilla, wrappedCallback)
48416
+ else
48417
+ local modCallbackCustom = modCallback
48418
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CUSTOM_CALLBACK_METHODS_KEY]
48419
+ if wrappedMethodsMap == nil then
48420
+ wrappedMethodsMap = __TS__New(Map)
48421
+ modFeatureConstructor[WRAPPED_CUSTOM_CALLBACK_METHODS_KEY] = wrappedMethodsMap
48400
48422
  end
48423
+ wrappedMethodsMap:set(modCallbackCustom, wrappedCallback)
48424
+ end
48425
+ if vanilla then
48426
+ mod:AddCallback(
48427
+ modCallback,
48428
+ wrappedCallback,
48429
+ table.unpack(parameters)
48430
+ )
48431
+ else
48401
48432
  mod:AddCallbackCustom(
48402
- modCallbackCustom,
48403
- newCallback,
48433
+ modCallback,
48434
+ wrappedCallback,
48404
48435
  table.unpack(parameters)
48405
48436
  )
48406
48437
  end
48407
48438
  end
48408
- function checkRegisterSaveDataManager(self, mod, modFeature)
48439
+ function removeCallback(self, modFeatureConstructor, mod, modCallback, vanilla)
48440
+ if vanilla then
48441
+ local modCallbackVanilla = modCallback
48442
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CALLBACK_METHODS_KEY]
48443
+ if wrappedMethodsMap == nil then
48444
+ return
48445
+ end
48446
+ local wrappedCallback = wrappedMethodsMap:get(modCallbackVanilla)
48447
+ mod:RemoveCallback(modCallback, wrappedCallback)
48448
+ else
48449
+ local modCallbackCustom = modCallback
48450
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CUSTOM_CALLBACK_METHODS_KEY]
48451
+ if wrappedMethodsMap == nil then
48452
+ return
48453
+ end
48454
+ local wrappedCallback = wrappedMethodsMap:get(modCallbackCustom)
48455
+ mod:RemoveCallbackCustom(modCallback, wrappedCallback)
48456
+ end
48457
+ end
48458
+ function initSaveDataManager(self, modFeature, tstlClassName, init)
48409
48459
  local ____modFeature_0 = modFeature
48410
48460
  local v = ____modFeature_0.v
48411
48461
  if v == nil then
@@ -48414,28 +48464,74 @@ function checkRegisterSaveDataManager(self, mod, modFeature)
48414
48464
  if not isTable(nil, v) then
48415
48465
  error("Failed to initialize a mod feature class due to having a \"v\" property that is not an object. (The \"v\" property is supposed to be an object that holds the variables for the class, managed by the save data manager.)")
48416
48466
  end
48417
- local ____mod_1 = mod
48418
- local saveDataManager = ____mod_1.saveDataManager
48419
- if saveDataManager == nil then
48467
+ local mod = modFeature.mod
48468
+ local saveDataManagerMethodName = init and "saveDataManager" or "saveDataManagerRemove"
48469
+ local saveDataManagerMethod = mod[saveDataManagerMethodName]
48470
+ if saveDataManagerMethod == nil then
48420
48471
  error("Failed to initialize a mod feature class due to having a \"v\" object and not having the save data manager initialized. You must pass \"ISCFeature.SAVE_DATA_MANAGER\" to the \"upgradeMod\" function.")
48421
48472
  end
48422
- local tstlClassName = getTSTLClassName(nil, modFeature)
48423
- saveDataManager(nil, tstlClassName, v)
48473
+ if type(saveDataManagerMethod) ~= "function" then
48474
+ error(("The \"" .. saveDataManagerMethodName) .. "\" property of the \"ModUpgraded\" object was not a function.")
48475
+ end
48476
+ if init then
48477
+ saveDataManagerMethod(nil, tstlClassName, v)
48478
+ else
48479
+ saveDataManagerMethod(nil, tstlClassName)
48480
+ end
48424
48481
  end
48425
48482
  ____exports.ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs"
48426
48483
  ____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs"
48484
+ WRAPPED_CALLBACK_METHODS_KEY = "__wrappedCallbackMethods"
48485
+ WRAPPED_CUSTOM_CALLBACK_METHODS_KEY = "__wrappedCustomCallbacksMethods"
48427
48486
  ____exports.ModFeature = __TS__Class()
48428
48487
  local ModFeature = ____exports.ModFeature
48429
48488
  ModFeature.name = "ModFeature"
48430
- function ModFeature.prototype.____constructor(self, mod)
48489
+ function ModFeature.prototype.____constructor(self, mod, init)
48490
+ if init == nil then
48491
+ init = true
48492
+ end
48493
+ self.initialized = false
48494
+ self.mod = mod
48495
+ if init then
48496
+ self:init()
48497
+ end
48498
+ end
48499
+ function ModFeature.prototype.init(self, init)
48500
+ if init == nil then
48501
+ init = true
48502
+ end
48503
+ if self.initialized == init then
48504
+ return
48505
+ end
48506
+ self.initialized = init
48431
48507
  local constructor = getTSTLClassConstructor(nil, self)
48432
48508
  if constructor == nil then
48433
48509
  error("Failed to get the TSTL class constructor for a mod feature.")
48434
48510
  end
48435
- local modFeatureConstructor = constructor
48436
- checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor, self)
48437
- checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor, self)
48438
- checkRegisterSaveDataManager(nil, mod, self)
48511
+ local tstlClassName = getTSTLClassName(nil, self)
48512
+ if tstlClassName == nil then
48513
+ error("Failed to get the TSTL class name for a mod feature.")
48514
+ end
48515
+ initDecoratedCallbacks(
48516
+ nil,
48517
+ self,
48518
+ constructor,
48519
+ tstlClassName,
48520
+ true,
48521
+ init
48522
+ )
48523
+ initDecoratedCallbacks(
48524
+ nil,
48525
+ self,
48526
+ constructor,
48527
+ tstlClassName,
48528
+ false,
48529
+ init
48530
+ )
48531
+ initSaveDataManager(nil, self, tstlClassName, init)
48532
+ end
48533
+ function ModFeature.prototype.uninit(self)
48534
+ self:init(false)
48439
48535
  end
48440
48536
  return ____exports
48441
48537
  end,
@@ -26,8 +26,29 @@ export declare const ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs";
26
26
  * }
27
27
  * }
28
28
  * ```
29
+ *
30
+ * In almost all cases, you will want the callback functions to be immediately subscribed after
31
+ * instantiating the class. However, if this is not the case, you can pass `false` as the optional
32
+ * second argument to the constructor.
29
33
  */
30
34
  export declare class ModFeature {
31
- constructor(mod: ModUpgradedBase);
35
+ private mod;
36
+ private initialized;
37
+ constructor(mod: ModUpgradedBase, init?: boolean);
38
+ /**
39
+ * Runs the `Mod.AddCallback` and `ModUpgraded.AddCallbackCustom` methods for all of the decorated
40
+ * callbacks. Additionally, subscribes the `v` object to the save data manager, if present.
41
+ *
42
+ * @param init Optional. Whether to initialize or uninitialize. Default is true.
43
+ */
44
+ init(init?: boolean): void;
45
+ /**
46
+ * Runs the `Mod.RemoveCallback` and `ModUpgraded.RemoveCallbackCustom` methods for all of the
47
+ * decorated callbacks. Additionally, unsubscribes the `v` object from the save data manager, if
48
+ * present.
49
+ *
50
+ * This is just an alias for `ModFeature.init(false)`.
51
+ */
52
+ uninit(): void;
32
53
  }
33
54
  //# sourceMappingURL=ModFeature.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAOtE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,qBAAa,UAAU;gBACT,GAAG,EAAE,eAAe;CAWjC"}
1
+ {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAatE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,WAAW,CAAS;gBAEhB,GAAG,EAAE,eAAe,EAAE,IAAI,UAAO;IAQ7C;;;;;OAKG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAqB9B;;;;;;OAMG;IACI,MAAM,IAAI,IAAI;CAGtB"}