isaacscript-common 19.1.1 → 20.1.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
@@ -4287,8 +4287,13 @@ export declare function getCircleDiscretizedPoints(centerPos: Vector, radius: fl
4287
4287
  * const gapers = getEntities(EntityType.GAPER);
4288
4288
  * const closestGaper = getClosestEntityTo(player, gapers);
4289
4289
  * ```
4290
+ *
4291
+ * @param referenceEntity The entity that is close by.
4292
+ * @param entities The array of entities to look through.
4293
+ * @param filterFunc Optional. A function to filter for a specific type of entity, like e.g. an
4294
+ * enemy with a certain amount of HP left.
4290
4295
  */
4291
- export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[]): T | undefined;
4296
+ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[], filterFunc?: (entity: T) => boolean): T | undefined;
4292
4297
 
4293
4298
  export declare function getClosestPlayer(position: Vector): EntityPlayer;
4294
4299
 
@@ -11294,26 +11299,31 @@ declare class ModdedElementSets extends Feature {
11294
11299
  export declare class ModFeature {
11295
11300
  private mod;
11296
11301
  /**
11297
- * An optional function that allows for conditional callback execution. If specified, any class
11302
+ * An optional method that allows for conditional callback execution. If specified, any class
11298
11303
  * method that is annotated with a `@Callback` or `@CallbackCustom` decorator will only be fired
11299
11304
  * if the executed conditional function returns true.
11300
11305
  *
11301
11306
  * This property is used to easily turn entire mod features on and off (rather than repeating
11302
11307
  * conditional logic and early returning at the beginning of every callback function).
11303
11308
  *
11304
- * By default, this is set to null. Override this property in your class if you need to use it.
11309
+ * Since the specific information for the firing callback is passed as arguments into the
11310
+ * conditional method, you can also write logic that would only apply to a specific type of
11311
+ * callback.
11312
+ *
11313
+ * By default, this is set to null, which means that all callback methods will fire
11314
+ * unconditionally. Override this property in your class if you need to use it.
11305
11315
  *
11306
11316
  * The function has the following signature:
11307
11317
  *
11308
11318
  * ```ts
11309
- * (
11310
- * vanilla: boolean, // Whether or not this is a vanilla or custom callback.
11311
- * modCallback: ModCallback | ModCallbackCustom,
11312
- * ...callbackArgs: unknown[]
11319
+ * <T extends boolean>(
11320
+ * vanilla: T, // Whether or not this is a vanilla or custom callback.
11321
+ * modCallback: T extends true ? ModCallback : ModCallbackCustom,
11322
+ * ...callbackArgs: unknown[] // This would be e.g. `pickup: EntityPickup` for the `POST_PICKUP_INIT` callback.
11313
11323
  * ) => boolean;
11314
11324
  * ```
11315
11325
  */
11316
- protected callbackConditionalFunc: ((vanilla: boolean, modCallback: ModCallback | ModCallbackCustom, ...callbackArgs: unknown[]) => boolean) | null;
11326
+ protected shouldCallbackMethodsFire: (<T extends boolean>(vanilla: T, modCallback: T extends true ? ModCallback : ModCallbackCustom, ...callbackArgs: unknown[]) => boolean) | null;
11317
11327
  /**
11318
11328
  * Whether or not the feature has registered its callbacks yet (and submitted its variables to the
11319
11329
  * save data manager, if any).
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 19.1.1
3
+ isaacscript-common 20.1.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -19478,12 +19478,12 @@ function ____exports.doesEntityExist(self, entityType, variant, subType, ignoreF
19478
19478
  )
19479
19479
  return count > 0
19480
19480
  end
19481
- function ____exports.getClosestEntityTo(self, referenceEntity, entities)
19481
+ function ____exports.getClosestEntityTo(self, referenceEntity, entities, filterFunc)
19482
19482
  local closestEntity
19483
19483
  local closestDistance = math.huge
19484
19484
  for ____, entity in ipairs(entities) do
19485
19485
  local distance = referenceEntity.Position:Distance(entity.Position)
19486
- if distance < closestDistance then
19486
+ if distance < closestDistance and (filterFunc == nil or filterFunc(nil, entity)) then
19487
19487
  closestEntity = entity
19488
19488
  closestDistance = distance
19489
19489
  end
@@ -49510,7 +49510,7 @@ function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, va
49510
49510
  end
49511
49511
  function addCallback(self, modFeature, modFeatureConstructor, mod, modCallback, callback, parameters, vanilla)
49512
49512
  local function wrappedCallback(____, ...)
49513
- local conditionalFunc = modFeature.callbackConditionalFunc
49513
+ local conditionalFunc = modFeature.shouldCallbackMethodsFire
49514
49514
  if conditionalFunc ~= nil then
49515
49515
  local shouldRun = conditionalFunc(nil, vanilla, modCallback, ...)
49516
49516
  if not shouldRun then
@@ -49605,7 +49605,7 @@ function ModFeature.prototype.____constructor(self, mod, init)
49605
49605
  if init == nil then
49606
49606
  init = true
49607
49607
  end
49608
- self.callbackConditionalFunc = nil
49608
+ self.shouldCallbackMethodsFire = nil
49609
49609
  self.initialized = false
49610
49610
  self.mod = mod
49611
49611
  if init then
@@ -39,26 +39,31 @@ export declare const MOD_FEATURE_CUSTOM_CALLBACKS_KEY = "__customCallbacks";
39
39
  export declare class ModFeature {
40
40
  private mod;
41
41
  /**
42
- * An optional function that allows for conditional callback execution. If specified, any class
42
+ * An optional method that allows for conditional callback execution. If specified, any class
43
43
  * method that is annotated with a `@Callback` or `@CallbackCustom` decorator will only be fired
44
44
  * if the executed conditional function returns true.
45
45
  *
46
46
  * This property is used to easily turn entire mod features on and off (rather than repeating
47
47
  * conditional logic and early returning at the beginning of every callback function).
48
48
  *
49
- * By default, this is set to null. Override this property in your class if you need to use it.
49
+ * Since the specific information for the firing callback is passed as arguments into the
50
+ * conditional method, you can also write logic that would only apply to a specific type of
51
+ * callback.
52
+ *
53
+ * By default, this is set to null, which means that all callback methods will fire
54
+ * unconditionally. Override this property in your class if you need to use it.
50
55
  *
51
56
  * The function has the following signature:
52
57
  *
53
58
  * ```ts
54
- * (
55
- * vanilla: boolean, // Whether or not this is a vanilla or custom callback.
56
- * modCallback: ModCallback | ModCallbackCustom,
57
- * ...callbackArgs: unknown[]
59
+ * <T extends boolean>(
60
+ * vanilla: T, // Whether or not this is a vanilla or custom callback.
61
+ * modCallback: T extends true ? ModCallback : ModCallbackCustom,
62
+ * ...callbackArgs: unknown[] // This would be e.g. `pickup: EntityPickup` for the `POST_PICKUP_INIT` callback.
58
63
  * ) => boolean;
59
64
  * ```
60
65
  */
61
- protected callbackConditionalFunc: ((vanilla: boolean, modCallback: ModCallback | ModCallbackCustom, ...callbackArgs: unknown[]) => boolean) | null;
66
+ protected shouldCallbackMethodsFire: (<T extends boolean>(vanilla: T, modCallback: T extends true ? ModCallback : ModCallbackCustom, ...callbackArgs: unknown[]) => boolean) | null;
62
67
  /**
63
68
  * Whether or not the feature has registered its callbacks yet (and submitted its variables to the
64
69
  * save data manager, if any).
@@ -1 +1 @@
1
- {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAS/D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAyBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAkB;IAE7B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,CAAC,uBAAuB,EAC7B,CAAC,CACC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,GAAG,iBAAiB,EAC5C,GAAG,YAAY,EAAE,OAAO,EAAE,KACvB,OAAO,CAAC,GACb,IAAI,CAAQ;IAEhB;;;;;;OAMG;IACI,WAAW,UAAS;gBAEf,GAAG,EAAE,eAAe,EAAE,IAAI,UAAO;IAQ7C;;;;;OAKG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAqB9B;;;;;;OAMG;IACI,MAAM,IAAI,IAAI;CAGtB"}
1
+ {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAS/D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAyBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAkB;IAE7B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CAAC,yBAAyB,EAC/B,CAAC,CAAC,CAAC,SAAS,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,iBAAiB,EAC7D,GAAG,YAAY,EAAE,OAAO,EAAE,KACvB,OAAO,CAAC,GACb,IAAI,CAAQ;IAEhB;;;;;;OAMG;IACI,WAAW,UAAS;gBAEf,GAAG,EAAE,eAAe,EAAE,IAAI,UAAO;IAQ7C;;;;;OAKG;IACI,IAAI,CAAC,IAAI,UAAO,GAAG,IAAI;IAqB9B;;;;;;OAMG;IACI,MAAM,IAAI,IAAI;CAGtB"}
@@ -64,7 +64,7 @@ function initDecoratedCallbacks(self, modFeature, constructor, tstlClassName, va
64
64
  end
65
65
  function addCallback(self, modFeature, modFeatureConstructor, mod, modCallback, callback, parameters, vanilla)
66
66
  local function wrappedCallback(____, ...)
67
- local conditionalFunc = modFeature.callbackConditionalFunc
67
+ local conditionalFunc = modFeature.shouldCallbackMethodsFire
68
68
  if conditionalFunc ~= nil then
69
69
  local shouldRun = conditionalFunc(nil, vanilla, modCallback, ...)
70
70
  if not shouldRun then
@@ -190,7 +190,7 @@ function ModFeature.prototype.____constructor(self, mod, init)
190
190
  if init == nil then
191
191
  init = true
192
192
  end
193
- self.callbackConditionalFunc = nil
193
+ self.shouldCallbackMethodsFire = nil
194
194
  self.initialized = false
195
195
  self.mod = mod
196
196
  if init then
@@ -34,8 +34,13 @@ export declare function doesEntityExist(entityType?: EntityType, variant?: numbe
34
34
  * const gapers = getEntities(EntityType.GAPER);
35
35
  * const closestGaper = getClosestEntityTo(player, gapers);
36
36
  * ```
37
+ *
38
+ * @param referenceEntity The entity that is close by.
39
+ * @param entities The array of entities to look through.
40
+ * @param filterFunc Optional. A function to filter for a specific type of entity, like e.g. an
41
+ * enemy with a certain amount of HP left.
37
42
  */
38
- export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[]): T | undefined;
43
+ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[], filterFunc?: (entity: T) => boolean): T | undefined;
39
44
  /** Helper function to get the entity type, variant, and sub-type from an `EntityID`. */
40
45
  export declare function getConstituentsFromEntityID(entityID: EntityID): [entityType: EntityType, variant: int, subType: int];
41
46
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../src/functions/entities.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAK1D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAkB7C;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,UAAU,GAAE,UAAe,EAC3B,OAAO,SAAK,EACZ,OAAO,SAAK,EACZ,cAAc,UAAQ,GACrB,GAAG,CAcL;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,UAAU,GAAE,UAAe,EAC3B,OAAO,SAAK,EACZ,OAAO,SAAK,EACZ,cAAc,UAAQ,GACrB,OAAO,CAGT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EACpD,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,CAAC,EAAE,GACZ,CAA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AU,EACtB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,mBAAmB,EAAE,MAAM,GAAG,GAAG,EACjC,SAAS,EAAE,IAAI,GAAG,GAAG,EACrB,QAAQ,GAAE,MAAmB,EAC7B,OAAO,GAAE,MAAM,GAAG,SAAqB,GACtC,MAAM,CAUR"}
@@ -143,12 +143,17 @@ end
143
143
  -- const gapers = getEntities(EntityType.GAPER);
144
144
  -- const closestGaper = getClosestEntityTo(player, gapers);
145
145
  -- ```
146
- function ____exports.getClosestEntityTo(self, referenceEntity, entities)
146
+ --
147
+ -- @param referenceEntity The entity that is close by.
148
+ -- @param entities The array of entities to look through.
149
+ -- @param filterFunc Optional. A function to filter for a specific type of entity, like e.g. an
150
+ -- enemy with a certain amount of HP left.
151
+ function ____exports.getClosestEntityTo(self, referenceEntity, entities, filterFunc)
147
152
  local closestEntity
148
153
  local closestDistance = math.huge
149
154
  for ____, entity in ipairs(entities) do
150
155
  local distance = referenceEntity.Position:Distance(entity.Position)
151
- if distance < closestDistance then
156
+ if distance < closestDistance and (filterFunc == nil or filterFunc(nil, entity)) then
152
157
  closestEntity = entity
153
158
  closestDistance = distance
154
159
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "19.1.1",
3
+ "version": "20.1.0",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -74,29 +74,34 @@ export class ModFeature {
74
74
  private mod: ModUpgradedBase;
75
75
 
76
76
  /**
77
- * An optional function that allows for conditional callback execution. If specified, any class
77
+ * An optional method that allows for conditional callback execution. If specified, any class
78
78
  * method that is annotated with a `@Callback` or `@CallbackCustom` decorator will only be fired
79
79
  * if the executed conditional function returns true.
80
80
  *
81
81
  * This property is used to easily turn entire mod features on and off (rather than repeating
82
82
  * conditional logic and early returning at the beginning of every callback function).
83
83
  *
84
- * By default, this is set to null. Override this property in your class if you need to use it.
84
+ * Since the specific information for the firing callback is passed as arguments into the
85
+ * conditional method, you can also write logic that would only apply to a specific type of
86
+ * callback.
87
+ *
88
+ * By default, this is set to null, which means that all callback methods will fire
89
+ * unconditionally. Override this property in your class if you need to use it.
85
90
  *
86
91
  * The function has the following signature:
87
92
  *
88
93
  * ```ts
89
- * (
90
- * vanilla: boolean, // Whether or not this is a vanilla or custom callback.
91
- * modCallback: ModCallback | ModCallbackCustom,
92
- * ...callbackArgs: unknown[]
94
+ * <T extends boolean>(
95
+ * vanilla: T, // Whether or not this is a vanilla or custom callback.
96
+ * modCallback: T extends true ? ModCallback : ModCallbackCustom,
97
+ * ...callbackArgs: unknown[] // This would be e.g. `pickup: EntityPickup` for the `POST_PICKUP_INIT` callback.
93
98
  * ) => boolean;
94
99
  * ```
95
100
  */
96
- protected callbackConditionalFunc:
97
- | ((
98
- vanilla: boolean,
99
- modCallback: ModCallback | ModCallbackCustom,
101
+ protected shouldCallbackMethodsFire:
102
+ | (<T extends boolean>(
103
+ vanilla: T,
104
+ modCallback: T extends true ? ModCallback : ModCallbackCustom,
100
105
  ...callbackArgs: unknown[]
101
106
  ) => boolean)
102
107
  | null = null;
@@ -250,7 +255,7 @@ function addCallback(
250
255
  // first argument. (Otherwise, the method will not be able to properly access `this`.
251
256
  const wrappedCallback = (...callbackArgs: unknown[]) => {
252
257
  // eslint-disable-next-line @typescript-eslint/dot-notation
253
- const conditionalFunc = modFeature["callbackConditionalFunc"];
258
+ const conditionalFunc = modFeature["shouldCallbackMethodsFire"];
254
259
  if (conditionalFunc !== null) {
255
260
  const shouldRun = conditionalFunc(vanilla, modCallback, ...callbackArgs);
256
261
  if (!shouldRun) {
@@ -83,17 +83,26 @@ export function doesEntityExist(
83
83
  * const gapers = getEntities(EntityType.GAPER);
84
84
  * const closestGaper = getClosestEntityTo(player, gapers);
85
85
  * ```
86
+ *
87
+ * @param referenceEntity The entity that is close by.
88
+ * @param entities The array of entities to look through.
89
+ * @param filterFunc Optional. A function to filter for a specific type of entity, like e.g. an
90
+ * enemy with a certain amount of HP left.
86
91
  */
87
92
  export function getClosestEntityTo<T extends AnyEntity>(
88
93
  referenceEntity: Entity,
89
94
  entities: T[],
95
+ filterFunc?: (entity: T) => boolean,
90
96
  ): T | undefined {
91
97
  let closestEntity: T | undefined;
92
98
  let closestDistance = math.huge;
93
99
  for (const entity of entities) {
94
100
  const distance = referenceEntity.Position.Distance(entity.Position);
95
101
 
96
- if (distance < closestDistance) {
102
+ if (
103
+ distance < closestDistance &&
104
+ (filterFunc === undefined || filterFunc(entity))
105
+ ) {
97
106
  closestEntity = entity;
98
107
  closestDistance = distance;
99
108
  }