isaacscript-common 81.0.4 → 82.0.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.
Files changed (168) hide show
  1. package/dist/arrays/cachedEnumValues.d.ts +17 -5
  2. package/dist/arrays/cachedEnumValues.d.ts.map +1 -1
  3. package/dist/arrays/cachedEnumValues.lua +1 -1
  4. package/dist/classes/ModFeature.d.ts +1 -1
  5. package/dist/classes/ModFeature.d.ts.map +1 -1
  6. package/dist/classes/features/other/CustomItemPools.d.ts +1 -1
  7. package/dist/classes/features/other/CustomItemPools.d.ts.map +1 -1
  8. package/dist/classes/features/other/CustomItemPools.lua +4 -2
  9. package/dist/classes/features/other/CustomStages.lua +2 -2
  10. package/dist/classes/features/other/DisableInputs.d.ts +1 -1
  11. package/dist/classes/features/other/DisableInputs.d.ts.map +1 -1
  12. package/dist/classes/features/other/ModdedElementSets.d.ts +4 -4
  13. package/dist/classes/features/other/ModdedElementSets.d.ts.map +1 -1
  14. package/dist/classes/features/other/ModdedElementSets.lua +7 -2
  15. package/dist/classes/features/other/Pause.lua +2 -2
  16. package/dist/classes/features/other/PreventGridEntityRespawn.lua +1 -1
  17. package/dist/classes/features/other/SaveDataManager.d.ts +1 -1
  18. package/dist/classes/features/other/SaveDataManager.d.ts.map +1 -1
  19. package/dist/functions/array.d.ts +5 -5
  20. package/dist/functions/array.d.ts.map +1 -1
  21. package/dist/functions/arrayLua.d.ts +14 -14
  22. package/dist/functions/arrayLua.d.ts.map +1 -1
  23. package/dist/functions/arrayLua.lua +7 -7
  24. package/dist/functions/benchmark.d.ts +1 -1
  25. package/dist/functions/benchmark.d.ts.map +1 -1
  26. package/dist/functions/bitwise.d.ts +1 -1
  27. package/dist/functions/bitwise.d.ts.map +1 -1
  28. package/dist/functions/bosses.d.ts +4 -2
  29. package/dist/functions/bosses.d.ts.map +1 -1
  30. package/dist/functions/bosses.lua +8 -7
  31. package/dist/functions/cards.d.ts +1 -1
  32. package/dist/functions/cards.d.ts.map +1 -1
  33. package/dist/functions/challenges.d.ts +1 -1
  34. package/dist/functions/challenges.d.ts.map +1 -1
  35. package/dist/functions/curses.d.ts +1 -1
  36. package/dist/functions/curses.d.ts.map +1 -1
  37. package/dist/functions/doors.d.ts +5 -5
  38. package/dist/functions/doors.d.ts.map +1 -1
  39. package/dist/functions/external.d.ts +1 -1
  40. package/dist/functions/external.d.ts.map +1 -1
  41. package/dist/functions/flag.d.ts +5 -4
  42. package/dist/functions/flag.d.ts.map +1 -1
  43. package/dist/functions/gridEntities.d.ts +5 -5
  44. package/dist/functions/gridEntities.d.ts.map +1 -1
  45. package/dist/functions/gridEntities.lua +1 -1
  46. package/dist/functions/input.d.ts +5 -5
  47. package/dist/functions/input.d.ts.map +1 -1
  48. package/dist/functions/itemPool.d.ts +2 -2
  49. package/dist/functions/itemPool.d.ts.map +1 -1
  50. package/dist/functions/jsonRoom.d.ts +1 -1
  51. package/dist/functions/jsonRoom.d.ts.map +1 -1
  52. package/dist/functions/level.d.ts +2 -2
  53. package/dist/functions/level.d.ts.map +1 -1
  54. package/dist/functions/levelGrid.d.ts +2 -2
  55. package/dist/functions/levelGrid.d.ts.map +1 -1
  56. package/dist/functions/logEntities.d.ts +3 -3
  57. package/dist/functions/logEntities.d.ts.map +1 -1
  58. package/dist/functions/logMisc.d.ts +2 -1
  59. package/dist/functions/logMisc.d.ts.map +1 -1
  60. package/dist/functions/map.d.ts.map +1 -1
  61. package/dist/functions/merge.d.ts +1 -1
  62. package/dist/functions/merge.d.ts.map +1 -1
  63. package/dist/functions/npcDataStructures.d.ts +3 -3
  64. package/dist/functions/npcDataStructures.d.ts.map +1 -1
  65. package/dist/functions/playerCollectibles.d.ts +7 -7
  66. package/dist/functions/playerCollectibles.d.ts.map +1 -1
  67. package/dist/functions/playerDataStructures.d.ts +3 -3
  68. package/dist/functions/playerDataStructures.d.ts.map +1 -1
  69. package/dist/functions/playerTrinkets.d.ts +2 -2
  70. package/dist/functions/playerTrinkets.d.ts.map +1 -1
  71. package/dist/functions/players.d.ts +4 -4
  72. package/dist/functions/players.d.ts.map +1 -1
  73. package/dist/functions/rng.d.ts +3 -2
  74. package/dist/functions/rng.d.ts.map +1 -1
  75. package/dist/functions/rooms.d.ts +4 -4
  76. package/dist/functions/rooms.d.ts.map +1 -1
  77. package/dist/functions/run.d.ts +2 -2
  78. package/dist/functions/run.d.ts.map +1 -1
  79. package/dist/functions/set.d.ts.map +1 -1
  80. package/dist/functions/sort.d.ts +1 -1
  81. package/dist/functions/sort.d.ts.map +1 -1
  82. package/dist/functions/stage.d.ts +3 -3
  83. package/dist/functions/stage.d.ts.map +1 -1
  84. package/dist/functions/string.d.ts +3 -2
  85. package/dist/functions/string.d.ts.map +1 -1
  86. package/dist/functions/table.d.ts +4 -4
  87. package/dist/functions/table.d.ts.map +1 -1
  88. package/dist/functions/trinketGive.d.ts +1 -1
  89. package/dist/functions/trinketGive.d.ts.map +1 -1
  90. package/dist/functions/utils.d.ts +1 -1
  91. package/dist/functions/utils.d.ts.map +1 -1
  92. package/dist/functions/vector.d.ts +1 -1
  93. package/dist/functions/vector.d.ts.map +1 -1
  94. package/dist/functions/weighted.d.ts +2 -2
  95. package/dist/functions/weighted.d.ts.map +1 -1
  96. package/dist/index.d.ts +1 -0
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.rollup.d.ts +113 -108
  99. package/dist/indexLua.d.ts +1 -0
  100. package/dist/indexLua.d.ts.map +1 -1
  101. package/dist/isaacscript-common.lua +115 -96
  102. package/dist/sets/bossSets.d.ts +3 -2
  103. package/dist/sets/bossSets.d.ts.map +1 -1
  104. package/dist/sets/bossSets.lua +73 -69
  105. package/dist/types/AnyFunction.d.ts +1 -1
  106. package/dist/types/AnyFunction.d.ts.map +1 -1
  107. package/dist/types/ReadonlyRecord.d.ts +2 -0
  108. package/dist/types/ReadonlyRecord.d.ts.map +1 -0
  109. package/dist/types/ReadonlyRecord.lua +2 -0
  110. package/package.json +2 -2
  111. package/src/arrays/cachedEnumValues.ts +23 -39
  112. package/src/classes/ModFeature.ts +4 -4
  113. package/src/classes/ModUpgraded.ts +1 -1
  114. package/src/classes/features/callbackLogic/PlayerReorderedCallbacks.ts +1 -0
  115. package/src/classes/features/other/CustomItemPools.ts +10 -3
  116. package/src/classes/features/other/CustomStages.ts +2 -2
  117. package/src/classes/features/other/DisableInputs.ts +4 -1
  118. package/src/classes/features/other/ItemPoolDetection.ts +2 -2
  119. package/src/classes/features/other/ModdedElementSets.ts +6 -6
  120. package/src/classes/features/other/Pause.ts +2 -2
  121. package/src/classes/features/other/PickupIndexCreation.ts +1 -1
  122. package/src/classes/features/other/PreventGridEntityRespawn.ts +1 -1
  123. package/src/classes/features/other/RunInNFrames.ts +2 -0
  124. package/src/classes/features/other/SaveDataManager.ts +3 -1
  125. package/src/core/upgradeMod.ts +4 -1
  126. package/src/functions/array.ts +18 -5
  127. package/src/functions/arrayLua.ts +20 -20
  128. package/src/functions/benchmark.ts +1 -1
  129. package/src/functions/bitwise.ts +1 -1
  130. package/src/functions/bosses.ts +9 -11
  131. package/src/functions/cards.ts +1 -1
  132. package/src/functions/challenges.ts +1 -1
  133. package/src/functions/curses.ts +1 -1
  134. package/src/functions/deepCopy.ts +6 -6
  135. package/src/functions/doors.ts +7 -5
  136. package/src/functions/external.ts +1 -1
  137. package/src/functions/flag.ts +5 -4
  138. package/src/functions/gridEntities.ts +6 -6
  139. package/src/functions/input.ts +5 -5
  140. package/src/functions/itemPool.ts +4 -2
  141. package/src/functions/jsonRoom.ts +1 -1
  142. package/src/functions/level.ts +2 -2
  143. package/src/functions/levelGrid.ts +2 -2
  144. package/src/functions/logEntities.ts +6 -3
  145. package/src/functions/logMisc.ts +2 -1
  146. package/src/functions/map.ts +2 -0
  147. package/src/functions/merge.ts +4 -3
  148. package/src/functions/npcDataStructures.ts +11 -3
  149. package/src/functions/playerCollectibles.ts +7 -7
  150. package/src/functions/playerDataStructures.ts +8 -3
  151. package/src/functions/playerTrinkets.ts +2 -2
  152. package/src/functions/players.ts +6 -4
  153. package/src/functions/rng.ts +8 -2
  154. package/src/functions/rooms.ts +4 -4
  155. package/src/functions/run.ts +6 -2
  156. package/src/functions/set.ts +3 -0
  157. package/src/functions/sort.ts +5 -1
  158. package/src/functions/stage.ts +5 -3
  159. package/src/functions/string.ts +3 -2
  160. package/src/functions/table.ts +4 -4
  161. package/src/functions/trinketGive.ts +1 -1
  162. package/src/functions/utils.ts +1 -1
  163. package/src/functions/vector.ts +1 -1
  164. package/src/functions/weighted.ts +2 -2
  165. package/src/index.ts +1 -0
  166. package/src/sets/bossSets.ts +81 -117
  167. package/src/types/AnyFunction.ts +1 -1
  168. package/src/types/ReadonlyRecord.ts +3 -0
@@ -142,7 +142,7 @@ export function logAllGridEntities(
142
142
  }
143
143
 
144
144
  /** Helper function for logging an array of specific entities. */
145
- export function logEntities(this: void, entities: Entity[]): void {
145
+ export function logEntities(this: void, entities: readonly Entity[]): void {
146
146
  for (const entity of entities) {
147
147
  logEntity(entity);
148
148
  }
@@ -295,7 +295,10 @@ function getTearVariantName(tear: EntityTear) {
295
295
  }
296
296
 
297
297
  /** Helper function for logging an array of specific grid entities. */
298
- export function logGridEntities(this: void, gridEntities: GridEntity[]): void {
298
+ export function logGridEntities(
299
+ this: void,
300
+ gridEntities: readonly GridEntity[],
301
+ ): void {
299
302
  for (const gridEntity of gridEntities) {
300
303
  logGridEntity(gridEntity);
301
304
  }
@@ -386,7 +389,7 @@ export function logPtrHash(this: void, ptrHash: PtrHash): void {
386
389
  * Helper function to log information about the entity that corresponding to one or more pointer
387
390
  * hashes. (Only use this when debugging, since retrieving the corresponding entity is expensive.)
388
391
  */
389
- export function logPtrHashes(this: void, ptrHashes: PtrHash[]): void {
392
+ export function logPtrHashes(this: void, ptrHashes: readonly PtrHash[]): void {
390
393
  for (const ptrHash of ptrHashes) {
391
394
  logPtrHash(ptrHash);
392
395
  }
@@ -20,6 +20,7 @@ import {
20
20
  } from "isaac-typescript-definitions";
21
21
  import { game, musicManager, sfxManager } from "../core/cachedClasses";
22
22
  import type { ReadonlyMap } from "../types/ReadonlyMap";
23
+ import type { ReadonlyRecord } from "../types/ReadonlyRecord";
23
24
  import { ReadonlySet } from "../types/ReadonlySet";
24
25
  import { arrayToString, isArray } from "./array";
25
26
  import { getBossID } from "./bosses";
@@ -140,7 +141,7 @@ export function logEntityID(this: void, entity: Entity): void {
140
141
  export function logFlags<T extends BitFlag | BitFlag128>(
141
142
  this: void,
142
143
  flags: T | BitFlags<T>,
143
- flagEnum: Record<string, T>,
144
+ flagEnum: ReadonlyRecord<string, T>,
144
145
  description = "",
145
146
  ): void {
146
147
  if (description !== "") {
@@ -33,6 +33,7 @@ export function defaultMapGetHash<V, A extends unknown[]>(
33
33
  * `mapSetHash` helper function.
34
34
  */
35
35
  export function defaultMapSetHash<V>(
36
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
36
37
  map: Map<PtrHash, V>,
37
38
  entity: Entity,
38
39
  value: V,
@@ -78,6 +79,7 @@ export function getReversedMap<K, V>(
78
79
  * the map uses `PtrHash` as an index.
79
80
  */
80
81
  export function mapSetHash<V>(
82
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
81
83
  map: Map<PtrHash, V>,
82
84
  entity: Entity,
83
85
  value: V,
@@ -53,9 +53,9 @@ import { getTraversalDescription } from "./utils";
53
53
  */
54
54
  export function merge(
55
55
  oldObject:
56
- | LuaMap<AnyNotNil, unknown>
57
- | Map<AnyNotNil, unknown>
58
- | Set<AnyNotNil>,
56
+ | Readonly<LuaMap<AnyNotNil, unknown>>
57
+ | ReadonlyMap<AnyNotNil, unknown>
58
+ | ReadonlySet<AnyNotNil>,
59
59
  newTable: LuaMap<AnyNotNil, unknown>,
60
60
  traversalDescription: string,
61
61
  classConstructors = new LuaMap<string, AnyClass>(),
@@ -131,6 +131,7 @@ function mergeSerializedArray(
131
131
  }
132
132
 
133
133
  function mergeSerializedTSTLObject(
134
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
134
135
  oldObject: Map<AnyNotNil, unknown> | Set<AnyNotNil>,
135
136
  newTable: LuaMap<AnyNotNil, unknown>,
136
137
  traversalDescription: string,
@@ -41,6 +41,7 @@ export function defaultMapGetNPC<V, Args extends unknown[]>(
41
41
  * `mapSetNPC` helper function.
42
42
  */
43
43
  export function defaultMapSetNPC<V>(
44
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
44
45
  map: Map<PtrHash, V>,
45
46
  npc: EntityNPC,
46
47
  value: V,
@@ -53,6 +54,7 @@ export function defaultMapSetNPC<V>(
53
54
  * `Map.delete` method if you have a set of this type.
54
55
  */
55
56
  export function mapDeleteNPC(
57
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
56
58
  map: Map<PtrHash, unknown>,
57
59
  npc: EntityNPC,
58
60
  ): boolean {
@@ -81,7 +83,7 @@ export function mapDeleteNPC(
81
83
  * ```
82
84
  */
83
85
  export function mapGetNPC<V>(
84
- map: Map<PtrHash, V>,
86
+ map: ReadonlyMap<PtrHash, V>,
85
87
  npc: EntityNPC,
86
88
  ): V | undefined {
87
89
  const ptrHash = GetPtrHash(npc);
@@ -92,7 +94,10 @@ export function mapGetNPC<V>(
92
94
  * Helper function to make using maps with an index of `PtrHash` easier. Use this instead of the
93
95
  * `Map.has` method if you have a map of this type.
94
96
  */
95
- export function mapHasNPC<V>(map: Map<PtrHash, V>, npc: EntityNPC): boolean {
97
+ export function mapHasNPC<V>(
98
+ map: ReadonlyMap<PtrHash, V>,
99
+ npc: EntityNPC,
100
+ ): boolean {
96
101
  const ptrHash = GetPtrHash(npc);
97
102
  return map.has(ptrHash);
98
103
  }
@@ -118,6 +123,7 @@ export function mapHasNPC<V>(map: Map<PtrHash, V>, npc: EntityNPC): boolean {
118
123
  * ```
119
124
  */
120
125
  export function mapSetNPC<V>(
126
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
121
127
  map: Map<PtrHash, V>,
122
128
  npc: EntityNPC,
123
129
  value: V,
@@ -130,6 +136,7 @@ export function mapSetNPC<V>(
130
136
  * Helper function to make using sets with an type of `PtrHash` easier. Use this instead of the
131
137
  * `Set.add` method if you have a set of this type.
132
138
  */
139
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
133
140
  export function setAddNPC(set: Set<PtrHash>, npc: EntityNPC): void {
134
141
  const ptrHash = GetPtrHash(npc);
135
142
  set.add(ptrHash);
@@ -139,6 +146,7 @@ export function setAddNPC(set: Set<PtrHash>, npc: EntityNPC): void {
139
146
  * Helper function to make using sets with an type of `PtrHash` easier. Use this instead of the
140
147
  * `Set.delete` method if you have a set of this type.
141
148
  */
149
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
142
150
  export function setDeleteNPC(set: Set<PtrHash>, npc: EntityNPC): boolean {
143
151
  const ptrHash = GetPtrHash(npc);
144
152
  return set.delete(ptrHash);
@@ -148,7 +156,7 @@ export function setDeleteNPC(set: Set<PtrHash>, npc: EntityNPC): boolean {
148
156
  * Helper function to make using sets with an type of `PtrHash` easier. Use this instead of the
149
157
  * `Set.has` method if you have a set of this type.
150
158
  */
151
- export function setHasNPC(set: Set<PtrHash>, npc: EntityNPC): boolean {
159
+ export function setHasNPC(set: ReadonlySet<PtrHash>, npc: EntityNPC): boolean {
152
160
  const ptrHash = GetPtrHash(npc);
153
161
  return set.has(ptrHash);
154
162
  }
@@ -19,7 +19,7 @@ import { isCharacter } from "./players";
19
19
  */
20
20
  export function addCollectible(
21
21
  player: EntityPlayer,
22
- ...collectibleTypes: CollectibleType[]
22
+ ...collectibleTypes: readonly CollectibleType[]
23
23
  ): void {
24
24
  for (const collectibleType of collectibleTypes) {
25
25
  player.AddCollectible(collectibleType);
@@ -93,7 +93,7 @@ export function getAdjustedPrice(basePrice: int): int {
93
93
  */
94
94
  export function getPlayerCollectibleCount(
95
95
  player: EntityPlayer,
96
- ...collectibleTypes: CollectibleType[]
96
+ ...collectibleTypes: readonly CollectibleType[]
97
97
  ): int {
98
98
  let numCollectibles = 0;
99
99
  for (const collectibleType of collectibleTypes) {
@@ -111,7 +111,7 @@ export function getPlayerCollectibleCount(
111
111
  * check for. It only returns the players that have all of the collectibles.
112
112
  */
113
113
  export function getPlayersWithCollectible(
114
- ...collectibleTypes: CollectibleType[]
114
+ ...collectibleTypes: readonly CollectibleType[]
115
115
  ): readonly EntityPlayer[] {
116
116
  const players = getPlayers();
117
117
 
@@ -150,7 +150,7 @@ export function getTotalPlayerCollectibles(
150
150
  */
151
151
  export function hasCollectible(
152
152
  player: EntityPlayer,
153
- ...collectibleTypes: CollectibleType[]
153
+ ...collectibleTypes: readonly CollectibleType[]
154
154
  ): boolean {
155
155
  return collectibleTypes.some((collectibleType) =>
156
156
  player.HasCollectible(collectibleType),
@@ -168,7 +168,7 @@ export function hasCollectible(
168
168
  export function hasCollectibleInActiveSlot(
169
169
  player: EntityPlayer,
170
170
  collectibleType: CollectibleType,
171
- ...activeSlots: ActiveSlot[]
171
+ ...activeSlots: readonly ActiveSlot[]
172
172
  ): boolean {
173
173
  const matchingActiveSlotsSet = new ReadonlySet(activeSlots);
174
174
  const activeItemSlots = getActiveItemSlots(player, collectibleType);
@@ -245,7 +245,7 @@ export function removeAllActiveItems(player: EntityPlayer): void {
245
245
  */
246
246
  export function removeCollectible(
247
247
  player: EntityPlayer,
248
- ...collectibleTypes: CollectibleType[]
248
+ ...collectibleTypes: readonly CollectibleType[]
249
249
  ): void {
250
250
  for (const collectibleType of collectibleTypes) {
251
251
  player.RemoveCollectible(collectibleType);
@@ -276,7 +276,7 @@ export function removeCollectibleCostume(
276
276
  * remove.
277
277
  */
278
278
  export function removeCollectibleFromAllPlayers(
279
- ...collectibleTypes: CollectibleType[]
279
+ ...collectibleTypes: readonly CollectibleType[]
280
280
  ): void {
281
281
  for (const player of getAllPlayers()) {
282
282
  for (const collectibleType of collectibleTypes) {
@@ -39,6 +39,7 @@ export function defaultMapGetPlayer<V, Args extends unknown[]>(
39
39
  * `mapSetPlayer` helper function.
40
40
  */
41
41
  export function defaultMapSetPlayer<V>(
42
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
42
43
  map: Map<PlayerIndex, V>,
43
44
  player: EntityPlayer,
44
45
  value: V,
@@ -51,6 +52,7 @@ export function defaultMapSetPlayer<V>(
51
52
  * `Map.delete` method if you have a set of this type.
52
53
  */
53
54
  export function mapDeletePlayer(
55
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
54
56
  map: Map<PlayerIndex, unknown>,
55
57
  player: EntityPlayer,
56
58
  ): boolean {
@@ -79,7 +81,7 @@ export function mapDeletePlayer(
79
81
  * ```
80
82
  */
81
83
  export function mapGetPlayer<V>(
82
- map: Map<PlayerIndex, V>,
84
+ map: ReadonlyMap<PlayerIndex, V>,
83
85
  player: EntityPlayer,
84
86
  ): V | undefined {
85
87
  const playerIndex = getPlayerIndex(player);
@@ -91,7 +93,7 @@ export function mapGetPlayer<V>(
91
93
  * `Map.has` method if you have a map of this type.
92
94
  */
93
95
  export function mapHasPlayer<V>(
94
- map: Map<PlayerIndex, V>,
96
+ map: ReadonlyMap<PlayerIndex, V>,
95
97
  player: EntityPlayer,
96
98
  ): boolean {
97
99
  const playerIndex = getPlayerIndex(player);
@@ -119,6 +121,7 @@ export function mapHasPlayer<V>(
119
121
  * ```
120
122
  */
121
123
  export function mapSetPlayer<V>(
124
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
122
125
  map: Map<PlayerIndex, V>,
123
126
  player: EntityPlayer,
124
127
  value: V,
@@ -132,6 +135,7 @@ export function mapSetPlayer<V>(
132
135
  * `Set.add` method if you have a set of this type.
133
136
  */
134
137
  export function setAddPlayer(
138
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
135
139
  set: Set<PlayerIndex>,
136
140
  player: EntityPlayer,
137
141
  ): void {
@@ -144,6 +148,7 @@ export function setAddPlayer(
144
148
  * `Set.delete` method if you have a set of this type.
145
149
  */
146
150
  export function setDeletePlayer(
151
+ // eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
147
152
  set: Set<PlayerIndex>,
148
153
  player: EntityPlayer,
149
154
  ): boolean {
@@ -156,7 +161,7 @@ export function setDeletePlayer(
156
161
  * `Set.has` method if you have a set of this type.
157
162
  */
158
163
  export function setHasPlayer(
159
- set: Set<PlayerIndex>,
164
+ set: ReadonlySet<PlayerIndex>,
160
165
  player: EntityPlayer,
161
166
  ): boolean {
162
167
  const playerIndex = getPlayerIndex(player);
@@ -98,7 +98,7 @@ export function getPlayerTrinkets(
98
98
  * for. It only returns the players that have all of the trinkets.
99
99
  */
100
100
  export function getPlayersWithTrinket(
101
- ...trinketTypes: TrinketType[]
101
+ ...trinketTypes: readonly TrinketType[]
102
102
  ): readonly EntityPlayer[] {
103
103
  const players = getPlayers();
104
104
 
@@ -143,7 +143,7 @@ export function hasOpenTrinketSlot(player: EntityPlayer): boolean {
143
143
  */
144
144
  export function hasTrinket(
145
145
  player: EntityPlayer,
146
- ...trinketTypes: TrinketType[]
146
+ ...trinketTypes: readonly TrinketType[]
147
147
  ): boolean {
148
148
  return trinketTypes.some((trinketType) => player.HasTrinket(trinketType));
149
149
  }
@@ -34,7 +34,9 @@ export function anyPlayerHoldingItem(): boolean {
34
34
  * This function is variadic, meaning that you can supply as many characters as you want to check
35
35
  * for. Returns true if any of the characters supplied are present.
36
36
  */
37
- export function anyPlayerIs(...matchingCharacters: PlayerType[]): boolean {
37
+ export function anyPlayerIs(
38
+ ...matchingCharacters: readonly PlayerType[]
39
+ ): boolean {
38
40
  const matchingCharacterSet = new ReadonlySet(matchingCharacters);
39
41
  const characters = getCharacters();
40
42
 
@@ -271,7 +273,7 @@ export function getPlayerNumHitsRemaining(player: EntityPlayer): int {
271
273
  * for. Returns true if any of the characters supplied are present.
272
274
  */
273
275
  export function getPlayersOfType(
274
- ...characters: PlayerType[]
276
+ ...characters: readonly PlayerType[]
275
277
  ): readonly EntityPlayer[] {
276
278
  const charactersSet = new ReadonlySet(characters);
277
279
  const players = getPlayers();
@@ -321,7 +323,7 @@ export function getPlayersWithControllerIndex(
321
323
  */
322
324
  export function hasForm(
323
325
  player: EntityPlayer,
324
- ...playerForms: PlayerForm[]
326
+ ...playerForms: readonly PlayerForm[]
325
327
  ): boolean {
326
328
  return playerForms.some((playerForm) => player.HasPlayerForm(playerForm));
327
329
  }
@@ -379,7 +381,7 @@ export function isBethany(player: EntityPlayer): boolean {
379
381
  */
380
382
  export function isCharacter(
381
383
  player: EntityPlayer,
382
- ...characters: PlayerType[]
384
+ ...characters: readonly PlayerType[]
383
385
  ): boolean {
384
386
  const characterSet = new ReadonlySet(characters);
385
387
  const character = player.GetPlayerType();
@@ -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";