isaacscript-common 9.19.3 → 10.0.1

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 (45) hide show
  1. package/dist/index.d.ts +8 -6
  2. package/dist/isaacscript-common.lua +83 -55
  3. package/dist/lualib_bundle.lua +53 -37
  4. package/dist/package.lua +2 -2
  5. package/dist/src/features/saveDataManager/load.d.ts +1 -1
  6. package/dist/src/features/saveDataManager/maps.d.ts +1 -1
  7. package/dist/src/features/saveDataManager/merge.d.ts +1 -1
  8. package/dist/src/features/saveDataManager/save.d.ts +1 -1
  9. package/dist/src/functions/bitSet128.d.ts +1 -1
  10. package/dist/src/functions/bitSet128.d.ts.map +1 -1
  11. package/dist/src/functions/bitSet128.lua +2 -2
  12. package/dist/src/functions/color.d.ts +1 -1
  13. package/dist/src/functions/color.d.ts.map +1 -1
  14. package/dist/src/functions/color.lua +2 -2
  15. package/dist/src/functions/entities.d.ts +1 -1
  16. package/dist/src/functions/globals.d.ts +1 -1
  17. package/dist/src/functions/jsonHelpers.d.ts +1 -1
  18. package/dist/src/functions/kColor.d.ts +1 -1
  19. package/dist/src/functions/kColor.d.ts.map +1 -1
  20. package/dist/src/functions/kColor.lua +2 -2
  21. package/dist/src/functions/log.d.ts +2 -2
  22. package/dist/src/functions/log.d.ts.map +1 -1
  23. package/dist/src/functions/positionVelocity.d.ts +3 -1
  24. package/dist/src/functions/positionVelocity.d.ts.map +1 -1
  25. package/dist/src/functions/positionVelocity.lua +9 -1
  26. package/dist/src/functions/rng.d.ts +1 -1
  27. package/dist/src/functions/table.d.ts +4 -4
  28. package/dist/src/functions/table.d.ts.map +1 -1
  29. package/dist/src/functions/table.lua +8 -4
  30. package/dist/src/functions/tstlClass.d.ts +1 -1
  31. package/dist/src/functions/types.d.ts +1 -1
  32. package/dist/src/functions/vector.d.ts +1 -1
  33. package/dist/src/functions/vector.d.ts.map +1 -1
  34. package/dist/src/functions/vector.lua +2 -2
  35. package/dist/src/interfaces/private/TSTLClassMetatable.d.ts +1 -1
  36. package/dist/src/types/SerializedIsaacAPIClass.d.ts +1 -1
  37. package/dist/src/types/TSTLClass.d.ts +1 -1
  38. package/package.json +2 -2
  39. package/src/functions/bitSet128.ts +6 -2
  40. package/src/functions/color.ts +6 -2
  41. package/src/functions/kColor.ts +6 -2
  42. package/src/functions/log.ts +8 -6
  43. package/src/functions/positionVelocity.ts +10 -0
  44. package/src/functions/table.ts +15 -6
  45. package/src/functions/vector.ts +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "9.19.3",
3
+ "version": "10.0.1",
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.0.0"
26
26
  }
27
27
  }
@@ -1,6 +1,10 @@
1
1
  import { SerializationBrand } from "../enums/private/SerializationBrand";
2
2
  import { isIsaacAPIClassOfType } from "./isaacAPIClass";
3
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
3
+ import {
4
+ copyUserdataValuesToTable,
5
+ getNumbersFromTable,
6
+ tableHasKeys,
7
+ } from "./table";
4
8
  import { isTable } from "./types";
5
9
 
6
10
  export type SerializedBitSet128 = LuaMap<string, unknown> & {
@@ -86,7 +90,7 @@ export function serializeBitSet128(bitSet128: BitSet128): SerializedBitSet128 {
86
90
  }
87
91
 
88
92
  const bitSet128Table = new LuaMap<string, unknown>();
89
- copyValuesToTable(bitSet128, KEYS, bitSet128Table);
93
+ copyUserdataValuesToTable(bitSet128, KEYS, bitSet128Table);
90
94
  bitSet128Table.set(SerializationBrand.BIT_SET_128, "");
91
95
  return bitSet128Table as SerializedBitSet128;
92
96
  }
@@ -2,7 +2,11 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
2
2
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
3
3
  import { getRandom } from "./random";
4
4
  import { getRandomSeed, isRNG, newRNG } from "./rng";
5
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
5
+ import {
6
+ copyUserdataValuesToTable,
7
+ getNumbersFromTable,
8
+ tableHasKeys,
9
+ } from "./table";
6
10
  import { isTable } from "./types";
7
11
 
8
12
  export type SerializedColor = LuaMap<string, unknown> & {
@@ -120,7 +124,7 @@ export function serializeColor(color: Color): SerializedColor {
120
124
  }
121
125
 
122
126
  const colorTable = new LuaMap<string, unknown>();
123
- copyValuesToTable(color, KEYS, colorTable);
127
+ copyUserdataValuesToTable(color, KEYS, colorTable);
124
128
  colorTable.set(SerializationBrand.COLOR, "");
125
129
  return colorTable as SerializedColor;
126
130
  }
@@ -2,7 +2,11 @@ import { SerializationBrand } from "../enums/private/SerializationBrand";
2
2
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
3
3
  import { getRandom } from "./random";
4
4
  import { getRandomSeed, isRNG, newRNG } from "./rng";
5
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
5
+ import {
6
+ copyUserdataValuesToTable,
7
+ getNumbersFromTable,
8
+ tableHasKeys,
9
+ } from "./table";
6
10
  import { isTable } from "./types";
7
11
 
8
12
  export type SerializedKColor = LuaMap<string, unknown> & {
@@ -117,7 +121,7 @@ export function serializeKColor(kColor: KColor): SerializedKColor {
117
121
  }
118
122
 
119
123
  const kColorTable = new LuaMap<string, unknown>();
120
- copyValuesToTable(kColor, KEYS, kColorTable);
124
+ copyUserdataValuesToTable(kColor, KEYS, kColorTable);
121
125
  kColorTable.set(SerializationBrand.K_COLOR, "");
122
126
  return kColorTable as SerializedKColor;
123
127
  }
@@ -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,10 +47,13 @@ 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,
53
55
  avoidActiveEntities = false,
56
+ minimumDistance?: float,
54
57
  ): Vector {
55
58
  const room = game.GetRoom();
56
59
  const heavenDoors = getEffects(
@@ -79,6 +82,13 @@ export function findFreePosition(
79
82
  continue;
80
83
  }
81
84
 
85
+ if (minimumDistance !== undefined) {
86
+ const distance = startingPosition.Distance(position);
87
+ if (distance < minimumDistance) {
88
+ continue;
89
+ }
90
+ }
91
+
82
92
  return position;
83
93
  }
84
94
 
@@ -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,
@@ -4,7 +4,11 @@ import { angleToDirection } from "./direction";
4
4
  import { isaacAPIClassEquals, isIsaacAPIClassOfType } from "./isaacAPIClass";
5
5
  import { getRandomFloat } from "./random";
6
6
  import { getRandomSeed, isRNG, newRNG } from "./rng";
7
- import { copyValuesToTable, getNumbersFromTable, tableHasKeys } from "./table";
7
+ import {
8
+ copyUserdataValuesToTable,
9
+ getNumbersFromTable,
10
+ tableHasKeys,
11
+ } from "./table";
8
12
  import { isTable } from "./types";
9
13
 
10
14
  export type SerializedVector = LuaMap<string, unknown> & {
@@ -104,7 +108,7 @@ export function serializeVector(vector: Vector): SerializedVector {
104
108
  }
105
109
 
106
110
  const vectorTable = new LuaMap<string, unknown>();
107
- copyValuesToTable(vector, KEYS, vectorTable);
111
+ copyUserdataValuesToTable(vector, KEYS, vectorTable);
108
112
  vectorTable.set(SerializationBrand.VECTOR, "");
109
113
  return vectorTable as SerializedVector;
110
114
  }