isaacscript-common 9.20.0 → 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 (95) hide show
  1. package/dist/index.d.ts +73 -24
  2. package/dist/isaacscript-common.lua +253 -138
  3. package/dist/lualib_bundle.lua +53 -37
  4. package/dist/package.lua +2 -2
  5. package/dist/src/features/deployJSONRoom.d.ts +16 -6
  6. package/dist/src/features/deployJSONRoom.d.ts.map +1 -1
  7. package/dist/src/features/deployJSONRoom.lua +16 -6
  8. package/dist/src/features/saveDataManager/load.d.ts +1 -1
  9. package/dist/src/features/saveDataManager/maps.d.ts +1 -1
  10. package/dist/src/features/saveDataManager/merge.d.ts +1 -1
  11. package/dist/src/features/saveDataManager/save.d.ts +1 -1
  12. package/dist/src/functions/bitSet128.d.ts +3 -2
  13. package/dist/src/functions/bitSet128.d.ts.map +1 -1
  14. package/dist/src/functions/bitSet128.lua +2 -2
  15. package/dist/src/functions/color.d.ts +3 -4
  16. package/dist/src/functions/color.d.ts.map +1 -1
  17. package/dist/src/functions/color.lua +2 -2
  18. package/dist/src/functions/curses.d.ts +1 -1
  19. package/dist/src/functions/curses.lua +1 -1
  20. package/dist/src/functions/deepCopy.d.ts +2 -1
  21. package/dist/src/functions/deepCopy.d.ts.map +1 -1
  22. package/dist/src/functions/deepCopy.lua +19 -25
  23. package/dist/src/functions/deepCopyTests.lua +13 -26
  24. package/dist/src/functions/entities.d.ts +1 -1
  25. package/dist/src/functions/globals.d.ts +1 -1
  26. package/dist/src/functions/jsonHelpers.d.ts +1 -1
  27. package/dist/src/functions/kColor.d.ts +3 -4
  28. package/dist/src/functions/kColor.d.ts.map +1 -1
  29. package/dist/src/functions/kColor.lua +2 -2
  30. package/dist/src/functions/log.d.ts +2 -2
  31. package/dist/src/functions/log.d.ts.map +1 -1
  32. package/dist/src/functions/positionVelocity.d.ts +2 -0
  33. package/dist/src/functions/positionVelocity.d.ts.map +1 -1
  34. package/dist/src/functions/positionVelocity.lua +2 -0
  35. package/dist/src/functions/rng.d.ts +3 -3
  36. package/dist/src/functions/rng.d.ts.map +1 -1
  37. package/dist/src/functions/serialization.d.ts +11 -4
  38. package/dist/src/functions/serialization.d.ts.map +1 -1
  39. package/dist/src/functions/serialization.lua +15 -0
  40. package/dist/src/functions/table.d.ts +4 -4
  41. package/dist/src/functions/table.d.ts.map +1 -1
  42. package/dist/src/functions/table.lua +8 -4
  43. package/dist/src/functions/tstlClass.d.ts +1 -1
  44. package/dist/src/functions/types.d.ts +1 -1
  45. package/dist/src/functions/vector.d.ts +3 -2
  46. package/dist/src/functions/vector.d.ts.map +1 -1
  47. package/dist/src/functions/vector.lua +2 -2
  48. package/dist/src/functions/weighted.d.ts +6 -0
  49. package/dist/src/functions/weighted.d.ts.map +1 -0
  50. package/dist/src/functions/weighted.lua +35 -0
  51. package/dist/src/index.d.ts +2 -1
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/dist/src/index.lua +8 -0
  54. package/dist/src/interfaces/SaveData.d.ts +3 -8
  55. package/dist/src/interfaces/SaveData.d.ts.map +1 -1
  56. package/dist/src/interfaces/private/TSTLClassMetatable.d.ts +1 -1
  57. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts +1 -1
  58. package/dist/src/objects/isaacAPIClassTypeToBrand.d.ts.map +1 -1
  59. package/dist/src/objects/isaacAPIClassTypeToBrand.lua +2 -2
  60. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts +36 -8
  61. package/dist/src/objects/isaacAPIClassTypeToFunctions.d.ts.map +1 -1
  62. package/dist/src/objects/isaacAPIClassTypeToFunctions.lua +42 -7
  63. package/dist/src/types/TSTLClass.d.ts +1 -1
  64. package/dist/src/types/WeightedArray.d.ts +4 -0
  65. package/dist/src/types/WeightedArray.d.ts.map +1 -0
  66. package/dist/src/types/{SerializedIsaacAPIClass.lua → WeightedArray.lua} +0 -0
  67. package/package.json +2 -2
  68. package/src/features/deployJSONRoom.ts +16 -6
  69. package/src/features/saveDataManager/exports.ts +1 -1
  70. package/src/functions/bitSet128.ts +8 -2
  71. package/src/functions/color.ts +8 -2
  72. package/src/functions/curses.ts +1 -1
  73. package/src/functions/deepCopy.ts +25 -15
  74. package/src/functions/deepCopyTests.ts +19 -41
  75. package/src/functions/initArray.ts +1 -1
  76. package/src/functions/kColor.ts +8 -2
  77. package/src/functions/log.ts +8 -6
  78. package/src/functions/positionVelocity.ts +2 -0
  79. package/src/functions/rng.ts +2 -0
  80. package/src/functions/serialization.ts +72 -18
  81. package/src/functions/table.ts +15 -6
  82. package/src/functions/vector.ts +11 -3
  83. package/src/functions/weighted.ts +36 -0
  84. package/src/index.ts +2 -1
  85. package/src/interfaces/SaveData.ts +4 -3
  86. package/src/objects/isaacAPIClassTypeToBrand.ts +1 -1
  87. package/src/objects/isaacAPIClassTypeToFunctions.ts +58 -9
  88. package/src/types/WeightedArray.ts +2 -0
  89. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts +0 -12
  90. package/dist/src/enums/private/CopyableIsaacAPIClassType.d.ts.map +0 -1
  91. package/dist/src/enums/private/CopyableIsaacAPIClassType.lua +0 -10
  92. package/dist/src/types/SerializedIsaacAPIClass.d.ts +0 -11
  93. package/dist/src/types/SerializedIsaacAPIClass.d.ts.map +0 -1
  94. package/src/enums/private/CopyableIsaacAPIClassType.ts +0 -11
  95. package/src/types/SerializedIsaacAPIClass.ts +0 -9
@@ -1,7 +1,7 @@
1
1
  /// <reference types="lua-types/5.3" />
2
2
  /// <reference types="lua-types/5.3" />
3
3
  /// <reference types="lua-types/5.3" />
4
- /// <reference types="typescript-to-lua/language-extensions" />
4
+ /// <reference types="@typescript-to-lua/language-extensions" />
5
5
  export interface TSTLClassMetatable {
6
6
  ____constructor: () => void;
7
7
  __index: unknown;
@@ -1,4 +1,4 @@
1
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
3
  export declare const ISAAC_API_CLASS_TYPE_TO_BRAND: {
4
4
  readonly [key in CopyableIsaacAPIClassType]: SerializationBrand;
@@ -1 +1 @@
1
- {"version":3,"file":"isaacAPIClassTypeToBrand.d.ts","sourceRoot":"","sources":["../../../src/objects/isaacAPIClassTypeToBrand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,eAAO,MAAM,6BAA6B,EAAE;IAC1C,QAAQ,EAAE,GAAG,IAAI,yBAAyB,GAAG,kBAAkB;CAOvD,CAAC"}
1
+ {"version":3,"file":"isaacAPIClassTypeToBrand.d.ts","sourceRoot":"","sources":["../../../src/objects/isaacAPIClassTypeToBrand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,eAAO,MAAM,6BAA6B,EAAE;IAC1C,QAAQ,EAAE,GAAG,IAAI,yBAAyB,GAAG,kBAAkB;CAOvD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  local ____exports = {}
2
- local ____CopyableIsaacAPIClassType = require("src.enums.private.CopyableIsaacAPIClassType")
3
- local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
2
+ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
3
+ local CopyableIsaacAPIClassType = ____isaac_2Dtypescript_2Ddefinitions.CopyableIsaacAPIClassType
4
4
  local ____SerializationBrand = require("src.enums.private.SerializationBrand")
5
5
  local SerializationBrand = ____SerializationBrand.SerializationBrand
6
6
  ____exports.ISAAC_API_CLASS_TYPE_TO_BRAND = {
@@ -1,12 +1,40 @@
1
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
2
- interface IsaacAPIClassTypeFunctions {
3
- isSerialized: (object: unknown) => object is unknown;
4
- copy: (object: any) => any;
5
- serialize: (object: any) => any;
6
- deserialize: (object: any) => any;
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
+ import { SerializedBitSet128 } from "../functions/bitSet128";
3
+ import { SerializedColor } from "../functions/color";
4
+ import { SerializedKColor } from "../functions/kColor";
5
+ import { SerializedRNG } from "../functions/rng";
6
+ import { SerializedVector } from "../functions/vector";
7
+ /** A type representing an Isaac API class that can be safely copied or serialized. */
8
+ export declare type CopyableIsaacAPIClass = BitSet128 | Color | KColor | RNG | Vector;
9
+ /**
10
+ * A type representing an Isaac API class like `Color` or `RNG` that has been written to the
11
+ * "save#.dat" file. It is used by the save data manager when reading and writing to that file.
12
+ *
13
+ * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
14
+ */
15
+ export declare type SerializedIsaacAPIClass = SerializedBitSet128 | SerializedColor | SerializedKColor | SerializedRNG | SerializedVector;
16
+ export interface IsaacAPIClassTypeToType {
17
+ [CopyableIsaacAPIClassType.BIT_SET_128]: BitSet128;
18
+ [CopyableIsaacAPIClassType.COLOR]: Color;
19
+ [CopyableIsaacAPIClassType.K_COLOR]: KColor;
20
+ [CopyableIsaacAPIClassType.RNG]: RNG;
21
+ [CopyableIsaacAPIClassType.VECTOR]: Vector;
22
+ }
23
+ export interface IsaacAPIClassTypeToSerializedType {
24
+ [CopyableIsaacAPIClassType.BIT_SET_128]: SerializedBitSet128;
25
+ [CopyableIsaacAPIClassType.COLOR]: SerializedColor;
26
+ [CopyableIsaacAPIClassType.K_COLOR]: SerializedKColor;
27
+ [CopyableIsaacAPIClassType.RNG]: SerializedRNG;
28
+ [CopyableIsaacAPIClassType.VECTOR]: SerializedVector;
29
+ }
30
+ export interface IsaacAPIClassTypeFunctions<T, SerializedT> {
31
+ is: (object: unknown) => object is T;
32
+ isSerialized: (object: unknown) => object is SerializedT;
33
+ copy: (object: T) => T;
34
+ serialize: (object: T) => SerializedT;
35
+ deserialize: (object: SerializedT) => T;
7
36
  }
8
37
  export declare const ISAAC_API_CLASS_TYPE_TO_FUNCTIONS: {
9
- readonly [key in CopyableIsaacAPIClassType]: IsaacAPIClassTypeFunctions;
38
+ readonly [key in CopyableIsaacAPIClassType]: IsaacAPIClassTypeFunctions<IsaacAPIClassTypeToType[key], IsaacAPIClassTypeToSerializedType[key]>;
10
39
  };
11
- export {};
12
40
  //# sourceMappingURL=isaacAPIClassTypeToFunctions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isaacAPIClassTypeToFunctions.d.ts","sourceRoot":"","sources":["../../../src/objects/isaacAPIClassTypeToFunctions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAgCvF,UAAU,0BAA0B;IAClC,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,IAAI,OAAO,CAAC;IACrD,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC3B,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAED,eAAO,MAAM,iCAAiC,EAAE;IAC9C,QAAQ,EAAE,GAAG,IAAI,yBAAyB,GAAG,0BAA0B;CAgC/D,CAAC"}
1
+ {"version":3,"file":"isaacAPIClassTypeToFunctions.d.ts","sourceRoot":"","sources":["../../../src/objects/isaacAPIClassTypeToFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAML,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAML,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAKL,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;AAE7B,sFAAsF;AACtF,oBAAY,qBAAqB,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;AAE9E;;;;;GAKG;AACH,oBAAY,uBAAuB,GAC/B,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,aAAa,GACb,gBAAgB,CAAC;AAErB,MAAM,WAAW,uBAAuB;IACtC,CAAC,yBAAyB,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC;IACnD,CAAC,yBAAyB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACzC,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC5C,CAAC,yBAAyB,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;IACrC,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC5C;AAED,MAAM,WAAW,iCAAiC;IAChD,CAAC,yBAAyB,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAC7D,CAAC,yBAAyB,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACnD,CAAC,yBAAyB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACtD,CAAC,yBAAyB,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC;IAC/C,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACtD;AAED,MAAM,WAAW,0BAA0B,CAAC,CAAC,EAAE,WAAW;IACxD,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC;IACrC,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,IAAI,WAAW,CAAC;IACzD,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;IACvB,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,WAAW,CAAC;IACtC,WAAW,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,CAAC;CACzC;AAED,eAAO,MAAM,iCAAiC,EAAE;IAC9C,QAAQ,EAAE,GAAG,IAAI,yBAAyB,GAAG,0BAA0B,CACrE,uBAAuB,CAAC,GAAG,CAAC,EAC5B,iCAAiC,CAAC,GAAG,CAAC,CACvC;CAqCO,CAAC"}
@@ -1,36 +1,71 @@
1
1
  local ____exports = {}
2
- local ____CopyableIsaacAPIClassType = require("src.enums.private.CopyableIsaacAPIClassType")
3
- local CopyableIsaacAPIClassType = ____CopyableIsaacAPIClassType.CopyableIsaacAPIClassType
2
+ local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
3
+ local CopyableIsaacAPIClassType = ____isaac_2Dtypescript_2Ddefinitions.CopyableIsaacAPIClassType
4
4
  local ____bitSet128 = require("src.functions.bitSet128")
5
5
  local copyBitSet128 = ____bitSet128.copyBitSet128
6
6
  local deserializeBitSet128 = ____bitSet128.deserializeBitSet128
7
+ local isBitSet128 = ____bitSet128.isBitSet128
7
8
  local isSerializedBitSet128 = ____bitSet128.isSerializedBitSet128
8
9
  local serializeBitSet128 = ____bitSet128.serializeBitSet128
9
10
  local ____color = require("src.functions.color")
10
11
  local copyColor = ____color.copyColor
11
12
  local deserializeColor = ____color.deserializeColor
13
+ local isColor = ____color.isColor
12
14
  local isSerializedColor = ____color.isSerializedColor
13
15
  local serializeColor = ____color.serializeColor
14
16
  local ____kColor = require("src.functions.kColor")
15
17
  local copyKColor = ____kColor.copyKColor
16
18
  local deserializeKColor = ____kColor.deserializeKColor
19
+ local isKColor = ____kColor.isKColor
17
20
  local isSerializedKColor = ____kColor.isSerializedKColor
18
21
  local serializeKColor = ____kColor.serializeKColor
19
22
  local ____rng = require("src.functions.rng")
20
23
  local copyRNG = ____rng.copyRNG
21
24
  local deserializeRNG = ____rng.deserializeRNG
25
+ local isRNG = ____rng.isRNG
22
26
  local isSerializedRNG = ____rng.isSerializedRNG
23
27
  local serializeRNG = ____rng.serializeRNG
24
28
  local ____vector = require("src.functions.vector")
25
29
  local copyVector = ____vector.copyVector
26
30
  local deserializeVector = ____vector.deserializeVector
27
31
  local isSerializedVector = ____vector.isSerializedVector
32
+ local isVector = ____vector.isVector
28
33
  local serializeVector = ____vector.serializeVector
29
34
  ____exports.ISAAC_API_CLASS_TYPE_TO_FUNCTIONS = {
30
- [CopyableIsaacAPIClassType.BIT_SET_128] = {isSerialized = isSerializedBitSet128, copy = copyBitSet128, serialize = serializeBitSet128, deserialize = deserializeBitSet128},
31
- [CopyableIsaacAPIClassType.COLOR] = {isSerialized = isSerializedColor, copy = copyColor, serialize = serializeColor, deserialize = deserializeColor},
32
- [CopyableIsaacAPIClassType.K_COLOR] = {isSerialized = isSerializedKColor, copy = copyKColor, serialize = serializeKColor, deserialize = deserializeKColor},
33
- [CopyableIsaacAPIClassType.RNG] = {isSerialized = isSerializedRNG, copy = copyRNG, serialize = serializeRNG, deserialize = deserializeRNG},
34
- [CopyableIsaacAPIClassType.VECTOR] = {isSerialized = isSerializedVector, copy = copyVector, serialize = serializeVector, deserialize = deserializeVector}
35
+ [CopyableIsaacAPIClassType.BIT_SET_128] = {
36
+ is = isBitSet128,
37
+ isSerialized = isSerializedBitSet128,
38
+ copy = copyBitSet128,
39
+ serialize = serializeBitSet128,
40
+ deserialize = deserializeBitSet128
41
+ },
42
+ [CopyableIsaacAPIClassType.COLOR] = {
43
+ is = isColor,
44
+ isSerialized = isSerializedColor,
45
+ copy = copyColor,
46
+ serialize = serializeColor,
47
+ deserialize = deserializeColor
48
+ },
49
+ [CopyableIsaacAPIClassType.K_COLOR] = {
50
+ is = isKColor,
51
+ isSerialized = isSerializedKColor,
52
+ copy = copyKColor,
53
+ serialize = serializeKColor,
54
+ deserialize = deserializeKColor
55
+ },
56
+ [CopyableIsaacAPIClassType.RNG] = {
57
+ is = isRNG,
58
+ isSerialized = isSerializedRNG,
59
+ copy = copyRNG,
60
+ serialize = serializeRNG,
61
+ deserialize = deserializeRNG
62
+ },
63
+ [CopyableIsaacAPIClassType.VECTOR] = {
64
+ is = isVector,
65
+ isSerialized = isSerializedVector,
66
+ copy = copyVector,
67
+ serialize = serializeVector,
68
+ deserialize = deserializeVector
69
+ }
35
70
  }
36
71
  return ____exports
@@ -1,4 +1,4 @@
1
- /// <reference types="typescript-to-lua/language-extensions" />
1
+ /// <reference types="@typescript-to-lua/language-extensions" />
2
2
  /**
3
3
  * This is a type representing a user-created class from TypeScript code.
4
4
  *
@@ -0,0 +1,4 @@
1
+ /// <reference types="isaac-typescript-definitions" />
2
+ /** An array where each element is paired with a number indicating that elements 'weight'. */
3
+ export declare type WeightedArray<T> = Array<[T, float]>;
4
+ //# sourceMappingURL=WeightedArray.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WeightedArray.d.ts","sourceRoot":"","sources":["../../../src/types/WeightedArray.ts"],"names":[],"mappings":";AAAA,6FAA6F;AAC7F,oBAAY,aAAa,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "9.20.0",
3
+ "version": "10.0.2",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -22,6 +22,6 @@
22
22
  "main": "dist/src/index",
23
23
  "types": "dist/src/index.d.ts",
24
24
  "dependencies": {
25
- "isaac-typescript-definitions": "^6.0.0"
25
+ "isaac-typescript-definitions": "^7.2.0"
26
26
  }
27
27
  }
@@ -225,16 +225,21 @@ function respawnPersistentEntities() {
225
225
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
226
226
  * all of the entries and grid entities in the provided JSON room.
227
227
  *
228
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
229
+ * my-rooms.xml`).
230
+ *
228
231
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
229
232
  *
230
233
  * For example:
231
234
  *
232
235
  * ```ts
233
236
  *
234
- * import customRooms from "./customRooms";
237
+ * import customRooms from "./customRooms.json";
235
238
  *
236
- * const firstJSONRoom = customRooms.rooms.room[0];
237
- * deployJSONRoom(firstJSONRoom);
239
+ * export function postNewRoom(): void {
240
+ * const firstJSONRoom = customRooms.rooms.room[0];
241
+ * deployJSONRoom(firstJSONRoom);
242
+ * }
238
243
  * ```
239
244
  *
240
245
  * @param jsonRoom The JSON room to deploy. *
@@ -277,6 +282,9 @@ export function deployJSONRoom(
277
282
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
278
283
  * all of the entries and grid entities in one of the provided JSON rooms.
279
284
  *
285
+ * You can create JSON rooms by using the `convert-xml-to-json` tool (e.g. `npx convert-xml-to-json
286
+ * my-rooms.xml`).
287
+ *
280
288
  * This function is meant to be used in the `POST_NEW_ROOM` callback.
281
289
  *
282
290
  * Note that this function does not simply choose a random element in the provided array; it will
@@ -286,10 +294,12 @@ export function deployJSONRoom(
286
294
  * For example:
287
295
  *
288
296
  * ```ts
289
- * import customRooms from "./customRooms";
297
+ * import customRooms from "./customRooms.json";
290
298
  *
291
- * const jsonRooms = customRooms.rooms.room;
292
- * deployRandomJSONRoom(jsonRooms);
299
+ * export function postNewRoom(): void {
300
+ * const jsonRooms = customRooms.rooms.room;
301
+ * deployRandomJSONRoom(jsonRooms);
302
+ * }
293
303
  * ```
294
304
  *
295
305
  * @param jsonRooms An array of JSON rooms to randomly select from. In practice, this will be
@@ -153,7 +153,7 @@ export function saveDataManager<Persistent, Run, Level>(
153
153
 
154
154
  // Make a copy of the initial save data so that we can use it to restore the default values later
155
155
  // on.
156
- const saveDataCopy = deepCopy(v, SerializationType.NONE, key) as typeof v;
156
+ const saveDataCopy = deepCopy(v, SerializationType.NONE, key);
157
157
  saveDataDefaultsMap.set(key, saveDataCopy);
158
158
 
159
159
  // Store the conditional function for later, if present.
@@ -1,10 +1,16 @@
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
1
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
2
3
  import { isIsaacAPIClassOfType } from "./isaacAPIClass";
3
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
4
+ import {
5
+ copyUserdataValuesToTable,
6
+ getNumbersFromTable,
7
+ tableHasKeys,
8
+ } from "./table";
4
9
  import { isTable } from "./types";
5
10
 
6
11
  export type SerializedBitSet128 = LuaMap<string, unknown> & {
7
12
  readonly __serializedBitSet128Brand: symbol;
13
+ readonly __kind: CopyableIsaacAPIClassType.BIT_SET_128;
8
14
  };
9
15
 
10
16
  const OBJECT_NAME = "BitSet128";
@@ -86,7 +92,7 @@ export function serializeBitSet128(bitSet128: BitSet128): SerializedBitSet128 {
86
92
  }
87
93
 
88
94
  const bitSet128Table = new LuaMap<string, unknown>();
89
- copyValuesToTable(bitSet128, KEYS, bitSet128Table);
95
+ copyUserdataValuesToTable(bitSet128, KEYS, bitSet128Table);
90
96
  bitSet128Table.set(SerializationBrand.BIT_SET_128, "");
91
97
  return bitSet128Table as SerializedBitSet128;
92
98
  }
@@ -1,12 +1,18 @@
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
1
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
2
3
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
3
4
  import { getRandom } from "./random";
4
5
  import { getRandomSeed, isRNG, newRNG } from "./rng";
5
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
6
+ import {
7
+ copyUserdataValuesToTable,
8
+ getNumbersFromTable,
9
+ tableHasKeys,
10
+ } from "./table";
6
11
  import { isTable } from "./types";
7
12
 
8
13
  export type SerializedColor = LuaMap<string, unknown> & {
9
14
  readonly __serializedColorBrand: symbol;
15
+ readonly __kind: CopyableIsaacAPIClassType.COLOR;
10
16
  };
11
17
 
12
18
  const OBJECT_NAME = "Color";
@@ -120,7 +126,7 @@ export function serializeColor(color: Color): SerializedColor {
120
126
  }
121
127
 
122
128
  const colorTable = new LuaMap<string, unknown>();
123
- copyValuesToTable(color, KEYS, colorTable);
129
+ copyUserdataValuesToTable(color, KEYS, colorTable);
124
130
  colorTable.set(SerializationBrand.COLOR, "");
125
131
  return colorTable as SerializedColor;
126
132
  }
@@ -5,7 +5,7 @@ import { hasFlag } from "./flag";
5
5
  /**
6
6
  * Helper function to get the actual bit flag for modded curses.
7
7
  *
8
- * Will throw a runtime error if the provided curse does not exist.
8
+ * Will throw a run-time error if the provided curse does not exist.
9
9
  *
10
10
  * Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
11
11
  * a bit flag.
@@ -1,17 +1,16 @@
1
1
  import { DefaultMap } from "../classes/DefaultMap";
2
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
3
2
  import { SerializationBrand } from "../enums/private/SerializationBrand";
4
3
  import { SerializationType } from "../enums/SerializationType";
5
4
  import { SAVE_DATA_MANAGER_DEBUG } from "../features/saveDataManager/saveDataManagerConstants";
6
5
  import { isSerializationBrand } from "../features/saveDataManager/serializationBrands";
7
6
  import { TSTLClass } from "../types/TSTLClass";
8
7
  import { isArray } from "./array";
9
- import { getEnumValues } from "./enums";
10
8
  import { getIsaacAPIClassName } from "./isaacAPIClass";
11
9
  import { log } from "./log";
12
10
  import {
13
11
  copyIsaacAPIClass,
14
12
  deserializeIsaacAPIClass,
13
+ isCopyableIsaacAPIClass,
15
14
  isSerializedIsaacAPIClass,
16
15
  serializeIsaacAPIClass,
17
16
  } from "./serialization";
@@ -26,10 +25,6 @@ import {
26
25
  import { asString, isNumber, isPrimitive } from "./types";
27
26
  import { getTraversalDescription, twoDimensionalSort } from "./utils";
28
27
 
29
- const COPYABLE_ISAAC_API_CLASS_TYPES_SET = new Set<string>(
30
- getEnumValues(CopyableIsaacAPIClassType),
31
- );
32
-
33
28
  /**
34
29
  * `deepCopy` is a semi-generic deep cloner. It will recursively copy all of the values so that none
35
30
  * of the nested references remain.
@@ -64,6 +59,18 @@ const COPYABLE_ISAAC_API_CLASS_TYPES_SET = new Set<string>(
64
59
  * @param insideMap Optional. Tracks whether or not the deep copy function is in the process of
65
60
  * recursively copying a TSTL Map. Default is false.
66
61
  */
62
+ export function deepCopy<T>(
63
+ value: T,
64
+ serializationType?: SerializationType.NONE,
65
+ traversalDescription?: string,
66
+ insideMap?: boolean,
67
+ ): T;
68
+ export function deepCopy(
69
+ value: unknown,
70
+ serializationType: SerializationType,
71
+ traversalDescription?: string,
72
+ insideMap?: boolean,
73
+ ): unknown; // The return types for serialization/deserialization are non-trivial, so we do not type them.
67
74
  export function deepCopy(
68
75
  value: unknown,
69
76
  serializationType = SerializationType.NONE,
@@ -101,6 +108,12 @@ export function deepCopy(
101
108
  );
102
109
  }
103
110
 
111
+ if (serializationType === SerializationType.DESERIALIZE) {
112
+ error(
113
+ `The deep copy function does not support deserialization of "${traversalDescription}", since it is type: ${valueType}`,
114
+ );
115
+ }
116
+
104
117
  // We cannot copy this, so simply return the reference.
105
118
  return value;
106
119
  }
@@ -126,7 +139,7 @@ function deepCopyTable(
126
139
  serializationType: SerializationType,
127
140
  traversalDescription: string,
128
141
  insideMap: boolean,
129
- ) {
142
+ ): unknown {
130
143
  // First, handle the cases of TSTL classes or serialized TSTL classes.
131
144
  if (isDefaultMap(luaMap) || luaMap.has(SerializationBrand.DEFAULT_MAP)) {
132
145
  return deepCopyDefaultMap(
@@ -651,11 +664,6 @@ function deepCopyUserdata(
651
664
  serializationType: SerializationType,
652
665
  traversalDescription: string,
653
666
  ) {
654
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
655
- if (SAVE_DATA_MANAGER_DEBUG) {
656
- log("deepCopy is copying userdata.");
657
- }
658
-
659
667
  const classType = getIsaacAPIClassName(value);
660
668
  if (classType === undefined) {
661
669
  error(
@@ -663,9 +671,9 @@ function deepCopyUserdata(
663
671
  );
664
672
  }
665
673
 
666
- if (!COPYABLE_ISAAC_API_CLASS_TYPES_SET.has(classType)) {
674
+ if (!isCopyableIsaacAPIClass(value)) {
667
675
  error(
668
- `The deep copy function does not support copying "${traversalDescription}", since it is an Isaac API class of type: ${classType}`,
676
+ `The deep copy function does not support serializing "${traversalDescription}", since it is an Isaac API class of type: ${classType}`,
669
677
  );
670
678
  }
671
679
 
@@ -679,7 +687,9 @@ function deepCopyUserdata(
679
687
  }
680
688
 
681
689
  case SerializationType.DESERIALIZE: {
682
- return deserializeIsaacAPIClass(value);
690
+ error(
691
+ `The deep copy function can not deserialize "${traversalDescription}", since it is userdata.`,
692
+ );
683
693
  }
684
694
  }
685
695
  }
@@ -49,7 +49,7 @@ function copiedObjectIsTable() {
49
49
  abc: "def",
50
50
  };
51
51
  const newObject = deepCopy(
52
- oldObject as unknown as LuaMap,
52
+ oldObject,
53
53
  SerializationType.NONE,
54
54
  "copiedObjectIsTable",
55
55
  );
@@ -64,12 +64,11 @@ function copiedObjectHasKeyAndValueString() {
64
64
  const oldObject = {
65
65
  abc: valueToLookFor,
66
66
  };
67
- const newTable = deepCopy(
68
- oldObject as unknown as LuaMap,
67
+ const newObject = deepCopy(
68
+ oldObject,
69
69
  SerializationType.NONE,
70
70
  "copiedObjectHasKeyAndValueString",
71
71
  );
72
- const newObject = newTable as typeof oldObject;
73
72
 
74
73
  const value = newObject[keyToLookFor];
75
74
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -91,12 +90,11 @@ function copiedTableHasKeyAndValueNumber() {
91
90
  const oldTable = new LuaMap<AnyNotNil, unknown>();
92
91
  oldTable.set(keyToLookFor, valueToLookFor);
93
92
 
94
- const newObject = deepCopy(
93
+ const newTable = deepCopy(
95
94
  oldTable,
96
95
  SerializationType.NONE,
97
96
  "copiedTableHasKeyAndValueNumber",
98
97
  );
99
- const newTable = newObject as LuaMap<AnyNotNil, unknown>;
100
98
 
101
99
  const value = newTable.get(keyToLookFor) as number | undefined;
102
100
  if (value === undefined) {
@@ -117,12 +115,11 @@ function copiedTableDoesNotCoerceTypes() {
117
115
  const oldTable = new LuaMap<AnyNotNil, unknown>();
118
116
  oldTable.set(keyToLookFor, valueToLookFor);
119
117
 
120
- const newObject = deepCopy(
118
+ const newTable = deepCopy(
121
119
  oldTable,
122
120
  SerializationType.NONE,
123
121
  "copiedTableDoesNotCoerceTypes",
124
122
  );
125
- const newTable = newObject as LuaMap<AnyNotNil, unknown>;
126
123
 
127
124
  const keyString = tostring(keyToLookFor);
128
125
  const valueString = tostring(valueToLookFor);
@@ -148,12 +145,11 @@ function copiedObjectHasNoReferencesForPrimitivesForward() {
148
145
  abc: originalStringValue,
149
146
  def: originalNumberValue,
150
147
  };
151
- const newTable = deepCopy(
152
- oldObject as unknown as LuaMap,
148
+ const newObject = deepCopy(
149
+ oldObject,
153
150
  SerializationType.NONE,
154
151
  "copiedObjectHasNoReferencesForPrimitivesForward",
155
152
  );
156
- const newObject = newTable as typeof oldObject;
157
153
 
158
154
  oldObject.abc = "newValue";
159
155
  if (oldObject.abc === newObject.abc) {
@@ -173,12 +169,11 @@ function copiedObjectHasNoReferencesForPrimitivesBackward() {
173
169
  abc: originalStringValue,
174
170
  def: originalNumberValue,
175
171
  };
176
- const newTable = deepCopy(
177
- oldObject as unknown as LuaMap,
172
+ const newObject = deepCopy(
173
+ oldObject,
178
174
  SerializationType.NONE,
179
175
  "copiedObjectHasNoReferencesForPrimitivesBackward",
180
176
  );
181
- const newObject = newTable as typeof oldObject;
182
177
 
183
178
  newObject.abc = "newValue";
184
179
  if (newObject.abc === oldObject.abc) {
@@ -196,12 +191,11 @@ function copiedObjectHasNoReferencesForArray() {
196
191
  const oldObject = {
197
192
  abc: [1, 2, 3],
198
193
  };
199
- const newTable = deepCopy(
200
- oldObject as unknown as LuaMap,
194
+ const newObject = deepCopy(
195
+ oldObject,
201
196
  SerializationType.NONE,
202
197
  "copiedObjectHasNoReferencesForArray",
203
198
  );
204
- const newObject = newTable as typeof oldObject;
205
199
 
206
200
  if (oldObject.abc === newObject.abc) {
207
201
  error("The copied object has the same point to the child array.");
@@ -237,12 +231,11 @@ function copiedObjectHasChildObject() {
237
231
  def: valueToLookFor,
238
232
  },
239
233
  };
240
- const newTable = deepCopy(
241
- oldObject as unknown as LuaMap,
234
+ const newObject = deepCopy(
235
+ oldObject,
242
236
  SerializationType.NONE,
243
237
  "copiedObjectHasChildObject",
244
238
  );
245
- const newObject = newTable as typeof oldObject;
246
239
 
247
240
  const childObject = newObject[childObjectIndex];
248
241
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -274,8 +267,7 @@ function copiedMapIsMap() {
274
267
  const oldMap = new Map<string, string>();
275
268
  oldMap.set(keyToLookFor, valueToLookFor);
276
269
 
277
- const newObject = deepCopy(oldMap, SerializationType.NONE, "copiedMapIsMap");
278
- const newMap = newObject as Map<string, string>;
270
+ const newMap = deepCopy(oldMap, SerializationType.NONE, "copiedMapIsMap");
279
271
 
280
272
  if (!isTSTLMap(newMap)) {
281
273
  error(`The copied Map was not a Map and has a type of: ${typeof newMap}`);
@@ -288,13 +280,7 @@ function copiedMapHasValue() {
288
280
  const oldMap = new Map<string, string>();
289
281
  oldMap.set(keyToLookFor, valueToLookFor);
290
282
 
291
- const newTable = deepCopy(
292
- oldMap,
293
- SerializationType.NONE,
294
- "copiedMapHasValue",
295
- );
296
-
297
- const newMap = newTable as typeof oldMap;
283
+ const newMap = deepCopy(oldMap, SerializationType.NONE, "copiedMapHasValue");
298
284
 
299
285
  if (!isTSTLMap(newMap)) {
300
286
  error(`The copied Map was not a Map and has a type of: ${typeof newMap}`);
@@ -314,8 +300,7 @@ function copiedSetIsSet() {
314
300
  const oldSet = new Set<string>();
315
301
  oldSet.add(valueToLookFor);
316
302
 
317
- const newTable = deepCopy(oldSet, SerializationType.NONE, "copiedSetIsSet");
318
- const newSet = newTable as Set<string>;
303
+ const newSet = deepCopy(oldSet, SerializationType.NONE, "copiedSetIsSet");
319
304
 
320
305
  if (!isTSTLSet(newSet)) {
321
306
  error(`The copied Set was not a Set and has a type of: ${typeof newSet}`);
@@ -327,12 +312,7 @@ function copiedSetHasValue() {
327
312
  const oldSet = new Set<string>();
328
313
  oldSet.add(valueToLookFor);
329
314
 
330
- const newTable = deepCopy(
331
- oldSet,
332
- SerializationType.NONE,
333
- "copiedSetHasValue",
334
- );
335
- const newSet = newTable as Set<string>;
315
+ const newSet = deepCopy(oldSet, SerializationType.NONE, "copiedSetHasValue");
336
316
 
337
317
  if (!isTSTLSet(newSet)) {
338
318
  error(`The copied Set was not a Set and has a type of: ${typeof newSet}`);
@@ -354,12 +334,11 @@ function copiedMapHasChildMap() {
354
334
  const oldMap = new Map<string, Map<number, number>>();
355
335
  oldMap.set(keyToLookFor, oldChildMap);
356
336
 
357
- const newTable = deepCopy(
337
+ const newMap = deepCopy(
358
338
  oldMap,
359
339
  SerializationType.NONE,
360
340
  "copiedMapHasChildMap",
361
341
  );
362
- const newMap = newTable as typeof oldMap;
363
342
 
364
343
  if (!isTSTLMap(newMap)) {
365
344
  error(`The copied Map was not a Map and had a type of: ${typeof newMap}`);
@@ -398,12 +377,11 @@ function copiedDefaultMapHasChildDefaultMap() {
398
377
  oldChildMap.getAndSetDefault(childMapKey1);
399
378
  oldChildMap.set(childMapKey2, childMapCustomValue);
400
379
 
401
- const newTable = deepCopy(
380
+ const newParentMap = deepCopy(
402
381
  oldParentMap,
403
382
  SerializationType.NONE,
404
383
  "copiedDefaultMapHasChildDefaultMap",
405
384
  );
406
- const newParentMap = newTable as typeof oldParentMap;
407
385
 
408
386
  if (!isDefaultMap(newParentMap)) {
409
387
  error(
@@ -23,7 +23,7 @@ export function initArray<T>(defaultValue: T, size: int): T[] {
23
23
  if (isPrimitive(defaultValue)) {
24
24
  array.push(defaultValue);
25
25
  } else {
26
- const copy = deepCopy(defaultValue) as T;
26
+ const copy = deepCopy(defaultValue);
27
27
  array.push(copy);
28
28
  }
29
29
  });