isaacscript-common 6.10.1 → 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/functions/deepCopy.lua +20 -3
- package/dist/functions/deepCopyTests.d.ts.map +1 -1
- package/dist/functions/deepCopyTests.lua +65 -1
- package/dist/functions/mergeTests.lua +0 -4
- package/package.json +1 -1
- package/src/functions/deepCopy.ts +18 -1
- package/src/functions/deepCopyTests.ts +116 -0
- package/src/functions/mergeTests.ts +0 -8
|
@@ -452,6 +452,14 @@ function getCopiedEntries(self, object, serializationType, traversalDescription,
|
|
|
452
452
|
if SAVE_DATA_MANAGER_DEBUG then
|
|
453
453
|
__TS__ArraySort(entries, twoDimensionalSort)
|
|
454
454
|
end
|
|
455
|
+
local convertStringKeysToNumbers = serializationType == SerializationType.DESERIALIZE and __TS__ArraySome(
|
|
456
|
+
entries,
|
|
457
|
+
function(____, ____bindingPattern0)
|
|
458
|
+
local key
|
|
459
|
+
key = ____bindingPattern0[1]
|
|
460
|
+
return key == SerializationBrand.OBJECT_WITH_NUMBER_KEYS
|
|
461
|
+
end
|
|
462
|
+
)
|
|
455
463
|
local hasNumberKeys = __TS__ArraySome(
|
|
456
464
|
entries,
|
|
457
465
|
function(____, ____bindingPattern0)
|
|
@@ -467,7 +475,7 @@ function getCopiedEntries(self, object, serializationType, traversalDescription,
|
|
|
467
475
|
local value = ____value[2]
|
|
468
476
|
do
|
|
469
477
|
if isSerializationBrand(nil, key) then
|
|
470
|
-
goto
|
|
478
|
+
goto __continue87
|
|
471
479
|
end
|
|
472
480
|
traversalDescription = getTraversalDescription(nil, key, traversalDescription)
|
|
473
481
|
local newValue = ____exports.deepCopy(
|
|
@@ -477,10 +485,19 @@ function getCopiedEntries(self, object, serializationType, traversalDescription,
|
|
|
477
485
|
traversalDescription,
|
|
478
486
|
insideMap
|
|
479
487
|
)
|
|
480
|
-
local keyToUse =
|
|
488
|
+
local keyToUse = key
|
|
489
|
+
if convertStringKeysToNumbers then
|
|
490
|
+
local numberKey = tonumber(key)
|
|
491
|
+
if numberKey ~= nil then
|
|
492
|
+
keyToUse = numberKey
|
|
493
|
+
end
|
|
494
|
+
end
|
|
495
|
+
if convertNumberKeysToStrings then
|
|
496
|
+
keyToUse = tostring(key)
|
|
497
|
+
end
|
|
481
498
|
copiedEntries[#copiedEntries + 1] = {keyToUse, newValue}
|
|
482
499
|
end
|
|
483
|
-
::
|
|
500
|
+
::__continue87::
|
|
484
501
|
end
|
|
485
502
|
return {entries = copiedEntries, convertedNumberKeysToStrings = convertNumberKeysToStrings}
|
|
486
503
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepCopyTests.d.ts","sourceRoot":"","sources":["../../src/functions/deepCopyTests.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"deepCopyTests.d.ts","sourceRoot":"","sources":["../../src/functions/deepCopyTests.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CA2BvC"}
|
|
@@ -3,8 +3,10 @@ local __TS__TypeOf = ____lualib.__TS__TypeOf
|
|
|
3
3
|
local Map = ____lualib.Map
|
|
4
4
|
local __TS__New = ____lualib.__TS__New
|
|
5
5
|
local Set = ____lualib.Set
|
|
6
|
+
local __TS__Spread = ____lualib.__TS__Spread
|
|
7
|
+
local __TS__ArrayIncludes = ____lualib.__TS__ArrayIncludes
|
|
6
8
|
local ____exports = {}
|
|
7
|
-
local copiedObjectIsTable, copiedObjectHasKeyAndValueString, copiedTableHasKeyAndValueNumber, copiedTableDoesNotCoerceTypes, copiedObjectHasNoReferencesForPrimitivesForward, copiedObjectHasNoReferencesForPrimitivesBackward, copiedObjectHasNoReferencesForArray, copiedObjectHasChildObject, copiedMapIsMap, copiedMapHasValue, copiedSetIsSet, copiedSetHasValue, copiedMapHasChildMap, copiedDefaultMapHasChildDefaultMap, copiedDefaultMapHasBrand
|
|
9
|
+
local copiedObjectIsTable, copiedObjectHasKeyAndValueString, copiedTableHasKeyAndValueNumber, copiedTableDoesNotCoerceTypes, copiedObjectHasNoReferencesForPrimitivesForward, copiedObjectHasNoReferencesForPrimitivesBackward, copiedObjectHasNoReferencesForArray, copiedObjectHasChildObject, copiedMapIsMap, copiedMapHasValue, copiedSetIsSet, copiedSetHasValue, copiedMapHasChildMap, copiedDefaultMapHasChildDefaultMap, copiedDefaultMapHasBrand, copiedSerializedMapHasStringKeyType, copiedSerializedMapHasNumberKeyType, copiedSerializedDefaultMapHasStringKeyType, copiedSerializedDefaultMapHasNumberKeyType
|
|
8
10
|
local ____DefaultMap = require("classes.DefaultMap")
|
|
9
11
|
local DefaultMap = ____DefaultMap.DefaultMap
|
|
10
12
|
local ____SerializationBrand = require("enums.private.SerializationBrand")
|
|
@@ -297,6 +299,64 @@ function copiedDefaultMapHasBrand(self)
|
|
|
297
299
|
error("The copied DefaultMap does not have the brand: " .. SerializationBrand.DEFAULT_MAP)
|
|
298
300
|
end
|
|
299
301
|
end
|
|
302
|
+
function copiedSerializedMapHasStringKeyType(self)
|
|
303
|
+
local mapKey = "123"
|
|
304
|
+
local mapValue = 456
|
|
305
|
+
local oldMap = __TS__New(Map)
|
|
306
|
+
oldMap:set(mapKey, mapValue)
|
|
307
|
+
local tempTable = deepCopy(nil, oldMap, SerializationType.SERIALIZE, "copiedSerializedMapHasStringKeyTypeSerialize")
|
|
308
|
+
local newTable = deepCopy(nil, tempTable, SerializationType.DESERIALIZE, "copiedSerializedMapHasStringKeyTypeDeserialize")
|
|
309
|
+
local newMap = newTable
|
|
310
|
+
if not __TS__ArrayIncludes(
|
|
311
|
+
{__TS__Spread(newMap:keys())},
|
|
312
|
+
mapKey
|
|
313
|
+
) then
|
|
314
|
+
error((("The copied Map did not have a key of: " .. mapKey) .. " with type ") .. type(mapKey))
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
function copiedSerializedMapHasNumberKeyType(self)
|
|
318
|
+
local mapKey = 123
|
|
319
|
+
local mapValue = 456
|
|
320
|
+
local oldMap = __TS__New(Map)
|
|
321
|
+
oldMap:set(mapKey, mapValue)
|
|
322
|
+
local tempTable = deepCopy(nil, oldMap, SerializationType.SERIALIZE, "copiedSerializedMapHasNumberKeyTypeSerialize")
|
|
323
|
+
local newTable = deepCopy(nil, tempTable, SerializationType.DESERIALIZE, "copiedSerializedMapHasNumberKeyTypeDeserialize")
|
|
324
|
+
local newMap = newTable
|
|
325
|
+
if not __TS__ArrayIncludes(
|
|
326
|
+
{__TS__Spread(newMap:keys())},
|
|
327
|
+
mapKey
|
|
328
|
+
) then
|
|
329
|
+
error((("The copied Map did not have a key of: " .. tostring(mapKey)) .. " with type ") .. type(mapKey))
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
function copiedSerializedDefaultMapHasStringKeyType(self)
|
|
333
|
+
local mapKey = "123"
|
|
334
|
+
local oldMap = __TS__New(DefaultMap, 456)
|
|
335
|
+
oldMap:getAndSetDefault(mapKey)
|
|
336
|
+
local tempTable = deepCopy(nil, oldMap, SerializationType.SERIALIZE, "copiedSerializedDefaultMapHasStringKeyTypeSerialize")
|
|
337
|
+
local newTable = deepCopy(nil, tempTable, SerializationType.DESERIALIZE, "copiedSerializedDefaultMapHasStringKeyTypeDeserialize")
|
|
338
|
+
local newMap = newTable
|
|
339
|
+
if not __TS__ArrayIncludes(
|
|
340
|
+
{__TS__Spread(newMap:keys())},
|
|
341
|
+
mapKey
|
|
342
|
+
) then
|
|
343
|
+
error((("The copied DefaultMap did not have a key of: " .. mapKey) .. " with type ") .. type(mapKey))
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
function copiedSerializedDefaultMapHasNumberKeyType(self)
|
|
347
|
+
local mapKey = 123
|
|
348
|
+
local oldMap = __TS__New(DefaultMap, 456)
|
|
349
|
+
oldMap:getAndSetDefault(mapKey)
|
|
350
|
+
local tempTable = deepCopy(nil, oldMap, SerializationType.SERIALIZE, "copiedSerializedDefaultMapHasNumberKeyTypeSerialize")
|
|
351
|
+
local newTable = deepCopy(nil, tempTable, SerializationType.DESERIALIZE, "copiedSerializedDefaultMapHasNumberKeyTypeDeserialize")
|
|
352
|
+
local newMap = newTable
|
|
353
|
+
if not __TS__ArrayIncludes(
|
|
354
|
+
{__TS__Spread(newMap:keys())},
|
|
355
|
+
mapKey
|
|
356
|
+
) then
|
|
357
|
+
error((("The copied DefaultMap did not have a key of: " .. tostring(mapKey)) .. " with type ") .. type(mapKey))
|
|
358
|
+
end
|
|
359
|
+
end
|
|
300
360
|
--- Run the suite of tests that prove that the "deepCopy" helper function works properly.
|
|
301
361
|
--
|
|
302
362
|
-- This function is only useful if you are troubleshooting the "deepCopy" function.
|
|
@@ -316,6 +376,10 @@ function ____exports.runDeepCopyTests(self)
|
|
|
316
376
|
copiedMapHasChildMap(nil)
|
|
317
377
|
copiedDefaultMapHasChildDefaultMap(nil)
|
|
318
378
|
copiedDefaultMapHasBrand(nil)
|
|
379
|
+
copiedSerializedMapHasStringKeyType(nil)
|
|
380
|
+
copiedSerializedMapHasNumberKeyType(nil)
|
|
381
|
+
copiedSerializedDefaultMapHasStringKeyType(nil)
|
|
382
|
+
copiedSerializedDefaultMapHasNumberKeyType(nil)
|
|
319
383
|
log("All deep copy tests passed!")
|
|
320
384
|
end
|
|
321
385
|
return ____exports
|
|
@@ -149,7 +149,6 @@ function oldTableHasFilledDefaultMap(self)
|
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
function oldTableHasVector(self)
|
|
152
|
-
log("Starting test: oldTableHasVector")
|
|
153
152
|
local key = "foo"
|
|
154
153
|
local x = 50
|
|
155
154
|
local y = 60
|
|
@@ -173,7 +172,6 @@ function oldTableHasVector(self)
|
|
|
173
172
|
end
|
|
174
173
|
end
|
|
175
174
|
function oldTableHasVectorSerialized(self)
|
|
176
|
-
log("Starting test: oldTableHasVectorSerialized")
|
|
177
175
|
local key = "foo"
|
|
178
176
|
local x = 50
|
|
179
177
|
local y = 60
|
|
@@ -198,7 +196,6 @@ function oldTableHasVectorSerialized(self)
|
|
|
198
196
|
end
|
|
199
197
|
end
|
|
200
198
|
function oldTableHasRNG(self)
|
|
201
|
-
log("Starting test: oldTableHasRNG")
|
|
202
199
|
local key = "foo"
|
|
203
200
|
local seed = 50
|
|
204
201
|
local newValue = newRNG(nil, seed)
|
|
@@ -219,7 +216,6 @@ function oldTableHasRNG(self)
|
|
|
219
216
|
end
|
|
220
217
|
end
|
|
221
218
|
function oldTableHasRNGSerialized(self)
|
|
222
|
-
log("Starting test: oldTableHasRNGSerialized")
|
|
223
219
|
local key = "foo"
|
|
224
220
|
local seed = 50
|
|
225
221
|
local newValue = newRNG(nil, seed)
|
package/package.json
CHANGED
|
@@ -568,6 +568,14 @@ function getCopiedEntries(
|
|
|
568
568
|
entries.sort(twoDimensionalSort);
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// During serialization, we brand some Lua tables with a special identifier to signify that it has
|
|
572
|
+
// keys that should be deserialized to numbers.
|
|
573
|
+
const convertStringKeysToNumbers =
|
|
574
|
+
serializationType === SerializationType.DESERIALIZE &&
|
|
575
|
+
entries.some(
|
|
576
|
+
([key]) => key === (SerializationBrand.OBJECT_WITH_NUMBER_KEYS as string),
|
|
577
|
+
);
|
|
578
|
+
|
|
571
579
|
const hasNumberKeys = entries.some(([key]) => isNumber(key));
|
|
572
580
|
const convertNumberKeysToStrings =
|
|
573
581
|
serializationType === SerializationType.SERIALIZE && hasNumberKeys;
|
|
@@ -589,7 +597,16 @@ function getCopiedEntries(
|
|
|
589
597
|
insideMap,
|
|
590
598
|
);
|
|
591
599
|
|
|
592
|
-
|
|
600
|
+
let keyToUse = key;
|
|
601
|
+
if (convertStringKeysToNumbers) {
|
|
602
|
+
const numberKey = tonumber(key);
|
|
603
|
+
if (numberKey !== undefined) {
|
|
604
|
+
keyToUse = numberKey;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (convertNumberKeysToStrings) {
|
|
608
|
+
keyToUse = tostring(key);
|
|
609
|
+
}
|
|
593
610
|
copiedEntries.push([keyToUse, newValue]);
|
|
594
611
|
}
|
|
595
612
|
|
|
@@ -32,6 +32,12 @@ export function runDeepCopyTests(): void {
|
|
|
32
32
|
copiedDefaultMapHasChildDefaultMap();
|
|
33
33
|
copiedDefaultMapHasBrand();
|
|
34
34
|
|
|
35
|
+
copiedSerializedMapHasStringKeyType();
|
|
36
|
+
copiedSerializedMapHasNumberKeyType();
|
|
37
|
+
|
|
38
|
+
copiedSerializedDefaultMapHasStringKeyType();
|
|
39
|
+
copiedSerializedDefaultMapHasNumberKeyType();
|
|
40
|
+
|
|
35
41
|
log("All deep copy tests passed!");
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -457,3 +463,113 @@ function copiedDefaultMapHasBrand() {
|
|
|
457
463
|
);
|
|
458
464
|
}
|
|
459
465
|
}
|
|
466
|
+
|
|
467
|
+
function copiedSerializedMapHasStringKeyType() {
|
|
468
|
+
const mapKey = "123";
|
|
469
|
+
const mapValue = 456;
|
|
470
|
+
const oldMap = new Map<string, number>();
|
|
471
|
+
oldMap.set(mapKey, mapValue);
|
|
472
|
+
|
|
473
|
+
const tempTable = deepCopy(
|
|
474
|
+
oldMap,
|
|
475
|
+
SerializationType.SERIALIZE,
|
|
476
|
+
"copiedSerializedMapHasStringKeyTypeSerialize",
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
const newTable = deepCopy(
|
|
480
|
+
tempTable,
|
|
481
|
+
SerializationType.DESERIALIZE,
|
|
482
|
+
"copiedSerializedMapHasStringKeyTypeDeserialize",
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
const newMap = newTable as Map<string, number>;
|
|
486
|
+
if (![...newMap.keys()].includes(mapKey)) {
|
|
487
|
+
error(
|
|
488
|
+
`The copied Map did not have a key of: ${mapKey} with type ${type(
|
|
489
|
+
mapKey,
|
|
490
|
+
)}`,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function copiedSerializedMapHasNumberKeyType() {
|
|
496
|
+
const mapKey = 123;
|
|
497
|
+
const mapValue = 456;
|
|
498
|
+
const oldMap = new Map<number, number>();
|
|
499
|
+
oldMap.set(mapKey, mapValue);
|
|
500
|
+
|
|
501
|
+
const tempTable = deepCopy(
|
|
502
|
+
oldMap,
|
|
503
|
+
SerializationType.SERIALIZE,
|
|
504
|
+
"copiedSerializedMapHasNumberKeyTypeSerialize",
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
const newTable = deepCopy(
|
|
508
|
+
tempTable,
|
|
509
|
+
SerializationType.DESERIALIZE,
|
|
510
|
+
"copiedSerializedMapHasNumberKeyTypeDeserialize",
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const newMap = newTable as Map<number, number>;
|
|
514
|
+
if (![...newMap.keys()].includes(mapKey)) {
|
|
515
|
+
error(
|
|
516
|
+
`The copied Map did not have a key of: ${mapKey} with type ${type(
|
|
517
|
+
mapKey,
|
|
518
|
+
)}`,
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function copiedSerializedDefaultMapHasStringKeyType() {
|
|
524
|
+
const mapKey = "123";
|
|
525
|
+
const oldMap = new DefaultMap<string, number>(456);
|
|
526
|
+
oldMap.getAndSetDefault(mapKey);
|
|
527
|
+
|
|
528
|
+
const tempTable = deepCopy(
|
|
529
|
+
oldMap,
|
|
530
|
+
SerializationType.SERIALIZE,
|
|
531
|
+
"copiedSerializedDefaultMapHasStringKeyTypeSerialize",
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
const newTable = deepCopy(
|
|
535
|
+
tempTable,
|
|
536
|
+
SerializationType.DESERIALIZE,
|
|
537
|
+
"copiedSerializedDefaultMapHasStringKeyTypeDeserialize",
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
const newMap = newTable as DefaultMap<string, number>;
|
|
541
|
+
if (![...newMap.keys()].includes(mapKey)) {
|
|
542
|
+
error(
|
|
543
|
+
`The copied DefaultMap did not have a key of: ${mapKey} with type ${type(
|
|
544
|
+
mapKey,
|
|
545
|
+
)}`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function copiedSerializedDefaultMapHasNumberKeyType() {
|
|
551
|
+
const mapKey = 123;
|
|
552
|
+
const oldMap = new DefaultMap<number, number>(456);
|
|
553
|
+
oldMap.getAndSetDefault(mapKey);
|
|
554
|
+
|
|
555
|
+
const tempTable = deepCopy(
|
|
556
|
+
oldMap,
|
|
557
|
+
SerializationType.SERIALIZE,
|
|
558
|
+
"copiedSerializedDefaultMapHasNumberKeyTypeSerialize",
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
const newTable = deepCopy(
|
|
562
|
+
tempTable,
|
|
563
|
+
SerializationType.DESERIALIZE,
|
|
564
|
+
"copiedSerializedDefaultMapHasNumberKeyTypeDeserialize",
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
const newMap = newTable as DefaultMap<number, number>;
|
|
568
|
+
if (![...newMap.keys()].includes(mapKey)) {
|
|
569
|
+
error(
|
|
570
|
+
`The copied DefaultMap did not have a key of: ${mapKey} with type ${type(
|
|
571
|
+
mapKey,
|
|
572
|
+
)}`,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|