isaacscript-common 4.9.1 → 5.0.2

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.
@@ -38,6 +38,8 @@ local ____cards = require("functions.cards")
38
38
  local getCardName = ____cards.getCardName
39
39
  local ____character = require("functions.character")
40
40
  local getCharacterName = ____character.getCharacterName
41
+ local ____charge = require("functions.charge")
42
+ local addCharge = ____charge.addCharge
41
43
  local ____collectibles = require("functions.collectibles")
42
44
  local isValidCollectibleType = ____collectibles.isValidCollectibleType
43
45
  local ____entitySpecific = require("functions.entitySpecific")
@@ -199,7 +201,7 @@ function ____exports.addCharges(self, params)
199
201
  printConsole(nil, "That is an invalid amount of arguments.")
200
202
  return
201
203
  end
202
- local activeSlotString, chargeString = table.unpack(args)
204
+ local activeSlotString, numChargeString = table.unpack(args)
203
205
  local activeSlot = tonumber(activeSlotString)
204
206
  if activeSlot == nil then
205
207
  printConsole(
@@ -215,19 +217,17 @@ function ____exports.addCharges(self, params)
215
217
  )
216
218
  return
217
219
  end
218
- local chargeNum = 1
219
- if chargeString ~= nil then
220
- local chargeNumAttempt = tonumber(chargeString)
221
- if chargeNumAttempt == nil then
222
- printConsole(nil, "The provided charge amount is invalid: " .. chargeString)
220
+ local numCharges = 1
221
+ if numChargeString ~= nil then
222
+ local numChargesAttempt = tonumber(numChargeString)
223
+ if numChargesAttempt == nil then
224
+ printConsole(nil, "The provided charge amount is invalid: " .. numChargeString)
223
225
  return
224
226
  end
225
- chargeNum = chargeNumAttempt
227
+ numCharges = numChargesAttempt
226
228
  end
227
229
  local player = Isaac.GetPlayer()
228
- local currentCharge = player:GetActiveCharge(activeSlot)
229
- local newCharge = currentCharge + chargeNum
230
- player:SetActiveCharge(newCharge, activeSlot)
230
+ addCharge(nil, player, activeSlot, numCharges)
231
231
  end
232
232
  --- Warps to the Angel Room for the floor. If the Devil Room has already been visited or initialized,
233
233
  -- this will uninitialize it and make an Angel Room instead.
@@ -1,19 +1,40 @@
1
1
  import { ActiveSlot } from "isaac-typescript-definitions";
2
2
  /**
3
- * Helper function to add a charge to a player's active item, emulating what happens when a room is
4
- * cleared.
3
+ * Helper function to add a charge to the player's active item. Will flash the HUD and play the
4
+ * appropriate sound effect, depending on whether the charge is partially full or completely full.
5
+ *
6
+ * If the player's active item is already fully charged, then this function will return 0 and not
7
+ * flash the HUD or play a sound effect.
5
8
  *
6
9
  * This function will take the following things into account:
7
- * - L rooms and 2x2 rooms granting a double charge
8
10
  * - The Battery
9
11
  * - AAA Battery
10
12
  *
11
13
  * @param player The player to grant the charges to.
12
- * @param ignoreBigRoomDoubleCharge Optional. If set to true, it will treat the current room as a
13
- * 1x1 room for the purposes of calculating how much charge to
14
- * grant. Default is false.
14
+ * @param activeSlot The slot to grant the charges to.
15
+ * @param numCharges Optional. The amount of charges to grant. Default is 1.
16
+ * @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
17
+ * @returns The amount of charges that were actually granted. For example, if the active item was
18
+ * only one away from a full charge, but the `numCharges` provided to this function was 2,
19
+ * then this function would return 1.
15
20
  */
16
- export declare function addRoomClearCharge(player: EntityPlayer, ignoreBigRoomDoubleCharge?: boolean): void;
21
+ export declare function addCharge(player: EntityPlayer, activeSlot: ActiveSlot, numCharges?: number, playSoundEffect?: boolean): int;
22
+ /**
23
+ * Helper function to add a charge to a player's active item(s), emulating what happens when a room
24
+ * is cleared.
25
+ *
26
+ * This function will take the following things into account:
27
+ * - 2x2 rooms and L rooms granting a double charge
28
+ * - The Battery
29
+ * - AAA Battery
30
+ *
31
+ * @param player The player to grant the charges to.
32
+ * @param bigRoomDoubleCharge Optional. If set to false, it will treat the current room as a 1x1
33
+ * room for the purposes of calculating how much charge to grant. Default
34
+ * is true.
35
+ * @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
36
+ */
37
+ export declare function addRoomClearCharge(player: EntityPlayer, bigRoomDoubleCharge?: boolean, playSoundEffect?: boolean): void;
17
38
  /**
18
39
  * Helper function to add a charge to one of a player's active items, emulating what happens when a
19
40
  * room is cleared.
@@ -25,11 +46,12 @@ export declare function addRoomClearCharge(player: EntityPlayer, ignoreBigRoomDo
25
46
  *
26
47
  * @param player The player to grant the charges to.
27
48
  * @param activeSlot The active item slot to grant the charges to.
28
- * @param ignoreBigRoomDoubleCharge Optional. If set to true, it will treat the current room as a
29
- * 1x1 room for the purposes of calculating how much charge to
30
- * grant. Default is false.
49
+ * @param bigRoomDoubleCharge Optional. If set to false, it will treat the current room as a 1x1
50
+ * room for the purposes of calculating how much charge to grant. Default
51
+ * is true.
52
+ * @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
31
53
  */
32
- export declare function addRoomClearChargeToSlot(player: EntityPlayer, activeSlot: ActiveSlot, ignoreBigRoomDoubleCharge?: boolean): void;
54
+ export declare function addRoomClearChargeToSlot(player: EntityPlayer, activeSlot: ActiveSlot, bigRoomDoubleCharge?: boolean, playSoundEffect?: boolean): void;
33
55
  /**
34
56
  * Helper function to add a charge to every player's active item, emulating what happens when a room
35
57
  * is cleared.
@@ -1,9 +1,8 @@
1
1
  local ____exports = {}
2
- local getNumChargesToAdd, getNumChargesWithAAAModifier, shouldPlayFullRechargeSound
2
+ local getClampedChargesToAdd, getChargesToAddWithAAAModifier, shouldPlayFullRechargeSound
3
3
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
4
4
  local ActiveSlot = ____isaac_2Dtypescript_2Ddefinitions.ActiveSlot
5
5
  local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
6
- local RoomShape = ____isaac_2Dtypescript_2Ddefinitions.RoomShape
7
6
  local SoundEffect = ____isaac_2Dtypescript_2Ddefinitions.SoundEffect
8
7
  local TrinketType = ____isaac_2Dtypescript_2Ddefinitions.TrinketType
9
8
  local ____cachedClasses = require("cachedClasses")
@@ -13,41 +12,80 @@ local ____collectibles = require("functions.collectibles")
13
12
  local getCollectibleMaxCharges = ____collectibles.getCollectibleMaxCharges
14
13
  local ____playerIndex = require("functions.playerIndex")
15
14
  local getPlayers = ____playerIndex.getPlayers
16
- --- Helper function to add a charge to one of a player's active items, emulating what happens when a
17
- -- room is cleared.
15
+ local ____roomShape = require("functions.roomShape")
16
+ local getRoomShapeCharges = ____roomShape.getRoomShapeCharges
17
+ --- Helper function to add a charge to the player's active item. Will flash the HUD and play the
18
+ -- appropriate sound effect, depending on whether the charge is partially full or completely full.
19
+ --
20
+ -- If the player's active item is already fully charged, then this function will return 0 and not
21
+ -- flash the HUD or play a sound effect.
18
22
  --
19
23
  -- This function will take the following things into account:
20
- -- - L rooms and 2x2 rooms granting a double charge
21
24
  -- - The Battery
22
25
  -- - AAA Battery
23
26
  --
24
27
  -- @param player The player to grant the charges to.
25
- -- @param activeSlot The active item slot to grant the charges to.
26
- -- @param ignoreBigRoomDoubleCharge Optional. If set to true, it will treat the current room as a
27
- -- 1x1 room for the purposes of calculating how much charge to
28
- -- grant. Default is false.
29
- function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, ignoreBigRoomDoubleCharge)
30
- if ignoreBigRoomDoubleCharge == nil then
31
- ignoreBigRoomDoubleCharge = false
32
- end
33
- if not player:NeedsCharge(activeSlot) then
34
- return
28
+ -- @param activeSlot The slot to grant the charges to.
29
+ -- @param numCharges Optional. The amount of charges to grant. Default is 1.
30
+ -- @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
31
+ -- @returns The amount of charges that were actually granted. For example, if the active item was
32
+ -- only one away from a full charge, but the `numCharges` provided to this function was 2,
33
+ -- then this function would return 1.
34
+ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEffect)
35
+ if numCharges == nil then
36
+ numCharges = 1
37
+ end
38
+ if playSoundEffect == nil then
39
+ playSoundEffect = true
35
40
  end
36
41
  local hud = game:GetHUD()
42
+ local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
43
+ local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
37
44
  local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
38
- local chargesToAdd = getNumChargesToAdd(nil, player, activeSlot, ignoreBigRoomDoubleCharge)
39
- local modifiedChargesToAdd = getNumChargesWithAAAModifier(nil, player, activeSlot, chargesToAdd)
40
45
  local newCharge = totalCharge + modifiedChargesToAdd
46
+ if newCharge == totalCharge then
47
+ return 0
48
+ end
41
49
  player:SetActiveCharge(newCharge, activeSlot)
42
50
  hud:FlashChargeBar(player, activeSlot)
43
- ____exports.playChargeSoundEffect(nil, player, activeSlot)
51
+ if playSoundEffect then
52
+ ____exports.playChargeSoundEffect(nil, player, activeSlot)
53
+ end
54
+ return modifiedChargesToAdd
44
55
  end
45
- function getNumChargesToAdd(self, player, activeSlot, ignoreBigRoomDoubleCharge)
46
- if ignoreBigRoomDoubleCharge == nil then
47
- ignoreBigRoomDoubleCharge = false
56
+ --- Helper function to add a charge to one of a player's active items, emulating what happens when a
57
+ -- room is cleared.
58
+ --
59
+ -- This function will take the following things into account:
60
+ -- - L rooms and 2x2 rooms granting a double charge
61
+ -- - The Battery
62
+ -- - AAA Battery
63
+ --
64
+ -- @param player The player to grant the charges to.
65
+ -- @param activeSlot The active item slot to grant the charges to.
66
+ -- @param bigRoomDoubleCharge Optional. If set to false, it will treat the current room as a 1x1
67
+ -- room for the purposes of calculating how much charge to grant. Default
68
+ -- is true.
69
+ -- @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
70
+ function ____exports.addRoomClearChargeToSlot(self, player, activeSlot, bigRoomDoubleCharge, playSoundEffect)
71
+ if bigRoomDoubleCharge == nil then
72
+ bigRoomDoubleCharge = true
73
+ end
74
+ if playSoundEffect == nil then
75
+ playSoundEffect = true
48
76
  end
49
77
  local room = game:GetRoom()
50
78
  local roomShape = room:GetRoomShape()
79
+ local numCharges = bigRoomDoubleCharge and getRoomShapeCharges(nil, roomShape) or 1
80
+ ____exports.addCharge(
81
+ nil,
82
+ player,
83
+ activeSlot,
84
+ numCharges,
85
+ playSoundEffect
86
+ )
87
+ end
88
+ function getClampedChargesToAdd(self, player, activeSlot, numCharges)
51
89
  local activeItem = player:GetActiveItem(activeSlot)
52
90
  local activeCharge = player:GetActiveCharge(activeSlot)
53
91
  local batteryCharge = player:GetBatteryCharge(activeSlot)
@@ -65,12 +103,9 @@ function getNumChargesToAdd(self, player, activeSlot, ignoreBigRoomDoubleCharge)
65
103
  if hasBattery and batteryCharge + 1 == maxCharges then
66
104
  return 1
67
105
  end
68
- if roomShape >= RoomShape.SHAPE_2x2 and not ignoreBigRoomDoubleCharge then
69
- return 2
70
- end
71
- return 1
106
+ return numCharges
72
107
  end
73
- function getNumChargesWithAAAModifier(self, player, activeSlot, chargesToAdd)
108
+ function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
74
109
  local activeItem = player:GetActiveItem(activeSlot)
75
110
  local activeCharge = player:GetActiveCharge(activeSlot)
76
111
  local batteryCharge = player:GetBatteryCharge(activeSlot)
@@ -81,10 +116,10 @@ function getNumChargesWithAAAModifier(self, player, activeSlot, chargesToAdd)
81
116
  return chargesToAdd
82
117
  end
83
118
  if not hasBattery and activeCharge + chargesToAdd == maxCharges - 1 then
84
- return maxCharges + 1
119
+ return chargesToAdd + 1
85
120
  end
86
121
  if hasBattery and batteryCharge + chargesToAdd == maxCharges - 1 then
87
- return maxCharges + 1
122
+ return chargesToAdd + 1
88
123
  end
89
124
  return chargesToAdd
90
125
  end
@@ -110,28 +145,38 @@ function shouldPlayFullRechargeSound(self, player, activeSlot)
110
145
  local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
111
146
  local maxCharges = getCollectibleMaxCharges(nil, activeItem)
112
147
  if not hasBattery then
113
- return not player:NeedsCharge(activeSlot)
148
+ return activeCharge == maxCharges
114
149
  end
115
- return not player:NeedsCharge(activeSlot) or activeCharge == maxCharges and batteryCharge == 0
150
+ return batteryCharge == maxCharges or activeCharge == maxCharges and batteryCharge == 0
116
151
  end
117
- --- Helper function to add a charge to a player's active item, emulating what happens when a room is
118
- -- cleared.
152
+ --- Helper function to add a charge to a player's active item(s), emulating what happens when a room
153
+ -- is cleared.
119
154
  --
120
155
  -- This function will take the following things into account:
121
- -- - L rooms and 2x2 rooms granting a double charge
156
+ -- - 2x2 rooms and L rooms granting a double charge
122
157
  -- - The Battery
123
158
  -- - AAA Battery
124
159
  --
125
160
  -- @param player The player to grant the charges to.
126
- -- @param ignoreBigRoomDoubleCharge Optional. If set to true, it will treat the current room as a
127
- -- 1x1 room for the purposes of calculating how much charge to
128
- -- grant. Default is false.
129
- function ____exports.addRoomClearCharge(self, player, ignoreBigRoomDoubleCharge)
130
- if ignoreBigRoomDoubleCharge == nil then
131
- ignoreBigRoomDoubleCharge = false
161
+ -- @param bigRoomDoubleCharge Optional. If set to false, it will treat the current room as a 1x1
162
+ -- room for the purposes of calculating how much charge to grant. Default
163
+ -- is true.
164
+ -- @param playSoundEffect Optional. Whether to play a charge-related sound effect. Default is true.
165
+ function ____exports.addRoomClearCharge(self, player, bigRoomDoubleCharge, playSoundEffect)
166
+ if bigRoomDoubleCharge == nil then
167
+ bigRoomDoubleCharge = true
168
+ end
169
+ if playSoundEffect == nil then
170
+ playSoundEffect = true
132
171
  end
133
172
  for ____, activeSlot in ipairs({ActiveSlot.PRIMARY, ActiveSlot.SECONDARY, ActiveSlot.POCKET}) do
134
- ____exports.addRoomClearChargeToSlot(nil, player, activeSlot, ignoreBigRoomDoubleCharge)
173
+ ____exports.addRoomClearChargeToSlot(
174
+ nil,
175
+ player,
176
+ activeSlot,
177
+ bigRoomDoubleCharge,
178
+ playSoundEffect
179
+ )
135
180
  end
136
181
  end
137
182
  --- Helper function to add a charge to every player's active item, emulating what happens when a room
@@ -6,18 +6,25 @@ import { DoorSlot, RoomShape } from "isaac-typescript-definitions";
6
6
  * started.
7
7
  */
8
8
  export declare function getGridIndexDelta(roomShape: RoomShape, doorSlot: DoorSlot): int | undefined;
9
+ /**
10
+ * Helper function to see if a given room shape will grant a single charge or a double charge to the
11
+ * player's active item(s).
12
+ *
13
+ * For example, `RoomShape.SHAPE_2x2` will return 2.
14
+ */
15
+ export declare function getRoomShapeBottomRightPosition(roomShape: RoomShape): Vector;
9
16
  /**
10
17
  * Helper function to get the grid position of the bottom-right tile of a given room shape.
11
18
  *
12
19
  * "Vector(0, 0)" corresponds to the top left tile of a room, not including the walls. (The top-left
13
20
  * wall would be at "Vector(-1, -1)".)
14
21
  */
15
- export declare function getRoomShapeBottomRightPosition(roomShape: RoomShape): Vector;
22
+ export declare function getRoomShapeBounds(roomShape: RoomShape): readonly [width: int, height: int];
16
23
  /**
17
24
  * Helper function to get the bounds of a room shape, which are a box representing its contents.
18
25
  * This does not include the tiles that the walls are on. L rooms use the same bounds as a 2x2 room.
19
26
  */
20
- export declare function getRoomShapeBounds(roomShape: RoomShape): readonly [width: int, height: int];
27
+ export declare function getRoomShapeCharges(roomShape: RoomShape): int;
21
28
  /**
22
29
  * Helper function to get the dimensions of a room shape's layout. This is NOT the size of the
23
30
  * room's actual contents! For that, use the `getRoomShapeBounds` function.
@@ -41,3 +48,10 @@ export declare function getRoomShapeTopLeftPosition(roomShape: RoomShape): Vecto
41
48
  export declare function getRoomShapeVolume(roomShape: RoomShape): int;
42
49
  export declare function getRoomShapeWidth(roomShape: RoomShape): int;
43
50
  export declare function isLRoom(roomShape: RoomShape): boolean;
51
+ /**
52
+ * Helper function to see if a given room shape will grant a single charge or a double charge to the
53
+ * player's active item(s).
54
+ *
55
+ * For example, `RoomShape.SHAPE_2x2` will return true.
56
+ */
57
+ export declare function isRoomShapeDoubleCharge(roomShape: RoomShape): boolean;
@@ -1,6 +1,8 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local Map = ____lualib.Map
3
3
  local ____exports = {}
4
+ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
5
+ local RoomShape = ____isaac_2Dtypescript_2Ddefinitions.RoomShape
4
6
  local ____roomShapeBounds = require("objects.roomShapeBounds")
5
7
  local ROOM_SHAPE_BOUNDS = ____roomShapeBounds.ROOM_SHAPE_BOUNDS
6
8
  local ____roomShapeLayoutSizes = require("objects.roomShapeLayoutSizes")
@@ -17,6 +19,13 @@ local ____roomShapeVolumes = require("objects.roomShapeVolumes")
17
19
  local ROOM_SHAPE_VOLUMES = ____roomShapeVolumes.ROOM_SHAPE_VOLUMES
18
20
  local ____LRoomShapesSet = require("sets.LRoomShapesSet")
19
21
  local L_ROOM_SHAPES_SET = ____LRoomShapesSet.L_ROOM_SHAPES_SET
22
+ --- Helper function to see if a given room shape will grant a single charge or a double charge to the
23
+ -- player's active item(s).
24
+ --
25
+ -- For example, `RoomShape.SHAPE_2x2` will return true.
26
+ function ____exports.isRoomShapeDoubleCharge(self, roomShape)
27
+ return roomShape >= RoomShape.SHAPE_2x2
28
+ end
20
29
  --- Helper function to get the grid index delta that a door out of the given room shape would lead
21
30
  -- to. For example, if you went through the bottom door in a room of `RoomShape.SHAPE_1x2`, you
22
31
  -- would end up in a room with a grid index that is +26 units from the `SafeGridIndex` of where you
@@ -25,17 +34,24 @@ function ____exports.getGridIndexDelta(self, roomShape, doorSlot)
25
34
  local doorSlotToGridIndexMap = ROOM_SHAPE_TO_DOOR_SLOTS_TO_GRID_INDEX_DELTA[roomShape]
26
35
  return doorSlotToGridIndexMap:get(doorSlot)
27
36
  end
37
+ --- Helper function to see if a given room shape will grant a single charge or a double charge to the
38
+ -- player's active item(s).
39
+ --
40
+ -- For example, `RoomShape.SHAPE_2x2` will return 2.
41
+ function ____exports.getRoomShapeBottomRightPosition(self, roomShape)
42
+ return ROOM_SHAPE_TO_BOTTOM_RIGHT_POSITION[roomShape]
43
+ end
28
44
  --- Helper function to get the grid position of the bottom-right tile of a given room shape.
29
45
  --
30
46
  -- "Vector(0, 0)" corresponds to the top left tile of a room, not including the walls. (The top-left
31
47
  -- wall would be at "Vector(-1, -1)".)
32
- function ____exports.getRoomShapeBottomRightPosition(self, roomShape)
33
- return ROOM_SHAPE_TO_BOTTOM_RIGHT_POSITION[roomShape]
48
+ function ____exports.getRoomShapeBounds(self, roomShape)
49
+ return ROOM_SHAPE_BOUNDS[roomShape]
34
50
  end
35
51
  --- Helper function to get the bounds of a room shape, which are a box representing its contents.
36
52
  -- This does not include the tiles that the walls are on. L rooms use the same bounds as a 2x2 room.
37
- function ____exports.getRoomShapeBounds(self, roomShape)
38
- return ROOM_SHAPE_BOUNDS[roomShape]
53
+ function ____exports.getRoomShapeCharges(self, roomShape)
54
+ return ____exports.isRoomShapeDoubleCharge(nil, roomShape) and 2 or 1
39
55
  end
40
56
  --- Helper function to get the dimensions of a room shape's layout. This is NOT the size of the
41
57
  -- room's actual contents! For that, use the `getRoomShapeBounds` function.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The coordinates correspond to the x and y values that are present in a room's XML file.
3
+ *
4
+ * e.g. `<door exists="False" x="-1" y="3" />`
5
+ */
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "4.9.1",
3
+ "version": "5.0.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "index",
23
23
  "types": "index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^3.0.17"
25
+ "isaac-typescript-definitions": "^3.0.18"
26
26
  }
27
27
  }