isaacscript-common 87.6.2 → 87.7.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.
- package/dist/functions/array.d.ts +3 -17
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/array.js +12 -30
- package/dist/functions/array.lua +43 -59
- package/dist/functions/debugFunctions.d.ts.map +1 -1
- package/dist/functions/debugFunctions.js +0 -1
- package/dist/functions/logMisc.lua +0 -1
- package/dist/functions/map.d.ts +1 -1
- package/dist/functions/map.d.ts.map +1 -1
- package/dist/functions/map.js +0 -1
- package/dist/functions/set.d.ts +1 -1
- package/dist/functions/set.d.ts.map +1 -1
- package/dist/functions/set.js +0 -4
- package/dist/functions/sort.d.ts.map +1 -1
- package/dist/functions/sort.js +0 -1
- package/dist/functions/utils.d.ts +11 -1
- package/dist/functions/utils.d.ts.map +1 -1
- package/dist/functions/utils.js +19 -1
- package/dist/functions/utils.lua +17 -1
- package/dist/index.rollup.d.ts +17 -21
- package/dist/isaacscript-common.lua +8741 -8707
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +4 -4
- package/src/functions/array.ts +8 -32
- package/src/functions/debugFunctions.ts +0 -1
- package/src/functions/map.ts +1 -2
- package/src/functions/set.ts +6 -5
- package/src/functions/sort.ts +1 -1
- package/src/functions/utils.ts +19 -1
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "87.
|
|
3
|
+
"version": "87.7.0",
|
|
4
4
|
"description": "Helper functions and features for IsaacScript mods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"isaac-typescript-definitions": "42.2.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@microsoft/api-extractor": "7.52.
|
|
44
|
-
"complete-node": "
|
|
43
|
+
"@microsoft/api-extractor": "7.52.10",
|
|
44
|
+
"complete-node": "9.0.0",
|
|
45
45
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
46
|
-
"typescript-eslint": "8.
|
|
46
|
+
"typescript-eslint": "8.39.0",
|
|
47
47
|
"typescript-to-lua": "1.31.4"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/functions/array.ts
CHANGED
|
@@ -29,16 +29,14 @@ export function arrayEquals<T>(
|
|
|
29
29
|
* array. If the specified element(s) are not found in the array, it will simply return a shallow
|
|
30
30
|
* copy of the array.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
32
|
+
* If there is more than one matching element in the array, this function will remove all of them.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* matching element. If you want to remove all of the elements, use the `arrayRemoveAll` function
|
|
36
|
-
* instead.
|
|
34
|
+
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
37
35
|
*/
|
|
38
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
39
36
|
export function arrayRemove<T>(
|
|
40
37
|
originalArray: readonly T[],
|
|
41
38
|
...elementsToRemove: readonly T[]
|
|
39
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
42
40
|
): T[] {
|
|
43
41
|
const elementsToRemoveSet = new ReadonlySet(elementsToRemove);
|
|
44
42
|
|
|
@@ -52,27 +50,6 @@ export function arrayRemove<T>(
|
|
|
52
50
|
return array;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
/**
|
|
56
|
-
* Shallow copies and removes the specified element(s) from the array. Returns the copied array. If
|
|
57
|
-
* the specified element(s) are not found in the array, it will simply return a shallow copy of the
|
|
58
|
-
* array.
|
|
59
|
-
*
|
|
60
|
-
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
61
|
-
*
|
|
62
|
-
* If there is more than one matching element in the array, this function will remove every matching
|
|
63
|
-
* element. If you want to only remove the first matching element, use the `arrayRemove` function
|
|
64
|
-
* instead.
|
|
65
|
-
*/
|
|
66
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
67
|
-
export function arrayRemoveAll<T>(
|
|
68
|
-
originalArray: readonly T[],
|
|
69
|
-
...elementsToRemove: readonly T[]
|
|
70
|
-
): T[] {
|
|
71
|
-
const array = copyArray(originalArray);
|
|
72
|
-
arrayRemoveAllInPlace(array, ...elementsToRemove);
|
|
73
|
-
return array;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
53
|
/**
|
|
77
54
|
* Removes all of the specified element(s) from the array. If the specified element(s) are not found
|
|
78
55
|
* in the array, this function will do nothing.
|
|
@@ -118,11 +95,11 @@ export function arrayRemoveAllInPlace<T>(
|
|
|
118
95
|
*
|
|
119
96
|
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
120
97
|
*/
|
|
121
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
122
98
|
export function arrayRemoveInPlace<T>(
|
|
123
99
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
124
100
|
array: T[],
|
|
125
101
|
...elementsToRemove: readonly T[]
|
|
102
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
126
103
|
): T[] {
|
|
127
104
|
const removedElements: T[] = [];
|
|
128
105
|
|
|
@@ -144,10 +121,10 @@ export function arrayRemoveInPlace<T>(
|
|
|
144
121
|
*
|
|
145
122
|
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
146
123
|
*/
|
|
147
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
148
124
|
export function arrayRemoveIndex<T>(
|
|
149
125
|
originalArray: readonly T[],
|
|
150
126
|
...indexesToRemove: readonly int[]
|
|
127
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
151
128
|
): T[] {
|
|
152
129
|
const indexesToRemoveSet = new ReadonlySet(indexesToRemove);
|
|
153
130
|
|
|
@@ -169,11 +146,11 @@ export function arrayRemoveIndex<T>(
|
|
|
169
146
|
*
|
|
170
147
|
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
171
148
|
*/
|
|
172
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
173
149
|
export function arrayRemoveIndexInPlace<T>(
|
|
174
150
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
175
151
|
array: T[],
|
|
176
152
|
...indexesToRemove: readonly int[]
|
|
153
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
177
154
|
): T[] {
|
|
178
155
|
const legalIndexes = indexesToRemove.filter(
|
|
179
156
|
(i) => i >= 0 && i < array.length,
|
|
@@ -266,11 +243,10 @@ export function emptyArray(array: unknown[]): void {
|
|
|
266
243
|
* This is named `filterMap` after the Rust function:
|
|
267
244
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
268
245
|
*/
|
|
269
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
270
246
|
export function filterMap<OldT, NewT>(
|
|
271
247
|
array: readonly OldT[],
|
|
272
248
|
func: (element: OldT) => NewT | undefined,
|
|
273
|
-
): NewT[] {
|
|
249
|
+
): readonly NewT[] {
|
|
274
250
|
const filteredArray: NewT[] = [];
|
|
275
251
|
|
|
276
252
|
for (const element of array) {
|
|
@@ -647,10 +623,10 @@ export function setAllArrayElements<T>(array: T[], value: T): void {
|
|
|
647
623
|
* `RNG.Next` method will be called. If `undefined` is provided, it will default to
|
|
648
624
|
* a random seed.
|
|
649
625
|
*/
|
|
650
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
651
626
|
export function shuffleArray<T>(
|
|
652
627
|
originalArray: readonly T[],
|
|
653
628
|
seedOrRNG: Seed | RNG | undefined,
|
|
629
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
654
630
|
): T[] {
|
|
655
631
|
const array = copyArray(originalArray);
|
|
656
632
|
shuffleArrayInPlace(array, seedOrRNG);
|
|
@@ -42,7 +42,6 @@ export function getTime(useSocketIfAvailable = true): int | float {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (isLuaDebugEnabled()) {
|
|
45
|
-
// eslint-disable-next-line unicorn/prefer-module
|
|
46
45
|
const [ok, requiredSocket] = pcall(require, "socket");
|
|
47
46
|
if (ok) {
|
|
48
47
|
const socket = requiredSocket as Socket;
|
package/src/functions/map.ts
CHANGED
|
@@ -101,10 +101,9 @@ export function mapSetHash<V>(
|
|
|
101
101
|
*
|
|
102
102
|
* Also see the `objectToReadonlyMap` function.
|
|
103
103
|
*/
|
|
104
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
105
104
|
export function objectToMap<K extends string | number | symbol, V>(
|
|
106
105
|
object: Record<K, V>,
|
|
107
|
-
):
|
|
106
|
+
): ReadonlyMap<K, V> {
|
|
108
107
|
const map = new Map<K, V>();
|
|
109
108
|
|
|
110
109
|
for (const [key, value] of Object.entries(object)) {
|
package/src/functions/set.ts
CHANGED
|
@@ -26,8 +26,9 @@ export function addSetsToSet<T>(
|
|
|
26
26
|
*
|
|
27
27
|
* This function is variadic, meaning that you can specify N sets.
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
export function combineSets<T>(
|
|
30
|
+
...sets: ReadonlyArray<ReadonlySet<T>>
|
|
31
|
+
): ReadonlySet<T> {
|
|
31
32
|
const newSet = new Set<T>();
|
|
32
33
|
for (const set of sets) {
|
|
33
34
|
for (const value of set) {
|
|
@@ -123,9 +124,9 @@ export function getSetCombinations<T extends number | string>(
|
|
|
123
124
|
* Normally, set values are returned in insertion order, so use this function when the ordering of
|
|
124
125
|
* the contents is important.
|
|
125
126
|
*/
|
|
126
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
127
127
|
export function getSortedSetValues<T extends number | string>(
|
|
128
128
|
set: ReadonlySet<T>,
|
|
129
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
129
130
|
): T[] {
|
|
130
131
|
const values = [...set];
|
|
131
132
|
|
|
@@ -167,9 +168,9 @@ export function objectKeysToReadonlySet<K extends string | number | symbol, V>(
|
|
|
167
168
|
*
|
|
168
169
|
* Also see the `objectKeysToReadonlySet` function.
|
|
169
170
|
*/
|
|
170
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
171
171
|
export function objectKeysToSet<K extends string | number | symbol, V>(
|
|
172
172
|
object: Record<K, V>,
|
|
173
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
173
174
|
): Set<K> {
|
|
174
175
|
const set = new Set<K>();
|
|
175
176
|
|
|
@@ -203,9 +204,9 @@ export function objectValuesToReadonlySet<
|
|
|
203
204
|
*
|
|
204
205
|
* Also see the `objectValuesToReadonlySet` function.
|
|
205
206
|
*/
|
|
206
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
207
207
|
export function objectValuesToSet<K extends string | number | symbol, V>(
|
|
208
208
|
object: Record<K, V>,
|
|
209
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
209
210
|
): Set<V> {
|
|
210
211
|
const set = new Set<V>();
|
|
211
212
|
|
package/src/functions/sort.ts
CHANGED
|
@@ -149,11 +149,11 @@ export function sortTwoDimensionalArray<T>(
|
|
|
149
149
|
*
|
|
150
150
|
* Under the hood, this uses the merge sort algorithm.
|
|
151
151
|
*/
|
|
152
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
153
152
|
export function stableSort<T>(
|
|
154
153
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
155
154
|
array: T[],
|
|
156
155
|
sortFunc: (a: T, b: T) => -1 | 0 | 1 = sortNormal,
|
|
156
|
+
// eslint-disable-next-line complete/no-mutable-return
|
|
157
157
|
): T[] {
|
|
158
158
|
// Base case: an array of zero or one elements is already sorted
|
|
159
159
|
if (array.length <= 1) {
|
package/src/functions/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { game } from "../core/cachedClasses";
|
|
1
2
|
import { ReadonlySet } from "../types/ReadonlySet";
|
|
2
3
|
import { getAllPlayers } from "./playerIndex";
|
|
3
4
|
import { isFunction } from "./types";
|
|
@@ -155,7 +156,7 @@ export function isMultiplayer(): boolean {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
|
-
* Helper function to check if the player
|
|
159
|
+
* Helper function to check if the player has the Repentance DLC installed.
|
|
159
160
|
*
|
|
160
161
|
* This function should always be used over the `REPENTANCE` constant, since the latter is not safe.
|
|
161
162
|
*
|
|
@@ -181,6 +182,23 @@ export function isRepentance(): boolean {
|
|
|
181
182
|
return isFunction(getAnimation);
|
|
182
183
|
}
|
|
183
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Helper function to check if the player has the Repentance+ DLC installed.
|
|
187
|
+
*
|
|
188
|
+
* This function should always be used over the `REPENTANCE_PLUS` constant, since the latter is not
|
|
189
|
+
* safe.
|
|
190
|
+
*
|
|
191
|
+
* Specifically, this function checks for `Room:DamageGridWithSource` method:
|
|
192
|
+
* https://bindingofisaacrebirth.wiki.gg/wiki/The_Binding_of_Isaac:_Repentance%2B#Modding_Changes
|
|
193
|
+
*/
|
|
194
|
+
export function isRepentancePlus(): boolean {
|
|
195
|
+
const room = game.GetRoom();
|
|
196
|
+
const metatable = getmetatable(room) as LuaMap<string, unknown> | undefined;
|
|
197
|
+
assertDefined(metatable, "Failed to get the metatable of the room class.");
|
|
198
|
+
const damageGridWithSource = metatable.get("DamageGridWithSource");
|
|
199
|
+
return isFunction(damageGridWithSource);
|
|
200
|
+
}
|
|
201
|
+
|
|
184
202
|
/**
|
|
185
203
|
* Helper function to check if the player is using REPENTOGON, an exe-hack which expands the modding
|
|
186
204
|
* API.
|