isaacscript-common 84.1.1 → 84.2.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/classes/features/callbackLogic/PlayerCollectibleDetection.d.ts.map +1 -1
- package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.js +3 -2
- package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.lua +4 -2
- package/dist/functions/array.d.ts +1 -1
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/array.js +2 -1
- package/dist/functions/array.lua +3 -1
- package/dist/functions/enums.d.ts.map +1 -1
- package/dist/functions/enums.js +7 -4
- package/dist/functions/enums.lua +9 -4
- package/dist/functions/logMisc.d.ts +2 -2
- package/dist/functions/logMisc.d.ts.map +1 -1
- package/dist/functions/logMisc.js +3 -4
- package/dist/functions/logMisc.lua +4 -3
- package/dist/functions/set.d.ts +3 -3
- package/dist/functions/set.d.ts.map +1 -1
- package/dist/functions/set.js +2 -1
- package/dist/functions/set.lua +3 -1
- package/dist/functions/sort.d.ts +2 -1
- package/dist/functions/sort.d.ts.map +1 -1
- package/dist/functions/sort.js +3 -2
- package/dist/functions/sort.lua +6 -6
- package/dist/functions/table.js +1 -1
- package/dist/functions/types.d.ts.map +1 -1
- package/dist/functions/types.js +7 -5
- package/dist/functions/types.lua +3 -1
- package/dist/index.rollup.d.ts +9 -7
- package/dist/isaacscript-common.lua +33 -19
- package/dist/lib/jsonLua.d.ts +12 -0
- package/dist/lib/jsonLua.js +701 -0
- package/package.json +1 -1
- package/src/classes/features/callbackLogic/PlayerCollectibleDetection.ts +3 -2
- package/src/functions/array.ts +3 -2
- package/src/functions/enums.ts +7 -6
- package/src/functions/logMisc.ts +5 -6
- package/src/functions/set.ts +7 -4
- package/src/functions/sort.ts +2 -2
- package/src/functions/table.ts +1 -1
- package/src/functions/types.ts +7 -5
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
mapSetPlayer,
|
|
17
17
|
} from "../../../functions/playerDataStructures";
|
|
18
18
|
import { getPlayerFromPtr } from "../../../functions/players";
|
|
19
|
+
import { sortNormal } from "../../../functions/sort";
|
|
19
20
|
import { repeat } from "../../../functions/utils";
|
|
20
21
|
import type { PickingUpItem } from "../../../types/PickingUpItem";
|
|
21
22
|
import type { PlayerIndex } from "../../../types/PlayerIndex";
|
|
@@ -262,8 +263,8 @@ export class PlayerCollectibleDetection extends Feature {
|
|
|
262
263
|
// For example, it is possible for the player to switch Schoolbag items, which will cause the
|
|
263
264
|
// collectibles in the array to be the same, but in a different order. Thus, we sort both arrays
|
|
264
265
|
// before comparing them.
|
|
265
|
-
oldCollectibleTypes.sort();
|
|
266
|
-
newCollectibleTypes.sort();
|
|
266
|
+
oldCollectibleTypes.sort(sortNormal);
|
|
267
|
+
newCollectibleTypes.sort(sortNormal);
|
|
267
268
|
|
|
268
269
|
if (!arrayEquals(oldCollectibleTypes, newCollectibleTypes)) {
|
|
269
270
|
// One or more active items have changed (with the player's total collectible count remaining
|
package/src/functions/array.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ReadonlySet } from "../types/ReadonlySet";
|
|
|
2
2
|
import type { WidenLiteral } from "../types/WidenLiteral";
|
|
3
3
|
import { getRandomInt } from "./random";
|
|
4
4
|
import { isRNG, newRNG } from "./rng";
|
|
5
|
+
import { sortNormal } from "./sort";
|
|
5
6
|
import { isNumber, isTable } from "./types";
|
|
6
7
|
import { assertDefined, eRange } from "./utils";
|
|
7
8
|
|
|
@@ -359,7 +360,7 @@ function addCombinations<T>(
|
|
|
359
360
|
* Helper function to get the duplicate elements in an array. Only one element for each value will
|
|
360
361
|
* be returned. The elements will be sorted before they are returned.
|
|
361
362
|
*/
|
|
362
|
-
export function getArrayDuplicateElements<T>(
|
|
363
|
+
export function getArrayDuplicateElements<T extends number | string>(
|
|
363
364
|
array: readonly T[],
|
|
364
365
|
): readonly T[] {
|
|
365
366
|
const duplicateElements = new Set<T>();
|
|
@@ -373,7 +374,7 @@ export function getArrayDuplicateElements<T>(
|
|
|
373
374
|
}
|
|
374
375
|
|
|
375
376
|
const values = [...duplicateElements];
|
|
376
|
-
return values.sort();
|
|
377
|
+
return values.sort(sortNormal);
|
|
377
378
|
}
|
|
378
379
|
|
|
379
380
|
/**
|
package/src/functions/enums.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReadonlySet } from "../types/ReadonlySet";
|
|
2
2
|
import { getRandomArrayElement } from "./array";
|
|
3
|
+
import { sortNormal } from "./sort";
|
|
3
4
|
import { isNumber, isString } from "./types";
|
|
4
5
|
import { assertDefined, iRange } from "./utils";
|
|
5
6
|
|
|
@@ -151,11 +152,11 @@ export function getHighestEnumValue<T extends TranspiledEnum>(
|
|
|
151
152
|
transpiledEnum: T,
|
|
152
153
|
): T[keyof T] {
|
|
153
154
|
const enumValues = getEnumValues(transpiledEnum);
|
|
154
|
-
|
|
155
|
-
const lastElement =
|
|
155
|
+
const sortedValues = enumValues.toSorted(sortNormal);
|
|
156
|
+
const lastElement = sortedValues.at(-1);
|
|
156
157
|
assertDefined(
|
|
157
158
|
lastElement,
|
|
158
|
-
"Failed to get the
|
|
159
|
+
"Failed to get the highest value from an enum since the enum was empty.",
|
|
159
160
|
);
|
|
160
161
|
|
|
161
162
|
return lastElement;
|
|
@@ -173,11 +174,11 @@ export function getLowestEnumValue<T extends TranspiledEnum>(
|
|
|
173
174
|
transpiledEnum: T,
|
|
174
175
|
): T[keyof T] {
|
|
175
176
|
const enumValues = getEnumValues(transpiledEnum);
|
|
176
|
-
|
|
177
|
-
const firstElement =
|
|
177
|
+
const sortedValues = enumValues.toSorted(sortNormal);
|
|
178
|
+
const firstElement = sortedValues[0];
|
|
178
179
|
assertDefined(
|
|
179
180
|
firstElement,
|
|
180
|
-
"Failed to get the
|
|
181
|
+
"Failed to get the lowest value from an enum since the enum was empty.",
|
|
181
182
|
);
|
|
182
183
|
|
|
183
184
|
return firstElement;
|
package/src/functions/logMisc.ts
CHANGED
|
@@ -38,6 +38,7 @@ import { getPlayerHealth } from "./playerHealth";
|
|
|
38
38
|
import { getPlayerName } from "./players";
|
|
39
39
|
import { getRoomData, getRoomGridIndex, getRoomListIndex } from "./roomData";
|
|
40
40
|
import { combineSets, getSortedSetValues } from "./set";
|
|
41
|
+
import { sortNormal } from "./sort";
|
|
41
42
|
import { iterateTableInOrder } from "./table";
|
|
42
43
|
import { getTrinketName } from "./trinkets";
|
|
43
44
|
import { isDefaultMap, isTSTLMap, isTSTLSet } from "./tstlClass";
|
|
@@ -257,7 +258,7 @@ export function logLevelStateFlags(this: void): void {
|
|
|
257
258
|
*/
|
|
258
259
|
export function logMap(
|
|
259
260
|
this: void,
|
|
260
|
-
map: ReadonlyMap<
|
|
261
|
+
map: ReadonlyMap<number | string, unknown>,
|
|
261
262
|
name?: string,
|
|
262
263
|
): void {
|
|
263
264
|
if (!isTSTLMap(map) && !isDefaultMap(map)) {
|
|
@@ -269,11 +270,10 @@ export function logMap(
|
|
|
269
270
|
log(`Logging a TSTL map${suffix}:`);
|
|
270
271
|
|
|
271
272
|
const mapKeys = [...map.keys()];
|
|
272
|
-
mapKeys.sort();
|
|
273
|
+
mapKeys.sort(sortNormal);
|
|
273
274
|
|
|
274
275
|
for (const key of mapKeys) {
|
|
275
276
|
const value = map.get(key);
|
|
276
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
277
277
|
log(` ${key} --> ${value}`);
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -405,7 +405,7 @@ export function logSeedEffects(this: void): void {
|
|
|
405
405
|
*/
|
|
406
406
|
export function logSet(
|
|
407
407
|
this: void,
|
|
408
|
-
set: ReadonlySet<
|
|
408
|
+
set: ReadonlySet<number | string>,
|
|
409
409
|
name?: string,
|
|
410
410
|
): void {
|
|
411
411
|
if (!isTSTLSet(set)) {
|
|
@@ -418,7 +418,6 @@ export function logSet(
|
|
|
418
418
|
|
|
419
419
|
const setValues = getSortedSetValues(set);
|
|
420
420
|
for (const value of setValues) {
|
|
421
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
422
421
|
log(` Value: ${value}`);
|
|
423
422
|
}
|
|
424
423
|
|
|
@@ -510,7 +509,7 @@ export function logTableDifferences<K extends AnyNotNil, V>(
|
|
|
510
509
|
|
|
511
510
|
const keysSet = combineSets(table1KeysSet, table2KeysSet);
|
|
512
511
|
const keys = [...keysSet.values()];
|
|
513
|
-
keys.sort();
|
|
512
|
+
keys.sort(); // eslint-disable-line @typescript-eslint/require-array-sort-compare
|
|
514
513
|
|
|
515
514
|
for (const key of keys) {
|
|
516
515
|
const value1 = table1.get(key);
|
package/src/functions/set.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReadonlySet } from "../types/ReadonlySet";
|
|
2
2
|
import { getArrayCombinations, getRandomArrayElement, sumArray } from "./array";
|
|
3
|
+
import { sortNormal } from "./sort";
|
|
3
4
|
import { isPrimitive } from "./types";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -78,7 +79,7 @@ export function deleteSetsFromSet<T>(
|
|
|
78
79
|
* a random seed.
|
|
79
80
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
80
81
|
*/
|
|
81
|
-
export function getRandomSetElement<T>(
|
|
82
|
+
export function getRandomSetElement<T extends number | string>(
|
|
82
83
|
set: ReadonlySet<T>,
|
|
83
84
|
seedOrRNG: Seed | RNG | undefined,
|
|
84
85
|
exceptions: readonly T[] = [],
|
|
@@ -106,7 +107,7 @@ export function getRandomSetElement<T>(
|
|
|
106
107
|
* @param set The set to get the combinations of.
|
|
107
108
|
* @param includeEmptyArray Whether to include an empty array in the combinations.
|
|
108
109
|
*/
|
|
109
|
-
export function getSetCombinations<T>(
|
|
110
|
+
export function getSetCombinations<T extends number | string>(
|
|
110
111
|
set: ReadonlySet<T>,
|
|
111
112
|
includeEmptyArray: boolean,
|
|
112
113
|
): ReadonlyArray<ReadonlySet<T>> {
|
|
@@ -123,7 +124,9 @@ export function getSetCombinations<T>(
|
|
|
123
124
|
* the contents is important.
|
|
124
125
|
*/
|
|
125
126
|
// eslint-disable-next-line isaacscript/no-mutable-return
|
|
126
|
-
export function getSortedSetValues<T
|
|
127
|
+
export function getSortedSetValues<T extends number | string>(
|
|
128
|
+
set: ReadonlySet<T>,
|
|
129
|
+
): T[] {
|
|
127
130
|
const values = [...set];
|
|
128
131
|
|
|
129
132
|
// Check for problematic types in order to throw a helpful error message.
|
|
@@ -137,7 +140,7 @@ export function getSortedSetValues<T>(set: ReadonlySet<T>): T[] {
|
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
|
|
140
|
-
values.sort();
|
|
143
|
+
values.sort(sortNormal);
|
|
141
144
|
|
|
142
145
|
return values;
|
|
143
146
|
}
|
package/src/functions/sort.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNumber, isString, isTable } from "./types";
|
|
2
2
|
|
|
3
|
-
function sortNormal(a: unknown, b: unknown): -1 | 0 | 1 {
|
|
3
|
+
export function sortNormal(a: unknown, b: unknown): -1 | 0 | 1 {
|
|
4
4
|
if (!isNumber(a) && !isString(a)) {
|
|
5
5
|
error(
|
|
6
6
|
`Failed to normal sort since the first value was not a number or string and was instead: ${type(
|
|
@@ -79,7 +79,7 @@ export function sortObjectArrayByKey(key: string) {
|
|
|
79
79
|
*
|
|
80
80
|
* ```ts
|
|
81
81
|
* const myArray = [[1, 2], [2, 3], [3, 4]];
|
|
82
|
-
* myArray.sort(
|
|
82
|
+
* myArray.sort(sortTwoDimensionalArray);
|
|
83
83
|
* ```
|
|
84
84
|
*
|
|
85
85
|
* This function also properly handles when the array elements are strings or numbers (instead of
|
package/src/functions/table.ts
CHANGED
|
@@ -186,7 +186,7 @@ export function iterateTableInOrder<K extends AnyNotNil, V>(
|
|
|
186
186
|
return;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
keys.sort();
|
|
189
|
+
keys.sort(); // eslint-disable-line @typescript-eslint/require-array-sort-compare
|
|
190
190
|
for (const key of keys) {
|
|
191
191
|
const keyIndex = key as unknown as K;
|
|
192
192
|
const value = luaMap.get(keyIndex);
|
package/src/functions/types.ts
CHANGED
|
@@ -171,12 +171,12 @@ export function asTrinketType(num: int): TrinketType {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
export function isBoolean(variable: unknown): variable is boolean {
|
|
174
|
-
return
|
|
174
|
+
return typeof variable === "boolean";
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
178
178
|
export function isFunction(variable: unknown): variable is Function {
|
|
179
|
-
return
|
|
179
|
+
return typeof variable === "function";
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export function isInteger(variable: unknown): variable is int {
|
|
@@ -188,14 +188,14 @@ export function isInteger(variable: unknown): variable is int {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
export function isNumber(variable: unknown): variable is number {
|
|
191
|
-
return
|
|
191
|
+
return typeof variable === "number";
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/** Helper function to detect if a variable is a boolean, number, or string. */
|
|
195
195
|
export function isPrimitive(
|
|
196
196
|
variable: unknown,
|
|
197
197
|
): variable is boolean | number | string {
|
|
198
|
-
const variableType =
|
|
198
|
+
const variableType = typeof variable;
|
|
199
199
|
return (
|
|
200
200
|
variableType === "boolean" ||
|
|
201
201
|
variableType === "number" ||
|
|
@@ -204,16 +204,18 @@ export function isPrimitive(
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
export function isString(variable: unknown): variable is string {
|
|
207
|
-
return
|
|
207
|
+
return typeof variable === "string";
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
export function isTable(
|
|
211
211
|
variable: unknown,
|
|
212
212
|
): variable is LuaMap<AnyNotNil, unknown> {
|
|
213
|
+
// We cannot use `typeof` here since "table" is not a JavaScript type.
|
|
213
214
|
return type(variable) === "table";
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
export function isUserdata(variable: unknown): variable is LuaUserdata {
|
|
218
|
+
// We cannot use `typeof` here since "userdata" is not a JavaScript type.
|
|
217
219
|
return type(variable) === "userdata";
|
|
218
220
|
}
|
|
219
221
|
|