isaacscript-common 20.0.0 → 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
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 20.
|
|
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
|
|
@@ -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;;;;;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+143,17 @@ end
|
|
|
143
143
|
-- const gapers = getEntities(EntityType.GAPER);
|
|
144
144
|
-- const closestGaper = getClosestEntityTo(player, gapers);
|
|
145
145
|
-- ```
|
|
146
|
-
|
|
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
|
@@ -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 (
|
|
102
|
+
if (
|
|
103
|
+
distance < closestDistance &&
|
|
104
|
+
(filterFunc === undefined || filterFunc(entity))
|
|
105
|
+
) {
|
|
97
106
|
closestEntity = entity;
|
|
98
107
|
closestDistance = distance;
|
|
99
108
|
}
|