isaacscript-common 20.8.0 → 20.9.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.
package/dist/index.d.ts CHANGED
@@ -3299,6 +3299,19 @@ export declare function doesPlayerHaveAllBlackHearts(player: EntityPlayer): bool
3299
3299
  */
3300
3300
  export declare function doesPlayerHaveAllSoulHearts(player: EntityPlayer): boolean;
3301
3301
 
3302
+ /**
3303
+ * Helper function to measure a vector to see if it has a non-zero length using a threshold to
3304
+ * ignore extremely small values.
3305
+ *
3306
+ * Use this function instead of explicitly checking if the length is 0 because vectors in the game
3307
+ * are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length.
3308
+ *
3309
+ * @param vector The vector to measure.
3310
+ * @param threshold Optional. The threshold from 0 to consider to be a non-zero vector. Default is
3311
+ * 0.01.
3312
+ */
3313
+ export declare function doesVectorHaveAnyLength(vector: Vector, threshold?: number): boolean;
3314
+
3302
3315
  export declare const DOGMA_ROOM_GRID_INDEX = 109;
3303
3316
 
3304
3317
  export declare const DOOR_HITBOX_RADIUS = 11;
@@ -6932,8 +6945,22 @@ export declare function initArray<T>(defaultValue: T, size: int): T[];
6932
6945
  /**
6933
6946
  * Helper function to instantiate an array of mod features all at once. Use this function if your
6934
6947
  * mod uses the pattern of expressing mod features as `ModFeature` classes.
6948
+ *
6949
+ * For example:
6950
+ *
6951
+ * ```ts
6952
+ * const features = [
6953
+ * MyFeature1,
6954
+ * MyFeature2,
6955
+ * MyFeature3,
6956
+ * ] as const;
6957
+ * initModFeatures(mod, modFeatures);
6958
+ * ```
6959
+ *
6960
+ * @returns An array of the instantiated features in the same order that the constructors were
6961
+ * passed in.
6935
6962
  */
6936
- export declare function initModFeatures(mod: ModUpgraded, modFeatures: Array<typeof ModFeature>): void;
6963
+ export declare function initModFeatures(mod: ModUpgraded, modFeatures: Array<typeof ModFeature>): ModFeature[];
6937
6964
 
6938
6965
  /** Helper function to determine if the current room shape is one of the four L room shapes. */
6939
6966
  export declare function inLRoom(): boolean;
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 20.8.0
3
+ isaacscript-common 20.9.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -17401,6 +17401,12 @@ function ____exports.deserializeVector(self, vector)
17401
17401
  end
17402
17402
  return Vector(x, y)
17403
17403
  end
17404
+ function ____exports.doesVectorHaveAnyLength(self, vector, threshold)
17405
+ if threshold == nil then
17406
+ threshold = 0.01
17407
+ end
17408
+ return vector:Length() >= threshold
17409
+ end
17404
17410
  function ____exports.getRandomVector(self, seedOrRNG)
17405
17411
  if seedOrRNG == nil then
17406
17412
  seedOrRNG = getRandomSeed(nil)
@@ -19745,6 +19751,7 @@ local ____types = require("src.functions.types")
19745
19751
  local asNumber = ____types.asNumber
19746
19752
  local isPrimitive = ____types.isPrimitive
19747
19753
  local ____vector = require("src.functions.vector")
19754
+ local doesVectorHaveAnyLength = ____vector.doesVectorHaveAnyLength
19748
19755
  local isVector = ____vector.isVector
19749
19756
  local vectorToString = ____vector.vectorToString
19750
19757
  function setPrimitiveEntityFields(self, entity, metatable, entityFields)
@@ -19935,7 +19942,7 @@ function ____exports.isEntityMoving(self, entity, threshold)
19935
19942
  if threshold == nil then
19936
19943
  threshold = 0.01
19937
19944
  end
19938
- return entity.Velocity:Length() >= threshold
19945
+ return doesVectorHaveAnyLength(nil, entity.Velocity, threshold)
19939
19946
  end
19940
19947
  function ____exports.isStoryBoss(self, entityType)
19941
19948
  return STORY_BOSSES_SET:has(entityType)
@@ -50910,9 +50917,12 @@ local ____lualib = require("lualib_bundle")
50910
50917
  local __TS__New = ____lualib.__TS__New
50911
50918
  local ____exports = {}
50912
50919
  function ____exports.initModFeatures(self, mod, modFeatures)
50920
+ local instantiatedModFeatures = {}
50913
50921
  for ____, modFeature in ipairs(modFeatures) do
50914
- __TS__New(modFeature, mod)
50922
+ local instantiatedModFeature = __TS__New(modFeature, mod)
50923
+ instantiatedModFeatures[#instantiatedModFeatures + 1] = instantiatedModFeature
50915
50924
  end
50925
+ return instantiatedModFeatures
50916
50926
  end
50917
50927
  return ____exports
50918
50928
  end,
@@ -27,6 +27,7 @@ local ____types = require("src.functions.types")
27
27
  local asNumber = ____types.asNumber
28
28
  local isPrimitive = ____types.isPrimitive
29
29
  local ____vector = require("src.functions.vector")
30
+ local doesVectorHaveAnyLength = ____vector.doesVectorHaveAnyLength
30
31
  local isVector = ____vector.isVector
31
32
  local vectorToString = ____vector.vectorToString
32
33
  function setPrimitiveEntityFields(self, entity, metatable, entityFields)
@@ -303,7 +304,7 @@ function ____exports.isEntityMoving(self, entity, threshold)
303
304
  if threshold == nil then
304
305
  threshold = 0.01
305
306
  end
306
- return entity.Velocity:Length() >= threshold
307
+ return doesVectorHaveAnyLength(nil, entity.Velocity, threshold)
307
308
  end
308
309
  --- Helper function to determine if the specified entity type is an end-game story boss, like Isaac,
309
310
  -- Blue Baby, Mega Satan, The Beast, and so on. This is useful because certain effects should only
@@ -3,6 +3,20 @@ import { ModUpgraded } from "../types/ModUpgraded";
3
3
  /**
4
4
  * Helper function to instantiate an array of mod features all at once. Use this function if your
5
5
  * mod uses the pattern of expressing mod features as `ModFeature` classes.
6
+ *
7
+ * For example:
8
+ *
9
+ * ```ts
10
+ * const features = [
11
+ * MyFeature1,
12
+ * MyFeature2,
13
+ * MyFeature3,
14
+ * ] as const;
15
+ * initModFeatures(mod, modFeatures);
16
+ * ```
17
+ *
18
+ * @returns An array of the instantiated features in the same order that the constructors were
19
+ * passed in.
6
20
  */
7
- export declare function initModFeatures(mod: ModUpgraded, modFeatures: Array<typeof ModFeature>): void;
21
+ export declare function initModFeatures(mod: ModUpgraded, modFeatures: Array<typeof ModFeature>): ModFeature[];
8
22
  //# sourceMappingURL=modFeatures.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modFeatures.d.ts","sourceRoot":"","sources":["../../../src/functions/modFeatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,KAAK,CAAC,OAAO,UAAU,CAAC,GACpC,IAAI,CAKN"}
1
+ {"version":3,"file":"modFeatures.d.ts","sourceRoot":"","sources":["../../../src/functions/modFeatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,KAAK,CAAC,OAAO,UAAU,CAAC,GACpC,UAAU,EAAE,CAUd"}
@@ -3,9 +3,26 @@ local __TS__New = ____lualib.__TS__New
3
3
  local ____exports = {}
4
4
  --- Helper function to instantiate an array of mod features all at once. Use this function if your
5
5
  -- mod uses the pattern of expressing mod features as `ModFeature` classes.
6
+ --
7
+ -- For example:
8
+ --
9
+ -- ```ts
10
+ -- const features = [
11
+ -- MyFeature1,
12
+ -- MyFeature2,
13
+ -- MyFeature3,
14
+ -- ] as const;
15
+ -- initModFeatures(mod, modFeatures);
16
+ -- ```
17
+ --
18
+ -- @returns An array of the instantiated features in the same order that the constructors were
19
+ -- passed in.
6
20
  function ____exports.initModFeatures(self, mod, modFeatures)
21
+ local instantiatedModFeatures = {}
7
22
  for ____, modFeature in ipairs(modFeatures) do
8
- __TS__New(modFeature, mod)
23
+ local instantiatedModFeature = __TS__New(modFeature, mod)
24
+ instantiatedModFeatures[#instantiatedModFeatures + 1] = instantiatedModFeature
9
25
  end
26
+ return instantiatedModFeatures
10
27
  end
11
28
  return ____exports
@@ -11,6 +11,18 @@ export declare function copyVector(vector: Vector): Vector;
11
11
  * the save data manager when reading data from the "save#.dat" file.)
12
12
  */
13
13
  export declare function deserializeVector(vector: SerializedVector): Vector;
14
+ /**
15
+ * Helper function to measure a vector to see if it has a non-zero length using a threshold to
16
+ * ignore extremely small values.
17
+ *
18
+ * Use this function instead of explicitly checking if the length is 0 because vectors in the game
19
+ * are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length.
20
+ *
21
+ * @param vector The vector to measure.
22
+ * @param threshold Optional. The threshold from 0 to consider to be a non-zero vector. Default is
23
+ * 0.01.
24
+ */
25
+ export declare function doesVectorHaveAnyLength(vector: Vector, threshold?: number): boolean;
14
26
  /**
15
27
  * Helper function to get a random vector between (-1, -1) and (1, 1).
16
28
  *
@@ -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;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,MAAM,CAOR;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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WhE;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,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,MAAM,CAIpE"}
@@ -52,6 +52,21 @@ function ____exports.deserializeVector(self, vector)
52
52
  end
53
53
  return Vector(x, y)
54
54
  end
55
+ --- Helper function to measure a vector to see if it has a non-zero length using a threshold to
56
+ -- ignore extremely small values.
57
+ --
58
+ -- Use this function instead of explicitly checking if the length is 0 because vectors in the game
59
+ -- are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length.
60
+ --
61
+ -- @param vector The vector to measure.
62
+ -- @param threshold Optional. The threshold from 0 to consider to be a non-zero vector. Default is
63
+ -- 0.01.
64
+ function ____exports.doesVectorHaveAnyLength(self, vector, threshold)
65
+ if threshold == nil then
66
+ threshold = 0.01
67
+ end
68
+ return vector:Length() >= threshold
69
+ end
55
70
  --- Helper function to get a random vector between (-1, -1) and (1, 1).
56
71
  --
57
72
  -- 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": "20.8.0",
3
+ "version": "20.9.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -10,7 +10,7 @@ import { getRandom } from "./random";
10
10
  import { isRNG, newRNG } from "./rng";
11
11
  import { setSpriteOpacity } from "./sprites";
12
12
  import { asNumber, isPrimitive } from "./types";
13
- import { isVector, vectorToString } from "./vector";
13
+ import { doesVectorHaveAnyLength, isVector, vectorToString } from "./vector";
14
14
 
15
15
  /** From DeadInfinity. */
16
16
  const DAMAGE_FLASH_COLOR: Readonly<Color> = Color(
@@ -316,7 +316,7 @@ export function hasArmor(entity: Entity): boolean {
316
316
  * @param threshold Optional. The threshold from 0 to consider to be moving. Default is 0.01.
317
317
  */
318
318
  export function isEntityMoving(entity: Entity, threshold = 0.01): boolean {
319
- return entity.Velocity.Length() >= threshold;
319
+ return doesVectorHaveAnyLength(entity.Velocity, threshold);
320
320
  }
321
321
 
322
322
  /**
@@ -4,13 +4,32 @@ import { ModUpgraded } from "../types/ModUpgraded";
4
4
  /**
5
5
  * Helper function to instantiate an array of mod features all at once. Use this function if your
6
6
  * mod uses the pattern of expressing mod features as `ModFeature` classes.
7
+ *
8
+ * For example:
9
+ *
10
+ * ```ts
11
+ * const features = [
12
+ * MyFeature1,
13
+ * MyFeature2,
14
+ * MyFeature3,
15
+ * ] as const;
16
+ * initModFeatures(mod, modFeatures);
17
+ * ```
18
+ *
19
+ * @returns An array of the instantiated features in the same order that the constructors were
20
+ * passed in.
7
21
  */
8
22
  export function initModFeatures(
9
23
  mod: ModUpgraded,
10
24
  modFeatures: Array<typeof ModFeature>,
11
- ): void {
25
+ ): ModFeature[] {
26
+ const instantiatedModFeatures: ModFeature[] = [];
27
+
12
28
  for (const modFeature of modFeatures) {
13
- // eslint-disable-next-line no-new, new-cap
14
- new modFeature(mod);
29
+ // eslint-disable-next-line new-cap
30
+ const instantiatedModFeature = new modFeature(mod);
31
+ instantiatedModFeatures.push(instantiatedModFeature);
15
32
  }
33
+
34
+ return instantiatedModFeatures;
16
35
  }
@@ -60,6 +60,24 @@ export function deserializeVector(vector: SerializedVector): Vector {
60
60
  return Vector(x, y);
61
61
  }
62
62
 
63
+ /**
64
+ * Helper function to measure a vector to see if it has a non-zero length using a threshold to
65
+ * ignore extremely small values.
66
+ *
67
+ * Use this function instead of explicitly checking if the length is 0 because vectors in the game
68
+ * are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length.
69
+ *
70
+ * @param vector The vector to measure.
71
+ * @param threshold Optional. The threshold from 0 to consider to be a non-zero vector. Default is
72
+ * 0.01.
73
+ */
74
+ export function doesVectorHaveAnyLength(
75
+ vector: Vector,
76
+ threshold = 0.01,
77
+ ): boolean {
78
+ return vector.Length() >= threshold;
79
+ }
80
+
63
81
  /**
64
82
  * Helper function to get a random vector between (-1, -1) and (1, 1).
65
83
  *