isaacscript-common 29.7.0 → 29.8.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.
@@ -6915,6 +6915,13 @@ export declare function getTSTLClassName(object: unknown): string | undefined;
6915
6915
  */
6916
6916
  export declare function getUnusedDoorSlots(): DoorSlot[];
6917
6917
 
6918
+ /**
6919
+ * Helper function to find the active slots that the player has the corresponding collectible type
6920
+ * in and have enough charge to be used. Returns an empty array if the player does not have the
6921
+ * collectible in any active slot or does not have enough charges.
6922
+ */
6923
+ export declare function getUsableActiveItemSlots(player: EntityPlayer, collectibleType: CollectibleType): ActiveSlot[];
6924
+
6918
6925
  /**
6919
6926
  * Helper function to get an array with every valid vanilla card sub-type.
6920
6927
  *
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 29.7.0
3
+ isaacscript-common 29.8.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -25339,6 +25339,8 @@ end
25339
25339
  return ____exports
25340
25340
  end,
25341
25341
  ["src.functions.charge"] = function(...)
25342
+ local ____lualib = require("lualib_bundle")
25343
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
25342
25344
  local ____exports = {}
25343
25345
  local getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
25344
25346
  local ____isaac_2Dtypescript_2Ddefinitions = require("lua_modules.isaac-typescript-definitions.dist.src.index")
@@ -25355,6 +25357,8 @@ local getCollectibleChargeType = ____collectibles.getCollectibleChargeType
25355
25357
  local getCollectibleMaxCharges = ____collectibles.getCollectibleMaxCharges
25356
25358
  local ____playerIndex = require("src.functions.playerIndex")
25357
25359
  local getPlayers = ____playerIndex.getPlayers
25360
+ local ____players = require("src.functions.players")
25361
+ local getActiveItemSlots = ____players.getActiveItemSlots
25358
25362
  local ____roomShape = require("src.functions.roomShape")
25359
25363
  local getRoomShapeCharges = ____roomShape.getRoomShapeCharges
25360
25364
  function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEffect)
@@ -25489,6 +25493,17 @@ function ____exports.addRoomClearCharges(self, bigRoomDoubleCharge)
25489
25493
  ____exports.addRoomClearCharge(nil, player, bigRoomDoubleCharge)
25490
25494
  end
25491
25495
  end
25496
+ function ____exports.getUsableActiveItemSlots(self, player, collectibleType)
25497
+ local maxCharges = getCollectibleMaxCharges(nil, collectibleType)
25498
+ local activeSlots = getActiveItemSlots(nil, player, collectibleType)
25499
+ return __TS__ArrayFilter(
25500
+ activeSlots,
25501
+ function(____, activeSlot)
25502
+ local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
25503
+ return totalCharge >= maxCharges
25504
+ end
25505
+ )
25506
+ end
25492
25507
  function ____exports.isActiveSlotDoubleCharged(self, player, activeSlot)
25493
25508
  if activeSlot == nil then
25494
25509
  activeSlot = ActiveSlot.PRIMARY
@@ -1,4 +1,4 @@
1
- import { ActiveSlot } from "isaac-typescript-definitions";
1
+ import { ActiveSlot, CollectibleType } from "isaac-typescript-definitions";
2
2
  /**
3
3
  * Helper function to add a charge to the player's active item. Will flash the HUD and play the
4
4
  * appropriate sound effect, depending on whether the charge is partially full or completely full.
@@ -90,6 +90,12 @@ export declare function getChargesAwayFromMax(player: EntityPlayer, activeSlot?:
90
90
  * @param activeSlot Optional. The slot to get the charges from. Default is `ActiveSlot.PRIMARY`.
91
91
  */
92
92
  export declare function getTotalCharge(player: EntityPlayer, activeSlot?: ActiveSlot): int;
93
+ /**
94
+ * Helper function to find the active slots that the player has the corresponding collectible type
95
+ * in and have enough charge to be used. Returns an empty array if the player does not have the
96
+ * collectible in any active slot or does not have enough charges.
97
+ */
98
+ export declare function getUsableActiveItemSlots(player: EntityPlayer, collectibleType: CollectibleType): ActiveSlot[];
93
99
  /**
94
100
  * Helper function to check if a player's active item is "double charged", meaning that it has both
95
101
  * a full normal charge and a full charge from The Battery.
@@ -1 +1 @@
1
- {"version":3,"file":"charge.d.ts","sourceRoot":"","sources":["../../../src/functions/charge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAKX,MAAM,8BAA8B,CAAC;AAStC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,EAC/B,UAAU,SAAI,EACd,eAAe,UAAO,GACrB,GAAG,CA+BL;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CAaN;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,EAC/B,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CA4BN;AAqBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,mBAAmB,UAAO,GAAG,IAAI,CAIpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,GAAG,CAQL;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,GAAG,CAKL;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,OAAO,CAMT;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,IAAI,CAYN"}
1
+ {"version":3,"file":"charge.d.ts","sourceRoot":"","sources":["../../../src/functions/charge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EAIhB,MAAM,8BAA8B,CAAC;AAUtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,EAC/B,UAAU,SAAI,EACd,eAAe,UAAO,GACrB,GAAG,CA+BL;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CAaN;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,EAC/B,mBAAmB,UAAO,EAC1B,eAAe,UAAO,GACrB,IAAI,CA4BN;AAqBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,mBAAmB,UAAO,GAAG,IAAI,CAIpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,GAAG,CAQL;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,GAAG,CAKL;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,GAC/B,UAAU,EAAE,CAOd;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,OAAO,CAMT;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,YAAY,EACpB,UAAU,aAAqB,GAC9B,IAAI,CAYN"}
@@ -1,3 +1,5 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
1
3
  local ____exports = {}
2
4
  local getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
3
5
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
@@ -14,6 +16,8 @@ local getCollectibleChargeType = ____collectibles.getCollectibleChargeType
14
16
  local getCollectibleMaxCharges = ____collectibles.getCollectibleMaxCharges
15
17
  local ____playerIndex = require("src.functions.playerIndex")
16
18
  local getPlayers = ____playerIndex.getPlayers
19
+ local ____players = require("src.functions.players")
20
+ local getActiveItemSlots = ____players.getActiveItemSlots
17
21
  local ____roomShape = require("src.functions.roomShape")
18
22
  local getRoomShapeCharges = ____roomShape.getRoomShapeCharges
19
23
  --- Helper function to add a charge to the player's active item. Will flash the HUD and play the
@@ -227,6 +231,20 @@ function ____exports.addRoomClearCharges(self, bigRoomDoubleCharge)
227
231
  ____exports.addRoomClearCharge(nil, player, bigRoomDoubleCharge)
228
232
  end
229
233
  end
234
+ --- Helper function to find the active slots that the player has the corresponding collectible type
235
+ -- in and have enough charge to be used. Returns an empty array if the player does not have the
236
+ -- collectible in any active slot or does not have enough charges.
237
+ function ____exports.getUsableActiveItemSlots(self, player, collectibleType)
238
+ local maxCharges = getCollectibleMaxCharges(nil, collectibleType)
239
+ local activeSlots = getActiveItemSlots(nil, player, collectibleType)
240
+ return __TS__ArrayFilter(
241
+ activeSlots,
242
+ function(____, activeSlot)
243
+ local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
244
+ return totalCharge >= maxCharges
245
+ end
246
+ )
247
+ end
230
248
  --- Helper function to check if a player's active item is "double charged", meaning that it has both
231
249
  -- a full normal charge and a full charge from The Battery.
232
250
  --
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "29.7.0",
3
+ "version": "29.8.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -11,6 +11,7 @@ import {
11
11
  getCollectibleMaxCharges,
12
12
  } from "./collectibles";
13
13
  import { getPlayers } from "./playerIndex";
14
+ import { getActiveItemSlots } from "./players";
14
15
  import { getRoomShapeCharges } from "./roomShape";
15
16
 
16
17
  /**
@@ -238,6 +239,23 @@ export function getTotalCharge(
238
239
  return activeCharge + batteryCharge;
239
240
  }
240
241
 
242
+ /**
243
+ * Helper function to find the active slots that the player has the corresponding collectible type
244
+ * in and have enough charge to be used. Returns an empty array if the player does not have the
245
+ * collectible in any active slot or does not have enough charges.
246
+ */
247
+ export function getUsableActiveItemSlots(
248
+ player: EntityPlayer,
249
+ collectibleType: CollectibleType,
250
+ ): ActiveSlot[] {
251
+ const maxCharges = getCollectibleMaxCharges(collectibleType);
252
+ const activeSlots = getActiveItemSlots(player, collectibleType);
253
+ return activeSlots.filter((activeSlot) => {
254
+ const totalCharge = getTotalCharge(player, activeSlot);
255
+ return totalCharge >= maxCharges;
256
+ });
257
+ }
258
+
241
259
  /**
242
260
  * Helper function to check if a player's active item is "double charged", meaning that it has both
243
261
  * a full normal charge and a full charge from The Battery.