isaacscript-common 33.15.0 → 34.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.
@@ -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
 
@@ -5717,16 +5719,6 @@ export declare function getLanguageName(): string;
5717
5719
  */
5718
5720
  export declare function getLasers(laserVariant?: LaserVariant | -1, subType?: number): EntityLaser[];
5719
5721
 
5720
- /**
5721
- * Helper function to return the last element of an array.
5722
- *
5723
- * If the array is empty, this will return undefined.
5724
- *
5725
- * (Note that TSTL does not support `Array.at(-1)`, which would make this helper function largely
5726
- * unnecessary.)
5727
- */
5728
- export declare function getLastElement<T>(array: T[]): T | undefined;
5729
-
5730
5722
  /**
5731
5723
  * Helper function that returns the number of the final frame in a particular animation for a
5732
5724
  * sprite. By default, it will use the currently playing animation, but you can also specify a
@@ -5755,6 +5747,16 @@ export declare function getLevelBossIDs(): BossID[];
5755
5747
  */
5756
5748
  export declare function getLowestArrayElement(array: number[]): number | undefined;
5757
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
+
5758
5760
  /**
5759
5761
  * Helper function to get the closest value from a map based on partial search text. For the
5760
5762
  * purposes of this function, both search text and map keys are converted to lowercase before
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 33.15.0
3
+ isaacscript-common 34.1.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -17090,9 +17090,6 @@ function ____exports.getHighestArrayElement(self, array)
17090
17090
  end
17091
17091
  return highestValue
17092
17092
  end
17093
- function ____exports.getLastElement(self, array)
17094
- return array[#array]
17095
- end
17096
17093
  function ____exports.getLowestArrayElement(self, array)
17097
17094
  if #array == 0 then
17098
17095
  return nil
@@ -17224,6 +17221,7 @@ return ____exports
17224
17221
  local ____lualib = require("lualib_bundle")
17225
17222
  local __TS__ArraySort = ____lualib.__TS__ArraySort
17226
17223
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
17224
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
17227
17225
  local __TS__ArrayIncludes = ____lualib.__TS__ArrayIncludes
17228
17226
  local __TS__New = ____lualib.__TS__New
17229
17227
  local ____exports = {}
@@ -17290,10 +17288,16 @@ function ____exports.getEnumValues(self, transpiledEnum)
17290
17288
  end
17291
17289
  function ____exports.getHighestEnumValue(self, transpiledEnum)
17292
17290
  local enumValues = ____exports.getEnumValues(nil, transpiledEnum)
17293
- local lastElement = enumValues[#enumValues]
17291
+ local lastElement = __TS__ArrayAt(enumValues, -1)
17294
17292
  assertDefined(nil, lastElement, "Failed to get the last value from an enum since the enum was empty.")
17295
17293
  return lastElement
17296
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
17297
17301
  function ____exports.getRandomEnumValue(self, transpiledEnum, seedOrRNG, exceptions)
17298
17302
  if seedOrRNG == nil then
17299
17303
  seedOrRNG = getRandomSeed(nil)
@@ -17319,7 +17323,7 @@ function ____exports.validateCustomEnum(self, transpiledEnumName, transpiledEnum
17319
17323
  end
17320
17324
  function ____exports.validateEnumContiguous(self, transpiledEnumName, transpiledEnum)
17321
17325
  local values = ____exports.getEnumValues(nil, transpiledEnum)
17322
- local lastValue = values[#values]
17326
+ local lastValue = __TS__ArrayAt(values, -1)
17323
17327
  assertDefined(nil, lastValue, "Failed to validate that an enum was contiguous, since the last value was undefined.")
17324
17328
  if not isNumber(nil, lastValue) then
17325
17329
  error("Failed to validate that an enum was contiguous, since the last value was not a number.")
@@ -21835,6 +21839,7 @@ local __TS__ArraySome = ____lualib.__TS__ArraySome
21835
21839
  local __TS__New = ____lualib.__TS__New
21836
21840
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
21837
21841
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
21842
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
21838
21843
  local __TS__ArrayFind = ____lualib.__TS__ArrayFind
21839
21844
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
21840
21845
  local ____exports = {}
@@ -21857,7 +21862,6 @@ local itemConfig = ____cachedClasses.itemConfig
21857
21862
  local ____ReadonlySet = require("src.types.ReadonlySet")
21858
21863
  local ReadonlySet = ____ReadonlySet.ReadonlySet
21859
21864
  local ____array = require("src.functions.array")
21860
- local getLastElement = ____array.getLastElement
21861
21865
  local sumArray = ____array.sumArray
21862
21866
  local ____characters = require("src.functions.characters")
21863
21867
  local getCharacterName = ____characters.getCharacterName
@@ -22002,7 +22006,7 @@ function ____exports.getEffectsList(self, player)
22002
22006
  end
22003
22007
  function ____exports.getFinalPlayer(self)
22004
22008
  local players = getPlayers(nil)
22005
- local lastPlayer = getLastElement(nil, players)
22009
+ local lastPlayer = __TS__ArrayAt(players, -1)
22006
22010
  assertDefined(nil, lastPlayer, "Failed to get the final player since there were 0 players.")
22007
22011
  return lastPlayer
22008
22012
  end
@@ -34607,6 +34611,7 @@ local ____lualib = require("lualib_bundle")
34607
34611
  local __TS__Class = ____lualib.__TS__Class
34608
34612
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
34609
34613
  local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
34614
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
34610
34615
  local ____exports = {}
34611
34616
  local ____cachedClasses = require("src.core.cachedClasses")
34612
34617
  local game = ____cachedClasses.game
@@ -34614,8 +34619,6 @@ local ____decorators = require("src.decorators")
34614
34619
  local Exported = ____decorators.Exported
34615
34620
  local ____ModCallbackCustom = require("src.enums.ModCallbackCustom")
34616
34621
  local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
34617
- local ____array = require("src.functions.array")
34618
- local getLastElement = ____array.getLastElement
34619
34622
  local ____dimensions = require("src.functions.dimensions")
34620
34623
  local getDimension = ____dimensions.getDimension
34621
34624
  local ____roomData = require("src.functions.roomData")
@@ -34684,7 +34687,7 @@ function RoomHistory.prototype.getRoomHistory(self)
34684
34687
  end
34685
34688
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getRoomHistory", true)
34686
34689
  function RoomHistory.prototype.getPreviousRoomDescription(self)
34687
- local previousRoomDescription = v.run.roomHistory[#v.run.roomHistory - 2 + 1]
34690
+ local previousRoomDescription = __TS__ArrayAt(v.run.roomHistory, -2)
34688
34691
  if previousRoomDescription ~= nil then
34689
34692
  return previousRoomDescription
34690
34693
  end
@@ -34696,7 +34699,7 @@ function RoomHistory.prototype.getPreviousRoomDescription(self)
34696
34699
  end
34697
34700
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getPreviousRoomDescription", true)
34698
34701
  function RoomHistory.prototype.getLatestRoomDescription(self)
34699
- return getLastElement(nil, v.run.roomHistory)
34702
+ return __TS__ArrayAt(v.run.roomHistory, -1)
34700
34703
  end
34701
34704
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getLatestRoomDescription", true)
34702
34705
  function RoomHistory.prototype.inFirstRoom(self)
@@ -51495,6 +51498,7 @@ local __TS__Class = ____lualib.__TS__Class
51495
51498
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
51496
51499
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
51497
51500
  local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
51501
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
51498
51502
  local ____exports = {}
51499
51503
  local ____decorators = require("src.decorators")
51500
51504
  local Exported = ____decorators.Exported
@@ -51503,7 +51507,6 @@ local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
51503
51507
  local ____array = require("src.functions.array")
51504
51508
  local arrayRemoveInPlace = ____array.arrayRemoveInPlace
51505
51509
  local copyArray = ____array.copyArray
51506
- local getLastElement = ____array.getLastElement
51507
51510
  local ____collectibles = require("src.functions.collectibles")
51508
51511
  local isActiveCollectible = ____collectibles.isActiveCollectible
51509
51512
  local ____playerDataStructures = require("src.functions.playerDataStructures")
@@ -51549,7 +51552,7 @@ end
51549
51552
  __TS__DecorateLegacy({Exported}, PlayerInventory.prototype, "getPlayerInventory", true)
51550
51553
  function PlayerInventory.prototype.getPlayerLastPassiveCollectible(self, player)
51551
51554
  local inventory = self:getPlayerInventory(player, false)
51552
- return getLastElement(nil, inventory)
51555
+ return __TS__ArrayAt(inventory, -1)
51553
51556
  end
51554
51557
  __TS__DecorateLegacy({Exported}, PlayerInventory.prototype, "getPlayerLastPassiveCollectible", true)
51555
51558
  return ____exports
@@ -1 +1 @@
1
- {"version":3,"file":"PlayerInventory.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/PlayerInventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAYpE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAYhD,qBAAa,eAAgB,SAAQ,OAAO;IAqB1C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAUnC;IAGF,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAUrC;IAEF;;;;;;;;;;;;;;;;;;;;;OAqBG;IAEI,kBAAkB,CACvB,MAAM,EAAE,YAAY,EACpB,yBAAyB,UAAO,GAC/B,eAAe,EAAE;IAgBpB;;;;;;;OAOG;IAEI,+BAA+B,CACpC,MAAM,EAAE,YAAY,GACnB,eAAe,GAAG,SAAS;CAI/B"}
1
+ {"version":3,"file":"PlayerInventory.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/PlayerInventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAQpE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAYhD,qBAAa,eAAgB,SAAQ,OAAO;IAqB1C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAUnC;IAGF,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAUrC;IAEF;;;;;;;;;;;;;;;;;;;;;OAqBG;IAEI,kBAAkB,CACvB,MAAM,EAAE,YAAY,EACpB,yBAAyB,UAAO,GAC/B,eAAe,EAAE;IAgBpB;;;;;;;OAOG;IAEI,+BAA+B,CACpC,MAAM,EAAE,YAAY,GACnB,eAAe,GAAG,SAAS;CAI/B"}
@@ -4,6 +4,7 @@ local __TS__Class = ____lualib.__TS__Class
4
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
5
5
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
6
  local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
7
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
7
8
  local ____exports = {}
8
9
  local ____decorators = require("src.decorators")
9
10
  local Exported = ____decorators.Exported
@@ -12,7 +13,6 @@ local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
12
13
  local ____array = require("src.functions.array")
13
14
  local arrayRemoveInPlace = ____array.arrayRemoveInPlace
14
15
  local copyArray = ____array.copyArray
15
- local getLastElement = ____array.getLastElement
16
16
  local ____collectibles = require("src.functions.collectibles")
17
17
  local isActiveCollectible = ____collectibles.isActiveCollectible
18
18
  local ____playerDataStructures = require("src.functions.playerDataStructures")
@@ -58,7 +58,7 @@ end
58
58
  __TS__DecorateLegacy({Exported}, PlayerInventory.prototype, "getPlayerInventory", true)
59
59
  function PlayerInventory.prototype.getPlayerLastPassiveCollectible(self, player)
60
60
  local inventory = self:getPlayerInventory(player, false)
61
- return getLastElement(nil, inventory)
61
+ return __TS__ArrayAt(inventory, -1)
62
62
  end
63
63
  __TS__DecorateLegacy({Exported}, PlayerInventory.prototype, "getPlayerLastPassiveCollectible", true)
64
64
  return ____exports
@@ -1 +1 @@
1
- {"version":3,"file":"RoomHistory.d.ts","sourceRoot":"","sources":["../../../../../src/classes/features/other/RoomHistory.ts"],"names":[],"mappings":";AAcA,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"}
@@ -2,6 +2,7 @@ local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
4
  local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
5
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
5
6
  local ____exports = {}
6
7
  local ____cachedClasses = require("src.core.cachedClasses")
7
8
  local game = ____cachedClasses.game
@@ -9,8 +10,6 @@ local ____decorators = require("src.decorators")
9
10
  local Exported = ____decorators.Exported
10
11
  local ____ModCallbackCustom = require("src.enums.ModCallbackCustom")
11
12
  local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
12
- local ____array = require("src.functions.array")
13
- local getLastElement = ____array.getLastElement
14
13
  local ____dimensions = require("src.functions.dimensions")
15
14
  local getDimension = ____dimensions.getDimension
16
15
  local ____roomData = require("src.functions.roomData")
@@ -79,7 +78,7 @@ function RoomHistory.prototype.getRoomHistory(self)
79
78
  end
80
79
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getRoomHistory", true)
81
80
  function RoomHistory.prototype.getPreviousRoomDescription(self)
82
- local previousRoomDescription = v.run.roomHistory[#v.run.roomHistory - 2 + 1]
81
+ local previousRoomDescription = __TS__ArrayAt(v.run.roomHistory, -2)
83
82
  if previousRoomDescription ~= nil then
84
83
  return previousRoomDescription
85
84
  end
@@ -91,7 +90,7 @@ function RoomHistory.prototype.getPreviousRoomDescription(self)
91
90
  end
92
91
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getPreviousRoomDescription", true)
93
92
  function RoomHistory.prototype.getLatestRoomDescription(self)
94
- return getLastElement(nil, v.run.roomHistory)
93
+ return __TS__ArrayAt(v.run.roomHistory, -1)
95
94
  end
96
95
  __TS__DecorateLegacy({Exported}, RoomHistory.prototype, "getLatestRoomDescription", true)
97
96
  function RoomHistory.prototype.inFirstRoom(self)
@@ -141,15 +141,6 @@ export declare function getArrayIndexes<T>(array: T[] | readonly T[]): int[];
141
141
  * in the array.
142
142
  */
143
143
  export declare function getHighestArrayElement(array: number[]): number | undefined;
144
- /**
145
- * Helper function to return the last element of an array.
146
- *
147
- * If the array is empty, this will return undefined.
148
- *
149
- * (Note that TSTL does not support `Array.at(-1)`, which would make this helper function largely
150
- * unnecessary.)
151
- */
152
- export declare function getLastElement<T>(array: T[]): T | undefined;
153
144
  /**
154
145
  * Helper function to get the lowest value in an array. Returns undefined if there were no elements
155
146
  * in the array.
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/functions/array.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAC1B,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GACzB,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,GAAG,gBAAgB,EAAE,CAAC,EAAE,GACvB,CAAC,EAAE,CAIL;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,aAAa,EAAE,CAAC,EAAE,GAAG,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,aAAa,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EACjC,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,CAAC,EAAE,CAKL;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,IAAI,CAWN;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAM3E"}
@@ -381,15 +381,6 @@ function ____exports.getHighestArrayElement(self, array)
381
381
  end
382
382
  return highestValue
383
383
  end
384
- --- Helper function to return the last element of an array.
385
- --
386
- -- If the array is empty, this will return undefined.
387
- --
388
- -- (Note that TSTL does not support `Array.at(-1)`, which would make this helper function largely
389
- -- unnecessary.)
390
- function ____exports.getLastElement(self, array)
391
- return array[#array]
392
- end
393
384
  --- Helper function to get the lowest value in an array. Returns undefined if there were no elements
394
385
  -- in the array.
395
386
  function ____exports.getLowestArrayElement(self, array)
@@ -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
  *
@@ -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,CAAC,CAAC,CAmBzC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,cAAc,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACvD,MAAM,EAAE,CAGV;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACvD,GAAG,CAGL;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAGrE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAUpE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,cAAc,EAAE,CAAC,EACjB,SAAS,GAAE,IAAI,GAAG,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,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,EACt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AgB,mBAAmB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAUpE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAUnE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,cAAc,EAAE,CAAC,EACjB,SAAS,GAAE,IAAI,GAAG,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,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,cAAc,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACvD,OAAO,CAGT;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.")
@@ -3,6 +3,7 @@ local __TS__ArraySome = ____lualib.__TS__ArraySome
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
5
5
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
6
+ local __TS__ArrayAt = ____lualib.__TS__ArrayAt
6
7
  local __TS__ArrayFind = ____lualib.__TS__ArrayFind
7
8
  local __TS__ArrayEvery = ____lualib.__TS__ArrayEvery
8
9
  local ____exports = {}
@@ -25,7 +26,6 @@ local itemConfig = ____cachedClasses.itemConfig
25
26
  local ____ReadonlySet = require("src.types.ReadonlySet")
26
27
  local ReadonlySet = ____ReadonlySet.ReadonlySet
27
28
  local ____array = require("src.functions.array")
28
- local getLastElement = ____array.getLastElement
29
29
  local sumArray = ____array.sumArray
30
30
  local ____characters = require("src.functions.characters")
31
31
  local getCharacterName = ____characters.getCharacterName
@@ -222,7 +222,7 @@ end
222
222
  -- method.
223
223
  function ____exports.getFinalPlayer(self)
224
224
  local players = getPlayers(nil)
225
- local lastPlayer = getLastElement(nil, players)
225
+ local lastPlayer = __TS__ArrayAt(players, -1)
226
226
  assertDefined(nil, lastPlayer, "Failed to get the final player since there were 0 players.")
227
227
  return lastPlayer
228
228
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "33.15.0",
3
+ "version": "34.1.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -1,11 +1,7 @@
1
1
  import type { CollectibleType } from "isaac-typescript-definitions";
2
2
  import { Exported } from "../../../decorators";
3
3
  import { ModCallbackCustom } from "../../../enums/ModCallbackCustom";
4
- import {
5
- arrayRemoveInPlace,
6
- copyArray,
7
- getLastElement,
8
- } from "../../../functions/array";
4
+ import { arrayRemoveInPlace, copyArray } from "../../../functions/array";
9
5
  import { isActiveCollectible } from "../../../functions/collectibles";
10
6
  import { defaultMapGetPlayer } from "../../../functions/playerDataStructures";
11
7
  import type { PlayerIndex } from "../../../types/PlayerIndex";
@@ -123,6 +119,6 @@ export class PlayerInventory extends Feature {
123
119
  player: EntityPlayer,
124
120
  ): CollectibleType | undefined {
125
121
  const inventory = this.getPlayerInventory(player, false);
126
- return getLastElement(inventory);
122
+ return inventory.at(-1);
127
123
  }
128
124
  }
@@ -1,7 +1,6 @@
1
1
  import { game } from "../../../core/cachedClasses";
2
2
  import { Exported } from "../../../decorators";
3
3
  import { ModCallbackCustom } from "../../../enums/ModCallbackCustom";
4
- import { getLastElement } from "../../../functions/array";
5
4
  import { getDimension } from "../../../functions/dimensions";
6
5
  import {
7
6
  getRoomGridIndex,
@@ -111,8 +110,7 @@ export class RoomHistory extends Feature {
111
110
  */
112
111
  @Exported
113
112
  public getPreviousRoomDescription(): Readonly<RoomDescription> {
114
- const previousRoomDescription =
115
- v.run.roomHistory[v.run.roomHistory.length - 2];
113
+ const previousRoomDescription = v.run.roomHistory.at(-2);
116
114
  if (previousRoomDescription !== undefined) {
117
115
  return previousRoomDescription;
118
116
  }
@@ -140,7 +138,7 @@ export class RoomHistory extends Feature {
140
138
  */
141
139
  @Exported
142
140
  public getLatestRoomDescription(): Readonly<RoomDescription> | undefined {
143
- return getLastElement(v.run.roomHistory);
141
+ return v.run.roomHistory.at(-1);
144
142
  }
145
143
 
146
144
  /** Helper function to detect if the player is on the first room of the room. */
@@ -360,18 +360,6 @@ export function getHighestArrayElement(array: number[]): number | undefined {
360
360
  return highestValue;
361
361
  }
362
362
 
363
- /**
364
- * Helper function to return the last element of an array.
365
- *
366
- * If the array is empty, this will return undefined.
367
- *
368
- * (Note that TSTL does not support `Array.at(-1)`, which would make this helper function largely
369
- * unnecessary.)
370
- */
371
- export function getLastElement<T>(array: T[]): T | undefined {
372
- return array[array.length - 1];
373
- }
374
-
375
363
  /**
376
364
  * Helper function to get the lowest value in an array. Returns undefined if there were no elements
377
365
  * in the array.
@@ -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
  *
@@ -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.",
@@ -15,7 +15,7 @@ import {
15
15
  } from "../arrays/cachedEnumValues";
16
16
  import { game, itemConfig } from "../core/cachedClasses";
17
17
  import { ReadonlySet } from "../types/ReadonlySet";
18
- import { getLastElement, sumArray } from "./array";
18
+ import { sumArray } from "./array";
19
19
  import { getCharacterName, isVanillaCharacter } from "./characters";
20
20
  import { getCollectibleMaxCharges } from "./collectibles";
21
21
  import { hasFlag } from "./flag";
@@ -250,7 +250,7 @@ export function getEffectsList(player: EntityPlayer): TemporaryEffect[] {
250
250
  export function getFinalPlayer(): EntityPlayer {
251
251
  const players = getPlayers();
252
252
 
253
- const lastPlayer = getLastElement(players);
253
+ const lastPlayer = players.at(-1);
254
254
  assertDefined(
255
255
  lastPlayer,
256
256
  "Failed to get the final player since there were 0 players.",