isaacscript-common 10.0.1 → 10.0.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.
Files changed (68) hide show
  1. package/dist/index.d.ts +66 -19
  2. package/dist/isaacscript-common.lua +181 -88
  3. package/dist/package.lua +2 -2
  4. package/dist/src/features/deployJSONRoom.d.ts +16 -6
  5. package/dist/src/features/deployJSONRoom.d.ts.map +1 -1
  6. package/dist/src/features/deployJSONRoom.lua +16 -6
  7. package/dist/src/functions/bitSet128.d.ts +2 -1
  8. package/dist/src/functions/bitSet128.d.ts.map +1 -1
  9. package/dist/src/functions/color.d.ts +2 -3
  10. package/dist/src/functions/color.d.ts.map +1 -1
  11. package/dist/src/functions/curses.d.ts +1 -1
  12. package/dist/src/functions/curses.lua +1 -1
  13. package/dist/src/functions/deepCopy.d.ts +2 -1
  14. package/dist/src/functions/deepCopy.d.ts.map +1 -1
  15. package/dist/src/functions/deepCopy.lua +19 -25
  16. package/dist/src/functions/deepCopyTests.lua +13 -26
  17. package/dist/src/functions/kColor.d.ts +2 -3
  18. package/dist/src/functions/kColor.d.ts.map +1 -1
  19. package/dist/src/functions/rng.d.ts +2 -2
  20. package/dist/src/functions/rng.d.ts.map +1 -1
  21. package/dist/src/functions/serialization.d.ts +11 -4
  22. package/dist/src/functions/serialization.d.ts.map +1 -1
  23. package/dist/src/functions/serialization.lua +15 -0
  24. package/dist/src/functions/vector.d.ts +2 -1
  25. package/dist/src/functions/vector.d.ts.map +1 -1
  26. package/dist/src/functions/weighted.d.ts +6 -0
  27. package/dist/src/functions/weighted.d.ts.map +1 -0
  28. package/dist/src/functions/weighted.lua +35 -0
  29. package/dist/src/index.d.ts +2 -1
  30. package/dist/src/index.d.ts.map +1 -1
  31. package/dist/src/index.lua +8 -0
  32. package/dist/src/interfaces/SaveData.d.ts +3 -8
  33. package/dist/src/interfaces/SaveData.d.ts.map +1 -1
  34. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts +1 -1
  35. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts.map +1 -1
  36. package/dist/src/objects/isaacAPIClassTypeToBrand.lua +2 -2
  37. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts +36 -8
  38. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -1
  39. package/dist/src/objects/isaacAPIClassTypeToFunctions.lua +42 -7
  40. package/dist/src/types/WeightedArray.d.ts +4 -0
  41. package/dist/src/types/WeightedArray.d.ts.map +1 -0
  42. package/dist/src/types/{SerializedIsaacAPIClass.lua → WeightedArray.lua} +0 -0
  43. package/package.json +2 -2
  44. package/src/features/deployJSONRoom.ts +16 -6
  45. package/src/features/saveDataManager/exports.ts +1 -1
  46. package/src/functions/bitSet128.ts +2 -0
  47. package/src/functions/color.ts +2 -0
  48. package/src/functions/curses.ts +1 -1
  49. package/src/functions/deepCopy.ts +25 -15
  50. package/src/functions/deepCopyTests.ts +19 -41
  51. package/src/functions/initArray.ts +1 -1
  52. package/src/functions/kColor.ts +2 -0
  53. package/src/functions/rng.ts +2 -0
  54. package/src/functions/serialization.ts +72 -18
  55. package/src/functions/vector.ts +5 -1
  56. package/src/functions/weighted.ts +36 -0
  57. package/src/index.ts +2 -1
  58. package/src/interfaces/SaveData.ts +4 -3
  59. package/src/objects/isaacAPIClassTypeToBrand.ts +1 -1
  60. package/src/objects/isaacAPIClassTypeToFunctions.ts +58 -9
  61. package/src/types/WeightedArray.ts +2 -0
  62. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts +0 -12
  63. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts.map +0 -1
  64. package/dist/src/enums/private/CopyableIsaacAPIClassType.lua +0 -10
  65. package/dist/src/types/SerializedIsaacAPIClass.d.ts +0 -11
  66. package/dist/src/types/SerializedIsaacAPIClass.d.ts.map +0 -1
  67. package/src/enums/private/CopyableIsaacAPIClassType.ts +0 -11
  68. package/src/types/SerializedIsaacAPIClass.ts +0 -9
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ import { CollectiblePedestalType } from 'isaac-typescript-definitions';
17
17
  import { CollectibleType } from 'isaac-typescript-definitions';
18
18
  import { Controller } from 'isaac-typescript-definitions';
19
19
  import { ControllerIndex } from 'isaac-typescript-definitions';
20
+ import { CopyableIsaacAPIClassType } from 'isaac-typescript-definitions';
20
21
  import { CrawlSpaceVariant } from 'isaac-typescript-definitions';
21
22
  import { DamageFlag } from 'isaac-typescript-definitions';
22
23
  import { DiceFloorSubType } from 'isaac-typescript-definitions';
@@ -915,6 +916,9 @@ export declare function convertDecimalToBinary(number: number, minLength?: int):
915
916
  */
916
917
  export declare function convertXMLGridEntityType(gridEntityXMLType: GridEntityXMLType, gridEntityXMLVariant: int): [GridEntityType, int] | undefined;
917
918
 
919
+ /** A type representing an Isaac API class that can be safely copied or serialized. */
920
+ declare type CopyableIsaacAPIClass = BitSet128 | Color | KColor | RNG | Vector;
921
+
918
922
  /**
919
923
  * Helper function to perform a shallow copy.
920
924
  *
@@ -936,7 +940,7 @@ export declare function copyColor(color: Color): Color;
936
940
  *
937
941
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
938
942
  */
939
- export declare function copyIsaacAPIClass(isaacAPIClass: unknown): unknown;
943
+ export declare function copyIsaacAPIClass<T extends CopyableIsaacAPIClass>(isaacAPIClass: T): T;
940
944
 
941
945
  /** Helper function to copy a `KColor` Isaac API class. */
942
946
  export declare function copyKColor(kColor: KColor): KColor;
@@ -1545,7 +1549,9 @@ export declare interface CustomStageTSConfig {
1545
1549
  * @param insideMap Optional. Tracks whether or not the deep copy function is in the process of
1546
1550
  * recursively copying a TSTL Map. Default is false.
1547
1551
  */
1548
- export declare function deepCopy(value: unknown, serializationType?: SerializationType, traversalDescription?: string, insideMap?: boolean): unknown;
1552
+ export declare function deepCopy<T>(value: T, serializationType?: SerializationType.NONE, traversalDescription?: string, insideMap?: boolean): T;
1553
+
1554
+ export declare function deepCopy(value: unknown, serializationType: SerializationType, traversalDescription?: string, insideMap?: boolean): unknown;
1549
1555
 
1550
1556
  export declare const DEFAULT_BASE_STAGE = LevelStage.BASEMENT_2;
1551
1557
 
@@ -1701,16 +1707,21 @@ export declare function deleteSetsFromSet<T>(mainSet: Set<T>, ...setsToRemove: A
1701
1707
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
1702
1708
  * all of the entries and grid entities in the provided JSON room.
1703
1709
  *
1710
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
1711
+ * my-rooms.xml`).
1712
+ *
1704
1713
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
1705
1714
  *
1706
1715
  * For example:
1707
1716
  *
1708
1717
  * ```ts
1709
1718
  *
1710
- * import customRooms from "./customRooms";
1719
+ * import customRooms from "./customRooms.json";
1711
1720
  *
1712
- * const firstJSONRoom = customRooms.rooms.room[0];
1713
- * deployJSONRoom(firstJSONRoom);
1721
+ * export function postNewRoom(): void {
1722
+ * const firstJSONRoom = customRooms.rooms.room[0];
1723
+ * deployJSONRoom(firstJSONRoom);
1724
+ * }
1714
1725
  * ```
1715
1726
  *
1716
1727
  * @param jsonRoom The JSON room to deploy. *
@@ -1726,6 +1737,9 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom | Readonly<JSONRoom>,
1726
1737
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
1727
1738
  * all of the entries and grid entities in one of the provided JSON rooms.
1728
1739
  *
1740
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
1741
+ * my-rooms.xml`).
1742
+ *
1729
1743
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
1730
1744
  *
1731
1745
  * Note that this function does not simply choose a random element in the provided array; it will
@@ -1735,10 +1749,12 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom | Readonly<JSONRoom>,
1735
1749
  * For example:
1736
1750
  *
1737
1751
  * ```ts
1738
- * import customRooms from "./customRooms";
1752
+ * import customRooms from "./customRooms.json";
1739
1753
  *
1740
- * const jsonRooms = customRooms.rooms.room;
1741
- * deployRandomJSONRoom(jsonRooms);
1754
+ * export function postNewRoom(): void {
1755
+ * const jsonRooms = customRooms.rooms.room;
1756
+ * deployRandomJSONRoom(jsonRooms);
1757
+ * }
1742
1758
  * ```
1743
1759
  *
1744
1760
  * @param jsonRooms An array of JSON rooms to randomly select from. In practice, this will be
@@ -1769,7 +1785,7 @@ export declare function deserializeColor(color: SerializedColor): Color;
1769
1785
  *
1770
1786
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
1771
1787
  */
1772
- export declare function deserializeIsaacAPIClass(serializedIsaacAPIClass: unknown): unknown;
1788
+ export declare function deserializeIsaacAPIClass<SerializedT extends SerializedIsaacAPIClass>(serializedIsaacAPIClass: SerializedT): IsaacAPIClassTypeToType[SerializedT["__kind"]];
1773
1789
 
1774
1790
  /**
1775
1791
  * Helper function to convert a `SerializedKColor` object to a normal `KColor` object. (This is used
@@ -2901,7 +2917,7 @@ export declare function getCrawlSpaces(crawlSpaceVariant?: CrawlSpaceVariant): G
2901
2917
  /**
2902
2918
  * Helper function to get the actual bit flag for modded curses.
2903
2919
  *
2904
- * Will throw a runtime error if the provided curse does not exist.
2920
+ * Will throw a run-time error if the provided curse does not exist.
2905
2921
  *
2906
2922
  * Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
2907
2923
  * a bit flag.
@@ -4453,6 +4469,9 @@ export declare function getRandomEnumValue<T>(transpiledEnum: T, seedOrRNG?: See
4453
4469
  */
4454
4470
  export declare function getRandomFloat(min: int, max: int, seedOrRNG?: Seed | RNG): float;
4455
4471
 
4472
+ /** Get a random value from a `WeightedArray`. (The second element in the array is the weight.) */
4473
+ export declare function getRandomFromWeightedArray<T>(weightedArray: WeightedArray<T>, seedOrRNG?: Seed | RNG): T;
4474
+
4456
4475
  /**
4457
4476
  * This returns a random integer between min and max. It is inclusive on both ends.
4458
4477
  *
@@ -5669,6 +5688,22 @@ export declare function irange(start: int, end?: int): int[];
5669
5688
  */
5670
5689
  export declare function isaacAPIClassEquals(object1: unknown, object2: unknown, keys: string[]): boolean;
5671
5690
 
5691
+ declare interface IsaacAPIClassTypeToSerializedType {
5692
+ [CopyableIsaacAPIClassType.BIT_SET_128]: SerializedBitSet128;
5693
+ [CopyableIsaacAPIClassType.COLOR]: SerializedColor;
5694
+ [CopyableIsaacAPIClassType.K_COLOR]: SerializedKColor;
5695
+ [CopyableIsaacAPIClassType.RNG]: SerializedRNG;
5696
+ [CopyableIsaacAPIClassType.VECTOR]: SerializedVector;
5697
+ }
5698
+
5699
+ declare interface IsaacAPIClassTypeToType {
5700
+ [CopyableIsaacAPIClassType.BIT_SET_128]: BitSet128;
5701
+ [CopyableIsaacAPIClassType.COLOR]: Color;
5702
+ [CopyableIsaacAPIClassType.K_COLOR]: KColor;
5703
+ [CopyableIsaacAPIClassType.RNG]: RNG;
5704
+ [CopyableIsaacAPIClassType.VECTOR]: Vector;
5705
+ }
5706
+
5672
5707
  /** Iterates over all inputs to determine if a particular button is pressed (i.e. held down). */
5673
5708
  export declare function isActionPressedOnAnyInput(buttonAction: ButtonAction): boolean;
5674
5709
 
@@ -5836,6 +5871,14 @@ export declare function isCollectibleUnlocked(collectibleType: CollectibleType,
5836
5871
  /** Helper function to check if something is an instantiated `Color` object. */
5837
5872
  export declare function isColor(object: unknown): object is Color;
5838
5873
 
5874
+ /**
5875
+ * Helper function to generically check if a given object is a copyable Isaac API class. (This is
5876
+ * used by the save data manager when determining what is safe to copy.)
5877
+ *
5878
+ * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
5879
+ */
5880
+ export declare function isCopyableIsaacAPIClass(object: unknown): object is CopyableIsaacAPIClass;
5881
+
5839
5882
  /**
5840
5883
  * Helper function to check if a `GridEntity` is a custom grid entity or if a grid index has a
5841
5884
  * custom grid entity.
@@ -10389,7 +10432,7 @@ export declare const SECOND_IN_MILLISECONDS = 1000;
10389
10432
  * The recursive nature of this type is based on the `Immutable` type:
10390
10433
  * https://stackoverflow.com/questions/41879327/deepreadonly-object-typescript
10391
10434
  */
10392
- declare type Serializable<T> = T extends SerializablePrimitive ? T : T extends SerializableIsaacAPIClass ? T : T extends IsaacAPIClass ? ErrorIsaacAPIClassIsNotSerializable : T extends Array<infer U> ? SerializableArray<U> : T extends ReadonlyArray<infer U> ? SerializableReadonlyArray<U> : T extends Map<infer K, infer V> ? SerializableMap<K, V> : T extends ReadonlyMap<infer K, infer V> ? SerializableReadonlyMap<K, V> : T extends Set<infer V> ? SerializableSet<V> : T extends ReadonlySet<infer V> ? SerializableReadonlySet<V> : SerializableObject<T>;
10435
+ declare type Serializable<T> = T extends SerializablePrimitive ? T : T extends CopyableIsaacAPIClass ? T : T extends IsaacAPIClass ? ErrorIsaacAPIClassIsNotSerializable : T extends Array<infer U> ? SerializableArray<U> : T extends ReadonlyArray<infer U> ? SerializableReadonlyArray<U> : T extends Map<infer K, infer V> ? SerializableMap<K, V> : T extends ReadonlyMap<infer K, infer V> ? SerializableReadonlyMap<K, V> : T extends Set<infer V> ? SerializableSet<V> : T extends ReadonlySet<infer V> ? SerializableReadonlySet<V> : SerializableObject<T>;
10393
10436
 
10394
10437
  declare type SerializableArray<T> = Array<SerializableInsideArrayOrMap<T>>;
10395
10438
 
@@ -10397,9 +10440,7 @@ declare type SerializableArray<T> = Array<SerializableInsideArrayOrMap<T>>;
10397
10440
  * This is mostly copied from the `Serializable` type. The difference is that we want to disallow
10398
10441
  * classes with methods.
10399
10442
  */
10400
- declare type SerializableInsideArrayOrMap<T> = T extends SerializablePrimitive ? T : T extends SerializableIsaacAPIClass ? T : T extends IsaacAPIClass ? ErrorIsaacAPIClassIsNotSerializable : T extends Array<infer U> ? SerializableArray<U> : T extends ReadonlyArray<infer U> ? SerializableReadonlyArray<U> : T extends Map<infer K, infer V> ? SerializableMap<K, V> : T extends ReadonlyMap<infer K, infer V> ? SerializableReadonlyMap<K, V> : T extends Set<infer V> ? SerializableSet<V> : T extends ReadonlySet<infer V> ? SerializableReadonlySet<V> : T extends HasMethods<T> ? ErrorCustomClassNotSerializable : T extends Function ? FunctionIsNotSerializable : SerializableObject<T>;
10401
-
10402
- declare type SerializableIsaacAPIClass = BitSet128 | Color | KColor | RNG | Vector;
10443
+ declare type SerializableInsideArrayOrMap<T> = T extends SerializablePrimitive ? T : T extends CopyableIsaacAPIClass ? T : T extends IsaacAPIClass ? ErrorIsaacAPIClassIsNotSerializable : T extends Array<infer U> ? SerializableArray<U> : T extends ReadonlyArray<infer U> ? SerializableReadonlyArray<U> : T extends Map<infer K, infer V> ? SerializableMap<K, V> : T extends ReadonlyMap<infer K, infer V> ? SerializableReadonlyMap<K, V> : T extends Set<infer V> ? SerializableSet<V> : T extends ReadonlySet<infer V> ? SerializableReadonlySet<V> : T extends HasMethods<T> ? ErrorCustomClassNotSerializable : T extends Function ? FunctionIsNotSerializable : SerializableObject<T>;
10403
10444
 
10404
10445
  declare type SerializableMap<K, V> = Map<SerializableInsideArrayOrMap<K>, SerializableInsideArrayOrMap<V>>;
10405
10446
 
@@ -10438,32 +10479,35 @@ export declare function serializeColor(color: Color): SerializedColor;
10438
10479
 
10439
10480
  export declare type SerializedBitSet128 = LuaMap<string, unknown> & {
10440
10481
  readonly __serializedBitSet128Brand: symbol;
10482
+ readonly __kind: CopyableIsaacAPIClassType.BIT_SET_128;
10441
10483
  };
10442
10484
 
10443
10485
  export declare type SerializedColor = LuaMap<string, unknown> & {
10444
10486
  readonly __serializedColorBrand: symbol;
10487
+ readonly __kind: CopyableIsaacAPIClassType.COLOR;
10445
10488
  };
10446
10489
 
10447
10490
  /**
10448
- * This is a type representing an Isaac API class like `Color` or `RNG` that has been written to the
10491
+ * A type representing an Isaac API class like `Color` or `RNG` that has been written to the
10449
10492
  * "save#.dat" file. It is used by the save data manager when reading and writing to that file.
10450
10493
  *
10451
10494
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
10452
10495
  */
10453
- export declare type SerializedIsaacAPIClass = LuaMap<string, unknown> & {
10454
- readonly __serializedIsaacAPIClassBrand: symbol;
10455
- };
10496
+ declare type SerializedIsaacAPIClass = SerializedBitSet128 | SerializedColor | SerializedKColor | SerializedRNG | SerializedVector;
10456
10497
 
10457
10498
  export declare type SerializedKColor = LuaMap<string, unknown> & {
10458
10499
  readonly __serializedKColorBrand: symbol;
10500
+ readonly __kind: CopyableIsaacAPIClassType.K_COLOR;
10459
10501
  };
10460
10502
 
10461
10503
  export declare type SerializedRNG = LuaMap<string, unknown> & {
10462
10504
  readonly __serializedRNGBrand: symbol;
10505
+ readonly __kind: CopyableIsaacAPIClassType.RNG;
10463
10506
  };
10464
10507
 
10465
10508
  export declare type SerializedVector = LuaMap<string, unknown> & {
10466
10509
  readonly __serializedVectorBrand: symbol;
10510
+ readonly __kind: CopyableIsaacAPIClassType.VECTOR;
10467
10511
  };
10468
10512
 
10469
10513
  /**
@@ -10472,7 +10516,7 @@ export declare type SerializedVector = LuaMap<string, unknown> & {
10472
10516
  *
10473
10517
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
10474
10518
  */
10475
- export declare function serializeIsaacAPIClass(isaacAPIClass: unknown): unknown;
10519
+ export declare function serializeIsaacAPIClass<T extends CopyableIsaacAPIClass>(isaacAPIClass: T): IsaacAPIClassTypeToSerializedType[T["__kind"]];
10476
10520
 
10477
10521
  /**
10478
10522
  * Helper function to convert a `KColor` object to a `SerializedKColor` object. (This is used by the
@@ -12032,6 +12076,9 @@ export declare function vectorToString(vector: Vector, round?: boolean): string;
12032
12076
  */
12033
12077
  export declare const VectorZero: Readonly<Vector>;
12034
12078
 
12079
+ /** An array where each element is paired with a number indicating that elements 'weight'. */
12080
+ export declare type WeightedArray<T> = Array<[T, float]>;
12081
+
12035
12082
  /**
12036
12083
  * Assuming that we are on the frame of fatal damage, this function returns whether or not
12037
12084
  * Mysterious Paper would rotate to Missing Poster on the frame that the "Game Over" screen would