isaacscript-common 15.2.1 → 15.3.0

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,20 @@ 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
+ constructor(mod: ModUpgradedBase, init?: boolean);
10725
+ /**
10726
+ * Runs the `Mod.AddCallback` and `ModUpgraded.AddCallbackCustom` methods for all of the decorated
10727
+ * callbacks. Additionally, subscribes the `v` object to the save data manager, if present.
10728
+ */
10729
+ init(init?: boolean): void;
10730
+ uninit(): void;
10709
10731
  }
10710
10732
 
10711
10733
  /**
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 15.2.1
3
+ isaacscript-common 15.3.0
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,82 @@ 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
48349
48344
  local ____exports = {}
48350
- local checkAddDecoratedCallbacks, checkAddDecoratedCallbacksCustom, checkRegisterSaveDataManager
48345
+ local initDecoratedCallbacks, initSaveDataManager, WRAPPED_CALLBACK_METHODS_KEY, WRAPPED_CUSTOM_CALLBACK_METHODS_KEY
48346
+ local ____array = require("src.functions.array")
48347
+ local isArray = ____array.isArray
48348
+ local ____deepCopy = require("src.functions.deepCopy")
48349
+ local deepCopy = ____deepCopy.deepCopy
48351
48350
  local ____tstlClass = require("src.functions.tstlClass")
48352
48351
  local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
48353
48352
  local getTSTLClassName = ____tstlClass.getTSTLClassName
48354
48353
  local ____types = require("src.functions.types")
48355
48354
  local isTable = ____types.isTable
48356
- function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor, modFeature)
48357
- local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
48355
+ function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, vanilla, init)
48356
+ local modFeatureConstructor = constructor
48357
+ local argsKey = vanilla and ____exports.ADD_CALLBACK_ARGS_KEY or ____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY
48358
+ local addCallbackArgs = modFeatureConstructor[argsKey]
48358
48359
  if addCallbackArgs == nil then
48359
48360
  return
48360
48361
  end
48361
- local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
48362
+ if not isArray(nil, addCallbackArgs) then
48363
+ 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.")
48364
+ end
48362
48365
  for ____, args in ipairs(addCallbackArgs) do
48363
- local parameters = args
48366
+ if not isArray(nil, args) then
48367
+ error("Failed to initialize/uninitialize the decorated callbacks on a mod feature since one of the callback arguments was not an array.")
48368
+ end
48369
+ local parameters = deepCopy(nil, args)
48364
48370
  local modCallback = table.remove(parameters, 1)
48365
48371
  if modCallback == nil then
48366
- error("Failed to get the ModCallback from the parameters for class: " .. tstlClassName)
48372
+ error("Failed to get the callback number from the parameters for class: " .. tstlClassName)
48367
48373
  end
48368
48374
  local callback = table.remove(parameters, 1)
48369
48375
  if callback == nil then
48370
- error("Failed to get the callback from the parameters for class: " .. tstlClassName)
48371
- end
48372
- local function newCallback(____, ...)
48373
- callback(modFeature, ...)
48376
+ error("Failed to get the callback function from the parameters for class: " .. tstlClassName)
48374
48377
  end
48375
- mod:AddCallback(
48376
- modCallback,
48377
- newCallback,
48378
- table.unpack(parameters)
48379
- )
48380
- end
48381
- 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
48386
- 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)
48397
- end
48398
- local function newCallback(____, ...)
48399
- callback(modFeature, ...)
48378
+ local mod = modFeature.mod
48379
+ if init then
48380
+ local function wrappedCallback(____, ...)
48381
+ callback(modFeature, ...)
48382
+ end
48383
+ if vanilla then
48384
+ local modCallbackVanilla = modCallback
48385
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CALLBACK_METHODS_KEY]
48386
+ wrappedMethodsMap:set(modCallbackVanilla, wrappedCallback)
48387
+ else
48388
+ local modCallbackCustom = modCallback
48389
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CUSTOM_CALLBACK_METHODS_KEY]
48390
+ wrappedMethodsMap:set(modCallbackCustom, wrappedCallback)
48391
+ end
48392
+ if vanilla then
48393
+ mod:AddCallback(
48394
+ modCallback,
48395
+ wrappedCallback,
48396
+ table.unpack(parameters)
48397
+ )
48398
+ else
48399
+ mod:AddCallbackCustom(
48400
+ modCallback,
48401
+ wrappedCallback,
48402
+ table.unpack(parameters)
48403
+ )
48404
+ end
48405
+ elseif vanilla then
48406
+ local modCallbackVanilla = modCallback
48407
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CALLBACK_METHODS_KEY]
48408
+ local wrappedCallback = wrappedMethodsMap:get(modCallbackVanilla)
48409
+ mod:RemoveCallback(modCallback, wrappedCallback)
48410
+ else
48411
+ local modCallbackCustom = modCallback
48412
+ local wrappedMethodsMap = modFeatureConstructor[WRAPPED_CUSTOM_CALLBACK_METHODS_KEY]
48413
+ local wrappedCallback = wrappedMethodsMap:get(modCallbackCustom)
48414
+ mod:RemoveCallbackCustom(modCallback, wrappedCallback)
48400
48415
  end
48401
- mod:AddCallbackCustom(
48402
- modCallbackCustom,
48403
- newCallback,
48404
- table.unpack(parameters)
48405
- )
48406
48416
  end
48407
48417
  end
48408
- function checkRegisterSaveDataManager(self, mod, modFeature)
48418
+ function initSaveDataManager(self, modFeature, tstlClassName, init)
48409
48419
  local ____modFeature_0 = modFeature
48410
48420
  local v = ____modFeature_0.v
48411
48421
  if v == nil then
@@ -48414,28 +48424,69 @@ function checkRegisterSaveDataManager(self, mod, modFeature)
48414
48424
  if not isTable(nil, v) then
48415
48425
  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
48426
  end
48417
- local ____mod_1 = mod
48418
- local saveDataManager = ____mod_1.saveDataManager
48419
- if saveDataManager == nil then
48427
+ local mod = modFeature.mod
48428
+ local saveDataManagerMethodName = init and "saveDataManager" or "saveDataManagerRemove"
48429
+ local saveDataManagerMethod = mod[saveDataManagerMethodName]
48430
+ if saveDataManagerMethod == nil then
48420
48431
  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
48432
  end
48422
- local tstlClassName = getTSTLClassName(nil, modFeature)
48423
- saveDataManager(nil, tstlClassName, v)
48433
+ if type(saveDataManagerMethod) ~= "function" then
48434
+ error(("The \"" .. saveDataManagerMethodName) .. "\" property of the \"ModUpgraded\" object was not a function.")
48435
+ end
48436
+ if init then
48437
+ saveDataManagerMethod(nil, tstlClassName, v)
48438
+ else
48439
+ saveDataManagerMethod(nil, tstlClassName)
48440
+ end
48424
48441
  end
48425
48442
  ____exports.ADD_CALLBACK_ARGS_KEY = "__addCallbackArgs"
48426
48443
  ____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs"
48444
+ WRAPPED_CALLBACK_METHODS_KEY = "__wrappedCallbackMethods"
48445
+ WRAPPED_CUSTOM_CALLBACK_METHODS_KEY = "__wrappedCustomCallbacksMethods"
48427
48446
  ____exports.ModFeature = __TS__Class()
48428
48447
  local ModFeature = ____exports.ModFeature
48429
48448
  ModFeature.name = "ModFeature"
48430
- function ModFeature.prototype.____constructor(self, mod)
48449
+ function ModFeature.prototype.____constructor(self, mod, init)
48450
+ if init == nil then
48451
+ init = true
48452
+ end
48453
+ self.mod = mod
48454
+ if init then
48455
+ self:init()
48456
+ end
48457
+ end
48458
+ function ModFeature.prototype.init(self, init)
48459
+ if init == nil then
48460
+ init = true
48461
+ end
48431
48462
  local constructor = getTSTLClassConstructor(nil, self)
48432
48463
  if constructor == nil then
48433
48464
  error("Failed to get the TSTL class constructor for a mod feature.")
48434
48465
  end
48435
- local modFeatureConstructor = constructor
48436
- checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor, self)
48437
- checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor, self)
48438
- checkRegisterSaveDataManager(nil, mod, self)
48466
+ local tstlClassName = getTSTLClassName(nil, constructor)
48467
+ if tstlClassName == nil then
48468
+ error("Failed to get the TSTL class name for a mod feature.")
48469
+ end
48470
+ initDecoratedCallbacks(
48471
+ nil,
48472
+ self,
48473
+ constructor,
48474
+ tstlClassName,
48475
+ true,
48476
+ init
48477
+ )
48478
+ initDecoratedCallbacks(
48479
+ nil,
48480
+ self,
48481
+ constructor,
48482
+ tstlClassName,
48483
+ false,
48484
+ init
48485
+ )
48486
+ initSaveDataManager(nil, self, tstlClassName, init)
48487
+ end
48488
+ function ModFeature.prototype.uninit(self)
48489
+ self:init(false)
48439
48490
  end
48440
48491
  return ____exports
48441
48492
  end,
@@ -26,8 +26,19 @@ 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
+ constructor(mod: ModUpgradedBase, init?: boolean);
37
+ /**
38
+ * Runs the `Mod.AddCallback` and `ModUpgraded.AddCallbackCustom` methods for all of the decorated
39
+ * callbacks. Additionally, subscribes the `v` object to the save data manager, if present.
40
+ */
41
+ init(init?: boolean): void;
42
+ uninit(): void;
32
43
  }
33
44
  //# 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;AAWtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAkB;gBAEjB,GAAG,EAAE,eAAe,EAAE,IAAI,UAAO;IAQ7C;;;OAGG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAgBvB,MAAM,IAAI,IAAI;CAGtB"}