isaacscript-common 6.9.0 → 6.10.2
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/features/customStage/customStageGridEntities.lua +2 -2
- package/dist/features/customStage/exports.d.ts.map +1 -1
- package/dist/features/customStage/exports.lua +5 -4
- package/dist/features/customStage/init.d.ts.map +1 -1
- package/dist/features/customStage/init.lua +12 -3
- package/dist/features/customStage/streakText.d.ts +4 -2
- package/dist/features/customStage/streakText.d.ts.map +1 -1
- package/dist/features/customStage/streakText.lua +216 -15
- package/dist/features/customStage/v.d.ts +4 -2
- package/dist/features/customStage/v.d.ts.map +1 -1
- package/dist/features/customStage/v.lua +9 -1
- package/dist/features/customStage/versusScreen.d.ts +1 -1
- package/dist/features/customStage/versusScreen.d.ts.map +1 -1
- package/dist/features/customStage/versusScreen.lua +2 -5
- package/dist/features/extraConsoleCommands/init.lua +1 -0
- package/dist/features/extraConsoleCommands/listCommands.d.ts +8 -0
- package/dist/features/extraConsoleCommands/listCommands.d.ts.map +1 -1
- package/dist/features/extraConsoleCommands/listCommands.lua +13 -0
- package/dist/features/saveDataManager/exports.d.ts.map +1 -1
- package/dist/features/saveDataManager/exports.lua +2 -4
- package/dist/features/saveDataManager/load.d.ts +1 -1
- package/dist/features/saveDataManager/load.d.ts.map +1 -1
- package/dist/features/saveDataManager/main.d.ts.map +1 -1
- package/dist/features/saveDataManager/main.lua +0 -1
- package/dist/features/saveDataManager/maps.d.ts +3 -3
- package/dist/features/saveDataManager/maps.d.ts.map +1 -1
- package/dist/features/saveDataManager/maps.lua +1 -4
- package/dist/features/saveDataManager/merge.d.ts +2 -2
- package/dist/features/saveDataManager/merge.d.ts.map +1 -1
- package/dist/features/saveDataManager/merge.lua +3 -3
- package/dist/features/saveDataManager/save.d.ts +1 -1
- package/dist/features/saveDataManager/save.d.ts.map +1 -1
- package/dist/features/saveDataManager/save.lua +1 -2
- package/dist/features/saveDataManager/{serializationBrand.d.ts → serializationBrands.d.ts} +1 -1
- package/dist/features/saveDataManager/serializationBrands.d.ts.map +1 -0
- package/dist/features/saveDataManager/{serializationBrand.lua → serializationBrands.lua} +0 -0
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/color.d.ts +1 -1
- package/dist/functions/color.d.ts.map +1 -1
- package/dist/functions/deepCopy.d.ts +1 -1
- package/dist/functions/deepCopy.lua +73 -37
- package/dist/functions/deepCopyTests.d.ts.map +1 -1
- package/dist/functions/deepCopyTests.lua +85 -18
- package/dist/functions/entities.d.ts +1 -1
- package/dist/functions/entities.d.ts.map +1 -1
- package/dist/functions/input.d.ts.map +1 -1
- package/dist/functions/input.lua +8 -10
- package/dist/functions/jsonHelpers.d.ts +1 -1
- package/dist/functions/jsonHelpers.d.ts.map +1 -1
- package/dist/functions/kColor.d.ts +1 -1
- package/dist/functions/kColor.d.ts.map +1 -1
- package/dist/functions/log.d.ts +1 -1
- package/dist/functions/log.d.ts.map +1 -1
- package/dist/functions/log.lua +3 -1
- package/dist/functions/mergeTests.d.ts +2 -2
- package/dist/functions/mergeTests.lua +2 -6
- package/dist/functions/playerIndex.d.ts +1 -1
- package/dist/functions/playerIndex.lua +1 -1
- package/dist/functions/rng.d.ts +1 -1
- package/dist/functions/rng.d.ts.map +1 -1
- package/dist/functions/table.d.ts +9 -9
- package/dist/functions/table.d.ts.map +1 -1
- package/dist/functions/table.lua +23 -21
- package/dist/functions/types.d.ts +1 -1
- package/dist/functions/types.d.ts.map +1 -1
- package/dist/functions/vector.d.ts +1 -1
- package/dist/functions/vector.d.ts.map +1 -1
- package/dist/interfaces/SaveData.d.ts +1 -1
- package/dist/interfaces/private/TSTLClassMetatable.d.ts +1 -1
- package/dist/interfaces/private/TSTLClassMetatable.d.ts.map +1 -1
- package/dist/lualib_bundle.lua +38 -7
- package/dist/types/PlayerIndex.d.ts +3 -2
- package/dist/types/PlayerIndex.d.ts.map +1 -1
- package/dist/types/private/IsaacAPIClass.d.ts +1 -1
- package/dist/types/private/IsaacAPIClass.d.ts.map +1 -1
- package/dist/types/private/SerializedIsaacAPIClass.d.ts +1 -1
- package/dist/types/private/SerializedIsaacAPIClass.d.ts.map +1 -1
- package/dist/types/private/TSTLClass.d.ts +1 -1
- package/dist/types/private/TSTLClass.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/features/customStage/customStageGridEntities.ts +4 -4
- package/src/features/customStage/exports.ts +5 -3
- package/src/features/customStage/init.ts +19 -7
- package/src/features/customStage/streakText.ts +284 -19
- package/src/features/customStage/v.ts +6 -1
- package/src/features/customStage/versusScreen.ts +2 -5
- package/src/features/extraConsoleCommands/init.ts +1 -0
- package/src/features/extraConsoleCommands/listCommands.ts +14 -0
- package/src/features/saveDataManager/exports.ts +3 -8
- package/src/features/saveDataManager/load.ts +2 -3
- package/src/features/saveDataManager/main.ts +4 -5
- package/src/features/saveDataManager/maps.ts +3 -3
- package/src/features/saveDataManager/merge.ts +11 -11
- package/src/features/saveDataManager/save.ts +6 -6
- package/src/features/saveDataManager/{serializationBrand.ts → serializationBrands.ts} +0 -0
- package/src/functions/array.ts +2 -4
- package/src/functions/color.ts +3 -3
- package/src/functions/deepCopy.ts +95 -41
- package/src/functions/deepCopyTests.ts +161 -28
- package/src/functions/entities.ts +7 -7
- package/src/functions/input.ts +7 -8
- package/src/functions/isaacAPIClass.ts +3 -3
- package/src/functions/jsonHelpers.ts +3 -3
- package/src/functions/kColor.ts +3 -3
- package/src/functions/log.ts +7 -4
- package/src/functions/mergeTests.ts +24 -32
- package/src/functions/playerIndex.ts +1 -1
- package/src/functions/rng.ts +3 -3
- package/src/functions/table.ts +25 -23
- package/src/functions/tstlClass.ts +1 -1
- package/src/functions/types.ts +3 -1
- package/src/functions/vector.ts +3 -3
- package/src/interfaces/SaveData.ts +1 -1
- package/src/interfaces/private/TSTLClassMetatable.ts +1 -1
- package/src/types/PlayerIndex.ts +3 -2
- package/src/types/private/IsaacAPIClass.ts +1 -1
- package/src/types/private/SerializedIsaacAPIClass.ts +1 -1
- package/src/types/private/TSTLClass.ts +1 -1
- package/dist/features/saveDataManager/serializationBrand.d.ts.map +0 -1
|
@@ -8,8 +8,8 @@ import { isSerializedIsaacAPIClass } from "./serialization";
|
|
|
8
8
|
import { copyVector, isVector } from "./vector";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Run the suite of tests that prove that the "merge"
|
|
12
|
-
*
|
|
11
|
+
* Run the suite of tests that prove that the "merge" function works properly. (This function is not
|
|
12
|
+
* exported but is used internally in the save data manager.)
|
|
13
13
|
*
|
|
14
14
|
* This function is only useful if you are troubleshooting the save data manager.
|
|
15
15
|
*/
|
|
@@ -37,10 +37,10 @@ function oldTableHasUpdatedValue() {
|
|
|
37
37
|
const newValue = "baz";
|
|
38
38
|
const oldTable = {
|
|
39
39
|
foo: oldValue,
|
|
40
|
-
} as unknown as
|
|
40
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
41
41
|
const newTable = {
|
|
42
42
|
foo: newValue,
|
|
43
|
-
} as unknown as
|
|
43
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
44
44
|
|
|
45
45
|
merge(oldTable, newTable, "oldTableHasUpdatedValue");
|
|
46
46
|
|
|
@@ -56,10 +56,10 @@ function newTableHasSameValue() {
|
|
|
56
56
|
const newValue = "baz";
|
|
57
57
|
const oldTable = {
|
|
58
58
|
foo: oldValue,
|
|
59
|
-
} as unknown as
|
|
59
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
60
60
|
const newTable = {
|
|
61
61
|
foo: newValue,
|
|
62
|
-
} as unknown as
|
|
62
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
63
63
|
|
|
64
64
|
merge(oldTable, newTable, "newTableHasSameValue");
|
|
65
65
|
|
|
@@ -74,10 +74,10 @@ function oldTableHasUpdatedValueFromNull() {
|
|
|
74
74
|
const newValue = "baz";
|
|
75
75
|
const oldTable = {
|
|
76
76
|
foo: null as string | null,
|
|
77
|
-
} as unknown as
|
|
77
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
78
78
|
const newTable = {
|
|
79
79
|
foo: newValue,
|
|
80
|
-
} as unknown as
|
|
80
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
81
81
|
|
|
82
82
|
merge(oldTable, newTable, "oldTableHasUpdatedValueFromNull");
|
|
83
83
|
|
|
@@ -109,13 +109,13 @@ function oldTableHasFilledChildTable() {
|
|
|
109
109
|
const newValue = "baz";
|
|
110
110
|
const oldTable = {
|
|
111
111
|
foo: null as Foo | null,
|
|
112
|
-
} as unknown as
|
|
112
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
113
113
|
const foo: Foo = {
|
|
114
114
|
bar: newValue,
|
|
115
115
|
};
|
|
116
116
|
const newTable = {
|
|
117
117
|
foo,
|
|
118
|
-
} as unknown as
|
|
118
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
119
119
|
|
|
120
120
|
merge(oldTable, newTable, "oldTableHasFilledChildTable");
|
|
121
121
|
|
|
@@ -148,8 +148,8 @@ function oldTableHasFilledMap() {
|
|
|
148
148
|
const serializedSaveData = deepCopy(saveData, SerializationType.SERIALIZE);
|
|
149
149
|
|
|
150
150
|
merge(
|
|
151
|
-
v as unknown as
|
|
152
|
-
serializedSaveData as
|
|
151
|
+
v as unknown as LuaMap,
|
|
152
|
+
serializedSaveData as LuaMap,
|
|
153
153
|
"oldTableHasFilledMap",
|
|
154
154
|
);
|
|
155
155
|
|
|
@@ -216,8 +216,8 @@ function oldTableHasFilledDefaultMap() {
|
|
|
216
216
|
const serializedSaveData = deepCopy(saveData, SerializationType.SERIALIZE);
|
|
217
217
|
|
|
218
218
|
merge(
|
|
219
|
-
v as unknown as
|
|
220
|
-
serializedSaveData as
|
|
219
|
+
v as unknown as LuaMap,
|
|
220
|
+
serializedSaveData as LuaMap,
|
|
221
221
|
"oldTableHasFilledDefaultMap",
|
|
222
222
|
);
|
|
223
223
|
|
|
@@ -266,8 +266,6 @@ function oldTableHasFilledDefaultMap() {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
function oldTableHasVector() {
|
|
269
|
-
log("Starting test: oldTableHasVector");
|
|
270
|
-
|
|
271
269
|
interface Foo {
|
|
272
270
|
bar: Vector;
|
|
273
271
|
}
|
|
@@ -278,13 +276,13 @@ function oldTableHasVector() {
|
|
|
278
276
|
const newValue = Vector(x, y);
|
|
279
277
|
const oldTable = {
|
|
280
278
|
foo: null as Foo | null,
|
|
281
|
-
} as unknown as
|
|
279
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
282
280
|
const foo: Foo = {
|
|
283
281
|
bar: newValue,
|
|
284
282
|
};
|
|
285
283
|
const newTable = {
|
|
286
284
|
foo,
|
|
287
|
-
} as unknown as
|
|
285
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
288
286
|
|
|
289
287
|
merge(oldTable, newTable, "oldTableHasVector");
|
|
290
288
|
|
|
@@ -307,8 +305,6 @@ function oldTableHasVector() {
|
|
|
307
305
|
}
|
|
308
306
|
|
|
309
307
|
function oldTableHasVectorSerialized() {
|
|
310
|
-
log("Starting test: oldTableHasVectorSerialized");
|
|
311
|
-
|
|
312
308
|
interface Foo {
|
|
313
309
|
bar: Vector;
|
|
314
310
|
}
|
|
@@ -319,18 +315,18 @@ function oldTableHasVectorSerialized() {
|
|
|
319
315
|
const newValue = Vector(x, y);
|
|
320
316
|
const oldTable = {
|
|
321
317
|
foo: null as Foo | null,
|
|
322
|
-
} as unknown as
|
|
318
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
323
319
|
const foo: Foo = {
|
|
324
320
|
bar: newValue,
|
|
325
321
|
};
|
|
326
322
|
const newTable = {
|
|
327
323
|
foo,
|
|
328
|
-
} as unknown as
|
|
324
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
329
325
|
const newTableSerialized = deepCopy(
|
|
330
326
|
newTable,
|
|
331
327
|
SerializationType.SERIALIZE,
|
|
332
328
|
"oldTableHasVectorSerialized",
|
|
333
|
-
) as
|
|
329
|
+
) as LuaMap<AnyNotNil, unknown>;
|
|
334
330
|
|
|
335
331
|
merge(oldTable, newTableSerialized, "oldTableHasVectorSerialized");
|
|
336
332
|
|
|
@@ -355,8 +351,6 @@ function oldTableHasVectorSerialized() {
|
|
|
355
351
|
}
|
|
356
352
|
|
|
357
353
|
function oldTableHasRNG() {
|
|
358
|
-
log("Starting test: oldTableHasRNG");
|
|
359
|
-
|
|
360
354
|
interface Foo {
|
|
361
355
|
bar: RNG;
|
|
362
356
|
}
|
|
@@ -366,13 +360,13 @@ function oldTableHasRNG() {
|
|
|
366
360
|
const newValue = newRNG(seed);
|
|
367
361
|
const oldTable = {
|
|
368
362
|
foo: null as Foo | null,
|
|
369
|
-
} as unknown as
|
|
363
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
370
364
|
const foo: Foo = {
|
|
371
365
|
bar: newValue,
|
|
372
366
|
};
|
|
373
367
|
const newTable = {
|
|
374
368
|
foo,
|
|
375
|
-
} as unknown as
|
|
369
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
376
370
|
|
|
377
371
|
merge(oldTable, newTable, "oldTableHasRNG");
|
|
378
372
|
|
|
@@ -392,8 +386,6 @@ function oldTableHasRNG() {
|
|
|
392
386
|
}
|
|
393
387
|
|
|
394
388
|
function oldTableHasRNGSerialized() {
|
|
395
|
-
log("Starting test: oldTableHasRNGSerialized");
|
|
396
|
-
|
|
397
389
|
interface Foo {
|
|
398
390
|
bar: RNG;
|
|
399
391
|
}
|
|
@@ -403,18 +395,18 @@ function oldTableHasRNGSerialized() {
|
|
|
403
395
|
const newValue = newRNG(seed);
|
|
404
396
|
const oldTable = {
|
|
405
397
|
foo: null as Foo | null,
|
|
406
|
-
} as unknown as
|
|
398
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
407
399
|
const foo: Foo = {
|
|
408
400
|
bar: newValue,
|
|
409
401
|
};
|
|
410
402
|
const newTable = {
|
|
411
403
|
foo,
|
|
412
|
-
} as unknown as
|
|
404
|
+
} as unknown as LuaMap<AnyNotNil, unknown>;
|
|
413
405
|
const newTableSerialized = deepCopy(
|
|
414
406
|
newTable,
|
|
415
407
|
SerializationType.SERIALIZE,
|
|
416
408
|
"oldTableHasRNGSerialized",
|
|
417
|
-
) as
|
|
409
|
+
) as LuaMap<AnyNotNil, unknown>;
|
|
418
410
|
|
|
419
411
|
merge(oldTable, newTableSerialized, "oldTableHasRNGSerialized");
|
|
420
412
|
|
|
@@ -64,7 +64,7 @@ export function getPlayerFromIndex(
|
|
|
64
64
|
* this is not desired, pass true for the `differentiateForgottenAndSoul` argument, and the RNG of
|
|
65
65
|
* Spoon Bender (3) will be used for The Soul.
|
|
66
66
|
*
|
|
67
|
-
* Also note that this index
|
|
67
|
+
* Also note that this index does not work in the `POST_PLAYER_INIT` function for players 2 through
|
|
68
68
|
* 4. With that said, in almost all cases, you should be lazy-initializing your data structures in
|
|
69
69
|
* other callbacks, so this should not be an issue.
|
|
70
70
|
*/
|
package/src/functions/rng.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
|
5
5
|
import { getNumbersFromTable, tableHasKeys } from "./table";
|
|
6
6
|
import { isTable } from "./types";
|
|
7
7
|
|
|
8
|
-
type SerializedRNG =
|
|
8
|
+
type SerializedRNG = LuaMap<string, unknown> & {
|
|
9
9
|
readonly __serializedRNGBrand: symbol;
|
|
10
10
|
};
|
|
11
11
|
|
|
@@ -63,7 +63,7 @@ export function copyRNG(
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const seed = rng.GetSeed();
|
|
66
|
-
const rngTable = new
|
|
66
|
+
const rngTable = new LuaMap<string, unknown>();
|
|
67
67
|
rngTable.set("seed", seed);
|
|
68
68
|
rngTable.set(SerializationBrand.RNG, "");
|
|
69
69
|
return rngTable as SerializedRNG;
|
|
@@ -77,7 +77,7 @@ export function copyRNG(
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const [seedNumber] = getNumbersFromTable(
|
|
80
|
-
rng as
|
|
80
|
+
rng as LuaMap<string, unknown>,
|
|
81
81
|
OBJECT_NAME,
|
|
82
82
|
...KEYS,
|
|
83
83
|
);
|
package/src/functions/table.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isBoolean, isNumber, isString } from "./types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* In a Map
|
|
4
|
+
* In a `Map`, you can use the `clear` method to delete every element. However, in a `LuaMap`, the
|
|
5
5
|
* `clear` method does not exist. Use this helper function as a drop-in replacement for this.
|
|
6
6
|
*/
|
|
7
|
-
export function clearTable(
|
|
8
|
-
for (const [key] of pairs(
|
|
9
|
-
|
|
7
|
+
export function clearTable(luaMap: LuaMap): void {
|
|
8
|
+
for (const [key] of pairs(luaMap)) {
|
|
9
|
+
luaMap.delete(key);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -14,13 +14,13 @@ export function clearTable(luaTable: LuaTable): void {
|
|
|
14
14
|
export function copyValuesToTable(
|
|
15
15
|
object: unknown,
|
|
16
16
|
keys: string[],
|
|
17
|
-
|
|
17
|
+
luaMap: LuaMap<string, unknown>,
|
|
18
18
|
): void {
|
|
19
|
-
const otherTable = object as
|
|
19
|
+
const otherTable = object as LuaMap<string, string | number>;
|
|
20
20
|
|
|
21
21
|
for (const key of keys) {
|
|
22
22
|
const value = otherTable.get(key);
|
|
23
|
-
|
|
23
|
+
luaMap.set(key, value);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -31,13 +31,13 @@ export function copyValuesToTable(
|
|
|
31
31
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
32
32
|
*/
|
|
33
33
|
export function getBooleansFromTable(
|
|
34
|
-
|
|
34
|
+
luaMap: LuaMap<string, unknown>,
|
|
35
35
|
objectName: string,
|
|
36
36
|
...keys: string[]
|
|
37
37
|
): boolean[] {
|
|
38
38
|
const booleans: boolean[] = [];
|
|
39
39
|
for (const key of keys) {
|
|
40
|
-
const value =
|
|
40
|
+
const value = luaMap.get(key);
|
|
41
41
|
if (value === undefined) {
|
|
42
42
|
error(
|
|
43
43
|
`Failed to find a value for "${key}" in a table representing a "${objectName}" object.`,
|
|
@@ -63,13 +63,13 @@ export function getBooleansFromTable(
|
|
|
63
63
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
64
64
|
*/
|
|
65
65
|
export function getNumbersFromTable(
|
|
66
|
-
|
|
66
|
+
luaMap: LuaMap<string, unknown>,
|
|
67
67
|
objectName: string,
|
|
68
68
|
...keys: string[]
|
|
69
69
|
): number[] {
|
|
70
70
|
const numbers: number[] = [];
|
|
71
71
|
for (const key of keys) {
|
|
72
|
-
const value =
|
|
72
|
+
const value = luaMap.get(key);
|
|
73
73
|
if (value === undefined) {
|
|
74
74
|
error(
|
|
75
75
|
`Failed to find a value for "${key}" in a table representing a "${objectName}" object.`,
|
|
@@ -103,13 +103,13 @@ export function getNumbersFromTable(
|
|
|
103
103
|
* This function is variadic, meaning that you can specify N arguments to get N values.
|
|
104
104
|
*/
|
|
105
105
|
export function getStringsFromTable(
|
|
106
|
-
|
|
106
|
+
luaMap: LuaMap<string, unknown>,
|
|
107
107
|
objectName: string,
|
|
108
108
|
...keys: string[]
|
|
109
109
|
): string[] {
|
|
110
110
|
const strings: string[] = [];
|
|
111
111
|
for (const key of keys) {
|
|
112
|
-
const value =
|
|
112
|
+
const value = luaMap.get(key);
|
|
113
113
|
if (value === undefined) {
|
|
114
114
|
error(
|
|
115
115
|
`Failed to find a value for "${key}" in a table representing a "${objectName}" object.`,
|
|
@@ -136,42 +136,44 @@ export function getStringsFromTable(
|
|
|
136
136
|
* This function will only work on tables that have number keys or string keys. It will throw a
|
|
137
137
|
* run-time error if it encounters a key of another type.
|
|
138
138
|
*
|
|
139
|
-
* @param
|
|
139
|
+
* @param luaMap The table to iterate over.
|
|
140
140
|
* @param func The function to run for each iteration.
|
|
141
141
|
* @param inOrder Optional. Whether to iterate in order. True by default. You can dynamically set to
|
|
142
142
|
* false in situations where iterating randomly would not matter and you need the
|
|
143
143
|
* extra performance.
|
|
144
144
|
*/
|
|
145
145
|
export function iterateTableInOrder<K, V>(
|
|
146
|
-
|
|
146
|
+
luaMap: LuaMap<K, V>,
|
|
147
147
|
func: (key: K, value: V) => void,
|
|
148
148
|
inOrder = true,
|
|
149
149
|
): void {
|
|
150
150
|
// First, handle the trivial case of a non-deterministic iteration.
|
|
151
151
|
if (!inOrder) {
|
|
152
|
-
for (const [key, value] of
|
|
152
|
+
for (const [key, value] of luaMap) {
|
|
153
153
|
func(key, value);
|
|
154
154
|
}
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
const keys = Object.keys(
|
|
158
|
+
const keys = Object.keys(luaMap);
|
|
159
159
|
const hasAllNumberKeys = keys.every((key) => isNumber(key));
|
|
160
160
|
const hasAllStringKeys = keys.every((key) => isString(key));
|
|
161
161
|
if (!hasAllNumberKeys && !hasAllStringKeys) {
|
|
162
162
|
// Since the table has non-homogenous keys, we won't be able to sort it. Revert to
|
|
163
163
|
// non-deterministic iteration in this case.
|
|
164
|
-
for (const [key, value] of
|
|
164
|
+
for (const [key, value] of luaMap) {
|
|
165
165
|
func(key, value);
|
|
166
166
|
}
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
|
-
keys.sort();
|
|
170
169
|
|
|
170
|
+
keys.sort();
|
|
171
171
|
for (const key of keys) {
|
|
172
172
|
const keyIndex = key as unknown as K;
|
|
173
|
-
const value =
|
|
174
|
-
|
|
173
|
+
const value = luaMap.get(keyIndex);
|
|
174
|
+
if (value !== undefined) {
|
|
175
|
+
func(keyIndex, value);
|
|
176
|
+
}
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
|
|
@@ -182,8 +184,8 @@ export function iterateTableInOrder<K, V>(
|
|
|
182
184
|
* for.
|
|
183
185
|
*/
|
|
184
186
|
export function tableHasKeys(
|
|
185
|
-
|
|
187
|
+
luaMap: LuaMap<AnyNotNil, unknown>,
|
|
186
188
|
...keys: string[]
|
|
187
189
|
): boolean {
|
|
188
|
-
return keys.every((key) =>
|
|
190
|
+
return keys.every((key) => luaMap.has(key));
|
|
189
191
|
}
|
|
@@ -146,7 +146,7 @@ export function newTSTLClass(oldClass: TSTLClass): TSTLClass {
|
|
|
146
146
|
|
|
147
147
|
/** This is a re-implementation of the transpiled "__TS__New" function. */
|
|
148
148
|
function newTSTLClassFromMetatable(metatable: TSTLClassMetatable): TSTLClass {
|
|
149
|
-
const newClass = new
|
|
149
|
+
const newClass = new LuaMap<AnyNotNil, unknown>();
|
|
150
150
|
const newClassMetatable = setmetatable(
|
|
151
151
|
newClass,
|
|
152
152
|
metatable.constructor.prototype,
|
package/src/functions/types.ts
CHANGED
|
@@ -27,7 +27,9 @@ export function isString(variable: unknown): variable is string {
|
|
|
27
27
|
return type(variable) === "string";
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function isTable(
|
|
30
|
+
export function isTable(
|
|
31
|
+
variable: unknown,
|
|
32
|
+
): variable is LuaMap<AnyNotNil, unknown> {
|
|
31
33
|
return type(variable) === "table";
|
|
32
34
|
}
|
|
33
35
|
|
package/src/functions/vector.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
|
|
|
6
6
|
import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
|
|
7
7
|
import { isTable } from "./types";
|
|
8
8
|
|
|
9
|
-
type SerializedVector =
|
|
9
|
+
type SerializedVector = LuaMap<string, unknown> & {
|
|
10
10
|
readonly __serializedVectorBrand: symbol;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -55,7 +55,7 @@ export function copyVector(
|
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const vectorTable = new
|
|
58
|
+
const vectorTable = new LuaMap<string, unknown>();
|
|
59
59
|
copyValuesToTable(vector, KEYS, vectorTable);
|
|
60
60
|
vectorTable.set(SerializationBrand.VECTOR, "");
|
|
61
61
|
return vectorTable as SerializedVector;
|
|
@@ -69,7 +69,7 @@ export function copyVector(
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
const [x, y] = getNumbersFromTable(
|
|
72
|
-
vector as
|
|
72
|
+
vector as LuaMap<string, unknown>,
|
|
73
73
|
OBJECT_NAME,
|
|
74
74
|
...KEYS,
|
|
75
75
|
);
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - `Set`
|
|
16
16
|
* - serializable Isaac API classes (such as `Color`)
|
|
17
17
|
* - TSTL classes (i.e. classes that you made yourself)
|
|
18
|
-
* - sub-objects or a `
|
|
18
|
+
* - sub-objects or a `LuaMap` that contains the above values
|
|
19
19
|
*
|
|
20
20
|
* (Unfortunately, it is not possible to create a recursive type definition that matches these
|
|
21
21
|
* properties. This means that the TypeScript compiler will not be able to validate that you are
|
package/src/types/PlayerIndex.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* PlayerIndex is a specific type of
|
|
3
|
-
*
|
|
2
|
+
* PlayerIndex is a specific type of number that represents a unique identifier for a player. Mods
|
|
3
|
+
* can signify that data structures handle `EntityPlayer` by using this type. For more information,
|
|
4
|
+
* see the documentation for the `getPlayerIndex` function.
|
|
4
5
|
*
|
|
5
6
|
* For example:
|
|
6
7
|
*
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializationBrand.d.ts","sourceRoot":"","sources":["../../../src/features/saveDataManager/serializationBrand.ts"],"names":[],"mappings":"AASA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAM1D"}
|