isaacscript-common 81.0.1 → 81.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/features/other/CharacterStats.d.ts +1 -1
- package/dist/classes/features/other/CharacterStats.d.ts.map +1 -1
- package/dist/classes/features/other/DeployJSONRoom.d.ts +1 -1
- package/dist/classes/features/other/DeployJSONRoom.d.ts.map +1 -1
- package/dist/classes/features/other/DeployJSONRoom.lua +1 -1
- package/dist/classes/features/other/DisableInputs.d.ts +2 -2
- package/dist/classes/features/other/DisableInputs.d.ts.map +1 -1
- package/dist/classes/features/other/ModdedElementSets.d.ts +2 -2
- package/dist/classes/features/other/ModdedElementSets.d.ts.map +1 -1
- package/dist/functions/array.d.ts +17 -17
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/bitwise.d.ts +2 -2
- package/dist/functions/bitwise.d.ts.map +1 -1
- package/dist/functions/bitwise.lua +1 -1
- package/dist/functions/doors.d.ts +1 -1
- package/dist/functions/doors.d.ts.map +1 -1
- package/dist/functions/doors.lua +2 -1
- package/dist/functions/entities.d.ts +4 -4
- package/dist/functions/entities.d.ts.map +1 -1
- package/dist/functions/entities.lua +2 -1
- package/dist/functions/enums.d.ts +1 -1
- package/dist/functions/enums.d.ts.map +1 -1
- package/dist/functions/gridEntities.d.ts +3 -3
- package/dist/functions/gridEntities.d.ts.map +1 -1
- package/dist/functions/isaacAPIClass.d.ts +1 -1
- package/dist/functions/isaacAPIClass.d.ts.map +1 -1
- package/dist/functions/itemPool.d.ts +1 -1
- package/dist/functions/itemPool.d.ts.map +1 -1
- package/dist/functions/itemPool.lua +0 -1
- package/dist/functions/jsonRoom.d.ts +3 -3
- package/dist/functions/jsonRoom.d.ts.map +1 -1
- package/dist/functions/logMisc.d.ts +5 -5
- package/dist/functions/logMisc.d.ts.map +1 -1
- package/dist/functions/map.d.ts +2 -3
- package/dist/functions/map.d.ts.map +1 -1
- package/dist/functions/map.lua +1 -1
- package/dist/functions/minimap.d.ts +1 -1
- package/dist/functions/minimap.d.ts.map +1 -1
- package/dist/functions/npcDataStructures.d.ts +1 -1
- package/dist/functions/npcDataStructures.d.ts.map +1 -1
- package/dist/functions/npcDataStructures.lua +1 -1
- package/dist/functions/playerDataStructures.d.ts +1 -1
- package/dist/functions/playerDataStructures.d.ts.map +1 -1
- package/dist/functions/playerDataStructures.lua +1 -1
- package/dist/functions/pocketItems.d.ts +1 -1
- package/dist/functions/pocketItems.d.ts.map +1 -1
- package/dist/functions/positionVelocity.d.ts +5 -5
- package/dist/functions/positionVelocity.d.ts.map +1 -1
- package/dist/functions/random.d.ts +1 -1
- package/dist/functions/random.d.ts.map +1 -1
- package/dist/functions/roomData.d.ts +1 -1
- package/dist/functions/roomData.d.ts.map +1 -1
- package/dist/functions/rooms.d.ts +1 -1
- package/dist/functions/rooms.d.ts.map +1 -1
- package/dist/functions/set.d.ts +10 -10
- package/dist/functions/set.d.ts.map +1 -1
- package/dist/functions/string.d.ts +1 -1
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/functions/table.d.ts +1 -1
- package/dist/functions/table.d.ts.map +1 -1
- package/dist/functions/transformations.d.ts +2 -2
- package/dist/functions/transformations.d.ts.map +1 -1
- package/dist/index.rollup.d.ts +74 -76
- package/dist/isaacscript-common.lua +10 -9
- package/dist/objects/itemPoolTypeToCollectibleTypesSet.d.ts +1 -1
- package/dist/objects/itemPoolTypeToCollectibleTypesSet.d.ts.map +1 -1
- package/dist/types/TupleWithLengthBetween.d.ts +1 -1
- package/dist/types/TupleWithLengthBetween.d.ts.map +1 -1
- package/dist/types/TupleWithMaxLength.d.ts +1 -1
- package/dist/types/TupleWithMaxLength.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/classes/features/callbackLogic/GridEntityUpdateDetection.ts +1 -1
- package/src/classes/features/other/CharacterStats.ts +2 -2
- package/src/classes/features/other/DeployJSONRoom.ts +3 -3
- package/src/classes/features/other/DisableInputs.ts +2 -2
- package/src/classes/features/other/ModdedElementSets.ts +2 -2
- package/src/functions/array.ts +38 -40
- package/src/functions/bitwise.ts +3 -3
- package/src/functions/deepCopy.ts +3 -3
- package/src/functions/doors.ts +7 -8
- package/src/functions/entities.ts +10 -12
- package/src/functions/enums.ts +1 -1
- package/src/functions/gridEntities.ts +3 -3
- package/src/functions/isaacAPIClass.ts +1 -1
- package/src/functions/itemPool.ts +1 -1
- package/src/functions/jsonRoom.ts +7 -5
- package/src/functions/logMisc.ts +5 -5
- package/src/functions/map.ts +7 -11
- package/src/functions/minimap.ts +1 -1
- package/src/functions/newArray.ts +1 -1
- package/src/functions/npcDataStructures.ts +2 -2
- package/src/functions/playerDataStructures.ts +2 -2
- package/src/functions/pocketItems.ts +2 -2
- package/src/functions/positionVelocity.ts +9 -9
- package/src/functions/random.ts +1 -1
- package/src/functions/roomData.ts +3 -1
- package/src/functions/rooms.ts +1 -1
- package/src/functions/set.ts +17 -15
- package/src/functions/sort.ts +1 -1
- package/src/functions/string.ts +1 -1
- package/src/functions/table.ts +1 -1
- package/src/functions/transformations.ts +2 -2
- package/src/objects/itemPoolTypeToCollectibleTypesSet.ts +3 -3
- package/src/types/TupleWithLengthBetween.ts +1 -1
- package/src/types/TupleWithMaxLength.ts +1 -4
|
@@ -88,7 +88,7 @@ export function getJSONRoomDoorSlotFlags(
|
|
|
88
88
|
* room.)
|
|
89
89
|
*/
|
|
90
90
|
export function getJSONRoomOfVariant(
|
|
91
|
-
jsonRooms:
|
|
91
|
+
jsonRooms: readonly JSONRoom[],
|
|
92
92
|
variant: int,
|
|
93
93
|
): JSONRoom | undefined {
|
|
94
94
|
const jsonRoomsOfVariant = jsonRooms.filter((jsonRoom) => {
|
|
@@ -127,7 +127,7 @@ export function getJSONRoomOfVariant(
|
|
|
127
127
|
* @param subType The sub-type to match.
|
|
128
128
|
*/
|
|
129
129
|
export function getJSONRoomsOfSubType(
|
|
130
|
-
jsonRooms:
|
|
130
|
+
jsonRooms: readonly JSONRoom[],
|
|
131
131
|
subType: int,
|
|
132
132
|
): readonly JSONRoom[] {
|
|
133
133
|
return jsonRooms.filter((jsonRoom) => {
|
|
@@ -209,7 +209,7 @@ export function getRandomJSONEntity(
|
|
|
209
209
|
* what the function is doing. Default is false.
|
|
210
210
|
*/
|
|
211
211
|
export function getRandomJSONRoom(
|
|
212
|
-
jsonRooms: JSONRoom[],
|
|
212
|
+
jsonRooms: readonly JSONRoom[],
|
|
213
213
|
seedOrRNG: Seed | RNG | undefined,
|
|
214
214
|
verbose = false,
|
|
215
215
|
): JSONRoom {
|
|
@@ -232,7 +232,9 @@ export function getRandomJSONRoom(
|
|
|
232
232
|
return randomJSONRoom;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
function getTotalWeightOfJSONObject(
|
|
235
|
+
function getTotalWeightOfJSONObject(
|
|
236
|
+
jsonOjectArray: readonly JSONObject[],
|
|
237
|
+
): float {
|
|
236
238
|
const weights = jsonOjectArray.map((jsonObject) => {
|
|
237
239
|
const weightString = jsonObject.$.weight;
|
|
238
240
|
const weight = tonumber(weightString);
|
|
@@ -248,7 +250,7 @@ function getTotalWeightOfJSONObject(jsonOjectArray: JSONObject[]): float {
|
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
function getJSONObjectWithChosenWeight<T extends JSONObject>(
|
|
251
|
-
jsonOjectArray: T[],
|
|
253
|
+
jsonOjectArray: readonly T[],
|
|
252
254
|
chosenWeight: float,
|
|
253
255
|
): T | undefined {
|
|
254
256
|
let weightAccumulator = 0;
|
package/src/functions/logMisc.ts
CHANGED
|
@@ -49,7 +49,7 @@ import { vectorToString } from "./vector";
|
|
|
49
49
|
*/
|
|
50
50
|
export function logArray<T>(
|
|
51
51
|
this: void,
|
|
52
|
-
array:
|
|
52
|
+
array: readonly T[],
|
|
53
53
|
name?: string,
|
|
54
54
|
): void {
|
|
55
55
|
// We do not assume the given array has contiguous values in order to be more permissive about the
|
|
@@ -74,7 +74,7 @@ export function logArray<T>(
|
|
|
74
74
|
*/
|
|
75
75
|
export function logCollectibleTypes(
|
|
76
76
|
this: void,
|
|
77
|
-
collectibleTypes:
|
|
77
|
+
collectibleTypes: readonly CollectibleType[],
|
|
78
78
|
name?: string,
|
|
79
79
|
): void {
|
|
80
80
|
if (name === undefined) {
|
|
@@ -192,7 +192,7 @@ export function logGameStateFlags(this: void): void {
|
|
|
192
192
|
*/
|
|
193
193
|
export function logItemPoolTypes(
|
|
194
194
|
this: void,
|
|
195
|
-
itemPoolTypes:
|
|
195
|
+
itemPoolTypes: readonly ItemPoolType[],
|
|
196
196
|
name?: string,
|
|
197
197
|
): void {
|
|
198
198
|
if (name === undefined) {
|
|
@@ -254,7 +254,7 @@ export function logLevelStateFlags(this: void): void {
|
|
|
254
254
|
*/
|
|
255
255
|
export function logMap(
|
|
256
256
|
this: void,
|
|
257
|
-
map:
|
|
257
|
+
map: ReadonlyMap<AnyNotNil, unknown>,
|
|
258
258
|
name?: string,
|
|
259
259
|
): void {
|
|
260
260
|
if (!isTSTLMap(map) && !isDefaultMap(map)) {
|
|
@@ -398,7 +398,7 @@ export function logSeedEffects(this: void): void {
|
|
|
398
398
|
*/
|
|
399
399
|
export function logSet(
|
|
400
400
|
this: void,
|
|
401
|
-
set:
|
|
401
|
+
set: ReadonlySet<AnyNotNil>,
|
|
402
402
|
name?: string,
|
|
403
403
|
): void {
|
|
404
404
|
if (!isTSTLSet(set)) {
|
package/src/functions/map.ts
CHANGED
|
@@ -2,11 +2,10 @@ import type { DefaultMap } from "../classes/DefaultMap";
|
|
|
2
2
|
import { sumArray } from "./array";
|
|
3
3
|
|
|
4
4
|
/** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
): Map<K, V> {
|
|
5
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
6
|
+
export function copyMap<K, V>(oldMap: ReadonlyMap<K, V>): Map<K, V> {
|
|
8
7
|
const newMap = new Map<K, V>();
|
|
9
|
-
for (const [key, value] of oldMap
|
|
8
|
+
for (const [key, value] of oldMap) {
|
|
10
9
|
newMap.set(key, value);
|
|
11
10
|
}
|
|
12
11
|
|
|
@@ -62,11 +61,9 @@ export function defaultMapSetHash<V>(
|
|
|
62
61
|
* ]);
|
|
63
62
|
* ```
|
|
64
63
|
*/
|
|
65
|
-
export function getReversedMap<K, V>(map: Map<K, V>): Map<V, K>;
|
|
66
|
-
export function getReversedMap<K, V>(map: ReadonlyMap<K, V>): ReadonlyMap<V, K>;
|
|
67
64
|
export function getReversedMap<K, V>(
|
|
68
|
-
map:
|
|
69
|
-
):
|
|
65
|
+
map: ReadonlyMap<K, V>,
|
|
66
|
+
): ReadonlyMap<V, K> {
|
|
70
67
|
const reverseMap = new Map<V, K>();
|
|
71
68
|
|
|
72
69
|
for (const [key, value] of map) {
|
|
@@ -102,6 +99,7 @@ export function mapSetHash<V>(
|
|
|
102
99
|
*
|
|
103
100
|
* Also see the `objectToReadonlyMap` function.
|
|
104
101
|
*/
|
|
102
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
105
103
|
export function objectToMap<K extends string | number | symbol, V>(
|
|
106
104
|
object: Record<K, V>,
|
|
107
105
|
): Map<K, V> {
|
|
@@ -134,9 +132,7 @@ export function objectToReadonlyMap<K extends string | number | symbol, V>(
|
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
/** Helper function to sum every value in a map together. */
|
|
137
|
-
export function sumMap(
|
|
138
|
-
map: Map<unknown, number> | ReadonlyMap<unknown, number>,
|
|
139
|
-
): number {
|
|
135
|
+
export function sumMap(map: ReadonlyMap<unknown, number>): number {
|
|
140
136
|
const values = [...map.values()];
|
|
141
137
|
return sumArray(values);
|
|
142
138
|
}
|
package/src/functions/minimap.ts
CHANGED
|
@@ -66,7 +66,7 @@ export function clearRoomDisplayFlags(roomGridIndex: int): void {
|
|
|
66
66
|
*/
|
|
67
67
|
export function getFloorDisplayFlags(
|
|
68
68
|
minimapAPI = true,
|
|
69
|
-
):
|
|
69
|
+
): ReadonlyMap<int, BitFlags<DisplayFlag>> {
|
|
70
70
|
const displayFlagsMap = new Map<int, BitFlags<DisplayFlag>>();
|
|
71
71
|
|
|
72
72
|
for (const roomDescriptor of getRoomsInsideGrid()) {
|
|
@@ -16,7 +16,7 @@ import { repeat } from "./utils";
|
|
|
16
16
|
* const arrayWithArrays = newArray([0], 20); // Has 20 elements of an array with a 0 in it.
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
// eslint-disable-next-line isaacscript/no-mutable-
|
|
19
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
20
20
|
export function newArray<T>(defaultValue: T, size: int): T[] {
|
|
21
21
|
const array: T[] = [];
|
|
22
22
|
repeat(size, () => {
|
|
@@ -130,9 +130,9 @@ export function mapSetNPC<V>(
|
|
|
130
130
|
* Helper function to make using sets with an type of `PtrHash` easier. Use this instead of the
|
|
131
131
|
* `Set.add` method if you have a set of this type.
|
|
132
132
|
*/
|
|
133
|
-
export function setAddNPC(set: Set<PtrHash>, npc: EntityNPC):
|
|
133
|
+
export function setAddNPC(set: Set<PtrHash>, npc: EntityNPC): void {
|
|
134
134
|
const ptrHash = GetPtrHash(npc);
|
|
135
|
-
|
|
135
|
+
set.add(ptrHash);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -134,9 +134,9 @@ export function mapSetPlayer<V>(
|
|
|
134
134
|
export function setAddPlayer(
|
|
135
135
|
set: Set<PlayerIndex>,
|
|
136
136
|
player: EntityPlayer,
|
|
137
|
-
):
|
|
137
|
+
): void {
|
|
138
138
|
const playerIndex = getPlayerIndex(player);
|
|
139
|
-
|
|
139
|
+
set.add(playerIndex);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -173,8 +173,8 @@ export function isFirstSlotPocketActiveItem(player: EntityPlayer): boolean {
|
|
|
173
173
|
|
|
174
174
|
/** Helper function to see if two sets of pocket item descriptions are identical. */
|
|
175
175
|
export function pocketItemsEquals(
|
|
176
|
-
pocketItems1:
|
|
177
|
-
pocketItems2:
|
|
176
|
+
pocketItems1: readonly PocketItemDescription[],
|
|
177
|
+
pocketItems2: readonly PocketItemDescription[],
|
|
178
178
|
): boolean {
|
|
179
179
|
if (pocketItems1.length !== pocketItems2.length) {
|
|
180
180
|
return false;
|
|
@@ -12,7 +12,7 @@ import { getPlayerCloserThan } from "./players";
|
|
|
12
12
|
const MAX_FIND_FREE_POSITION_ATTEMPTS = 100;
|
|
13
13
|
|
|
14
14
|
export function anyEntityCloserThan(
|
|
15
|
-
entities:
|
|
15
|
+
entities: readonly Entity[],
|
|
16
16
|
position: Vector,
|
|
17
17
|
distance: int,
|
|
18
18
|
): boolean {
|
|
@@ -110,8 +110,8 @@ export function findFreePosition(
|
|
|
110
110
|
* multiple times.
|
|
111
111
|
*/
|
|
112
112
|
export function getEntityPositions(
|
|
113
|
-
entities?:
|
|
114
|
-
):
|
|
113
|
+
entities?: readonly Entity[],
|
|
114
|
+
): ReadonlyMap<PtrHash, Vector> {
|
|
115
115
|
if (entities === undefined) {
|
|
116
116
|
entities = getEntities();
|
|
117
117
|
}
|
|
@@ -135,8 +135,8 @@ export function getEntityPositions(
|
|
|
135
135
|
* multiple times.
|
|
136
136
|
*/
|
|
137
137
|
export function getEntityVelocities(
|
|
138
|
-
entities?:
|
|
139
|
-
):
|
|
138
|
+
entities?: readonly Entity[],
|
|
139
|
+
): ReadonlyMap<PtrHash, Vector> {
|
|
140
140
|
if (entities === undefined) {
|
|
141
141
|
entities = getEntities();
|
|
142
142
|
}
|
|
@@ -164,8 +164,8 @@ export function getEntityVelocities(
|
|
|
164
164
|
* multiple times.
|
|
165
165
|
*/
|
|
166
166
|
export function setEntityPositions(
|
|
167
|
-
entityPositions:
|
|
168
|
-
entities?:
|
|
167
|
+
entityPositions: ReadonlyMap<PtrHash, Vector>,
|
|
168
|
+
entities?: readonly Entity[],
|
|
169
169
|
): void {
|
|
170
170
|
if (entities === undefined) {
|
|
171
171
|
entities = getEntities();
|
|
@@ -194,8 +194,8 @@ export function setEntityPositions(
|
|
|
194
194
|
* multiple times.
|
|
195
195
|
*/
|
|
196
196
|
export function setEntityVelocities(
|
|
197
|
-
entityVelocities:
|
|
198
|
-
entities?:
|
|
197
|
+
entityVelocities: ReadonlyMap<PtrHash, Vector>,
|
|
198
|
+
entities?: readonly Entity[],
|
|
199
199
|
): void {
|
|
200
200
|
if (entities === undefined) {
|
|
201
201
|
entities = getEntities();
|
package/src/functions/random.ts
CHANGED
|
@@ -13,7 +13,9 @@ import { hasFlag } from "./flag";
|
|
|
13
13
|
* Helper function to get the set of allowed door slots for the room at the supplied grid index.
|
|
14
14
|
* This corresponds to the doors that are enabled in the STB/XML file for the room.
|
|
15
15
|
*/
|
|
16
|
-
export function getRoomAllowedDoors(
|
|
16
|
+
export function getRoomAllowedDoors(
|
|
17
|
+
roomGridIndex?: int,
|
|
18
|
+
): ReadonlySet<DoorSlot> {
|
|
17
19
|
const allowedDoors = new Set<DoorSlot>();
|
|
18
20
|
|
|
19
21
|
const roomData = getRoomData(roomGridIndex);
|
package/src/functions/rooms.ts
CHANGED
|
@@ -545,7 +545,7 @@ export function is2x1Room(roomData: RoomConfig): boolean {
|
|
|
545
545
|
* @allowEmptyVariadic
|
|
546
546
|
*/
|
|
547
547
|
export function isAllRoomsClear(
|
|
548
|
-
onlyCheckRoomTypes?:
|
|
548
|
+
onlyCheckRoomTypes?: readonly RoomType[],
|
|
549
549
|
includeSecretRoom = false,
|
|
550
550
|
includeSuperSecretRoom = false,
|
|
551
551
|
includeUltraSecretRoom = false,
|
package/src/functions/set.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { isPrimitive } from "./types";
|
|
|
10
10
|
*/
|
|
11
11
|
export function addSetsToSet<T>(
|
|
12
12
|
mainSet: Set<T>,
|
|
13
|
-
...setsToAdd:
|
|
13
|
+
...setsToAdd: ReadonlyArray<ReadonlySet<T>>
|
|
14
14
|
): void {
|
|
15
15
|
for (const set of setsToAdd) {
|
|
16
16
|
for (const value of set) {
|
|
@@ -24,9 +24,8 @@ export function addSetsToSet<T>(
|
|
|
24
24
|
*
|
|
25
25
|
* This function is variadic, meaning that you can specify N sets.
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
): Set<T> {
|
|
27
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
28
|
+
export function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): Set<T> {
|
|
30
29
|
const newSet = new Set<T>();
|
|
31
30
|
for (const set of sets) {
|
|
32
31
|
for (const value of set) {
|
|
@@ -38,7 +37,8 @@ export function combineSets<T>(
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
|
|
41
|
-
|
|
40
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
41
|
+
export function copySet<T>(oldSet: ReadonlySet<T>): Set<T> {
|
|
42
42
|
const newSet = new Set<T>();
|
|
43
43
|
for (const value of oldSet) {
|
|
44
44
|
newSet.add(value);
|
|
@@ -55,7 +55,7 @@ export function copySet<T>(oldSet: Set<T> | ReadonlySet<T>): Set<T> {
|
|
|
55
55
|
*/
|
|
56
56
|
export function deleteSetsFromSet<T>(
|
|
57
57
|
mainSet: Set<T>,
|
|
58
|
-
...setsToRemove:
|
|
58
|
+
...setsToRemove: ReadonlyArray<ReadonlySet<T>>
|
|
59
59
|
): void {
|
|
60
60
|
for (const set of setsToRemove) {
|
|
61
61
|
for (const value of set) {
|
|
@@ -77,9 +77,9 @@ export function deleteSetsFromSet<T>(
|
|
|
77
77
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
78
78
|
*/
|
|
79
79
|
export function getRandomSetElement<T>(
|
|
80
|
-
set:
|
|
80
|
+
set: ReadonlySet<T>,
|
|
81
81
|
seedOrRNG: Seed | RNG | undefined,
|
|
82
|
-
exceptions:
|
|
82
|
+
exceptions: readonly T[] = [],
|
|
83
83
|
): T {
|
|
84
84
|
const array = getSortedSetValues(set);
|
|
85
85
|
return getRandomArrayElement(array, seedOrRNG, exceptions);
|
|
@@ -105,7 +105,7 @@ export function getRandomSetElement<T>(
|
|
|
105
105
|
* @param includeEmptyArray Whether to include an empty array in the combinations.
|
|
106
106
|
*/
|
|
107
107
|
export function getSetCombinations<T>(
|
|
108
|
-
set:
|
|
108
|
+
set: ReadonlySet<T>,
|
|
109
109
|
includeEmptyArray: boolean,
|
|
110
110
|
): ReadonlyArray<ReadonlySet<T>> {
|
|
111
111
|
const values = getSortedSetValues(set);
|
|
@@ -120,8 +120,8 @@ export function getSetCombinations<T>(
|
|
|
120
120
|
* Normally, set values are returned in insertion order, so use this function when the ordering of
|
|
121
121
|
* the contents is important.
|
|
122
122
|
*/
|
|
123
|
-
// eslint-disable-next-line isaacscript/no-mutable-
|
|
124
|
-
export function getSortedSetValues<T>(set:
|
|
123
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
124
|
+
export function getSortedSetValues<T>(set: ReadonlySet<T>): T[] {
|
|
125
125
|
const values = [...set];
|
|
126
126
|
|
|
127
127
|
// Check for problematic types in order to throw a helpful error message.
|
|
@@ -162,6 +162,7 @@ export function objectKeysToReadonlySet<K extends string | number | symbol, V>(
|
|
|
162
162
|
*
|
|
163
163
|
* Also see the `objectKeysToReadonlySet` function.
|
|
164
164
|
*/
|
|
165
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
165
166
|
export function objectKeysToSet<K extends string | number | symbol, V>(
|
|
166
167
|
object: Record<K, V>,
|
|
167
168
|
): Set<K> {
|
|
@@ -197,6 +198,7 @@ export function objectValuesToReadonlySet<
|
|
|
197
198
|
*
|
|
198
199
|
* Also see the `objectValuesToReadonlySet` function.
|
|
199
200
|
*/
|
|
201
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
200
202
|
export function objectValuesToSet<K extends string | number | symbol, V>(
|
|
201
203
|
object: Record<K, V>,
|
|
202
204
|
): Set<V> {
|
|
@@ -215,7 +217,7 @@ export function objectValuesToSet<K extends string | number | symbol, V>(
|
|
|
215
217
|
*
|
|
216
218
|
* This function is variadic, meaning that you can pass as many things as you want to add.
|
|
217
219
|
*/
|
|
218
|
-
export function setAdd<T>(set: Set<T>, ...elements: T[]): void {
|
|
220
|
+
export function setAdd<T>(set: Set<T>, ...elements: readonly T[]): void {
|
|
219
221
|
for (const element of elements) {
|
|
220
222
|
set.add(element);
|
|
221
223
|
}
|
|
@@ -229,14 +231,14 @@ export function setAdd<T>(set: Set<T>, ...elements: T[]): void {
|
|
|
229
231
|
* will return true if one or more elements are found.
|
|
230
232
|
*/
|
|
231
233
|
export function setHas<T>(
|
|
232
|
-
set:
|
|
233
|
-
...elements: T[]
|
|
234
|
+
set: ReadonlySet<T>,
|
|
235
|
+
...elements: readonly T[]
|
|
234
236
|
): boolean {
|
|
235
237
|
return elements.some((element) => set.has(element));
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
/** Helper function to sum every value in a set together. */
|
|
239
|
-
export function sumSet(set:
|
|
241
|
+
export function sumSet(set: ReadonlySet<number>): number {
|
|
240
242
|
const values = [...set];
|
|
241
243
|
return sumArray(values);
|
|
242
244
|
}
|
package/src/functions/sort.ts
CHANGED
|
@@ -146,7 +146,7 @@ export function sortTwoDimensionalArray<T>(a: T[], b: T[]): -1 | 0 | 1 {
|
|
|
146
146
|
*
|
|
147
147
|
* Under the hood, this uses the merge sort algorithm.
|
|
148
148
|
*/
|
|
149
|
-
// eslint-disable-next-line isaacscript/no-mutable-
|
|
149
|
+
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
150
150
|
export function stableSort<T>(
|
|
151
151
|
array: T[],
|
|
152
152
|
sortFunc: (a: T, b: T) => -1 | 0 | 1 = sortNormal,
|
package/src/functions/string.ts
CHANGED
|
@@ -120,7 +120,7 @@ export function getObjectPartialMatch<T>(
|
|
|
120
120
|
*/
|
|
121
121
|
export function getPartialMatch(
|
|
122
122
|
searchText: string,
|
|
123
|
-
array:
|
|
123
|
+
array: readonly string[],
|
|
124
124
|
): string | undefined {
|
|
125
125
|
const sortedArray = array.toSorted();
|
|
126
126
|
|
package/src/functions/table.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function clearTable(luaMap: LuaMap<AnyNotNil, unknown>): void {
|
|
|
14
14
|
/** Helper function to copy specific values from a userdata object (e.g. `Vector`) to a table. */
|
|
15
15
|
export function copyUserdataValuesToTable(
|
|
16
16
|
object: unknown,
|
|
17
|
-
keys:
|
|
17
|
+
keys: readonly string[],
|
|
18
18
|
luaMap: LuaMap<string, unknown>,
|
|
19
19
|
): void {
|
|
20
20
|
if (!isUserdata(object)) {
|
|
@@ -34,7 +34,7 @@ const TRANSFORMATIONS_THAT_GRANT_FLYING = new ReadonlySet<PlayerForm>([
|
|
|
34
34
|
/** Returns a set of the player's current transformations. */
|
|
35
35
|
export function getPlayerTransformations(
|
|
36
36
|
player: EntityPlayer,
|
|
37
|
-
):
|
|
37
|
+
): ReadonlySet<PlayerForm> {
|
|
38
38
|
const transformations = new Set<PlayerForm>();
|
|
39
39
|
for (const playerForm of PLAYER_FORM_VALUES) {
|
|
40
40
|
if (player.HasPlayerForm(playerForm)) {
|
|
@@ -65,7 +65,7 @@ export function getTransformationName(playerForm: PlayerForm): string {
|
|
|
65
65
|
*/
|
|
66
66
|
export function getTransformationsForCollectibleType(
|
|
67
67
|
collectibleType: CollectibleType,
|
|
68
|
-
):
|
|
68
|
+
): ReadonlySet<PlayerForm> {
|
|
69
69
|
const itemConfigTags = getCollectibleTags(collectibleType);
|
|
70
70
|
|
|
71
71
|
const transformationSet = new Set<PlayerForm>();
|
|
@@ -8,10 +8,10 @@ import { asCollectibleType, parseIntSafe } from "../functions/types";
|
|
|
8
8
|
import { ITEM_POOL_TYPE_TO_ITEM_POOL_NAME } from "../maps/itemPoolTypeToItemPoolName";
|
|
9
9
|
|
|
10
10
|
export const ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET: Readonly<
|
|
11
|
-
Record<ItemPoolType,
|
|
11
|
+
Record<ItemPoolType, ReadonlySet<CollectibleType>>
|
|
12
12
|
> = (() => {
|
|
13
13
|
const itemPoolTypeToCollectibleTypes: Partial<
|
|
14
|
-
Record<ItemPoolType,
|
|
14
|
+
Record<ItemPoolType, ReadonlySet<CollectibleType>>
|
|
15
15
|
> = {};
|
|
16
16
|
|
|
17
17
|
for (const itemPoolType of ITEM_POOL_TYPE_VALUES) {
|
|
@@ -39,7 +39,7 @@ export const ITEM_POOL_TYPE_TO_COLLECTIBLE_TYPES_SET: Readonly<
|
|
|
39
39
|
|
|
40
40
|
return itemPoolTypeToCollectibleTypes as Record<
|
|
41
41
|
ItemPoolType,
|
|
42
|
-
|
|
42
|
+
ReadonlySet<CollectibleType>
|
|
43
43
|
>;
|
|
44
44
|
})();
|
|
45
45
|
|
|
@@ -5,10 +5,7 @@ import type { IRange } from "./IRange";
|
|
|
5
5
|
*
|
|
6
6
|
* For example, `TupleWithMaxLength<string, 3>` will allow string tuples of size 0, 1, 2, or 3.
|
|
7
7
|
*/
|
|
8
|
-
export type TupleWithMaxLength<T, MaxLength extends number> =
|
|
9
|
-
| T[]
|
|
10
|
-
| readonly T[]
|
|
11
|
-
) & {
|
|
8
|
+
export type TupleWithMaxLength<T, MaxLength extends number> = readonly T[] & {
|
|
12
9
|
length: IRange<0, MaxLength>;
|
|
13
10
|
};
|
|
14
11
|
|