isaacscript-common 34.1.0 → 34.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/dist/index.rollup.d.ts +9 -6
- package/dist/isaacscript-common.lua +10 -6
- package/dist/src/functions/enums.d.ts +1 -1
- package/dist/src/functions/enums.d.ts.map +1 -1
- package/dist/src/functions/jsonRoom.d.ts.map +1 -1
- package/dist/src/functions/jsonRoom.lua +4 -5
- package/dist/src/functions/roomData.d.ts +8 -5
- package/dist/src/functions/roomData.d.ts.map +1 -1
- package/dist/src/functions/roomData.lua +13 -5
- package/package.json +1 -1
- package/src/functions/enums.ts +4 -4
- package/src/functions/jsonRoom.ts +4 -5
- package/src/functions/roomData.ts +15 -5
package/dist/index.rollup.d.ts
CHANGED
|
@@ -6718,12 +6718,15 @@ export declare function getRoomDescriptorsForType(...roomTypes: RoomType[]): Roo
|
|
|
6718
6718
|
export declare function getRoomDisplayFlags(roomGridIndex?: int, minimapAPI?: boolean): BitFlags<DisplayFlag>;
|
|
6719
6719
|
|
|
6720
6720
|
/**
|
|
6721
|
-
* Helper function to get the
|
|
6722
|
-
* as the top-left 1x1 section that the room overlaps with, or the top-right 1x1 section of a
|
|
6723
|
-
* `RoomType.SHAPE_LTL` room.)
|
|
6721
|
+
* Helper function to get the grid index of the current room.
|
|
6724
6722
|
*
|
|
6725
|
-
*
|
|
6726
|
-
*
|
|
6723
|
+
* - If the current room is inside of the grid, this function will return the `SafeGridIndex` from
|
|
6724
|
+
* the room descriptor. (The safe grid index is defined as the top-left 1x1 section that the room
|
|
6725
|
+
* overlaps with, or the top-right 1x1 section of a `RoomType.SHAPE_LTL` room.)
|
|
6726
|
+
* - If the current room is outside of the grid, it will return the index from the
|
|
6727
|
+
* `Level.GetCurrentRoomIndex` method (since `SafeGridIndex` is bugged for these cases, as
|
|
6728
|
+
* demonstrated by entering a Genesis room and entering `l
|
|
6729
|
+
* print(Game():GetLevel():GetCurrentRoomDesc().SafeGridIndex)` into the console).
|
|
6727
6730
|
*
|
|
6728
6731
|
* Use this function instead of the `Level.GetCurrentRoomIndex` method directly because the latter
|
|
6729
6732
|
* will return the specific 1x1 quadrant that the player entered the room at. For most situations,
|
|
@@ -8456,7 +8459,7 @@ export declare function isEntity(variable: unknown): variable is Entity;
|
|
|
8456
8459
|
export declare function isEntityMoving(entity: Entity, threshold?: number): boolean;
|
|
8457
8460
|
|
|
8458
8461
|
/** Helper function to validate that a particular value exists inside of an enum. */
|
|
8459
|
-
export declare function isEnumValue(value: number | string, transpiledEnum:
|
|
8462
|
+
export declare function isEnumValue<T extends Record<string, number | string>>(value: number | string, transpiledEnum: T): value is T[keyof T];
|
|
8460
8463
|
|
|
8461
8464
|
export declare function isEven(num: int): boolean;
|
|
8462
8465
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 34.1.
|
|
3
|
+
isaacscript-common 34.1.1
|
|
4
4
|
|
|
5
5
|
This is the "isaacscript-common" library, which was created with the IsaacScript tool.
|
|
6
6
|
|
|
@@ -26790,6 +26790,11 @@ function ____exports.getRoomDescriptorReadOnly(self)
|
|
|
26790
26790
|
return level:GetCurrentRoomDesc()
|
|
26791
26791
|
end
|
|
26792
26792
|
function ____exports.getRoomGridIndex(self)
|
|
26793
|
+
local level = game:GetLevel()
|
|
26794
|
+
local currentRoomIndex = level:GetCurrentRoomIndex()
|
|
26795
|
+
if currentRoomIndex < 0 then
|
|
26796
|
+
return currentRoomIndex
|
|
26797
|
+
end
|
|
26793
26798
|
local roomDescriptor = ____exports.getRoomDescriptorReadOnly(nil)
|
|
26794
26799
|
return roomDescriptor.SafeGridIndex
|
|
26795
26800
|
end
|
|
@@ -46725,12 +46730,11 @@ function getJSONObjectWithChosenWeight(self, jsonOjectArray, chosenWeight)
|
|
|
46725
46730
|
end
|
|
46726
46731
|
function ____exports.getJSONRoomDoorSlotFlags(self, jsonRoom)
|
|
46727
46732
|
local roomShapeString = jsonRoom["$"].shape
|
|
46728
|
-
local
|
|
46729
|
-
assertDefined(nil,
|
|
46730
|
-
if not isEnumValue(nil,
|
|
46731
|
-
error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(
|
|
46733
|
+
local roomShape = tonumber(roomShapeString)
|
|
46734
|
+
assertDefined(nil, roomShape, "Failed to parse the \"shape\" field of a JSON room: " .. roomShapeString)
|
|
46735
|
+
if not isEnumValue(nil, roomShape, RoomShape) then
|
|
46736
|
+
error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(roomShape))
|
|
46732
46737
|
end
|
|
46733
|
-
local roomShape = roomShapeNumber
|
|
46734
46738
|
local doorSlotFlags = DoorSlotFlagZero
|
|
46735
46739
|
for ____, door in ipairs(jsonRoom.door) do
|
|
46736
46740
|
do
|
|
@@ -83,7 +83,7 @@ export declare function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T];
|
|
|
83
83
|
*/
|
|
84
84
|
export declare function getRandomEnumValue<T>(transpiledEnum: T, seedOrRNG?: Seed | RNG, exceptions?: Array<T[keyof T]> | ReadonlyArray<T[keyof T]>): T[keyof T];
|
|
85
85
|
/** Helper function to validate that a particular value exists inside of an enum. */
|
|
86
|
-
export declare function isEnumValue(value: number | string, transpiledEnum:
|
|
86
|
+
export declare function isEnumValue<T extends Record<string, number | string>>(value: number | string, transpiledEnum: T): value is T[keyof T];
|
|
87
87
|
/**
|
|
88
88
|
* Helper function to check every value of a custom enum for -1. Will throw an run-time error if any
|
|
89
89
|
* -1 values are found. This is helpful because many methods of the Isaac class return -1 if they
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../../src/functions/enums.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,cAAc,EAAE,CAAC,GAChB,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK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CAGrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,OAAO,GACtB,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,CAAC,GAChB,IAAI,CAsBN;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,4BAA4B,CAE1C,CAAC,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAC/B,IAAI,SAAS,MAAM,GAAG,MAAM,KACzB,IAAI,CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonRoom.d.ts","sourceRoot":"","sources":["../../../src/functions/jsonRoom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAexE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"jsonRoom.d.ts","sourceRoot":"","sources":["../../../src/functions/jsonRoom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAexE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,YAAY,CAAC,CAqDxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,OAAO,EAAE,GAAG,GACX,QAAQ,GAAG,SAAS,CAoBtB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,EAC3C,OAAO,EAAE,GAAG,GACX,QAAQ,EAAE,CAMZ;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,UAAU,EAAE,EAC1B,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,UAAU,CAqBZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,GAAE,IAAI,GAAG,GAAqB,EACvC,OAAO,UAAQ,GACd,QAAQ,CAkBV"}
|
|
@@ -62,12 +62,11 @@ end
|
|
|
62
62
|
-- (A JSON room is an XML file converted to JSON so that it can be directly imported into your mod.)
|
|
63
63
|
function ____exports.getJSONRoomDoorSlotFlags(self, jsonRoom)
|
|
64
64
|
local roomShapeString = jsonRoom["$"].shape
|
|
65
|
-
local
|
|
66
|
-
assertDefined(nil,
|
|
67
|
-
if not isEnumValue(nil,
|
|
68
|
-
error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(
|
|
65
|
+
local roomShape = tonumber(roomShapeString)
|
|
66
|
+
assertDefined(nil, roomShape, "Failed to parse the \"shape\" field of a JSON room: " .. roomShapeString)
|
|
67
|
+
if not isEnumValue(nil, roomShape, RoomShape) then
|
|
68
|
+
error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(roomShape))
|
|
69
69
|
end
|
|
70
|
-
local roomShape = roomShapeNumber
|
|
71
70
|
local doorSlotFlags = DoorSlotFlagZero
|
|
72
71
|
for ____, door in ipairs(jsonRoom.door) do
|
|
73
72
|
do
|
|
@@ -18,12 +18,15 @@ export declare function getRoomDescriptor(roomGridIndex?: int): RoomDescriptor;
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function getRoomDescriptorReadOnly(): Readonly<RoomDescriptor>;
|
|
20
20
|
/**
|
|
21
|
-
* Helper function to get the
|
|
22
|
-
* as the top-left 1x1 section that the room overlaps with, or the top-right 1x1 section of a
|
|
23
|
-
* `RoomType.SHAPE_LTL` room.)
|
|
21
|
+
* Helper function to get the grid index of the current room.
|
|
24
22
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* - If the current room is inside of the grid, this function will return the `SafeGridIndex` from
|
|
24
|
+
* the room descriptor. (The safe grid index is defined as the top-left 1x1 section that the room
|
|
25
|
+
* overlaps with, or the top-right 1x1 section of a `RoomType.SHAPE_LTL` room.)
|
|
26
|
+
* - If the current room is outside of the grid, it will return the index from the
|
|
27
|
+
* `Level.GetCurrentRoomIndex` method (since `SafeGridIndex` is bugged for these cases, as
|
|
28
|
+
* demonstrated by entering a Genesis room and entering `l
|
|
29
|
+
* print(Game():GetLevel():GetCurrentRoomDesc().SafeGridIndex)` into the console).
|
|
27
30
|
*
|
|
28
31
|
* Use this function instead of the `Level.GetCurrentRoomIndex` method directly because the latter
|
|
29
32
|
* will return the specific 1x1 quadrant that the player entered the room at. For most situations,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roomData.d.ts","sourceRoot":"","sources":["../../../src/functions/roomData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,OAAO,EACR,MAAM,8BAA8B,CAAC;AAMtC;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAgBtE;AAGD,wBAAgB,WAAW,IAAI,UAAU,CAAC;AAC1C,wBAAgB,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,UAAU,GAAG,SAAS,CAAC;AAYzE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,cAAc,CAQrE;AAED;;;GAGG;AACH,wBAAgB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,CAAC,CAAC,CAG9D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAGvD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAG5D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,GAAG,IAAI,CAG1E"}
|
|
@@ -33,12 +33,15 @@ function ____exports.getRoomDescriptorReadOnly(self)
|
|
|
33
33
|
local level = game:GetLevel()
|
|
34
34
|
return level:GetCurrentRoomDesc()
|
|
35
35
|
end
|
|
36
|
-
--- Helper function to get the
|
|
37
|
-
-- as the top-left 1x1 section that the room overlaps with, or the top-right 1x1 section of a
|
|
38
|
-
-- `RoomType.SHAPE_LTL` room.)
|
|
36
|
+
--- Helper function to get the grid index of the current room.
|
|
39
37
|
--
|
|
40
|
-
--
|
|
41
|
-
--
|
|
38
|
+
-- - If the current room is inside of the grid, this function will return the `SafeGridIndex` from
|
|
39
|
+
-- the room descriptor. (The safe grid index is defined as the top-left 1x1 section that the room
|
|
40
|
+
-- overlaps with, or the top-right 1x1 section of a `RoomType.SHAPE_LTL` room.)
|
|
41
|
+
-- - If the current room is outside of the grid, it will return the index from the
|
|
42
|
+
-- `Level.GetCurrentRoomIndex` method (since `SafeGridIndex` is bugged for these cases, as
|
|
43
|
+
-- demonstrated by entering a Genesis room and entering `l
|
|
44
|
+
-- print(Game():GetLevel():GetCurrentRoomDesc().SafeGridIndex)` into the console).
|
|
42
45
|
--
|
|
43
46
|
-- Use this function instead of the `Level.GetCurrentRoomIndex` method directly because the latter
|
|
44
47
|
-- will return the specific 1x1 quadrant that the player entered the room at. For most situations,
|
|
@@ -47,6 +50,11 @@ end
|
|
|
47
50
|
-- Data structures that store data per room should use the room's `ListIndex` instead of
|
|
48
51
|
-- `SafeGridIndex`, since the former is unique across different dimensions.
|
|
49
52
|
function ____exports.getRoomGridIndex(self)
|
|
53
|
+
local level = game:GetLevel()
|
|
54
|
+
local currentRoomIndex = level:GetCurrentRoomIndex()
|
|
55
|
+
if currentRoomIndex < 0 then
|
|
56
|
+
return currentRoomIndex
|
|
57
|
+
end
|
|
50
58
|
local roomDescriptor = ____exports.getRoomDescriptorReadOnly(nil)
|
|
51
59
|
return roomDescriptor.SafeGridIndex
|
|
52
60
|
end
|
package/package.json
CHANGED
package/src/functions/enums.ts
CHANGED
|
@@ -154,12 +154,12 @@ export function getRandomEnumValue<T>(
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/** Helper function to validate that a particular value exists inside of an enum. */
|
|
157
|
-
export function isEnumValue(
|
|
157
|
+
export function isEnumValue<T extends Record<string, number | string>>(
|
|
158
158
|
value: number | string,
|
|
159
|
-
transpiledEnum:
|
|
160
|
-
):
|
|
159
|
+
transpiledEnum: T,
|
|
160
|
+
): value is T[keyof T] {
|
|
161
161
|
const enumValues = getEnumValues(transpiledEnum);
|
|
162
|
-
return enumValues.includes(value);
|
|
162
|
+
return enumValues.includes(value as T[keyof T]);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/**
|
|
@@ -25,18 +25,17 @@ export function getJSONRoomDoorSlotFlags(
|
|
|
25
25
|
jsonRoom: JSONRoom,
|
|
26
26
|
): BitFlags<DoorSlotFlag> {
|
|
27
27
|
const roomShapeString = jsonRoom.$.shape;
|
|
28
|
-
const
|
|
28
|
+
const roomShape = tonumber(roomShapeString);
|
|
29
29
|
assertDefined(
|
|
30
|
-
|
|
30
|
+
roomShape,
|
|
31
31
|
`Failed to parse the "shape" field of a JSON room: ${roomShapeString}`,
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
-
if (!isEnumValue(
|
|
34
|
+
if (!isEnumValue(roomShape, RoomShape)) {
|
|
35
35
|
error(
|
|
36
|
-
`Failed to parse the "shape" field of a JSON room since it was an invalid number: ${
|
|
36
|
+
`Failed to parse the "shape" field of a JSON room since it was an invalid number: ${roomShape}`,
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
const roomShape = roomShapeNumber as RoomShape;
|
|
40
39
|
|
|
41
40
|
let doorSlotFlags = DoorSlotFlagZero;
|
|
42
41
|
|
|
@@ -70,12 +70,15 @@ export function getRoomDescriptorReadOnly(): Readonly<RoomDescriptor> {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Helper function to get the
|
|
74
|
-
* as the top-left 1x1 section that the room overlaps with, or the top-right 1x1 section of a
|
|
75
|
-
* `RoomType.SHAPE_LTL` room.)
|
|
73
|
+
* Helper function to get the grid index of the current room.
|
|
76
74
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* - If the current room is inside of the grid, this function will return the `SafeGridIndex` from
|
|
76
|
+
* the room descriptor. (The safe grid index is defined as the top-left 1x1 section that the room
|
|
77
|
+
* overlaps with, or the top-right 1x1 section of a `RoomType.SHAPE_LTL` room.)
|
|
78
|
+
* - If the current room is outside of the grid, it will return the index from the
|
|
79
|
+
* `Level.GetCurrentRoomIndex` method (since `SafeGridIndex` is bugged for these cases, as
|
|
80
|
+
* demonstrated by entering a Genesis room and entering `l
|
|
81
|
+
* print(Game():GetLevel():GetCurrentRoomDesc().SafeGridIndex)` into the console).
|
|
79
82
|
*
|
|
80
83
|
* Use this function instead of the `Level.GetCurrentRoomIndex` method directly because the latter
|
|
81
84
|
* will return the specific 1x1 quadrant that the player entered the room at. For most situations,
|
|
@@ -85,6 +88,13 @@ export function getRoomDescriptorReadOnly(): Readonly<RoomDescriptor> {
|
|
|
85
88
|
* `SafeGridIndex`, since the former is unique across different dimensions.
|
|
86
89
|
*/
|
|
87
90
|
export function getRoomGridIndex(): int {
|
|
91
|
+
const level = game.GetLevel();
|
|
92
|
+
const currentRoomIndex = level.GetCurrentRoomIndex();
|
|
93
|
+
|
|
94
|
+
if (currentRoomIndex < 0) {
|
|
95
|
+
return currentRoomIndex;
|
|
96
|
+
}
|
|
97
|
+
|
|
88
98
|
const roomDescriptor = getRoomDescriptorReadOnly();
|
|
89
99
|
return roomDescriptor.SafeGridIndex;
|
|
90
100
|
}
|