isaacscript-common 34.0.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.
@@ -5581,6 +5581,8 @@ export declare function getHighestArrayElement(array: number[]): number | undefi
5581
5581
  *
5582
5582
  * Note that this is not necessarily the enum value that is declared last in the code, since there
5583
5583
  * is no way to infer that at run-time.
5584
+ *
5585
+ * Throws an error if the provided enum is empty.
5584
5586
  */
5585
5587
  export declare function getHighestEnumValue<T>(transpiledEnum: T): T[keyof T];
5586
5588
 
@@ -5745,6 +5747,16 @@ export declare function getLevelBossIDs(): BossID[];
5745
5747
  */
5746
5748
  export declare function getLowestArrayElement(array: number[]): number | undefined;
5747
5749
 
5750
+ /**
5751
+ * Helper function to get the enum value with the lowest value.
5752
+ *
5753
+ * Note that this is not necessarily the enum value that is declared first in the code, since there
5754
+ * is no way to infer that at run-time.
5755
+ *
5756
+ * Throws an error if the provided enum is empty.
5757
+ */
5758
+ export declare function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T];
5759
+
5748
5760
  /**
5749
5761
  * Helper function to get the closest value from a map based on partial search text. For the
5750
5762
  * purposes of this function, both search text and map keys are converted to lowercase before
@@ -6706,12 +6718,15 @@ export declare function getRoomDescriptorsForType(...roomTypes: RoomType[]): Roo
6706
6718
  export declare function getRoomDisplayFlags(roomGridIndex?: int, minimapAPI?: boolean): BitFlags<DisplayFlag>;
6707
6719
 
6708
6720
  /**
6709
- * Helper function to get the safe grid index of the current room. (The safe grid index is defined
6710
- * as the top-left 1x1 section that the room overlaps with, or the top-right 1x1 section of a
6711
- * `RoomType.SHAPE_LTL` room.)
6721
+ * Helper function to get the grid index of the current room.
6712
6722
  *
6713
- * Under the hood, this function uses the `Level.GetCurrentRoomDesc` method. (In Afterbirth+, this
6714
- * method was bugged for rooms outside of the grid, but it is now fixed.)
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).
6715
6730
  *
6716
6731
  * Use this function instead of the `Level.GetCurrentRoomIndex` method directly because the latter
6717
6732
  * will return the specific 1x1 quadrant that the player entered the room at. For most situations,
@@ -8444,7 +8459,7 @@ export declare function isEntity(variable: unknown): variable is Entity;
8444
8459
  export declare function isEntityMoving(entity: Entity, threshold?: number): boolean;
8445
8460
 
8446
8461
  /** Helper function to validate that a particular value exists inside of an enum. */
8447
- export declare function isEnumValue(value: number | string, transpiledEnum: Record<string | number, string | number>): boolean;
8462
+ export declare function isEnumValue<T extends Record<string, number | string>>(value: number | string, transpiledEnum: T): value is T[keyof T];
8448
8463
 
8449
8464
  export declare function isEven(num: int): boolean;
8450
8465
 
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 34.0.0
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
 
@@ -17221,6 +17221,7 @@ return ____exports
17221
17221
  local ____lualib = require("lualib_bundle")
17222
17222
  local __TS__ArraySort = ____lualib.__TS__ArraySort
17223
17223
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
17224
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
17224
17225
  local __TS__ArrayIncludes = ____lualib.__TS__ArrayIncludes
17225
17226
  local __TS__New = ____lualib.__TS__New
17226
17227
  local ____exports = {}
@@ -17287,10 +17288,16 @@ function ____exports.getEnumValues(self, transpiledEnum)
17287
17288
  end
17288
17289
  function ____exports.getHighestEnumValue(self, transpiledEnum)
17289
17290
  local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
17290
- local lastElement = enumValues[#enumValues]
17291
+ local lastElement = __TS__ArrayAt(enumValues, -1)
17291
17292
  assertDefined(nil, lastElement, "Failed to get the last value from an enum since the enum was empty.")
17292
17293
  return lastElement
17293
17294
  end
17295
+ function ____exports.getLowestEnumValue(self, transpiledEnum)
17296
+ local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
17297
+ local firstElement = enumValues[1]
17298
+ assertDefined(nil, firstElement, "Failed to get the first value from an enum since the enum was empty.")
17299
+ return firstElement
17300
+ end
17294
17301
  function ____exports.getRandomEnumValue(self, transpiledEnum, seedOrRNG, exceptions)
17295
17302
  if seedOrRNG == nil then
17296
17303
  seedOrRNG = getRandomSeed(nil)
@@ -17316,7 +17323,7 @@ function ____exports.validateCustomEnum(self, transpiledEnumName, transpiledEnum
17316
17323
  end
17317
17324
  function ____exports.validateEnumContiguous(self, transpiledEnumName, transpiledEnum)
17318
17325
  local values = ____exports.getEnumValues(nil, transpiledEnum)
17319
- local lastValue = values[#values]
17326
+ local lastValue = __TS__ArrayAt(values, -1)
17320
17327
  assertDefined(nil, lastValue, "Failed to validate that an enum was contiguous, since the last value was undefined.")
17321
17328
  if not isNumber(nil, lastValue) then
17322
17329
  error("Failed to validate that an enum was contiguous, since the last value was not a number.")
@@ -26783,6 +26790,11 @@ function ____exports.getRoomDescriptorReadOnly(self)
26783
26790
  return level:GetCurrentRoomDesc()
26784
26791
  end
26785
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
26786
26798
  local roomDescriptor = ____exports.getRoomDescriptorReadOnly(nil)
26787
26799
  return roomDescriptor.SafeGridIndex
26788
26800
  end
@@ -34680,7 +34692,7 @@ function RoomHistory.prototype.getRoomHistory(self)
34680
34692
  end
34681
34693
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getRoomHistory", true)
34682
34694
  function RoomHistory.prototype.getPreviousRoomDescription(self)
34683
- local previousRoomDescription = v.run.roomHistory[#v.run.roomHistory - 2 + 1]
34695
+ local previousRoomDescription = __TS__ArrayAt(v.run.roomHistory, -2)
34684
34696
  if previousRoomDescription ~= nil then
34685
34697
  return previousRoomDescription
34686
34698
  end
@@ -46718,12 +46730,11 @@ function getJSONObjectWithChosenWeight(self, jsonOjectArray, chosenWeight)
46718
46730
  end
46719
46731
  function ____exports.getJSONRoomDoorSlotFlags(self, jsonRoom)
46720
46732
  local roomShapeString = jsonRoom["$"].shape
46721
- local roomShapeNumber = tonumber(roomShapeString)
46722
- assertDefined(nil, roomShapeNumber, "Failed to parse the \"shape\" field of a JSON room: " .. roomShapeString)
46723
- if not isEnumValue(nil, roomShapeNumber, RoomShape) then
46724
- error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(roomShapeNumber))
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))
46725
46737
  end
46726
- local roomShape = roomShapeNumber
46727
46738
  local doorSlotFlags = DoorSlotFlagZero
46728
46739
  for ____, door in ipairs(jsonRoom.door) do
46729
46740
  do
@@ -1 +1 @@
1
- {"version":3,"file":"RoomHistory.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/RoomHistory.ts"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAQhD,qBAAa,WAAY,SAAQ,OAAO;IActC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAgC/B;IAEF;;;;OAIG;IAEI,yBAAyB,IAAI,IAAI;IAIxC;;;;;OAKG;IAEI,kBAAkB,IAAI,GAAG;IAIhC;;;;;OAKG;IAEI,cAAc,IAAI,aAAa,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAIjE;;;;;;;OAOG;IAEI,0BAA0B,IAAI,QAAQ,CAAC,eAAe,CAAC;IAiB9D;;;;;;;;;;OAUG;IAEI,wBAAwB,IAAI,QAAQ,CAAC,eAAe,CAAC,GAAG,SAAS;IAIxE,gFAAgF;IAEzE,WAAW,IAAI,OAAO;IAI7B;;;;;;;;;;OAUG;IAEI,aAAa,IAAI,OAAO;CAwBhC"}
1
+ {"version":3,"file":"RoomHistory.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/RoomHistory.ts"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAQhD,qBAAa,WAAY,SAAQ,OAAO;IActC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAgC/B;IAEF;;;;OAIG;IAEI,yBAAyB,IAAI,IAAI;IAIxC;;;;;OAKG;IAEI,kBAAkB,IAAI,GAAG;IAIhC;;;;;OAKG;IAEI,cAAc,IAAI,aAAa,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAIjE;;;;;;;OAOG;IAEI,0BAA0B,IAAI,QAAQ,CAAC,eAAe,CAAC;IAgB9D;;;;;;;;;;OAUG;IAEI,wBAAwB,IAAI,QAAQ,CAAC,eAAe,CAAC,GAAG,SAAS;IAIxE,gFAAgF;IAEzE,WAAW,IAAI,OAAO;IAI7B;;;;;;;;;;OAUG;IAEI,aAAa,IAAI,OAAO;CAwBhC"}
@@ -78,7 +78,7 @@ function RoomHistory.prototype.getRoomHistory(self)
78
78
  end
79
79
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getRoomHistory", true)
80
80
  function RoomHistory.prototype.getPreviousRoomDescription(self)
81
- local previousRoomDescription = v.run.roomHistory[#v.run.roomHistory - 2 + 1]
81
+ local previousRoomDescription = __TS__ArrayAt(v.run.roomHistory, -2)
82
82
  if previousRoomDescription ~= nil then
83
83
  return previousRoomDescription
84
84
  end
@@ -60,8 +60,19 @@ export declare function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]>;
60
60
  *
61
61
  * Note that this is not necessarily the enum value that is declared last in the code, since there
62
62
  * is no way to infer that at run-time.
63
+ *
64
+ * Throws an error if the provided enum is empty.
63
65
  */
64
66
  export declare function getHighestEnumValue<T>(transpiledEnum: T): T[keyof T];
67
+ /**
68
+ * Helper function to get the enum value with the lowest value.
69
+ *
70
+ * Note that this is not necessarily the enum value that is declared first in the code, since there
71
+ * is no way to infer that at run-time.
72
+ *
73
+ * Throws an error if the provided enum is empty.
74
+ */
75
+ export declare function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T];
65
76
  /**
66
77
  * Helper function to get a random value from the provided enum.
67
78
  *
@@ -72,7 +83,7 @@ export declare function getHighestEnumValue<T>(transpiledEnum: T): T[keyof T];
72
83
  */
73
84
  export declare function getRandomEnumValue<T>(transpiledEnum: T, seedOrRNG?: Seed | RNG, exceptions?: Array<T[keyof T]> | ReadonlyArray<T[keyof T]>): T[keyof T];
74
85
  /** Helper function to validate that a particular value exists inside of an enum. */
75
- export declare function isEnumValue(value: number | string, transpiledEnum: Record<string | number, string | number>): boolean;
86
+ export declare function isEnumValue<T extends Record<string, number | string>>(value: number | string, transpiledEnum: T): value is T[keyof T];
76
87
  /**
77
88
  * Helper function to check every value of a custom enum for -1. Will throw an run-time error if any
78
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,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC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GAAqB,EACvC,UAAU,GAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAM,GAC7D,CAAC,CAAC,MAAM,CAAC,CAAC,CAGZ;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACnE,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,cAAc,EAAE,CAAC,GAChB,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,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,6 +1,7 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArraySort = ____lualib.__TS__ArraySort
3
3
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
4
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
4
5
  local __TS__ArrayIncludes = ____lualib.__TS__ArrayIncludes
5
6
  local __TS__New = ____lualib.__TS__New
6
7
  local ____exports = {}
@@ -113,12 +114,26 @@ end
113
114
  --
114
115
  -- Note that this is not necessarily the enum value that is declared last in the code, since there
115
116
  -- is no way to infer that at run-time.
117
+ --
118
+ -- Throws an error if the provided enum is empty.
116
119
  function ____exports.getHighestEnumValue(self, transpiledEnum)
117
120
  local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
118
- local lastElement = enumValues[#enumValues]
121
+ local lastElement = __TS__ArrayAt(enumValues, -1)
119
122
  assertDefined(nil, lastElement, "Failed to get the last value from an enum since the enum was empty.")
120
123
  return lastElement
121
124
  end
125
+ --- Helper function to get the enum value with the lowest value.
126
+ --
127
+ -- Note that this is not necessarily the enum value that is declared first in the code, since there
128
+ -- is no way to infer that at run-time.
129
+ --
130
+ -- Throws an error if the provided enum is empty.
131
+ function ____exports.getLowestEnumValue(self, transpiledEnum)
132
+ local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
133
+ local firstElement = enumValues[1]
134
+ assertDefined(nil, firstElement, "Failed to get the first value from an enum since the enum was empty.")
135
+ return firstElement
136
+ end
122
137
  --- Helper function to get a random value from the provided enum.
123
138
  --
124
139
  -- @param transpiledEnum The enum to get the value from.
@@ -167,7 +182,7 @@ end
167
182
  -- This is useful to automate checking large enums for typos.
168
183
  function ____exports.validateEnumContiguous(self, transpiledEnumName, transpiledEnum)
169
184
  local values = ____exports.getEnumValues(nil, transpiledEnum)
170
- local lastValue = values[#values]
185
+ local lastValue = __TS__ArrayAt(values, -1)
171
186
  assertDefined(nil, lastValue, "Failed to validate that an enum was contiguous, since the last value was undefined.")
172
187
  if not isNumber(nil, lastValue) then
173
188
  error("Failed to validate that an enum was contiguous, since the last value was not a number.")
@@ -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,CAsDxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,E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jC,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 roomShapeNumber = tonumber(roomShapeString)
66
- assertDefined(nil, roomShapeNumber, "Failed to parse the \"shape\" field of a JSON room: " .. roomShapeString)
67
- if not isEnumValue(nil, roomShapeNumber, RoomShape) then
68
- error("Failed to parse the \"shape\" field of a JSON room since it was an invalid number: " .. tostring(roomShapeNumber))
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 safe grid index of the current room. (The safe grid index is defined
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
- * Under the hood, this function uses the `Level.GetCurrentRoomDesc` method. (In Afterbirth+, this
26
- * method was bugged for rooms outside of the grid, but it is now fixed.)
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,yBAAyB,IAAI,QAAQ,CAAC,cAAc,CAAC,CAGpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,IAAI,GAAG,CAGtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,MAA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E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,IAAI,GAAG,CAUtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,MAAM,CAGvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,SAAS,GAAG,SAAS,CAGvE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,OAAO,GAAG,CAAC,CAAC,CAGhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,CAGvD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,QAAQ,GAAG,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 safe grid index of the current room. (The safe grid index is defined
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
- -- Under the hood, this function uses the `Level.GetCurrentRoomDesc` method. (In Afterbirth+, this
41
- -- method was bugged for rooms outside of the grid, but it is now fixed.)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "34.0.0",
3
+ "version": "34.1.1",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -110,8 +110,7 @@ export class RoomHistory extends Feature {
110
110
  */
111
111
  @Exported
112
112
  public getPreviousRoomDescription(): Readonly<RoomDescription> {
113
- const previousRoomDescription =
114
- v.run.roomHistory[v.run.roomHistory.length - 2];
113
+ const previousRoomDescription = v.run.roomHistory.at(-2);
115
114
  if (previousRoomDescription !== undefined) {
116
115
  return previousRoomDescription;
117
116
  }
@@ -101,11 +101,13 @@ export function getEnumValues<T>(transpiledEnum: T): Array<T[keyof T]> {
101
101
  *
102
102
  * Note that this is not necessarily the enum value that is declared last in the code, since there
103
103
  * is no way to infer that at run-time.
104
+ *
105
+ * Throws an error if the provided enum is empty.
104
106
  */
105
107
  export function getHighestEnumValue<T>(transpiledEnum: T): T[keyof T] {
106
108
  const enumValues = getEnumValues(transpiledEnum);
107
109
 
108
- const lastElement = enumValues[enumValues.length - 1];
110
+ const lastElement = enumValues.at(-1);
109
111
  assertDefined(
110
112
  lastElement,
111
113
  "Failed to get the last value from an enum since the enum was empty.",
@@ -114,6 +116,26 @@ export function getHighestEnumValue<T>(transpiledEnum: T): T[keyof T] {
114
116
  return lastElement;
115
117
  }
116
118
 
119
+ /**
120
+ * Helper function to get the enum value with the lowest value.
121
+ *
122
+ * Note that this is not necessarily the enum value that is declared first in the code, since there
123
+ * is no way to infer that at run-time.
124
+ *
125
+ * Throws an error if the provided enum is empty.
126
+ */
127
+ export function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T] {
128
+ const enumValues = getEnumValues(transpiledEnum);
129
+
130
+ const firstElement = enumValues[0];
131
+ assertDefined(
132
+ firstElement,
133
+ "Failed to get the first value from an enum since the enum was empty.",
134
+ );
135
+
136
+ return firstElement;
137
+ }
138
+
117
139
  /**
118
140
  * Helper function to get a random value from the provided enum.
119
141
  *
@@ -132,12 +154,12 @@ export function getRandomEnumValue<T>(
132
154
  }
133
155
 
134
156
  /** Helper function to validate that a particular value exists inside of an enum. */
135
- export function isEnumValue(
157
+ export function isEnumValue<T extends Record<string, number | string>>(
136
158
  value: number | string,
137
- transpiledEnum: Record<string | number, string | number>,
138
- ): boolean {
159
+ transpiledEnum: T,
160
+ ): value is T[keyof T] {
139
161
  const enumValues = getEnumValues(transpiledEnum);
140
- return enumValues.includes(value);
162
+ return enumValues.includes(value as T[keyof T]);
141
163
  }
142
164
 
143
165
  /**
@@ -178,7 +200,7 @@ export function validateEnumContiguous<T>(
178
200
  transpiledEnum: T,
179
201
  ): void {
180
202
  const values = getEnumValues(transpiledEnum);
181
- const lastValue = values[values.length - 1];
203
+ const lastValue = values.at(-1);
182
204
  assertDefined(
183
205
  lastValue,
184
206
  "Failed to validate that an enum was contiguous, since the last value was undefined.",
@@ -25,18 +25,17 @@ export function getJSONRoomDoorSlotFlags(
25
25
  jsonRoom: JSONRoom,
26
26
  ): BitFlags<DoorSlotFlag> {
27
27
  const roomShapeString = jsonRoom.$.shape;
28
- const roomShapeNumber = tonumber(roomShapeString);
28
+ const roomShape = tonumber(roomShapeString);
29
29
  assertDefined(
30
- roomShapeNumber,
30
+ roomShape,
31
31
  `Failed to parse the "shape" field of a JSON room: ${roomShapeString}`,
32
32
  );
33
33
 
34
- if (!isEnumValue(roomShapeNumber, RoomShape)) {
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: ${roomShapeNumber}`,
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 safe grid index of the current room. (The safe grid index is defined
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
- * Under the hood, this function uses the `Level.GetCurrentRoomDesc` method. (In Afterbirth+, this
78
- * method was bugged for rooms outside of the grid, but it is now fixed.)
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
  }