isaacscript-common 81.0.4 → 81.0.5

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.
Files changed (149) hide show
  1. package/dist/classes/ModFeature.d.ts +1 -1
  2. package/dist/classes/ModFeature.d.ts.map +1 -1
  3. package/dist/classes/features/other/CustomItemPools.d.ts +1 -1
  4. package/dist/classes/features/other/CustomItemPools.d.ts.map +1 -1
  5. package/dist/classes/features/other/CustomItemPools.lua +4 -2
  6. package/dist/classes/features/other/DisableInputs.d.ts +1 -1
  7. package/dist/classes/features/other/DisableInputs.d.ts.map +1 -1
  8. package/dist/classes/features/other/ModdedElementSets.d.ts +4 -4
  9. package/dist/classes/features/other/ModdedElementSets.d.ts.map +1 -1
  10. package/dist/classes/features/other/ModdedElementSets.lua +7 -2
  11. package/dist/classes/features/other/SaveDataManager.d.ts +1 -1
  12. package/dist/classes/features/other/SaveDataManager.d.ts.map +1 -1
  13. package/dist/functions/array.d.ts +5 -5
  14. package/dist/functions/array.d.ts.map +1 -1
  15. package/dist/functions/arrayLua.d.ts +14 -14
  16. package/dist/functions/arrayLua.d.ts.map +1 -1
  17. package/dist/functions/arrayLua.lua +7 -7
  18. package/dist/functions/benchmark.d.ts +1 -1
  19. package/dist/functions/benchmark.d.ts.map +1 -1
  20. package/dist/functions/bitwise.d.ts +1 -1
  21. package/dist/functions/bitwise.d.ts.map +1 -1
  22. package/dist/functions/cards.d.ts +1 -1
  23. package/dist/functions/cards.d.ts.map +1 -1
  24. package/dist/functions/challenges.d.ts +1 -1
  25. package/dist/functions/challenges.d.ts.map +1 -1
  26. package/dist/functions/curses.d.ts +1 -1
  27. package/dist/functions/curses.d.ts.map +1 -1
  28. package/dist/functions/doors.d.ts +5 -5
  29. package/dist/functions/doors.d.ts.map +1 -1
  30. package/dist/functions/external.d.ts +1 -1
  31. package/dist/functions/external.d.ts.map +1 -1
  32. package/dist/functions/flag.d.ts +5 -4
  33. package/dist/functions/flag.d.ts.map +1 -1
  34. package/dist/functions/gridEntities.d.ts +5 -5
  35. package/dist/functions/gridEntities.d.ts.map +1 -1
  36. package/dist/functions/input.d.ts +5 -5
  37. package/dist/functions/input.d.ts.map +1 -1
  38. package/dist/functions/itemPool.d.ts +2 -2
  39. package/dist/functions/itemPool.d.ts.map +1 -1
  40. package/dist/functions/jsonRoom.d.ts +1 -1
  41. package/dist/functions/jsonRoom.d.ts.map +1 -1
  42. package/dist/functions/level.d.ts +2 -2
  43. package/dist/functions/level.d.ts.map +1 -1
  44. package/dist/functions/levelGrid.d.ts +2 -2
  45. package/dist/functions/levelGrid.d.ts.map +1 -1
  46. package/dist/functions/logEntities.d.ts +3 -3
  47. package/dist/functions/logEntities.d.ts.map +1 -1
  48. package/dist/functions/logMisc.d.ts +2 -1
  49. package/dist/functions/logMisc.d.ts.map +1 -1
  50. package/dist/functions/map.d.ts.map +1 -1
  51. package/dist/functions/merge.d.ts +1 -1
  52. package/dist/functions/merge.d.ts.map +1 -1
  53. package/dist/functions/npcDataStructures.d.ts +3 -3
  54. package/dist/functions/npcDataStructures.d.ts.map +1 -1
  55. package/dist/functions/playerCollectibles.d.ts +7 -7
  56. package/dist/functions/playerCollectibles.d.ts.map +1 -1
  57. package/dist/functions/playerDataStructures.d.ts +3 -3
  58. package/dist/functions/playerDataStructures.d.ts.map +1 -1
  59. package/dist/functions/playerTrinkets.d.ts +2 -2
  60. package/dist/functions/playerTrinkets.d.ts.map +1 -1
  61. package/dist/functions/players.d.ts +4 -4
  62. package/dist/functions/players.d.ts.map +1 -1
  63. package/dist/functions/rng.d.ts +3 -2
  64. package/dist/functions/rng.d.ts.map +1 -1
  65. package/dist/functions/rooms.d.ts +4 -4
  66. package/dist/functions/rooms.d.ts.map +1 -1
  67. package/dist/functions/run.d.ts +2 -2
  68. package/dist/functions/run.d.ts.map +1 -1
  69. package/dist/functions/set.d.ts.map +1 -1
  70. package/dist/functions/sort.d.ts +1 -1
  71. package/dist/functions/sort.d.ts.map +1 -1
  72. package/dist/functions/stage.d.ts +3 -3
  73. package/dist/functions/stage.d.ts.map +1 -1
  74. package/dist/functions/string.d.ts +3 -2
  75. package/dist/functions/string.d.ts.map +1 -1
  76. package/dist/functions/table.d.ts +4 -4
  77. package/dist/functions/table.d.ts.map +1 -1
  78. package/dist/functions/trinketGive.d.ts +1 -1
  79. package/dist/functions/trinketGive.d.ts.map +1 -1
  80. package/dist/functions/utils.d.ts +1 -1
  81. package/dist/functions/utils.d.ts.map +1 -1
  82. package/dist/functions/vector.d.ts +1 -1
  83. package/dist/functions/vector.d.ts.map +1 -1
  84. package/dist/functions/weighted.d.ts +2 -2
  85. package/dist/functions/weighted.d.ts.map +1 -1
  86. package/dist/index.d.ts +1 -0
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.rollup.d.ts +109 -107
  89. package/dist/indexLua.d.ts +1 -0
  90. package/dist/indexLua.d.ts.map +1 -1
  91. package/dist/isaacscript-common.lua +23 -12
  92. package/dist/types/AnyFunction.d.ts +1 -1
  93. package/dist/types/AnyFunction.d.ts.map +1 -1
  94. package/dist/types/ReadonlyRecord.d.ts +2 -0
  95. package/dist/types/ReadonlyRecord.d.ts.map +1 -0
  96. package/dist/types/ReadonlyRecord.lua +2 -0
  97. package/package.json +1 -1
  98. package/src/classes/ModFeature.ts +4 -4
  99. package/src/classes/ModUpgraded.ts +1 -1
  100. package/src/classes/features/callbackLogic/PlayerReorderedCallbacks.ts +1 -0
  101. package/src/classes/features/other/CustomItemPools.ts +10 -3
  102. package/src/classes/features/other/DisableInputs.ts +4 -1
  103. package/src/classes/features/other/ItemPoolDetection.ts +2 -2
  104. package/src/classes/features/other/ModdedElementSets.ts +6 -6
  105. package/src/classes/features/other/PickupIndexCreation.ts +1 -1
  106. package/src/classes/features/other/RunInNFrames.ts +2 -0
  107. package/src/classes/features/other/SaveDataManager.ts +3 -1
  108. package/src/core/upgradeMod.ts +4 -1
  109. package/src/functions/array.ts +18 -5
  110. package/src/functions/arrayLua.ts +20 -20
  111. package/src/functions/benchmark.ts +1 -1
  112. package/src/functions/bitwise.ts +1 -1
  113. package/src/functions/cards.ts +1 -1
  114. package/src/functions/challenges.ts +1 -1
  115. package/src/functions/curses.ts +1 -1
  116. package/src/functions/deepCopy.ts +6 -6
  117. package/src/functions/doors.ts +7 -5
  118. package/src/functions/external.ts +1 -1
  119. package/src/functions/flag.ts +5 -4
  120. package/src/functions/gridEntities.ts +5 -5
  121. package/src/functions/input.ts +5 -5
  122. package/src/functions/itemPool.ts +4 -2
  123. package/src/functions/jsonRoom.ts +1 -1
  124. package/src/functions/level.ts +2 -2
  125. package/src/functions/levelGrid.ts +2 -2
  126. package/src/functions/logEntities.ts +6 -3
  127. package/src/functions/logMisc.ts +2 -1
  128. package/src/functions/map.ts +2 -0
  129. package/src/functions/merge.ts +4 -3
  130. package/src/functions/npcDataStructures.ts +11 -3
  131. package/src/functions/playerCollectibles.ts +7 -7
  132. package/src/functions/playerDataStructures.ts +8 -3
  133. package/src/functions/playerTrinkets.ts +2 -2
  134. package/src/functions/players.ts +6 -4
  135. package/src/functions/rng.ts +8 -2
  136. package/src/functions/rooms.ts +4 -4
  137. package/src/functions/run.ts +6 -2
  138. package/src/functions/set.ts +3 -0
  139. package/src/functions/sort.ts +5 -1
  140. package/src/functions/stage.ts +5 -3
  141. package/src/functions/string.ts +3 -2
  142. package/src/functions/table.ts +4 -4
  143. package/src/functions/trinketGive.ts +1 -1
  144. package/src/functions/utils.ts +1 -1
  145. package/src/functions/vector.ts +1 -1
  146. package/src/functions/weighted.ts +2 -2
  147. package/src/index.ts +1 -0
  148. package/src/types/AnyFunction.ts +1 -1
  149. package/src/types/ReadonlyRecord.ts +3 -0
@@ -1,6 +1,7 @@
1
1
  import type { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
2
  import { game } from "../core/cachedClasses";
3
3
  import { SerializationBrand } from "../enums/private/SerializationBrand";
4
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord";
4
5
  import { traceback } from "./debugFunctions";
5
6
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
6
7
  import { logError } from "./log";
@@ -121,7 +122,10 @@ export function serializeRNG(rng: RNG): SerializedRNG {
121
122
  * Helper function to iterate over the provided object and set the seed for all of the values that
122
123
  * are RNG objects equal to a particular seed.
123
124
  */
124
- export function setAllRNGToSeed(object: unknown, seed: Seed): void {
125
+ export function setAllRNGToSeed(
126
+ object: ReadonlyRecord<string, RNG>,
127
+ seed: Seed,
128
+ ): void {
125
129
  if (!isTable(object)) {
126
130
  error(
127
131
  `Failed to iterate over the object containing RNG objects since the type of the provided object was: ${typeof object}`,
@@ -147,7 +151,9 @@ export function setAllRNGToSeed(object: unknown, seed: Seed): void {
147
151
  * Helper function to iterate over the provided object and set the seed for all of the values that
148
152
  * are RNG objects equal to the start seed for the current run.
149
153
  */
150
- export function setAllRNGToStartSeed(object: unknown): void {
154
+ export function setAllRNGToStartSeed(
155
+ object: ReadonlyRecord<string, RNG>,
156
+ ): void {
151
157
  const seeds = game.GetSeeds();
152
158
  const startSeed = seeds.GetStartSeed();
153
159
 
@@ -472,7 +472,7 @@ export function inMirrorRoom(): boolean {
472
472
  *
473
473
  * This function is variadic, which means you can pass as many room shapes as you want to match for.
474
474
  */
475
- export function inRoomShape(...roomShapes: RoomShape[]): boolean {
475
+ export function inRoomShape(...roomShapes: readonly RoomShape[]): boolean {
476
476
  const roomData = getRoomData();
477
477
  return isRoomShape(roomData, ...roomShapes);
478
478
  }
@@ -482,7 +482,7 @@ export function inRoomShape(...roomShapes: RoomShape[]): boolean {
482
482
  *
483
483
  * This function is variadic, which means you can pass as many room types as you want to match for.
484
484
  */
485
- export function inRoomType(...roomTypes: RoomType[]): boolean {
485
+ export function inRoomType(...roomTypes: readonly RoomType[]): boolean {
486
486
  const roomData = getRoomData();
487
487
  return isRoomType(roomData, ...roomTypes);
488
488
  }
@@ -806,7 +806,7 @@ export function isMirrorRoom(roomData: RoomConfig): boolean {
806
806
  */
807
807
  export function isRoomShape(
808
808
  roomData: RoomConfig,
809
- ...roomShapes: RoomShape[]
809
+ ...roomShapes: readonly RoomShape[]
810
810
  ): boolean {
811
811
  return roomShapes.includes(roomData.Shape);
812
812
  }
@@ -818,7 +818,7 @@ export function isRoomShape(
818
818
  */
819
819
  export function isRoomType(
820
820
  roomData: RoomConfig,
821
- ...roomTypes: RoomType[]
821
+ ...roomTypes: readonly RoomType[]
822
822
  ): boolean {
823
823
  return roomTypes.includes(roomData.Type);
824
824
  }
@@ -10,7 +10,9 @@ import { log } from "./log";
10
10
  import { isString } from "./types";
11
11
 
12
12
  /** Alias for the `anySeedEffectEnabled` function. */
13
- export function anyEasterEggEnabled(exceptions?: SeedEffect[]): boolean {
13
+ export function anyEasterEggEnabled(
14
+ exceptions?: readonly SeedEffect[],
15
+ ): boolean {
14
16
  return anySeedEffectEnabled(exceptions);
15
17
  }
16
18
 
@@ -19,7 +21,9 @@ export function anyEasterEggEnabled(exceptions?: SeedEffect[]): boolean {
19
21
  *
20
22
  * @param exceptions Optional. An array of seed effects to ignore.
21
23
  */
22
- export function anySeedEffectEnabled(exceptions?: SeedEffect[]): boolean {
24
+ export function anySeedEffectEnabled(
25
+ exceptions?: readonly SeedEffect[],
26
+ ): boolean {
23
27
  const seeds = game.GetSeeds();
24
28
 
25
29
  if (exceptions === undefined) {
@@ -9,6 +9,7 @@ import { isPrimitive } from "./types";
9
9
  * This function is variadic, meaning that you can specify N sets to add to the first set.
10
10
  */
11
11
  export function addSetsToSet<T>(
12
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
12
13
  mainSet: Set<T>,
13
14
  ...setsToAdd: ReadonlyArray<ReadonlySet<T>>
14
15
  ): void {
@@ -54,6 +55,7 @@ export function copySet<T>(oldSet: ReadonlySet<T>): Set<T> {
54
55
  * This function is variadic, meaning that you can specify N sets to remove from the first set.
55
56
  */
56
57
  export function deleteSetsFromSet<T>(
58
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
57
59
  mainSet: Set<T>,
58
60
  ...setsToRemove: ReadonlyArray<ReadonlySet<T>>
59
61
  ): void {
@@ -217,6 +219,7 @@ export function objectValuesToSet<K extends string | number | symbol, V>(
217
219
  *
218
220
  * This function is variadic, meaning that you can pass as many things as you want to add.
219
221
  */
222
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
220
223
  export function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void {
221
224
  for (const element of elements) {
222
225
  set.add(element);
@@ -88,7 +88,10 @@ export function sortObjectArrayByKey(key: string) {
88
88
  * From:
89
89
  * https://stackoverflow.com/questions/16096872/how-to-sort-2-dimensional-array-by-column-value
90
90
  */
91
- export function sortTwoDimensionalArray<T>(a: T[], b: T[]): -1 | 0 | 1 {
91
+ export function sortTwoDimensionalArray<T>(
92
+ a: readonly T[],
93
+ b: readonly T[],
94
+ ): -1 | 0 | 1 {
92
95
  const aType = type(a);
93
96
  const bType = type(b);
94
97
  if (aType !== bType) {
@@ -148,6 +151,7 @@ export function sortTwoDimensionalArray<T>(a: T[], b: T[]): -1 | 0 | 1 {
148
151
  */
149
152
  // eslint-disable-next-line isaacscript/no-mutable-return
150
153
  export function stableSort<T>(
154
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
151
155
  array: T[],
152
156
  sortFunc: (a: T, b: T) => -1 | 0 | 1 = sortNormal,
153
157
  ): T[] {
@@ -362,7 +362,9 @@ export function onDarkRoom(): boolean {
362
362
  *
363
363
  * This function is variadic, which means you can pass as many stages as you want to match for.
364
364
  */
365
- export function onEffectiveStage(...effectiveStages: LevelStage[]): boolean {
365
+ export function onEffectiveStage(
366
+ ...effectiveStages: readonly LevelStage[]
367
+ ): boolean {
366
368
  const thisEffectiveStage = getEffectiveStage();
367
369
  return effectiveStages.includes(thisEffectiveStage);
368
370
  }
@@ -422,7 +424,7 @@ export function onSheol(): boolean {
422
424
  *
423
425
  * This function is variadic, which means you can pass as many stages as you want to match for.
424
426
  */
425
- export function onStage(...stages: LevelStage[]): boolean {
427
+ export function onStage(...stages: readonly LevelStage[]): boolean {
426
428
  const level = game.GetLevel();
427
429
  const thisStage = level.GetStage();
428
430
  return stages.includes(thisStage);
@@ -447,7 +449,7 @@ export function onStageOrLower(stage: LevelStage): boolean {
447
449
  *
448
450
  * This function is variadic, which means you can pass as many room types as you want to match for.
449
451
  */
450
- export function onStageType(...stageTypes: StageType[]): boolean {
452
+ export function onStageType(...stageTypes: readonly StageType[]): boolean {
451
453
  const level = game.GetLevel();
452
454
  const thisStageType = level.GetStageType();
453
455
  return stageTypes.includes(thisStageType);
@@ -1,3 +1,4 @@
1
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord";
1
2
  import { parseIntSafe } from "./types";
2
3
  import { assertDefined } from "./utils";
3
4
 
@@ -81,7 +82,7 @@ export function getMapPartialMatch<T>(
81
82
  */
82
83
  export function getObjectPartialMatch<T>(
83
84
  searchText: string,
84
- object: Record<string, T>,
85
+ object: ReadonlyRecord<string, T>,
85
86
  ): [string, T] | undefined {
86
87
  const keys = Object.keys(object);
87
88
 
@@ -204,7 +205,7 @@ export function removeNonAlphanumericCharacters(str: string): string {
204
205
  */
205
206
  export function removeSubstring(
206
207
  string: string,
207
- ...substrings: string[]
208
+ ...substrings: readonly string[]
208
209
  ): string {
209
210
  for (const substring of substrings) {
210
211
  string = string.replaceAll(substring, "");
@@ -43,7 +43,7 @@ export function copyUserdataValuesToTable(
43
43
  export function getBooleansFromTable(
44
44
  luaMap: LuaMap<string, unknown>,
45
45
  objectName: string,
46
- ...keys: string[]
46
+ ...keys: readonly string[]
47
47
  ): readonly boolean[] {
48
48
  const booleans: boolean[] = [];
49
49
  for (const key of keys) {
@@ -75,7 +75,7 @@ export function getBooleansFromTable(
75
75
  export function getNumbersFromTable(
76
76
  luaMap: LuaMap<string, unknown>,
77
77
  objectName: string,
78
- ...keys: string[]
78
+ ...keys: readonly string[]
79
79
  ): readonly number[] {
80
80
  const numbers: number[] = [];
81
81
  for (const key of keys) {
@@ -114,7 +114,7 @@ export function getNumbersFromTable(
114
114
  export function getStringsFromTable(
115
115
  luaMap: LuaMap<string, unknown>,
116
116
  objectName: string,
117
- ...keys: string[]
117
+ ...keys: readonly string[]
118
118
  ): readonly string[] {
119
119
  const strings: string[] = [];
120
120
  for (const key of keys) {
@@ -204,7 +204,7 @@ export function iterateTableInOrder<K extends AnyNotNil, V>(
204
204
  */
205
205
  export function tableHasKeys(
206
206
  luaMap: LuaMap<AnyNotNil, unknown>,
207
- ...keys: string[]
207
+ ...keys: readonly string[]
208
208
  ): boolean {
209
209
  return keys.every((key) => luaMap.has(key));
210
210
  }
@@ -88,7 +88,7 @@ export function smeltTrinket(
88
88
  */
89
89
  export function smeltTrinkets(
90
90
  player: EntityPlayer,
91
- ...trinketTypes: TrinketType[]
91
+ ...trinketTypes: readonly TrinketType[]
92
92
  ): void {
93
93
  for (const trinketType of trinketTypes) {
94
94
  smeltTrinket(player, trinketType);
@@ -228,4 +228,4 @@ export function repeat(num: int, func: (i: int) => void): void {
228
228
  * @allowEmptyVariadic
229
229
  */
230
230
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
231
- export function todo(...args: unknown[]): void {}
231
+ export function todo(...args: readonly unknown[]): void {}
@@ -86,7 +86,7 @@ export function doesVectorHaveLength(
86
86
  */
87
87
  export function getClosestVectorTo(
88
88
  referenceVector: Vector,
89
- vectors: Vector[],
89
+ vectors: readonly Vector[],
90
90
  ): Vector | undefined {
91
91
  let closestVector: Vector | undefined;
92
92
  let closestDistance = math.huge;
@@ -17,7 +17,7 @@ import { assertDefined } from "./utils";
17
17
  * a random seed.
18
18
  */
19
19
  export function getRandomFromWeightedArray<T>(
20
- weightedArray: WeightedArray<T>,
20
+ weightedArray: Readonly<WeightedArray<T>>,
21
21
  seedOrRNG: Seed | RNG | undefined,
22
22
  ): T {
23
23
  const randomIndex = getRandomIndexFromWeightedArray(weightedArray, seedOrRNG);
@@ -45,7 +45,7 @@ export function getRandomFromWeightedArray<T>(
45
45
  * a random seed.
46
46
  */
47
47
  export function getRandomIndexFromWeightedArray<T>(
48
- weightedArray: WeightedArray<T>,
48
+ weightedArray: Readonly<WeightedArray<T>>,
49
49
  seedOrRNG: Seed | RNG | undefined,
50
50
  ): int {
51
51
  if (weightedArray.length === 0) {
package/src/index.ts CHANGED
@@ -185,6 +185,7 @@ export * from "./types/PlayerIndex";
185
185
  export * from "./types/PossibleStatType";
186
186
  export * from "./types/PublicInterface";
187
187
  export * from "./types/ReadonlyMap";
188
+ export * from "./types/ReadonlyRecord";
188
189
  export * from "./types/ReadonlySet";
189
190
  export * from "./types/StartsWithLowercase";
190
191
  export * from "./types/StartsWithUppercase";
@@ -2,4 +2,4 @@
2
2
  * Helper type to represent any function. This is safer than using the built-in `Function` type, as
3
3
  * it does not completely turn off all type safety.
4
4
  */
5
- export type AnyFunction = (...args: unknown[]) => unknown;
5
+ export type AnyFunction = (...args: readonly unknown[]) => unknown;
@@ -0,0 +1,3 @@
1
+ export type ReadonlyRecord<K extends string | number | symbol, V> = Readonly<
2
+ Record<K, V>
3
+ >;