isaacscript-common 15.0.4 → 15.0.5
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 +7 -1
- package/dist/isaacscript-common.lua +47 -5
- package/dist/src/functions/gridEntities.d.ts +4 -0
- package/dist/src/functions/gridEntities.d.ts.map +1 -1
- package/dist/src/functions/gridEntities.lua +48 -4
- package/dist/src/functions/math.d.ts +1 -1
- package/dist/src/functions/math.lua +1 -1
- package/package.json +1 -1
- package/src/functions/gridEntities.ts +68 -13
- package/src/functions/math.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4704,6 +4704,9 @@ export declare function getGridEntities(...gridEntityTypes: GridEntityType[]): G
|
|
|
4704
4704
|
*/
|
|
4705
4705
|
export declare function getGridEntitiesExcept(...gridEntityTypes: GridEntityType[]): GridEntity[];
|
|
4706
4706
|
|
|
4707
|
+
/** Helper function to get all grid entities in a given radius around a given point. */
|
|
4708
|
+
export declare function getGridEntitiesInRadius(targetPosition: Vector, radius: number): GridEntity[];
|
|
4709
|
+
|
|
4707
4710
|
/**
|
|
4708
4711
|
* Helper function to get a map of every grid entity in the current room. The indexes of the map are
|
|
4709
4712
|
* equal to the grid index. The values of the map are equal to the grid entities.
|
|
@@ -4713,6 +4716,9 @@ export declare function getGridEntitiesExcept(...gridEntityTypes: GridEntityType
|
|
|
4713
4716
|
*/
|
|
4714
4717
|
export declare function getGridEntitiesMap(...gridEntityTypes: GridEntityType[]): Map<int, GridEntity>;
|
|
4715
4718
|
|
|
4719
|
+
/** Helper function to get the top left and bottom right corners of a given grid entity. */
|
|
4720
|
+
export declare function getGridEntityCollisionPoints(gridEntity: GridEntity): [topLeft: Vector, bottomRight: Vector];
|
|
4721
|
+
|
|
4716
4722
|
/** Helper function to get a string containing the grid entity's type and variant. */
|
|
4717
4723
|
export declare function getGridEntityID(gridEntity: GridEntity): string;
|
|
4718
4724
|
|
|
@@ -12306,7 +12312,7 @@ export declare function roomUpdateSafe(): void;
|
|
|
12306
12312
|
* From: http://lua-users.org/wiki/SimpleRound
|
|
12307
12313
|
*
|
|
12308
12314
|
* @param num The number to round.
|
|
12309
|
-
* @param numDecimalPlaces Default is 0.
|
|
12315
|
+
* @param numDecimalPlaces Optional. Default is 0.
|
|
12310
12316
|
*/
|
|
12311
12317
|
export declare function round(num: float, numDecimalPlaces?: number): float;
|
|
12312
12318
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 15.0.
|
|
3
|
+
isaacscript-common 15.0.5
|
|
4
4
|
|
|
5
5
|
This is the "isaacscript-common" library, which was created with the IsaacScript tool.
|
|
6
6
|
|
|
@@ -25434,6 +25434,7 @@ local ____cachedClasses = require("src.core.cachedClasses")
|
|
|
25434
25434
|
local game = ____cachedClasses.game
|
|
25435
25435
|
local ____constants = require("src.core.constants")
|
|
25436
25436
|
local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
|
|
25437
|
+
local VectorOne = ____constants.VectorOne
|
|
25437
25438
|
local ____gridEntityTypeToBrokenStateMap = require("src.maps.gridEntityTypeToBrokenStateMap")
|
|
25438
25439
|
local GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP = ____gridEntityTypeToBrokenStateMap.GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP
|
|
25439
25440
|
local ____gridEntityXMLMap = require("src.maps.gridEntityXMLMap")
|
|
@@ -25456,6 +25457,7 @@ local asNumber = ____types.asNumber
|
|
|
25456
25457
|
local isNumber = ____types.isNumber
|
|
25457
25458
|
local ____utils = require("src.functions.utils")
|
|
25458
25459
|
local eRange = ____utils.eRange
|
|
25460
|
+
local iRange = ____utils.iRange
|
|
25459
25461
|
local ____vector = require("src.functions.vector")
|
|
25460
25462
|
local isVector = ____vector.isVector
|
|
25461
25463
|
local vectorEquals = ____vector.vectorEquals
|
|
@@ -25475,6 +25477,11 @@ function getAllGridEntities(self)
|
|
|
25475
25477
|
end
|
|
25476
25478
|
return gridEntities
|
|
25477
25479
|
end
|
|
25480
|
+
function ____exports.getGridEntityCollisionPoints(self, gridEntity)
|
|
25481
|
+
local topLeft = Vector(gridEntity.Position.X - DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y - DISTANCE_OF_GRID_TILE / 2)
|
|
25482
|
+
local bottomRight = Vector(gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2)
|
|
25483
|
+
return {topLeft, bottomRight}
|
|
25484
|
+
end
|
|
25478
25485
|
function ____exports.getTopLeftWallGridIndex(self)
|
|
25479
25486
|
local room = game:GetRoom()
|
|
25480
25487
|
local roomShape = room:GetRoomShape()
|
|
@@ -25568,8 +25575,7 @@ function ____exports.convertXMLGridEntityType(self, gridEntityXMLType, gridEntit
|
|
|
25568
25575
|
return {gridEntityType, variant}
|
|
25569
25576
|
end
|
|
25570
25577
|
function ____exports.getCollidingEntitiesWithGridEntity(self, gridEntity)
|
|
25571
|
-
local
|
|
25572
|
-
local gridEntityCollisionBottomRight = Vector(gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2)
|
|
25578
|
+
local topLeft, bottomRight = table.unpack(____exports.getGridEntityCollisionPoints(nil, gridEntity))
|
|
25573
25579
|
local closeEntities = Isaac.FindInRadius(gridEntity.Position, DISTANCE_OF_GRID_TILE * 2)
|
|
25574
25580
|
return __TS__ArrayFilter(
|
|
25575
25581
|
closeEntities,
|
|
@@ -25577,8 +25583,8 @@ function ____exports.getCollidingEntitiesWithGridEntity(self, gridEntity)
|
|
|
25577
25583
|
nil,
|
|
25578
25584
|
entity.Position,
|
|
25579
25585
|
entity.Size + 0.1,
|
|
25580
|
-
|
|
25581
|
-
|
|
25586
|
+
topLeft,
|
|
25587
|
+
bottomRight
|
|
25582
25588
|
) end
|
|
25583
25589
|
)
|
|
25584
25590
|
end
|
|
@@ -25612,6 +25618,42 @@ function ____exports.getGridEntitiesExcept(self, ...)
|
|
|
25612
25618
|
end
|
|
25613
25619
|
)
|
|
25614
25620
|
end
|
|
25621
|
+
function ____exports.getGridEntitiesInRadius(self, targetPosition, radius)
|
|
25622
|
+
radius = math.abs(radius)
|
|
25623
|
+
local topLeftOffset = VectorOne * -radius
|
|
25624
|
+
local mostTopLeftPosition = targetPosition + topLeftOffset
|
|
25625
|
+
local room = game:GetRoom()
|
|
25626
|
+
local diameter = radius * 2
|
|
25627
|
+
local iterations = math.ceil(diameter / DISTANCE_OF_GRID_TILE)
|
|
25628
|
+
local separation = diameter / iterations
|
|
25629
|
+
local gridEntities = {}
|
|
25630
|
+
local registeredGridIndexes = __TS__New(Set)
|
|
25631
|
+
for ____, x in ipairs(iRange(nil, iterations)) do
|
|
25632
|
+
for ____, y in ipairs(iRange(nil, iterations)) do
|
|
25633
|
+
do
|
|
25634
|
+
local position = mostTopLeftPosition + Vector(x * separation, y * separation)
|
|
25635
|
+
local gridIndex = room:GetGridIndex(position)
|
|
25636
|
+
local gridEntity = room:GetGridEntityFromPos(position)
|
|
25637
|
+
if gridEntity == nil or registeredGridIndexes:has(gridIndex) then
|
|
25638
|
+
goto __continue20
|
|
25639
|
+
end
|
|
25640
|
+
registeredGridIndexes:add(gridIndex)
|
|
25641
|
+
local topLeft, bottomRight = table.unpack(____exports.getGridEntityCollisionPoints(nil, gridEntity))
|
|
25642
|
+
if isCircleIntersectingRectangle(
|
|
25643
|
+
nil,
|
|
25644
|
+
targetPosition,
|
|
25645
|
+
radius,
|
|
25646
|
+
topLeft,
|
|
25647
|
+
bottomRight
|
|
25648
|
+
) then
|
|
25649
|
+
gridEntities[#gridEntities + 1] = gridEntity
|
|
25650
|
+
end
|
|
25651
|
+
end
|
|
25652
|
+
::__continue20::
|
|
25653
|
+
end
|
|
25654
|
+
end
|
|
25655
|
+
return gridEntities
|
|
25656
|
+
end
|
|
25615
25657
|
function ____exports.getGridEntitiesMap(self, ...)
|
|
25616
25658
|
local gridEntities = ____exports.getGridEntities(nil, ...)
|
|
25617
25659
|
local gridEntityMap = __TS__New(Map)
|
|
@@ -52,6 +52,8 @@ export declare function getGridEntities(...gridEntityTypes: GridEntityType[]): G
|
|
|
52
52
|
* exclude.
|
|
53
53
|
*/
|
|
54
54
|
export declare function getGridEntitiesExcept(...gridEntityTypes: GridEntityType[]): GridEntity[];
|
|
55
|
+
/** Helper function to get all grid entities in a given radius around a given point. */
|
|
56
|
+
export declare function getGridEntitiesInRadius(targetPosition: Vector, radius: number): GridEntity[];
|
|
55
57
|
/**
|
|
56
58
|
* Helper function to get a map of every grid entity in the current room. The indexes of the map are
|
|
57
59
|
* equal to the grid index. The values of the map are equal to the grid entities.
|
|
@@ -60,6 +62,8 @@ export declare function getGridEntitiesExcept(...gridEntityTypes: GridEntityType
|
|
|
60
62
|
* arguments to match specific grid entity types.
|
|
61
63
|
*/
|
|
62
64
|
export declare function getGridEntitiesMap(...gridEntityTypes: GridEntityType[]): Map<int, GridEntity>;
|
|
65
|
+
/** Helper function to get the top left and bottom right corners of a given grid entity. */
|
|
66
|
+
export declare function getGridEntityCollisionPoints(gridEntity: GridEntity): [topLeft: Vector, bottomRight: Vector];
|
|
63
67
|
/** Helper function to get a string containing the grid entity's type and variant. */
|
|
64
68
|
export declare function getGridEntityID(gridEntity: GridEntity): string;
|
|
65
69
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gridEntities.d.ts","sourceRoot":"","sources":["../../../src/functions/gridEntities.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACd,iBAAiB,EAIlB,MAAM,8BAA8B,CAAC;AAStC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAgCvD;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,iBAAiB,EAAE,iBAAiB,EACpC,oBAAoB,EAAE,GAAG,GACxB,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,SAAS,CAqBnC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,GAAG,EAAE,CAKzC;AAED;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CAChD,UAAU,EAAE,UAAU,GACrB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"gridEntities.d.ts","sourceRoot":"","sources":["../../../src/functions/gridEntities.ts"],"names":[],"mappings":"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"}
|
|
@@ -16,6 +16,7 @@ local ____cachedClasses = require("src.core.cachedClasses")
|
|
|
16
16
|
local game = ____cachedClasses.game
|
|
17
17
|
local ____constants = require("src.core.constants")
|
|
18
18
|
local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
|
|
19
|
+
local VectorOne = ____constants.VectorOne
|
|
19
20
|
local ____gridEntityTypeToBrokenStateMap = require("src.maps.gridEntityTypeToBrokenStateMap")
|
|
20
21
|
local GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP = ____gridEntityTypeToBrokenStateMap.GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP
|
|
21
22
|
local ____gridEntityXMLMap = require("src.maps.gridEntityXMLMap")
|
|
@@ -38,6 +39,7 @@ local asNumber = ____types.asNumber
|
|
|
38
39
|
local isNumber = ____types.isNumber
|
|
39
40
|
local ____utils = require("src.functions.utils")
|
|
40
41
|
local eRange = ____utils.eRange
|
|
42
|
+
local iRange = ____utils.iRange
|
|
41
43
|
local ____vector = require("src.functions.vector")
|
|
42
44
|
local isVector = ____vector.isVector
|
|
43
45
|
local vectorEquals = ____vector.vectorEquals
|
|
@@ -60,6 +62,12 @@ function getAllGridEntities(self)
|
|
|
60
62
|
end
|
|
61
63
|
return gridEntities
|
|
62
64
|
end
|
|
65
|
+
--- Helper function to get the top left and bottom right corners of a given grid entity.
|
|
66
|
+
function ____exports.getGridEntityCollisionPoints(self, gridEntity)
|
|
67
|
+
local topLeft = Vector(gridEntity.Position.X - DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y - DISTANCE_OF_GRID_TILE / 2)
|
|
68
|
+
local bottomRight = Vector(gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2)
|
|
69
|
+
return {topLeft, bottomRight}
|
|
70
|
+
end
|
|
63
71
|
--- Helper function to get the grid index of the top left wall. (This will depend on what the current
|
|
64
72
|
-- room shape is.)
|
|
65
73
|
function ____exports.getTopLeftWallGridIndex(self)
|
|
@@ -181,8 +189,7 @@ end
|
|
|
181
189
|
-- Note that this function will not work properly in the `POST_NEW_ROOM` callback, since entities do
|
|
182
190
|
-- not have collision yet in that callback.
|
|
183
191
|
function ____exports.getCollidingEntitiesWithGridEntity(self, gridEntity)
|
|
184
|
-
local
|
|
185
|
-
local gridEntityCollisionBottomRight = Vector(gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2, gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2)
|
|
192
|
+
local topLeft, bottomRight = table.unpack(____exports.getGridEntityCollisionPoints(nil, gridEntity))
|
|
186
193
|
local closeEntities = Isaac.FindInRadius(gridEntity.Position, DISTANCE_OF_GRID_TILE * 2)
|
|
187
194
|
return __TS__ArrayFilter(
|
|
188
195
|
closeEntities,
|
|
@@ -190,8 +197,8 @@ function ____exports.getCollidingEntitiesWithGridEntity(self, gridEntity)
|
|
|
190
197
|
nil,
|
|
191
198
|
entity.Position,
|
|
192
199
|
entity.Size + 0.1,
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
topLeft,
|
|
201
|
+
bottomRight
|
|
195
202
|
) end
|
|
196
203
|
)
|
|
197
204
|
end
|
|
@@ -251,6 +258,43 @@ function ____exports.getGridEntitiesExcept(self, ...)
|
|
|
251
258
|
end
|
|
252
259
|
)
|
|
253
260
|
end
|
|
261
|
+
--- Helper function to get all grid entities in a given radius around a given point.
|
|
262
|
+
function ____exports.getGridEntitiesInRadius(self, targetPosition, radius)
|
|
263
|
+
radius = math.abs(radius)
|
|
264
|
+
local topLeftOffset = VectorOne * -radius
|
|
265
|
+
local mostTopLeftPosition = targetPosition + topLeftOffset
|
|
266
|
+
local room = game:GetRoom()
|
|
267
|
+
local diameter = radius * 2
|
|
268
|
+
local iterations = math.ceil(diameter / DISTANCE_OF_GRID_TILE)
|
|
269
|
+
local separation = diameter / iterations
|
|
270
|
+
local gridEntities = {}
|
|
271
|
+
local registeredGridIndexes = __TS__New(Set)
|
|
272
|
+
for ____, x in ipairs(iRange(nil, iterations)) do
|
|
273
|
+
for ____, y in ipairs(iRange(nil, iterations)) do
|
|
274
|
+
do
|
|
275
|
+
local position = mostTopLeftPosition + Vector(x * separation, y * separation)
|
|
276
|
+
local gridIndex = room:GetGridIndex(position)
|
|
277
|
+
local gridEntity = room:GetGridEntityFromPos(position)
|
|
278
|
+
if gridEntity == nil or registeredGridIndexes:has(gridIndex) then
|
|
279
|
+
goto __continue20
|
|
280
|
+
end
|
|
281
|
+
registeredGridIndexes:add(gridIndex)
|
|
282
|
+
local topLeft, bottomRight = table.unpack(____exports.getGridEntityCollisionPoints(nil, gridEntity))
|
|
283
|
+
if isCircleIntersectingRectangle(
|
|
284
|
+
nil,
|
|
285
|
+
targetPosition,
|
|
286
|
+
radius,
|
|
287
|
+
topLeft,
|
|
288
|
+
bottomRight
|
|
289
|
+
) then
|
|
290
|
+
gridEntities[#gridEntities + 1] = gridEntity
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
::__continue20::
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
return gridEntities
|
|
297
|
+
end
|
|
254
298
|
--- Helper function to get a map of every grid entity in the current room. The indexes of the map are
|
|
255
299
|
-- equal to the grid index. The values of the map are equal to the grid entities.
|
|
256
300
|
--
|
|
@@ -40,7 +40,7 @@ export declare function lerpAngleDegrees(aStart: number, aEnd: number, percent:
|
|
|
40
40
|
* From: http://lua-users.org/wiki/SimpleRound
|
|
41
41
|
*
|
|
42
42
|
* @param num The number to round.
|
|
43
|
-
* @param numDecimalPlaces Default is 0.
|
|
43
|
+
* @param numDecimalPlaces Optional. Default is 0.
|
|
44
44
|
*/
|
|
45
45
|
export declare function round(num: float, numDecimalPlaces?: number): float;
|
|
46
46
|
/**
|
|
@@ -90,7 +90,7 @@ end
|
|
|
90
90
|
-- From: http://lua-users.org/wiki/SimpleRound
|
|
91
91
|
--
|
|
92
92
|
-- @param num The number to round.
|
|
93
|
-
-- @param numDecimalPlaces Default is 0.
|
|
93
|
+
-- @param numDecimalPlaces Optional. Default is 0.
|
|
94
94
|
function ____exports.round(self, num, numDecimalPlaces)
|
|
95
95
|
if numDecimalPlaces == nil then
|
|
96
96
|
numDecimalPlaces = 0
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TrapdoorVariant,
|
|
9
9
|
} from "isaac-typescript-definitions";
|
|
10
10
|
import { game } from "../core/cachedClasses";
|
|
11
|
-
import { DISTANCE_OF_GRID_TILE } from "../core/constants";
|
|
11
|
+
import { DISTANCE_OF_GRID_TILE, VectorOne } from "../core/constants";
|
|
12
12
|
import { GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP } from "../maps/gridEntityTypeToBrokenStateMap";
|
|
13
13
|
import { GRID_ENTITY_XML_MAP } from "../maps/gridEntityXMLMap";
|
|
14
14
|
import {
|
|
@@ -22,7 +22,7 @@ import { isCircleIntersectingRectangle } from "./math";
|
|
|
22
22
|
import { roomUpdateSafe } from "./rooms";
|
|
23
23
|
import { clearSprite } from "./sprites";
|
|
24
24
|
import { asNumber, isNumber } from "./types";
|
|
25
|
-
import { eRange } from "./utils";
|
|
25
|
+
import { eRange, iRange } from "./utils";
|
|
26
26
|
import { isVector, vectorEquals } from "./vector";
|
|
27
27
|
|
|
28
28
|
const BREAKABLE_GRID_ENTITY_TYPES_BY_EXPLOSIONS: ReadonlySet<GridEntityType> =
|
|
@@ -100,15 +100,7 @@ export function getAllGridIndexes(): int[] {
|
|
|
100
100
|
export function getCollidingEntitiesWithGridEntity(
|
|
101
101
|
gridEntity: GridEntity,
|
|
102
102
|
): Entity[] {
|
|
103
|
-
const
|
|
104
|
-
gridEntity.Position.X - DISTANCE_OF_GRID_TILE / 2,
|
|
105
|
-
gridEntity.Position.Y - DISTANCE_OF_GRID_TILE / 2,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const gridEntityCollisionBottomRight = Vector(
|
|
109
|
-
gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2,
|
|
110
|
-
gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2,
|
|
111
|
-
);
|
|
103
|
+
const [topLeft, bottomRight] = getGridEntityCollisionPoints(gridEntity);
|
|
112
104
|
|
|
113
105
|
const closeEntities = Isaac.FindInRadius(
|
|
114
106
|
gridEntity.Position,
|
|
@@ -123,8 +115,8 @@ export function getCollidingEntitiesWithGridEntity(
|
|
|
123
115
|
// We arbitrarily add 0.1 to account for entities that are already pushed back by the time
|
|
124
116
|
// the `POST_UPDATE` callback fires.
|
|
125
117
|
entity.Size + 0.1,
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
topLeft,
|
|
119
|
+
bottomRight,
|
|
128
120
|
),
|
|
129
121
|
);
|
|
130
122
|
}
|
|
@@ -205,6 +197,53 @@ export function getGridEntitiesExcept(
|
|
|
205
197
|
});
|
|
206
198
|
}
|
|
207
199
|
|
|
200
|
+
/** Helper function to get all grid entities in a given radius around a given point. */
|
|
201
|
+
export function getGridEntitiesInRadius(
|
|
202
|
+
targetPosition: Vector,
|
|
203
|
+
radius: number,
|
|
204
|
+
): GridEntity[] {
|
|
205
|
+
radius = math.abs(radius);
|
|
206
|
+
const topLeftOffset = VectorOne.mul(-radius);
|
|
207
|
+
const mostTopLeftPosition = targetPosition.add(topLeftOffset);
|
|
208
|
+
const room = game.GetRoom();
|
|
209
|
+
|
|
210
|
+
const diameter = radius * 2;
|
|
211
|
+
const iterations = math.ceil(diameter / DISTANCE_OF_GRID_TILE);
|
|
212
|
+
const separation = diameter / iterations;
|
|
213
|
+
|
|
214
|
+
const gridEntities: GridEntity[] = [];
|
|
215
|
+
const registeredGridIndexes = new Set<number>();
|
|
216
|
+
for (const x of iRange(iterations)) {
|
|
217
|
+
for (const y of iRange(iterations)) {
|
|
218
|
+
const position = mostTopLeftPosition.add(
|
|
219
|
+
Vector(x * separation, y * separation),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const gridIndex = room.GetGridIndex(position);
|
|
223
|
+
const gridEntity = room.GetGridEntityFromPos(position);
|
|
224
|
+
if (gridEntity === undefined || registeredGridIndexes.has(gridIndex)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
registeredGridIndexes.add(gridIndex);
|
|
229
|
+
const [topLeft, bottomRight] = getGridEntityCollisionPoints(gridEntity);
|
|
230
|
+
|
|
231
|
+
if (
|
|
232
|
+
isCircleIntersectingRectangle(
|
|
233
|
+
targetPosition,
|
|
234
|
+
radius,
|
|
235
|
+
topLeft,
|
|
236
|
+
bottomRight,
|
|
237
|
+
)
|
|
238
|
+
) {
|
|
239
|
+
gridEntities.push(gridEntity);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return gridEntities;
|
|
245
|
+
}
|
|
246
|
+
|
|
208
247
|
/**
|
|
209
248
|
* Helper function to get a map of every grid entity in the current room. The indexes of the map are
|
|
210
249
|
* equal to the grid index. The values of the map are equal to the grid entities.
|
|
@@ -226,6 +265,22 @@ export function getGridEntitiesMap(
|
|
|
226
265
|
return gridEntityMap;
|
|
227
266
|
}
|
|
228
267
|
|
|
268
|
+
/** Helper function to get the top left and bottom right corners of a given grid entity. */
|
|
269
|
+
export function getGridEntityCollisionPoints(
|
|
270
|
+
gridEntity: GridEntity,
|
|
271
|
+
): [topLeft: Vector, bottomRight: Vector] {
|
|
272
|
+
const topLeft = Vector(
|
|
273
|
+
gridEntity.Position.X - DISTANCE_OF_GRID_TILE / 2,
|
|
274
|
+
gridEntity.Position.Y - DISTANCE_OF_GRID_TILE / 2,
|
|
275
|
+
);
|
|
276
|
+
const bottomRight = Vector(
|
|
277
|
+
gridEntity.Position.X + DISTANCE_OF_GRID_TILE / 2,
|
|
278
|
+
gridEntity.Position.Y + DISTANCE_OF_GRID_TILE / 2,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
return [topLeft, bottomRight];
|
|
282
|
+
}
|
|
283
|
+
|
|
229
284
|
/** Helper function to get a string containing the grid entity's type and variant. */
|
|
230
285
|
export function getGridEntityID(gridEntity: GridEntity): string {
|
|
231
286
|
const gridEntityType = gridEntity.GetType();
|
package/src/functions/math.ts
CHANGED
|
@@ -122,7 +122,7 @@ export function lerpAngleDegrees(
|
|
|
122
122
|
* From: http://lua-users.org/wiki/SimpleRound
|
|
123
123
|
*
|
|
124
124
|
* @param num The number to round.
|
|
125
|
-
* @param numDecimalPlaces Default is 0.
|
|
125
|
+
* @param numDecimalPlaces Optional. Default is 0.
|
|
126
126
|
*/
|
|
127
127
|
export function round(num: float, numDecimalPlaces = 0): float {
|
|
128
128
|
const roundedNum = tonumber(string.format(`%.${numDecimalPlaces}f`, num));
|