isaacscript-common 5.0.2 → 5.1.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/functions/array.d.ts +4 -1
- package/functions/array.lua +14 -2
- package/functions/bitwise.d.ts +10 -2
- package/functions/bitwise.lua +13 -1
- package/functions/doors.d.ts +5 -0
- package/functions/doors.lua +8 -0
- package/functions/random.d.ts +2 -1
- package/functions/random.lua +3 -2
- package/functions/set.d.ts +1 -1
- package/functions/set.lua +1 -1
- package/objects/roomShapeToDoorSlotCoordinates.d.ts +4 -0
- package/objects/roomShapeToDoorSlotCoordinates.lua +84 -0
- package/package.json +1 -1
package/functions/array.d.ts
CHANGED
|
@@ -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
|
*
|
package/functions/array.lua
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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]
|
package/functions/bitwise.d.ts
CHANGED
|
@@ -6,8 +6,16 @@
|
|
|
6
6
|
export declare function arrayToBitFlags<T extends BitFlag | BitFlag128>(array: T[] | readonly T[]): BitFlags<T>;
|
|
7
7
|
/** Helper function to convert an array of bits to the resulting decimal number. */
|
|
8
8
|
export declare function convertBinaryToDecimal(bits: int[]): number;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to convert a number to an array of bits.
|
|
11
|
+
*
|
|
12
|
+
* @param number The number to convert.
|
|
13
|
+
* @param minLength Optional. Equal to the minimum amount of bits that should be returned. If the
|
|
14
|
+
* converted number of bits is below this number, 0's will be padded to the left
|
|
15
|
+
* side until the minimum length is met. Default is undefined (which will not cause
|
|
16
|
+
* any padding).
|
|
17
|
+
*/
|
|
18
|
+
export declare function convertDecimalToBinary(number: number, minLength?: int): int[];
|
|
11
19
|
/**
|
|
12
20
|
* Helper function to count the number of bits that are set to 1 in a binary representation of a
|
|
13
21
|
* number.
|
package/functions/bitwise.lua
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__ParseInt = ____lualib.__TS__ParseInt
|
|
3
|
+
local __TS__ArrayUnshift = ____lualib.__TS__ArrayUnshift
|
|
3
4
|
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____flag = require("functions.flag")
|
|
@@ -18,7 +19,13 @@ function ____exports.convertBinaryToDecimal(self, bits)
|
|
|
18
19
|
return __TS__ParseInt(bitsString, 2)
|
|
19
20
|
end
|
|
20
21
|
--- Helper function to convert a number to an array of bits.
|
|
21
|
-
|
|
22
|
+
--
|
|
23
|
+
-- @param number The number to convert.
|
|
24
|
+
-- @param minLength Optional. Equal to the minimum amount of bits that should be returned. If the
|
|
25
|
+
-- converted number of bits is below this number, 0's will be padded to the left
|
|
26
|
+
-- side until the minimum length is met. Default is undefined (which will not cause
|
|
27
|
+
-- any padding).
|
|
28
|
+
function ____exports.convertDecimalToBinary(self, number, minLength)
|
|
22
29
|
local bits = {}
|
|
23
30
|
local i = 0
|
|
24
31
|
while number > 0 do
|
|
@@ -26,6 +33,11 @@ function ____exports.convertDecimalToBinary(self, number)
|
|
|
26
33
|
number = math.floor(number / 2)
|
|
27
34
|
i = i + 1
|
|
28
35
|
end
|
|
36
|
+
if minLength ~= nil then
|
|
37
|
+
while #bits < minLength do
|
|
38
|
+
__TS__ArrayUnshift(bits, 0)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
29
41
|
return bits
|
|
30
42
|
end
|
|
31
43
|
--- Helper function to count the number of bits that are set to 1 in a binary representation of a
|
package/functions/doors.d.ts
CHANGED
|
@@ -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;
|
package/functions/doors.lua
CHANGED
|
@@ -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()
|
package/functions/random.d.ts
CHANGED
|
@@ -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;
|
package/functions/random.lua
CHANGED
|
@@ -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
|
package/functions/set.d.ts
CHANGED
|
@@ -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
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { DoorSlot, RoomShape } from "isaac-typescript-definitions";
|
|
1
2
|
/**
|
|
2
3
|
* The coordinates correspond to the x and y values that are present in a room's XML file.
|
|
3
4
|
*
|
|
4
5
|
* e.g. `<door exists="False" x="-1" y="3" />`
|
|
5
6
|
*/
|
|
7
|
+
export declare const ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES: {
|
|
8
|
+
readonly [key in RoomShape]: ReadonlyMap<DoorSlot, [x: int, y: int]>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local Map = ____lualib.Map
|
|
3
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local ____exports = {}
|
|
5
|
+
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
|
|
6
|
+
local DoorSlot = ____isaac_2Dtypescript_2Ddefinitions.DoorSlot
|
|
7
|
+
local RoomShape = ____isaac_2Dtypescript_2Ddefinitions.RoomShape
|
|
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" />`
|
|
11
|
+
____exports.ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES = {
|
|
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}}
|
|
22
|
+
}),
|
|
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}}
|
|
31
|
+
}),
|
|
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
|
+
})
|
|
83
|
+
}
|
|
84
|
+
return ____exports
|