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,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 SerializedKColor = LuaMap<string, unknown> & {
9
14
  readonly __serializedKColorBrand: symbol;
15
+ readonly __kind: CopyableIsaacAPIClassType.K_COLOR;
10
16
  };
11
17
 
12
18
  const OBJECT_NAME = "KColor";
@@ -117,7 +123,7 @@ export function serializeKColor(kColor: KColor): SerializedKColor {
117
123
  }
118
124
 
119
125
  const kColorTable = new LuaMap<string, unknown>();
120
- copyValuesToTable(kColor, KEYS, kColorTable);
126
+ copyUserdataValuesToTable(kColor, KEYS, kColorTable);
121
127
  kColorTable.set(SerializationBrand.K_COLOR, "");
122
128
  return kColorTable as SerializedKColor;
123
129
  }
@@ -402,7 +402,7 @@ export function logTable(luaTable: unknown, parentTables = 0): void {
402
402
  * Helper function to print out the differences between the entries of two tables. Note that this
403
403
  * will only do a shallow comparison.
404
404
  */
405
- export function logTableDifferences<K, V>(
405
+ export function logTableDifferences<K extends AnyNotNil, V>(
406
406
  table1: LuaMap<K, V>,
407
407
  table2: LuaMap<K, V>,
408
408
  ): void {
@@ -420,13 +420,17 @@ export function logTableDifferences<K, V>(
420
420
 
421
421
  for (const key of keys) {
422
422
  if (!table1KeysSet.has(key)) {
423
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
423
424
  log(` Table 1 is missing key: ${key}`);
424
425
  } else if (!table2KeysSet.has(key)) {
426
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
425
427
  log(` Table 2 is missing key: ${key}`);
426
428
  } else {
427
- const value1 = table1.get(key as unknown as K);
428
- const value2 = table2.get(key as unknown as K);
429
+ const value1 = table1.get(key);
430
+
431
+ const value2 = table2.get(key);
429
432
  if (value1 !== value2) {
433
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
430
434
  log(` ${key} --> "${value1}" versus "${value2}"`);
431
435
  }
432
436
  }
@@ -453,9 +457,7 @@ export function logUserdata(userdata: unknown): void {
453
457
  return;
454
458
  }
455
459
 
456
- const metatable = getmetatable(userdata) as
457
- | LuaMap<AnyNotNil, unknown>
458
- | undefined;
460
+ const metatable = getmetatable(userdata);
459
461
  if (metatable === undefined) {
460
462
  log("Userdata: [no metatable]");
461
463
  return;
@@ -47,6 +47,8 @@ export function anyPlayerCloserThan(
47
47
  * @param startingPosition The position to start searching from. If this position is not overlapping
48
48
  * with anything, then it will be returned.
49
49
  * @param avoidActiveEntities Optional. Default is false.
50
+ * @param minimumDistance Optional. If specified, will ensure that the randomly generated position
51
+ * is equal to or greater than the distance provided.
50
52
  */
51
53
  export function findFreePosition(
52
54
  startingPosition: Vector,
@@ -1,3 +1,4 @@
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
1
2
  import { game } from "../core/cachedClasses";
2
3
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
4
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
@@ -6,6 +7,7 @@ import { isTable } from "./types";
6
7
 
7
8
  export type SerializedRNG = LuaMap<string, unknown> & {
8
9
  readonly __serializedRNGBrand: symbol;
10
+ readonly __kind: CopyableIsaacAPIClassType.RNG;
9
11
  };
10
12
 
11
13
  /**
@@ -1,7 +1,13 @@
1
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
2
2
  import { ISAAC_API_CLASS_TYPE_TO_BRAND } from "../objects/isaacAPIClassTypeToBrand";
3
- import { ISAAC_API_CLASS_TYPE_TO_FUNCTIONS } from "../objects/isaacAPIClassTypeToFunctions";
4
- import { SerializedIsaacAPIClass } from "../types/SerializedIsaacAPIClass";
3
+ import {
4
+ CopyableIsaacAPIClass,
5
+ IsaacAPIClassTypeFunctions,
6
+ IsaacAPIClassTypeToSerializedType,
7
+ IsaacAPIClassTypeToType,
8
+ ISAAC_API_CLASS_TYPE_TO_FUNCTIONS,
9
+ SerializedIsaacAPIClass,
10
+ } from "../objects/isaacAPIClassTypeToFunctions";
5
11
  import { getIsaacAPIClassName } from "./isaacAPIClass";
6
12
  import { isTable, isUserdata } from "./types";
7
13
 
@@ -11,7 +17,9 @@ import { isTable, isUserdata } from "./types";
11
17
  *
12
18
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
13
19
  */
14
- export function copyIsaacAPIClass(isaacAPIClass: unknown): unknown {
20
+ export function copyIsaacAPIClass<T extends CopyableIsaacAPIClass>(
21
+ isaacAPIClass: T,
22
+ ): T {
15
23
  if (!isUserdata(isaacAPIClass)) {
16
24
  error(
17
25
  `Failed to copy an Isaac API class since the provided object was of type: ${typeof isaacAPIClass}`,
@@ -27,9 +35,19 @@ export function copyIsaacAPIClass(isaacAPIClass: unknown): unknown {
27
35
 
28
36
  const copyableIsaacAPIClassType =
29
37
  isaacAPIClassType as CopyableIsaacAPIClassType;
30
- const functions =
31
- ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[copyableIsaacAPIClassType];
32
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
38
+
39
+ type ThisIsaacAPIClassType = T;
40
+ type ThisSerializedIsaacAPIClassType =
41
+ IsaacAPIClassTypeToSerializedType[T["__kind"]];
42
+
43
+ const functions = ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[
44
+ copyableIsaacAPIClassType
45
+ ] as unknown as
46
+ | IsaacAPIClassTypeFunctions<
47
+ ThisIsaacAPIClassType,
48
+ ThisSerializedIsaacAPIClassType
49
+ >
50
+ | undefined;
33
51
  if (functions === undefined) {
34
52
  error(
35
53
  `Failed to copy an Isaac API class since the associated functions were not found for Isaac API class type: ${copyableIsaacAPIClassType}`,
@@ -46,9 +64,11 @@ export function copyIsaacAPIClass(isaacAPIClass: unknown): unknown {
46
64
  *
47
65
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
48
66
  */
49
- export function deserializeIsaacAPIClass(
50
- serializedIsaacAPIClass: unknown,
51
- ): unknown {
67
+ export function deserializeIsaacAPIClass<
68
+ SerializedT extends SerializedIsaacAPIClass,
69
+ >(
70
+ serializedIsaacAPIClass: SerializedT,
71
+ ): IsaacAPIClassTypeToType[SerializedT["__kind"]] {
52
72
  if (!isTable(serializedIsaacAPIClass)) {
53
73
  error(
54
74
  `Failed to deserialize an Isaac API class since the provided object was of type: ${typeof serializedIsaacAPIClass}`,
@@ -64,9 +84,17 @@ export function deserializeIsaacAPIClass(
64
84
  );
65
85
  }
66
86
 
67
- const functions =
68
- ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[copyableIsaacAPIClassType];
69
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
87
+ type ThisIsaacAPIClassType = IsaacAPIClassTypeToType[SerializedT["__kind"]];
88
+ type ThisSerializedIsaacAPIClassType = SerializedT;
89
+
90
+ const functions = ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[
91
+ copyableIsaacAPIClassType
92
+ ] as unknown as
93
+ | IsaacAPIClassTypeFunctions<
94
+ ThisIsaacAPIClassType,
95
+ ThisSerializedIsaacAPIClassType
96
+ >
97
+ | undefined;
70
98
  if (functions === undefined) {
71
99
  error(
72
100
  `Failed to deserialize an Isaac API class since the associated functions were not found for class type: ${copyableIsaacAPIClassType}`,
@@ -81,7 +109,7 @@ export function deserializeIsaacAPIClass(
81
109
  * serialized table for brands.
82
110
  */
83
111
  function getSerializedTableType(
84
- serializedIsaacAPIClass: LuaMap<AnyNotNil, unknown>,
112
+ serializedIsaacAPIClass: SerializedIsaacAPIClass,
85
113
  ): CopyableIsaacAPIClassType | undefined {
86
114
  for (const [copyableIsaacAPIClassType, serializationBrand] of Object.entries(
87
115
  ISAAC_API_CLASS_TYPE_TO_BRAND,
@@ -94,6 +122,20 @@ function getSerializedTableType(
94
122
  return undefined;
95
123
  }
96
124
 
125
+ /**
126
+ * Helper function to generically check if a given object is a copyable Isaac API class. (This is
127
+ * used by the save data manager when determining what is safe to copy.)
128
+ *
129
+ * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
130
+ */
131
+ export function isCopyableIsaacAPIClass(
132
+ object: unknown,
133
+ ): object is CopyableIsaacAPIClass {
134
+ const allFunctions = Object.values(ISAAC_API_CLASS_TYPE_TO_FUNCTIONS);
135
+ const isFunctions = allFunctions.map((functions) => functions.is);
136
+ return isFunctions.some((identityFunction) => identityFunction(object));
137
+ }
138
+
97
139
  /**
98
140
  * Helper function to generically check if a given Lua table is a serialized Isaac API class. (This
99
141
  * is used by the save data manager when reading data from the "save#.dat" file.)
@@ -118,7 +160,9 @@ export function isSerializedIsaacAPIClass(
118
160
  *
119
161
  * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
120
162
  */
121
- export function serializeIsaacAPIClass(isaacAPIClass: unknown): unknown {
163
+ export function serializeIsaacAPIClass<T extends CopyableIsaacAPIClass>(
164
+ isaacAPIClass: T,
165
+ ): IsaacAPIClassTypeToSerializedType[T["__kind"]] {
122
166
  if (!isUserdata(isaacAPIClass)) {
123
167
  error(
124
168
  `Failed to serialize an Isaac API class since the provided object was of type: ${typeof isaacAPIClass}`,
@@ -134,9 +178,19 @@ export function serializeIsaacAPIClass(isaacAPIClass: unknown): unknown {
134
178
 
135
179
  const copyableIsaacAPIClassType =
136
180
  isaacAPIClassType as CopyableIsaacAPIClassType;
137
- const functions =
138
- ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[copyableIsaacAPIClassType];
139
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
181
+
182
+ type ThisIsaacAPIClassType = T;
183
+ type ThisSerializedIsaacAPIClassType =
184
+ IsaacAPIClassTypeToSerializedType[T["__kind"]];
185
+
186
+ const functions = ISAAC_API_CLASS_TYPE_TO_FUNCTIONS[
187
+ copyableIsaacAPIClassType
188
+ ] as unknown as
189
+ | IsaacAPIClassTypeFunctions<
190
+ ThisIsaacAPIClassType,
191
+ ThisSerializedIsaacAPIClassType
192
+ >
193
+ | undefined;
140
194
  if (functions === undefined) {
141
195
  error(
142
196
  `Failed to serialize an Isaac API class since the associated functions were not found for class type: ${copyableIsaacAPIClassType}`,
@@ -1,4 +1,4 @@
1
- import { isBoolean, isNumber, isString } from "./types";
1
+ import { isBoolean, isNumber, isString, isUserdata } from "./types";
2
2
 
3
3
  /**
4
4
  * In a `Map`, you can use the `clear` method to delete every element. However, in a `LuaMap`, the
@@ -10,16 +10,25 @@ export function clearTable(luaMap: LuaMap<AnyNotNil, unknown>): void {
10
10
  }
11
11
  }
12
12
 
13
- /** Helper function to copy specific values from a object to a table. */
14
- export function copyValuesToTable(
13
+ /** Helper function to copy specific values from a userdata object (e.g. `Vector`) to a table. */
14
+ export function copyUserdataValuesToTable(
15
15
  object: unknown,
16
16
  keys: string[],
17
17
  luaMap: LuaMap<string, unknown>,
18
18
  ): void {
19
- const otherTable = object as LuaMap<string, string | number>;
19
+ if (!isUserdata(object)) {
20
+ error(
21
+ `Failed to copy an object values to a table, since the object was of type: ${type(
22
+ object,
23
+ )}`,
24
+ );
25
+ }
26
+
27
+ // We can access values on userdata objects similar to a normal table.
28
+ const userdata = object as unknown as LuaMap<AnyNotNil, unknown>;
20
29
 
21
30
  for (const key of keys) {
22
- const value = otherTable.get(key);
31
+ const value = userdata.get(key);
23
32
  luaMap.set(key, value);
24
33
  }
25
34
  }
@@ -142,7 +151,7 @@ export function getStringsFromTable(
142
151
  * false in situations where iterating randomly would not matter and you need the
143
152
  * extra performance.
144
153
  */
145
- export function iterateTableInOrder<K, V>(
154
+ export function iterateTableInOrder<K extends AnyNotNil, V>(
146
155
  luaMap: LuaMap<K, V>,
147
156
  func: (key: K, value: V) => void,
148
157
  inOrder = true,
@@ -1,14 +1,22 @@
1
- import { Direction } from "isaac-typescript-definitions";
1
+ import {
2
+ CopyableIsaacAPIClassType,
3
+ Direction,
4
+ } from "isaac-typescript-definitions";
2
5
  import { SerializationBrand } from "../enums/private/SerializationBrand";
3
6
  import { angleToDirection } from "./direction";
4
7
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
5
8
  import { getRandomFloat } from "./random";
6
9
  import { getRandomSeed, isRNG, newRNG } from "./rng";
7
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
10
+ import {
11
+ copyUserdataValuesToTable,
12
+ getNumbersFromTable,
13
+ tableHasKeys,
14
+ } from "./table";
8
15
  import { isTable } from "./types";
9
16
 
10
17
  export type SerializedVector = LuaMap<string, unknown> & {
11
18
  readonly __serializedVectorBrand: symbol;
19
+ readonly __kind: CopyableIsaacAPIClassType.VECTOR;
12
20
  };
13
21
 
14
22
  const OBJECT_NAME = "Vector";
@@ -104,7 +112,7 @@ export function serializeVector(vector: Vector): SerializedVector {
104
112
  }
105
113
 
106
114
  const vectorTable = new LuaMap<string, unknown>();
107
- copyValuesToTable(vector, KEYS, vectorTable);
115
+ copyUserdataValuesToTable(vector, KEYS, vectorTable);
108
116
  vectorTable.set(SerializationBrand.VECTOR, "");
109
117
  return vectorTable as SerializedVector;
110
118
  }
@@ -0,0 +1,36 @@
1
+ import { WeightedArray } from "../types/WeightedArray";
2
+ import { arrayToString, sumArray } from "./array";
3
+ import { getRandomFloat } from "./random";
4
+ import { getRandomSeed } from "./rng";
5
+
6
+ /** Get a random value from a `WeightedArray`. (The second element in the array is the weight.) */
7
+ export function getRandomFromWeightedArray<T>(
8
+ weightedArray: WeightedArray<T>,
9
+ seedOrRNG: Seed | RNG = getRandomSeed(),
10
+ ): T {
11
+ if (weightedArray.length === 0) {
12
+ error(
13
+ "Failed to get a random element from a weighted array since the provided array was empty.",
14
+ );
15
+ }
16
+
17
+ const weights = weightedArray.map((tuple) => tuple[1]);
18
+ const totalWeight = sumArray(weights);
19
+ const randomWeight = getRandomFloat(0, totalWeight, seedOrRNG);
20
+
21
+ let weightAccumulator = 0;
22
+ for (const tuple of weightedArray) {
23
+ const [element, weight] = tuple;
24
+
25
+ weightAccumulator += weight;
26
+ if (weightAccumulator >= randomWeight) {
27
+ return element;
28
+ }
29
+ }
30
+
31
+ error(
32
+ `Failed to get a random element from a weighted array: ${arrayToString(
33
+ weightedArray,
34
+ )}`,
35
+ );
36
+ }
package/src/index.ts CHANGED
@@ -149,6 +149,7 @@ export * from "./functions/types";
149
149
  export * from "./functions/ui";
150
150
  export * from "./functions/utils";
151
151
  export * from "./functions/vector";
152
+ export * from "./functions/weighted";
152
153
  export * from "./interfaces/ChargeBarSprites";
153
154
  export * from "./interfaces/Corner";
154
155
  export * from "./interfaces/CustomStageTSConfig";
@@ -174,5 +175,5 @@ export * from "./types/PickingUpItem";
174
175
  export * from "./types/PickupIndex";
175
176
  export * from "./types/PlayerIndex";
176
177
  export * from "./types/PossibleStatType";
177
- export * from "./types/SerializedIsaacAPIClass";
178
178
  export * from "./types/TSTLClass";
179
+ export * from "./types/WeightedArray";
@@ -1,5 +1,7 @@
1
1
  /* eslint-disable max-classes-per-file */
2
2
 
3
+ import { CopyableIsaacAPIClass } from "../objects/isaacAPIClassTypeToFunctions";
4
+
3
5
  /**
4
6
  * This is the format of the object that you give to the save data manager. It will contains all of
5
7
  * the variables for the particular mod feature.
@@ -45,7 +47,7 @@ type Serializable<T> =
45
47
  T extends SerializablePrimitive
46
48
  ? T
47
49
  : // Allow a specific subset of Isaac API classes that are copyable / serializable.
48
- T extends SerializableIsaacAPIClass
50
+ T extends CopyableIsaacAPIClass
49
51
  ? T
50
52
  : // Disallow all other Isaac API classes.
51
53
  T extends IsaacAPIClass
@@ -77,7 +79,7 @@ type SerializableInsideArrayOrMap<T> =
77
79
  T extends SerializablePrimitive
78
80
  ? T
79
81
  : // Allow a specific subset of Isaac API classes that are copyable / serializable.
80
- T extends SerializableIsaacAPIClass
82
+ T extends CopyableIsaacAPIClass
81
83
  ? T
82
84
  : // Disallow all other Isaac API classes.
83
85
  T extends IsaacAPIClass
@@ -125,7 +127,6 @@ type SerializableReadonlyMap<K, V> = ReadonlyMap<
125
127
  type SerializableSet<T> = Set<SerializableInsideArrayOrMap<T>>;
126
128
  type SerializableReadonlySet<T> = ReadonlySet<SerializableInsideArrayOrMap<T>>;
127
129
  type SerializableObject<T> = { [K in keyof T]: Serializable<T[K]> };
128
- type SerializableIsaacAPIClass = BitSet128 | Color | KColor | RNG | Vector;
129
130
 
130
131
  // eslint-disable-next-line @typescript-eslint/ban-types
131
132
  type HasMethods<T> = {} extends {
@@ -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
 
4
4
  export const ISAAC_API_CLASS_TYPE_TO_BRAND: {
@@ -1,72 +1,121 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import { CopyableIsaacAPIClassType } from "../enums/private/CopyableIsaacAPIClassType";
1
+ import { CopyableIsaacAPIClassType } from "isaac-typescript-definitions";
4
2
  import {
5
3
  copyBitSet128,
6
4
  deserializeBitSet128,
5
+ isBitSet128,
7
6
  isSerializedBitSet128,
8
7
  serializeBitSet128,
8
+ SerializedBitSet128,
9
9
  } from "../functions/bitSet128";
10
10
  import {
11
11
  copyColor,
12
12
  deserializeColor,
13
+ isColor,
13
14
  isSerializedColor,
14
15
  serializeColor,
16
+ SerializedColor,
15
17
  } from "../functions/color";
16
18
  import {
17
19
  copyKColor,
18
20
  deserializeKColor,
21
+ isKColor,
19
22
  isSerializedKColor,
23
+ SerializedKColor,
20
24
  serializeKColor,
21
25
  } from "../functions/kColor";
22
26
  import {
23
27
  copyRNG,
24
28
  deserializeRNG,
29
+ isRNG,
25
30
  isSerializedRNG,
31
+ SerializedRNG,
26
32
  serializeRNG,
27
33
  } from "../functions/rng";
28
34
  import {
29
35
  copyVector,
30
36
  deserializeVector,
31
37
  isSerializedVector,
38
+ isVector,
39
+ SerializedVector,
32
40
  serializeVector,
33
41
  } from "../functions/vector";
34
42
 
35
- interface IsaacAPIClassTypeFunctions {
36
- isSerialized: (object: unknown) => object is unknown;
37
- copy: (object: any) => any;
38
- serialize: (object: any) => any;
39
- deserialize: (object: any) => any;
43
+ /** A type representing an Isaac API class that can be safely copied or serialized. */
44
+ export type CopyableIsaacAPIClass = BitSet128 | Color | KColor | RNG | Vector;
45
+
46
+ /**
47
+ * A type representing an Isaac API class like `Color` or `RNG` that has been written to the
48
+ * "save#.dat" file. It is used by the save data manager when reading and writing to that file.
49
+ *
50
+ * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
51
+ */
52
+ export type SerializedIsaacAPIClass =
53
+ | SerializedBitSet128
54
+ | SerializedColor
55
+ | SerializedKColor
56
+ | SerializedRNG
57
+ | SerializedVector;
58
+
59
+ export interface IsaacAPIClassTypeToType {
60
+ [CopyableIsaacAPIClassType.BIT_SET_128]: BitSet128;
61
+ [CopyableIsaacAPIClassType.COLOR]: Color;
62
+ [CopyableIsaacAPIClassType.K_COLOR]: KColor;
63
+ [CopyableIsaacAPIClassType.RNG]: RNG;
64
+ [CopyableIsaacAPIClassType.VECTOR]: Vector;
65
+ }
66
+
67
+ export interface IsaacAPIClassTypeToSerializedType {
68
+ [CopyableIsaacAPIClassType.BIT_SET_128]: SerializedBitSet128;
69
+ [CopyableIsaacAPIClassType.COLOR]: SerializedColor;
70
+ [CopyableIsaacAPIClassType.K_COLOR]: SerializedKColor;
71
+ [CopyableIsaacAPIClassType.RNG]: SerializedRNG;
72
+ [CopyableIsaacAPIClassType.VECTOR]: SerializedVector;
73
+ }
74
+
75
+ export interface IsaacAPIClassTypeFunctions<T, SerializedT> {
76
+ is: (object: unknown) => object is T;
77
+ isSerialized: (object: unknown) => object is SerializedT;
78
+ copy: (object: T) => T;
79
+ serialize: (object: T) => SerializedT;
80
+ deserialize: (object: SerializedT) => T;
40
81
  }
41
82
 
42
83
  export const ISAAC_API_CLASS_TYPE_TO_FUNCTIONS: {
43
- readonly [key in CopyableIsaacAPIClassType]: IsaacAPIClassTypeFunctions;
84
+ readonly [key in CopyableIsaacAPIClassType]: IsaacAPIClassTypeFunctions<
85
+ IsaacAPIClassTypeToType[key],
86
+ IsaacAPIClassTypeToSerializedType[key]
87
+ >;
44
88
  } = {
45
89
  [CopyableIsaacAPIClassType.BIT_SET_128]: {
90
+ is: isBitSet128,
46
91
  isSerialized: isSerializedBitSet128,
47
92
  copy: copyBitSet128,
48
93
  serialize: serializeBitSet128,
49
94
  deserialize: deserializeBitSet128,
50
95
  },
51
96
  [CopyableIsaacAPIClassType.COLOR]: {
97
+ is: isColor,
52
98
  isSerialized: isSerializedColor,
53
99
  copy: copyColor,
54
100
  serialize: serializeColor,
55
101
  deserialize: deserializeColor,
56
102
  },
57
103
  [CopyableIsaacAPIClassType.K_COLOR]: {
104
+ is: isKColor,
58
105
  isSerialized: isSerializedKColor,
59
106
  copy: copyKColor,
60
107
  serialize: serializeKColor,
61
108
  deserialize: deserializeKColor,
62
109
  },
63
110
  [CopyableIsaacAPIClassType.RNG]: {
111
+ is: isRNG,
64
112
  isSerialized: isSerializedRNG,
65
113
  copy: copyRNG,
66
114
  serialize: serializeRNG,
67
115
  deserialize: deserializeRNG,
68
116
  },
69
117
  [CopyableIsaacAPIClassType.VECTOR]: {
118
+ is: isVector,
70
119
  isSerialized: isSerializedVector,
71
120
  copy: copyVector,
72
121
  serialize: serializeVector,
@@ -0,0 +1,2 @@
1
+ /** An array where each element is paired with a number indicating that elements 'weight'. */
2
+ export type WeightedArray<T> = Array<[T, float]>;
@@ -1,12 +0,0 @@
1
- /**
2
- * - This must match the JSDoc comments for `deepCopy` and `merge`.
3
- * - This must match the `SerializableIsaacAPIClass` type union.
4
- */
5
- export declare enum CopyableIsaacAPIClassType {
6
- BIT_SET_128 = "BitSet128",
7
- COLOR = "Color",
8
- K_COLOR = "KColor",
9
- RNG = "RNG",
10
- VECTOR = "Vector"
11
- }
12
- //# sourceMappingURL=CopyableIsaacAPIClassType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CopyableIsaacAPIClassType.d.ts","sourceRoot":"","sources":["../../../../src/enums/private/CopyableIsaacAPIClassType.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,yBAAyB;IACnC,WAAW,cAAc;IACzB,KAAK,UAAU;IACf,OAAO,WAAW;IAClB,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB"}
@@ -1,10 +0,0 @@
1
- local ____exports = {}
2
- --- - This must match the JSDoc comments for `deepCopy` and `merge`.
3
- -- - This must match the `SerializableIsaacAPIClass` type union.
4
- ____exports.CopyableIsaacAPIClassType = {}
5
- ____exports.CopyableIsaacAPIClassType.BIT_SET_128 = "BitSet128"
6
- ____exports.CopyableIsaacAPIClassType.COLOR = "Color"
7
- ____exports.CopyableIsaacAPIClassType.K_COLOR = "KColor"
8
- ____exports.CopyableIsaacAPIClassType.RNG = "RNG"
9
- ____exports.CopyableIsaacAPIClassType.VECTOR = "Vector"
10
- return ____exports
@@ -1,11 +0,0 @@
1
- /// <reference types="typescript-to-lua/language-extensions" />
2
- /**
3
- * This is a type representing an Isaac API class like `Color` or `RNG` that has been written to the
4
- * "save#.dat" file. It is used by the save data manager when reading and writing to that file.
5
- *
6
- * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
7
- */
8
- export declare type SerializedIsaacAPIClass = LuaMap<string, unknown> & {
9
- readonly __serializedIsaacAPIClassBrand: symbol;
10
- };
11
- //# sourceMappingURL=SerializedIsaacAPIClass.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SerializedIsaacAPIClass.d.ts","sourceRoot":"","sources":["../../../src/types/SerializedIsaacAPIClass.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,oBAAY,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC9D,QAAQ,CAAC,8BAA8B,EAAE,MAAM,CAAC;CACjD,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * - This must match the JSDoc comments for `deepCopy` and `merge`.
3
- * - This must match the `SerializableIsaacAPIClass` type union.
4
- */
5
- export enum CopyableIsaacAPIClassType {
6
- BIT_SET_128 = "BitSet128",
7
- COLOR = "Color",
8
- K_COLOR = "KColor",
9
- RNG = "RNG",
10
- VECTOR = "Vector",
11
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * This is a type representing an Isaac API class like `Color` or `RNG` that has been written to the
3
- * "save#.dat" file. It is used by the save data manager when reading and writing to that file.
4
- *
5
- * For the list of supported classes, see the `CopyableIsaacAPIClassType` enum.
6
- */
7
- export type SerializedIsaacAPIClass = LuaMap<string, unknown> & {
8
- readonly __serializedIsaacAPIClassBrand: symbol;
9
- };