isaacscript-common 30.0.0 → 30.2.0

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.
@@ -4618,6 +4618,15 @@ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity:
4618
4618
 
4619
4619
  export declare function getClosestPlayer(position: Vector): EntityPlayer;
4620
4620
 
4621
+ /**
4622
+ * Given an array of vectors, this helper function returns the closest one to a provided reference
4623
+ * vector.
4624
+ *
4625
+ * @param referenceVector The vector to compare against.
4626
+ * @param vectors The array of vectors to look through.
4627
+ */
4628
+ export declare function getClosestVectorTo(referenceVector: Vector, vectors: Vector[]): Vector | undefined;
4629
+
4621
4630
  /**
4622
4631
  * Helper function to get all of the coin pickup entities in the room.
4623
4632
  *
@@ -16623,6 +16632,13 @@ export declare const VectorOne: Readonly<Vector>;
16623
16632
  /** Helper function for finding out which way a vector is pointing. */
16624
16633
  export declare function vectorToDirection(vector: Vector): Direction;
16625
16634
 
16635
+ /**
16636
+ * Helper function to convert a room grid index expressed as a vector back into an integer.
16637
+ *
16638
+ * Also see the `roomGridIndexToVector` helper function.
16639
+ */
16640
+ export declare function vectorToRoomGridIndex(roomVector: Vector): int;
16641
+
16626
16642
  /**
16627
16643
  * Helper function to convert a vector to a string.
16628
16644
  *
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 30.0.0
3
+ isaacscript-common 30.2.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -17838,6 +17838,18 @@ function ____exports.doesVectorHaveLength(self, vector, threshold)
17838
17838
  end
17839
17839
  return vector:Length() >= threshold
17840
17840
  end
17841
+ function ____exports.getClosestVectorTo(self, referenceVector, vectors)
17842
+ local closestVector
17843
+ local closestDistance = math.huge
17844
+ for ____, vector in ipairs(vectors) do
17845
+ local distance = referenceVector:Distance(vector)
17846
+ if distance < closestDistance then
17847
+ closestVector = vector
17848
+ closestDistance = distance
17849
+ end
17850
+ end
17851
+ return closestVector
17852
+ end
17841
17853
  function ____exports.getRandomVector(self, seedOrRNG)
17842
17854
  if seedOrRNG == nil then
17843
17855
  seedOrRNG = getRandomSeed(nil)
@@ -47422,6 +47434,9 @@ function ____exports.roomGridIndexToVector(self, roomGridIndex)
47422
47434
  local y = math.floor(roomGridIndex / LEVEL_GRID_ROW_WIDTH)
47423
47435
  return Vector(x, y)
47424
47436
  end
47437
+ function ____exports.vectorToRoomGridIndex(self, roomVector)
47438
+ return roomVector.Y * LEVEL_GRID_ROW_WIDTH + roomVector.X
47439
+ end
47425
47440
  return ____exports
47426
47441
  end,
47427
47442
  ["src.functions.mergeTests"] = function(...)
@@ -200,4 +200,10 @@ export declare function roomExists(roomGridIndex: int): boolean;
200
200
  * - The bottom-right grid index of 168 is equal to coordinates of: (12, 12)
201
201
  */
202
202
  export declare function roomGridIndexToVector(roomGridIndex: int): Vector;
203
+ /**
204
+ * Helper function to convert a room grid index expressed as a vector back into an integer.
205
+ *
206
+ * Also see the `roomGridIndexToVector` helper function.
207
+ */
208
+ export declare function vectorToRoomGridIndex(roomVector: Vector): int;
203
209
  //# sourceMappingURL=levelGrid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"levelGrid.d.ts","sourceRoot":"","sources":["../../../src/functions/levelGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,QAAQ,EAKR,SAAS,EACT,QAAQ,EACT,MAAM,8BAA8B,CAAC;AA+BtC;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAK7E;AAED;;;;;;GAMG;AACH,wBAAgB,qCAAqC,CACnD,aAAa,CAAC,EAAE,GAAG,GAClB,GAAG,EAAE,CAKP;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAerE;AAED,0FAA0F;AAC1F,wBA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GRID_ROW_WIDTH)
421
421
  return Vector(x, y)
422
422
  end
423
+ --- Helper function to convert a room grid index expressed as a vector back into an integer.
424
+ --
425
+ -- Also see the `roomGridIndexToVector` helper function.
426
+ function ____exports.vectorToRoomGridIndex(self, roomVector)
427
+ return roomVector.Y * LEVEL_GRID_ROW_WIDTH + roomVector.X
428
+ end
423
429
  return ____exports
@@ -23,6 +23,14 @@ export declare function deserializeVector(vector: SerializedVector): Vector;
23
23
  * 0.01.
24
24
  */
25
25
  export declare function doesVectorHaveLength(vector: Vector, threshold?: number): boolean;
26
+ /**
27
+ * Given an array of vectors, this helper function returns the closest one to a provided reference
28
+ * vector.
29
+ *
30
+ * @param referenceVector The vector to compare against.
31
+ * @param vectors The array of vectors to look through.
32
+ */
33
+ export declare function getClosestVectorTo(referenceVector: Vector, vectors: Vector[]): Vector | undefined;
26
34
  /**
27
35
  * Helper function to get a random vector between (-1, -1) and (1, 1).
28
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"vector.d.ts","sourceRoot":"","sources":["../../../src/functions/vector.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,yBAAyB,EACzB,SAAS,EACV,MAAM,8BAA8B,CAAC;AAatC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACvD,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC;CACnD,CAAC;AAKF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQjD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAqBlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,SAAO,GACf,OAAO,CAET;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,SA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kB,CAChC,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EAAE,GAChB,MAAM,GAAG,SAAS,CAapB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,QAAQ,CAAC,MAAM,CAAC,CAOlB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,gBAAgB,CAM5B;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAE1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAWhE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAG3D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,MAAM,CAIpE"}
@@ -67,6 +67,23 @@ function ____exports.doesVectorHaveLength(self, vector, threshold)
67
67
  end
68
68
  return vector:Length() >= threshold
69
69
  end
70
+ --- Given an array of vectors, this helper function returns the closest one to a provided reference
71
+ -- vector.
72
+ --
73
+ -- @param referenceVector The vector to compare against.
74
+ -- @param vectors The array of vectors to look through.
75
+ function ____exports.getClosestVectorTo(self, referenceVector, vectors)
76
+ local closestVector
77
+ local closestDistance = math.huge
78
+ for ____, vector in ipairs(vectors) do
79
+ local distance = referenceVector:Distance(vector)
80
+ if distance < closestDistance then
81
+ closestVector = vector
82
+ closestDistance = distance
83
+ end
84
+ end
85
+ return closestVector
86
+ end
70
87
  --- Helper function to get a random vector between (-1, -1) and (1, 1).
71
88
  --
72
89
  -- To get random vectors with a bigger length, multiply this with a number.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "30.0.0",
3
+ "version": "30.2.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -558,3 +558,12 @@ export function roomGridIndexToVector(roomGridIndex: int): Vector {
558
558
 
559
559
  return Vector(x, y);
560
560
  }
561
+
562
+ /**
563
+ * Helper function to convert a room grid index expressed as a vector back into an integer.
564
+ *
565
+ * Also see the `roomGridIndexToVector` helper function.
566
+ */
567
+ export function vectorToRoomGridIndex(roomVector: Vector): int {
568
+ return roomVector.Y * LEVEL_GRID_ROW_WIDTH + roomVector.X;
569
+ }
@@ -78,6 +78,31 @@ export function doesVectorHaveLength(
78
78
  return vector.Length() >= threshold;
79
79
  }
80
80
 
81
+ /**
82
+ * Given an array of vectors, this helper function returns the closest one to a provided reference
83
+ * vector.
84
+ *
85
+ * @param referenceVector The vector to compare against.
86
+ * @param vectors The array of vectors to look through.
87
+ */
88
+ export function getClosestVectorTo(
89
+ referenceVector: Vector,
90
+ vectors: Vector[],
91
+ ): Vector | undefined {
92
+ let closestVector: Vector | undefined;
93
+ let closestDistance = math.huge;
94
+ for (const vector of vectors) {
95
+ const distance = referenceVector.Distance(vector);
96
+
97
+ if (distance < closestDistance) {
98
+ closestVector = vector;
99
+ closestDistance = distance;
100
+ }
101
+ }
102
+
103
+ return closestVector;
104
+ }
105
+
81
106
  /**
82
107
  * Helper function to get a random vector between (-1, -1) and (1, 1).
83
108
  *