isaacscript-common 5.0.1 → 5.1.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.
@@ -63,6 +63,7 @@ export declare function emptyArray<T>(array: T[]): void;
63
63
  * For example, if this function is provided an array containing 1, 2, and 3, then it will return an
64
64
  * array containing the following arrays:
65
65
  *
66
+ * - [] (if `includeEmptyArray` is set to true)
66
67
  * - [1]
67
68
  * - [2]
68
69
  * - [3]
@@ -117,8 +118,10 @@ export declare function getRandomArrayElementAndRemove<T>(array: T[], seedOrRNG?
117
118
  * @param array The array to get the index from.
118
119
  * @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
119
120
  * `RNG.Next` method will be called. Default is `getRandomSeed()`.
121
+ * @param exceptions Optional. An array of indexes that will be skipped over when getting the random
122
+ * index. Default is an empty array.
120
123
  */
121
- export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG): int;
124
+ export declare function getRandomArrayIndex<T>(array: T[] | readonly T[], seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
122
125
  /**
123
126
  * Initializes an array with all elements containing the specified default value.
124
127
  *
@@ -32,14 +32,25 @@ local ____repeat = ____utils["repeat"]
32
32
  -- @param array The array to get the index from.
33
33
  -- @param seedOrRNG Optional. The `Seed` or `RNG` object to use. If an `RNG` object is provided, the
34
34
  -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
35
- function ____exports.getRandomArrayIndex(self, array, seedOrRNG)
35
+ -- @param exceptions Optional. An array of indexes that will be skipped over when getting the random
36
+ -- index. Default is an empty array.
37
+ function ____exports.getRandomArrayIndex(self, array, seedOrRNG, exceptions)
36
38
  if seedOrRNG == nil then
37
39
  seedOrRNG = getRandomSeed(nil)
38
40
  end
41
+ if exceptions == nil then
42
+ exceptions = {}
43
+ end
39
44
  if #array == 0 then
40
45
  error("Failed to get a random array index since the provided array is empty.")
41
46
  end
42
- return getRandomInt(nil, 0, #array - 1, seedOrRNG)
47
+ return getRandomInt(
48
+ nil,
49
+ 0,
50
+ #array - 1,
51
+ seedOrRNG,
52
+ exceptions
53
+ )
43
54
  end
44
55
  --- Shuffles the provided array in-place using the Fisher-Yates algorithm.
45
56
  --
@@ -214,6 +225,7 @@ end
214
225
  -- For example, if this function is provided an array containing 1, 2, and 3, then it will return an
215
226
  -- array containing the following arrays:
216
227
  --
228
+ -- - [] (if `includeEmptyArray` is set to true)
217
229
  -- - [1]
218
230
  -- - [2]
219
231
  -- - [3]
@@ -1,5 +1,5 @@
1
1
  local ____exports = {}
2
- local getClampedChargesToAdd, 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
@@ -40,7 +40,7 @@ function ____exports.addCharge(self, player, activeSlot, numCharges, playSoundEf
40
40
  end
41
41
  local hud = game:GetHUD()
42
42
  local chargesToAdd = getClampedChargesToAdd(nil, player, activeSlot, numCharges)
43
- local modifiedChargesToAdd = getNumChargesWithAAAModifier(nil, player, activeSlot, chargesToAdd)
43
+ local modifiedChargesToAdd = getChargesToAddWithAAAModifier(nil, player, activeSlot, chargesToAdd)
44
44
  local totalCharge = ____exports.getTotalCharge(nil, player, activeSlot)
45
45
  local newCharge = totalCharge + modifiedChargesToAdd
46
46
  if newCharge == totalCharge then
@@ -105,7 +105,7 @@ function getClampedChargesToAdd(self, player, activeSlot, numCharges)
105
105
  end
106
106
  return numCharges
107
107
  end
108
- function getNumChargesWithAAAModifier(self, player, activeSlot, chargesToAdd)
108
+ function getChargesToAddWithAAAModifier(self, player, activeSlot, chargesToAdd)
109
109
  local activeItem = player:GetActiveItem(activeSlot)
110
110
  local activeCharge = player:GetActiveCharge(activeSlot)
111
111
  local batteryCharge = player:GetBatteryCharge(activeSlot)
@@ -145,9 +145,9 @@ function shouldPlayFullRechargeSound(self, player, activeSlot)
145
145
  local hasBattery = player:HasCollectible(CollectibleType.BATTERY)
146
146
  local maxCharges = getCollectibleMaxCharges(nil, activeItem)
147
147
  if not hasBattery then
148
- return not player:NeedsCharge(activeSlot)
148
+ return activeCharge == maxCharges
149
149
  end
150
- return not player:NeedsCharge(activeSlot) or activeCharge == maxCharges and batteryCharge == 0
150
+ return batteryCharge == maxCharges or activeCharge == maxCharges and batteryCharge == 0
151
151
  end
152
152
  --- Helper function to add a charge to a player's active item(s), emulating what happens when a room
153
153
  -- is cleared.
@@ -53,6 +53,11 @@ export declare function getDoors(...roomTypes: RoomType[]): GridEntityDoor[];
53
53
  export declare function getDoorsToRoomIndex(...roomGridIndex: int[]): GridEntityDoor[];
54
54
  export declare function getOppositeDoorSlot(doorSlot: DoorSlot): DoorSlot | undefined;
55
55
  export declare function getRepentanceDoor(): GridEntityDoor | undefined;
56
+ /**
57
+ * Helper function to get the room grid coordinates for a specific room shape and door slot
58
+ * combination.
59
+ */
60
+ export declare function getRoomShapeDoorSlotCoordinates(roomShape: RoomShape, doorSlot: DoorSlot): readonly [x: int, y: int] | undefined;
56
61
  /** Helper function to find unused door slots in the room that can be used to make custom doors. */
57
62
  export declare function getUnusedDoorSlots(): DoorSlot[];
58
63
  export declare function isAngelRoomDoor(door: GridEntityDoor): boolean;
@@ -24,6 +24,8 @@ local ____doorSlotToDoorSlotFlag = require("objects.doorSlotToDoorSlotFlag")
24
24
  local DOOR_SLOT_TO_DOOR_SLOT_FLAG = ____doorSlotToDoorSlotFlag.DOOR_SLOT_TO_DOOR_SLOT_FLAG
25
25
  local ____oppositeDoorSlots = require("objects.oppositeDoorSlots")
26
26
  local OPPOSITE_DOOR_SLOTS = ____oppositeDoorSlots.OPPOSITE_DOOR_SLOTS
27
+ local ____roomShapeToDoorSlotCoordinates = require("objects.roomShapeToDoorSlotCoordinates")
28
+ local ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES = ____roomShapeToDoorSlotCoordinates.ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES
27
29
  local ____roomShapeToDoorSlots = require("objects.roomShapeToDoorSlots")
28
30
  local ROOM_SHAPE_TO_DOOR_SLOTS = ____roomShapeToDoorSlots.ROOM_SHAPE_TO_DOOR_SLOTS
29
31
  local ____bitwise = require("functions.bitwise")
@@ -190,6 +192,12 @@ function ____exports.getRepentanceDoor(self)
190
192
  function(____, door) return ____exports.isRepentanceDoor(nil, door) end
191
193
  )
192
194
  end
195
+ --- Helper function to get the room grid coordinates for a specific room shape and door slot
196
+ -- combination.
197
+ function ____exports.getRoomShapeDoorSlotCoordinates(self, roomShape, doorSlot)
198
+ local coordinatesMap = ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES[roomShape]
199
+ return coordinatesMap:get(doorSlot)
200
+ end
193
201
  --- Helper function to find unused door slots in the room that can be used to make custom doors.
194
202
  function ____exports.getUnusedDoorSlots(self)
195
203
  local room = game:GetRoom()
@@ -42,6 +42,7 @@ export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RN
42
42
  * `RNG.Next` method will be called. Default is `getRandomSeed()`.
43
43
  * @param exceptions Optional. An array of elements that will be skipped over when getting the
44
44
  * random integer. For example, a min of 1, a max of 4, and an exceptions array of
45
- * `[2]` would cause the function to return either 1, 3, or 4.
45
+ * `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
46
+ * array.
46
47
  */
47
48
  export declare function getRandomInt(min: int, max: int, seedOrRNG?: Seed | RNG, exceptions?: int[] | readonly int[]): int;
@@ -59,7 +59,8 @@ end
59
59
  -- `RNG.Next` method will be called. Default is `getRandomSeed()`.
60
60
  -- @param exceptions Optional. An array of elements that will be skipped over when getting the
61
61
  -- random integer. For example, a min of 1, a max of 4, and an exceptions array of
62
- -- `[2]` would cause the function to return either 1, 3, or 4.
62
+ -- `[2]` would cause the function to return either 1, 3, or 4. Default is an empty
63
+ -- array.
63
64
  function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
64
65
  if seedOrRNG == nil then
65
66
  seedOrRNG = getRandomSeed(nil)
@@ -80,7 +81,7 @@ function ____exports.getRandomInt(self, min, max, seedOrRNG, exceptions)
80
81
  do
81
82
  randomInt = rng:RandomInt(max - min + 1) + min
82
83
  end
83
- until exceptionsSet:has(randomInt)
84
+ until not exceptionsSet:has(randomInt)
84
85
  return randomInt
85
86
  end
86
87
  return ____exports
@@ -38,7 +38,7 @@ export declare function getRandomSetElement<T>(set: Set<T> | ReadonlySet<T>, see
38
38
  * For example, if this function is provided a set containing 1, 2, and 3, then it will return an
39
39
  * array containing the following sets:
40
40
  *
41
- * - []
41
+ * - [] (if `includeEmptyArray` is set to true)
42
42
  * - [1]
43
43
  * - [2]
44
44
  * - [3]
package/functions/set.lua CHANGED
@@ -88,7 +88,7 @@ end
88
88
  -- For example, if this function is provided a set containing 1, 2, and 3, then it will return an
89
89
  -- array containing the following sets:
90
90
  --
91
- -- - []
91
+ -- - [] (if `includeEmptyArray` is set to true)
92
92
  -- - [1]
93
93
  -- - [2]
94
94
  -- - [3]
@@ -1,4 +1,9 @@
1
1
  import { DoorSlot, RoomShape } from "isaac-typescript-definitions";
2
+ /**
3
+ * The coordinates correspond to the x and y values that are present in a room's XML file.
4
+ *
5
+ * e.g. `<door exists="False" x="-1" y="3" />`
6
+ */
2
7
  export declare const ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES: {
3
- readonly [key in RoomShape]: ReadonlySet<DoorSlot>;
8
+ readonly [key in RoomShape]: ReadonlyMap<DoorSlot, [x: int, y: int]>;
4
9
  };
@@ -1,46 +1,84 @@
1
1
  local ____lualib = require("lualib_bundle")
2
- local Set = ____lualib.Set
2
+ local Map = ____lualib.Map
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local ____exports = {}
5
5
  local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
6
6
  local DoorSlot = ____isaac_2Dtypescript_2Ddefinitions.DoorSlot
7
7
  local RoomShape = ____isaac_2Dtypescript_2Ddefinitions.RoomShape
8
- local ALL_DOOR_SLOTS_SET = __TS__New(Set, {
9
- DoorSlot.LEFT_0,
10
- DoorSlot.UP_0,
11
- DoorSlot.RIGHT_0,
12
- DoorSlot.DOWN_0,
13
- DoorSlot.LEFT_1,
14
- DoorSlot.UP_1,
15
- DoorSlot.RIGHT_1,
16
- DoorSlot.DOWN_1
17
- })
8
+ --- The coordinates correspond to the x and y values that are present in a room's XML file.
9
+ --
10
+ -- e.g. `<door exists="False" x="-1" y="3" />`
18
11
  ____exports.ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES = {
19
- [RoomShape.SHAPE_1x1] = __TS__New(Set, {DoorSlot.LEFT_0, DoorSlot.UP_0, DoorSlot.RIGHT_0, DoorSlot.DOWN_0}),
20
- [RoomShape.IH] = __TS__New(Set, {DoorSlot.LEFT_0, DoorSlot.RIGHT_0}),
21
- [RoomShape.IV] = __TS__New(Set, {DoorSlot.UP_0, DoorSlot.DOWN_0}),
22
- [RoomShape.SHAPE_1x2] = __TS__New(Set, {
23
- DoorSlot.LEFT_0,
24
- DoorSlot.UP_0,
25
- DoorSlot.RIGHT_0,
26
- DoorSlot.DOWN_0,
27
- DoorSlot.LEFT_1,
28
- DoorSlot.RIGHT_1
12
+ [RoomShape.SHAPE_1x1] = __TS__New(Map, {{DoorSlot.LEFT_0, {-1, 3}}, {DoorSlot.UP_0, {6, -1}}, {DoorSlot.RIGHT_0, {13, 3}}, {DoorSlot.DOWN_0, {6, 7}}}),
13
+ [RoomShape.IH] = __TS__New(Map, {{DoorSlot.LEFT_0, {-1, 3}}, {DoorSlot.RIGHT_0, {13, 3}}}),
14
+ [RoomShape.IV] = __TS__New(Map, {{DoorSlot.UP_0, {6, -1}}, {DoorSlot.DOWN_0, {6, 7}}}),
15
+ [RoomShape.SHAPE_1x2] = __TS__New(Map, {
16
+ {DoorSlot.LEFT_0, {-1, 3}},
17
+ {DoorSlot.UP_0, {6, -1}},
18
+ {DoorSlot.RIGHT_0, {13, 3}},
19
+ {DoorSlot.DOWN_0, {6, 14}},
20
+ {DoorSlot.LEFT_1, {-1, 10}},
21
+ {DoorSlot.RIGHT_1, {13, 10}}
29
22
  }),
30
- [RoomShape.IIV] = __TS__New(Set, {DoorSlot.UP_0, DoorSlot.DOWN_0}),
31
- [RoomShape.SHAPE_2x1] = __TS__New(Set, {
32
- DoorSlot.LEFT_0,
33
- DoorSlot.UP_0,
34
- DoorSlot.RIGHT_0,
35
- DoorSlot.DOWN_0,
36
- DoorSlot.UP_1,
37
- DoorSlot.DOWN_1
23
+ [RoomShape.IIV] = __TS__New(Map, {{DoorSlot.UP_0, {6, -1}}, {DoorSlot.DOWN_0, {6, 14}}}),
24
+ [RoomShape.SHAPE_2x1] = __TS__New(Map, {
25
+ {DoorSlot.LEFT_0, {-1, 3}},
26
+ {DoorSlot.UP_0, {6, -1}},
27
+ {DoorSlot.RIGHT_0, {26, 3}},
28
+ {DoorSlot.DOWN_0, {6, 7}},
29
+ {DoorSlot.UP_1, {19, -1}},
30
+ {DoorSlot.DOWN_1, {19, 7}}
38
31
  }),
39
- [RoomShape.IIH] = __TS__New(Set, {DoorSlot.LEFT_0, DoorSlot.RIGHT_0}),
40
- [RoomShape.SHAPE_2x2] = ALL_DOOR_SLOTS_SET,
41
- [RoomShape.LTL] = ALL_DOOR_SLOTS_SET,
42
- [RoomShape.LTR] = ALL_DOOR_SLOTS_SET,
43
- [RoomShape.LBL] = ALL_DOOR_SLOTS_SET,
44
- [RoomShape.LBR] = ALL_DOOR_SLOTS_SET
32
+ [RoomShape.IIH] = __TS__New(Map, {{DoorSlot.LEFT_0, {-1, 3}}, {DoorSlot.RIGHT_0, {26, 3}}}),
33
+ [RoomShape.SHAPE_2x2] = __TS__New(Map, {
34
+ {DoorSlot.LEFT_0, {-1, 3}},
35
+ {DoorSlot.UP_0, {6, -1}},
36
+ {DoorSlot.RIGHT_0, {26, 3}},
37
+ {DoorSlot.DOWN_0, {6, 14}},
38
+ {DoorSlot.LEFT_1, {-1, 10}},
39
+ {DoorSlot.UP_1, {19, -1}},
40
+ {DoorSlot.RIGHT_1, {26, 10}},
41
+ {DoorSlot.DOWN_1, {19, 14}}
42
+ }),
43
+ [RoomShape.LTL] = __TS__New(Map, {
44
+ {DoorSlot.LEFT_0, {12, 3}},
45
+ {DoorSlot.UP_0, {6, 6}},
46
+ {DoorSlot.RIGHT_0, {26, 3}},
47
+ {DoorSlot.DOWN_0, {6, 14}},
48
+ {DoorSlot.LEFT_1, {-1, 10}},
49
+ {DoorSlot.UP_1, {19, -1}},
50
+ {DoorSlot.RIGHT_1, {26, 10}},
51
+ {DoorSlot.DOWN_1, {19, 14}}
52
+ }),
53
+ [RoomShape.LTR] = __TS__New(Map, {
54
+ {DoorSlot.LEFT_0, {-1, 3}},
55
+ {DoorSlot.UP_0, {6, -1}},
56
+ {DoorSlot.RIGHT_0, {13, 3}},
57
+ {DoorSlot.DOWN_0, {6, 14}},
58
+ {DoorSlot.LEFT_1, {-1, 10}},
59
+ {DoorSlot.UP_1, {19, 6}},
60
+ {DoorSlot.RIGHT_1, {26, 10}},
61
+ {DoorSlot.DOWN_1, {19, 14}}
62
+ }),
63
+ [RoomShape.LBL] = __TS__New(Map, {
64
+ {DoorSlot.LEFT_0, {-1, 3}},
65
+ {DoorSlot.UP_0, {6, -1}},
66
+ {DoorSlot.RIGHT_0, {26, 3}},
67
+ {DoorSlot.DOWN_0, {6, 7}},
68
+ {DoorSlot.LEFT_1, {12, 10}},
69
+ {DoorSlot.UP_1, {19, -1}},
70
+ {DoorSlot.RIGHT_1, {26, 10}},
71
+ {DoorSlot.DOWN_1, {19, 14}}
72
+ }),
73
+ [RoomShape.LBR] = __TS__New(Map, {
74
+ {DoorSlot.LEFT_0, {-1, 3}},
75
+ {DoorSlot.UP_0, {6, -1}},
76
+ {DoorSlot.RIGHT_0, {26, 3}},
77
+ {DoorSlot.DOWN_0, {6, 14}},
78
+ {DoorSlot.LEFT_1, {-1, 10}},
79
+ {DoorSlot.UP_1, {19, -1}},
80
+ {DoorSlot.RIGHT_1, {13, 10}},
81
+ {DoorSlot.DOWN_1, {19, 7}}
82
+ })
45
83
  }
46
84
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
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
  }