@makefully/platypus 4.1.5 → 4.1.8

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.
Files changed (136) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +3 -3
  3. package/lib/platypus.js +1 -1
  4. package/package.json +7 -6
  5. package/src/AABB.js +685 -0
  6. package/src/ActionState.js +121 -0
  7. package/src/AssetManager.js +206 -0
  8. package/src/CollisionData.js +96 -0
  9. package/src/CollisionDataContainer.js +127 -0
  10. package/src/CollisionShape.js +315 -0
  11. package/src/Component.js +231 -0
  12. package/src/Data.js +64 -0
  13. package/src/DataMap.js +204 -0
  14. package/src/Entity.js +404 -0
  15. package/src/EntityLinker.js +113 -0
  16. package/src/EventHandler.js +115 -0
  17. package/src/EventHandlerList.js +251 -0
  18. package/src/Game.js +840 -0
  19. package/src/Gamepad.js +175 -0
  20. package/src/ID3CaptionPlayer.js +61 -0
  21. package/src/Messenger.js +365 -0
  22. package/src/PIXIAnimation.js +622 -0
  23. package/src/RandomSet.js +140 -0
  24. package/src/SFXPlayer.js +120 -0
  25. package/src/StateMap.js +252 -0
  26. package/src/Storage.js +152 -0
  27. package/src/TickerClient.js +48 -0
  28. package/src/TickerServer.js +23 -0
  29. package/src/TimeEvent.js +50 -0
  30. package/src/TimeEventList.js +100 -0
  31. package/src/VOPlayer.js +684 -0
  32. package/src/Vector.js +702 -0
  33. package/src/components/AIChaser.js +161 -0
  34. package/src/components/AIPacer.js +107 -0
  35. package/src/components/AudioMusic.js +151 -0
  36. package/src/components/AudioSFX.js +673 -0
  37. package/src/components/AudioVO.js +301 -0
  38. package/src/components/CollisionBasic.js +826 -0
  39. package/src/components/CollisionFilter.js +74 -0
  40. package/src/components/CollisionGroup.js +448 -0
  41. package/src/components/CollisionTiles.js +608 -0
  42. package/src/components/ComponentSwitcher.js +173 -0
  43. package/src/components/ControllerInput.js +65 -0
  44. package/src/components/Counter.js +165 -0
  45. package/src/components/EntityCamera.js +215 -0
  46. package/src/components/EntityContainer.js +549 -0
  47. package/src/components/EntityController.js +541 -0
  48. package/src/components/HandlerCamera.js +1052 -0
  49. package/src/components/HandlerCollision.js +1318 -0
  50. package/src/components/HandlerController.js +291 -0
  51. package/src/components/HandlerLogic.js +394 -0
  52. package/src/components/HandlerRender.js +217 -0
  53. package/src/components/Interactive.js +502 -0
  54. package/src/components/LevelBuilder.js +524 -0
  55. package/src/components/LogicAngularMovement.js +154 -0
  56. package/src/components/LogicAttachment.js +265 -0
  57. package/src/components/LogicButton.js +466 -0
  58. package/src/components/LogicCarrier.js +39 -0
  59. package/src/components/LogicDestroyMe.js +58 -0
  60. package/src/components/LogicDirectionalMovement.js +325 -0
  61. package/src/components/LogicDragDrop.js +371 -0
  62. package/src/components/LogicImpactLaunch.js +144 -0
  63. package/src/components/LogicPacingPlatform.js +64 -0
  64. package/src/components/LogicPortable.js +112 -0
  65. package/src/components/LogicPortal.js +115 -0
  66. package/src/components/LogicPushable.js +98 -0
  67. package/src/components/LogicRebounder.js +136 -0
  68. package/src/components/LogicRegionSpawner.js +139 -0
  69. package/src/components/LogicRotationalMovement.js +205 -0
  70. package/src/components/LogicSpawner.js +159 -0
  71. package/src/components/LogicStateMachine.js +382 -0
  72. package/src/components/LogicSwitch.js +77 -0
  73. package/src/components/LogicTeleportee.js +68 -0
  74. package/src/components/LogicTeleporter.js +93 -0
  75. package/src/components/LogicTimer.js +178 -0
  76. package/src/components/LogicWindUpRacer.js +179 -0
  77. package/src/components/Motion.js +371 -0
  78. package/src/components/Mover.js +566 -0
  79. package/src/components/Node.js +289 -0
  80. package/src/components/NodeMap.js +295 -0
  81. package/src/components/NodeResident.js +636 -0
  82. package/src/components/Orientation.js +697 -0
  83. package/src/components/RandomEvents.js +73 -0
  84. package/src/components/RelativePosition.js +204 -0
  85. package/src/components/RelayFamily.js +106 -0
  86. package/src/components/RelayGame.js +53 -0
  87. package/src/components/RelayLinker.js +94 -0
  88. package/src/components/RelayParent.js +57 -0
  89. package/src/components/RelaySelf.js +55 -0
  90. package/src/components/Render.js +178 -0
  91. package/src/components/RenderAnimator.js +275 -0
  92. package/src/components/RenderContainer.js +646 -0
  93. package/src/components/RenderDebug.js +319 -0
  94. package/src/components/RenderDestroyMe.js +59 -0
  95. package/src/components/RenderLottie.js +149 -0
  96. package/src/components/RenderProgress.js +120 -0
  97. package/src/components/RenderSpine.js +840 -0
  98. package/src/components/RenderSprite.js +527 -0
  99. package/src/components/RenderText.js +147 -0
  100. package/src/components/RenderTiles.js +1440 -0
  101. package/src/components/SceneChanger.js +128 -0
  102. package/src/components/TiledLoader.js +1459 -0
  103. package/src/components/Timeline.js +314 -0
  104. package/src/components/Tutorial.js +267 -0
  105. package/src/components/Tween.js +296 -0
  106. package/src/components/VoiceOver.js +373 -0
  107. package/src/components/XHR.js +129 -0
  108. package/src/components/index.js +79 -0
  109. package/src/factory.js +305 -0
  110. package/src/index.js +159 -0
  111. package/src/mixins/PIXI.Graphics.js +41 -0
  112. package/src/platypus.css +68 -0
  113. package/src/sayHello.js +50 -0
  114. package/src/shapes/Capsule.js +74 -0
  115. package/src/shapes/Circle.js +43 -0
  116. package/src/shapes/Ellipse.js +117 -0
  117. package/src/shapes/Point.js +191 -0
  118. package/src/shapes/Polygon.js +112 -0
  119. package/src/shapes/Polyline.js +97 -0
  120. package/src/shapes/Rectangle.js +78 -0
  121. package/src/shapes/RoundedRectangle.js +33 -0
  122. package/src/shapes/Segment.js +346 -0
  123. package/src/shapes/adjustedXY.js +19 -0
  124. package/src/shapes/castFromBox2D.js +92 -0
  125. package/src/shapes/castFromObject.js +53 -0
  126. package/src/shapes/castFromPixiGraphics.js +6 -0
  127. package/src/shapes/castFromPixiShape.js +89 -0
  128. package/src/shapes/castToBox2D.js +190 -0
  129. package/src/shapes/castToPixiGraphics.js +100 -0
  130. package/src/shapes/castToPixiShape.js +61 -0
  131. package/src/shapes/checkPointsMap.js +313 -0
  132. package/src/shapes/index.js +35 -0
  133. package/src/utils/array.js +73 -0
  134. package/src/utils/string.js +39 -0
  135. package/lib/243.platypus.mjs +0 -1
  136. package/lib/platypus.mjs +0 -1
@@ -0,0 +1,608 @@
1
+ import AABB from '../AABB.js';
2
+ import CollisionShape from '../CollisionShape.js';
3
+ import Data from '../Data.js';
4
+ import {arrayCache} from '../utils/array.js';
5
+ import createComponentClass from '../factory.js';
6
+
7
+ export default (function () {
8
+ const
9
+ maskJumpThrough = 0x10000000,
10
+ maskRotation = 0x20000000,
11
+ maskXFlip = 0x80000000,
12
+ maskYFlip = 0x40000000,
13
+ maskIndex = 0x0fffffff,
14
+ getDefaultType = function () {
15
+ return this.collisionType;
16
+ },
17
+ getCollisionType = function (index) {
18
+ return this.collisionTypeMap[index & maskIndex] || this.collisionType;
19
+ },
20
+ flipDiagonal = function (num) {
21
+ if (num === 0) {
22
+ return num;
23
+ } else {
24
+ return num ^ maskYFlip ^ maskRotation;
25
+ }
26
+ },
27
+ flipDiagonalInverse = function (num) {
28
+ if (num === 0) {
29
+ return num;
30
+ } else {
31
+ return num ^ maskXFlip ^ maskRotation;
32
+ }
33
+ },
34
+ flipX = function (num) {
35
+ if (num === 0) {
36
+ return num;
37
+ } else {
38
+ return num ^ maskXFlip;
39
+ }
40
+ },
41
+ flipY = function (num) {
42
+ if (num === 0) {
43
+ return num;
44
+ } else {
45
+ return num ^ maskYFlip;
46
+ }
47
+ },
48
+ rotate90 = function (num) {
49
+ if (num === 0) {
50
+ return num;
51
+ } else if (maskRotation & num) {
52
+ return num ^ maskYFlip ^ maskRotation;
53
+ } else {
54
+ return num ^ maskXFlip ^ maskRotation;
55
+ }
56
+ },
57
+ rotate180 = function (num) {
58
+ if (num === 0) {
59
+ return num;
60
+ } else {
61
+ return num ^ maskXFlip ^ maskYFlip;
62
+ }
63
+ },
64
+ rotate270 = function (num) {
65
+ if (num === 0) {
66
+ return num;
67
+ } else if (maskRotation & num) {
68
+ return num ^ maskXFlip ^ maskRotation;
69
+ } else {
70
+ return num ^ maskYFlip ^ maskRotation;
71
+ }
72
+ },
73
+ copySection = function (array, originX, originY, width, height) {
74
+ const
75
+ arr = arrayCache.setUp();
76
+
77
+ for (let y = 0; y < height; y++) {
78
+ arr[y] = arrayCache.setUp();
79
+ for (let x = 0; x < width; x++) {
80
+ arr[y][x] = array[originX + x][originY + y];
81
+ }
82
+ }
83
+ return arr;
84
+ },
85
+ cutSection = function (array, originX, originY, width, height) {
86
+ const
87
+ arr = arrayCache.setUp();
88
+
89
+ for (let y = 0; y < height; y++) {
90
+ arr[y] = arrayCache.setUp();
91
+ for (let x = 0; x < width; x++) {
92
+ arr[y][x] = array[originX + x][originY + y];
93
+ array[originX + x][originY + y] = -1;
94
+ }
95
+ }
96
+ return arr;
97
+ },
98
+ pasteSection = function (destinationArray, sourceArray, originX, originY, width, height) {
99
+ for (let y = 0; y < height; y++) {
100
+ for (let x = 0; x < width; x++) {
101
+ destinationArray[originX + x][originY + y] = sourceArray[y][x];
102
+ }
103
+ }
104
+ return destinationArray;
105
+ },
106
+ transforms = {
107
+ "diagonal": function (array, originX, originY, width, height) {
108
+ const
109
+ arr = copySection(array, originX, originY, width, height),
110
+ fD = flipDiagonal;
111
+
112
+ for (let x = 0; x < width; x++) {
113
+ for (let y = 0; y < height; y++) {
114
+ array[originX + x][originY + y] = fD(arr[x][y]);
115
+ }
116
+ }
117
+ arrayCache.recycle(arr, 2);
118
+ return array;
119
+ },
120
+ "diagonal-inverse": function (array, originX, originY, width, height) {
121
+ const
122
+ arr = copySection(array, originX, originY, width, height),
123
+ fDI = flipDiagonalInverse;
124
+
125
+ for (let x = 0; x < width; x++) {
126
+ for (let y = 0; y < height; y++) {
127
+ array[originX + width - x - 1][originY + height - y - 1] = fDI(arr[x][y]);
128
+ }
129
+ }
130
+ arrayCache.recycle(arr, 2);
131
+ return array;
132
+ },
133
+ "horizontal": function (array, originX, originY, width, height) {
134
+ const
135
+ arr = copySection(array, originX, originY, width, height),
136
+ fX = flipX;
137
+
138
+ for (let y = 0; y < height; y++) {
139
+ for (let x = 0; x < width; x++) {
140
+ array[originX + width - x - 1][originY + y] = fX(arr[y][x]);
141
+ }
142
+ }
143
+ arrayCache.recycle(arr, 2);
144
+ return array;
145
+ },
146
+ "vertical": function (array, originX, originY, width, height) {
147
+ const
148
+ arr = copySection(array, originX, originY, width, height),
149
+ fY = flipY;
150
+
151
+ for (let y = 0; y < height; y++) {
152
+ for (let x = 0; x < width; x++) {
153
+ array[originX + x][originY + height - y - 1] = fY(arr[y][x]);
154
+ }
155
+ }
156
+ arrayCache.recycle(arr, 2);
157
+ return array;
158
+ },
159
+ "rotate-90": function (array, originX, originY, width, height) {
160
+ const
161
+ arr = copySection(array, originX, originY, width, height),
162
+ r90 = rotate90;
163
+
164
+ for (let y = 0; y < height; y++) {
165
+ for (let x = 0; x < width; x++) {
166
+ array[originX + height - y - 1][originY + x] = r90(arr[y][x]);
167
+ }
168
+ }
169
+ arrayCache.recycle(arr, 2);
170
+ return array;
171
+ },
172
+ "rotate-180": function (array, originX, originY, width, height) {
173
+ const
174
+ arr = copySection(array, originX, originY, width, height),
175
+ r180 = rotate180;
176
+
177
+ for (let y = 0; y < height; y++) {
178
+ for (let x = 0; x < width; x++) {
179
+ array[originX + width - x - 1][originY + height - y - 1] = r180(arr[y][x]);
180
+ }
181
+ }
182
+ arrayCache.recycle(arr, 2);
183
+ return array;
184
+ },
185
+ "rotate-270": function (array, originX, originY, width, height) {
186
+ const
187
+ arr = copySection(array, originX, originY, width, height),
188
+ r270 = rotate270;
189
+
190
+ for (let y = 0; y < height; y++) {
191
+ for (let x = 0; x < width; x++) {
192
+ array[originX + y][originY + width - x - 1] = r270(arr[y][x]);
193
+ }
194
+ }
195
+ arrayCache.recycle(arr, 2);
196
+ return array;
197
+ },
198
+ "translate": function (array, originX, originY, width, height, dx, dy) {
199
+ const
200
+ arr = cutSection(array, originX, originY, width, height);
201
+
202
+ for (let y = 0; y < height; y++) {
203
+ for (let x = 0; x < width; x++) {
204
+ array[originX + x + dx][originY + y + dy] = arr[y][x];
205
+ }
206
+ }
207
+ arrayCache.recycle(arr, 2);
208
+ return array;
209
+ }
210
+ };
211
+
212
+ return createComponentClass(/** @lends platypus.components.CollisionTiles.prototype */{
213
+ id: 'CollisionTiles',
214
+
215
+ properties: {
216
+ /**
217
+ * Maps tile indexes to particular collision types. This defaults to a "tiles" collision type for all non-zero values if a particular collision map is not provided.
218
+ *
219
+ * @property collisionTypeMap
220
+ * @type Object
221
+ * @default null
222
+ */
223
+ collisionTypeMap: null,
224
+
225
+ /**
226
+ * Sets the default collision type for non-zero map tiles.
227
+ *
228
+ * @property collisionType
229
+ * @type String
230
+ * @default "tiles"
231
+ */
232
+ collisionType: 'tiles',
233
+
234
+ /**
235
+ * The map's top offset.
236
+ *
237
+ * @property top
238
+ * @type Number
239
+ * @default 0
240
+ */
241
+ top: 0,
242
+
243
+ /**
244
+ * The map's left offset.
245
+ *
246
+ * @property left
247
+ * @type Number
248
+ * @default 0
249
+ */
250
+ left: 0
251
+ },
252
+
253
+ publicProperties: {
254
+ /**
255
+ * A 3D array describing the layers of the tile-map with off (0) and on (!0) states. The indexes match Tiled map data indexes with an additional bit setting (0x2000000) for jumpthrough tiles. Example: `[[[0, 0, 0], [1, 0, 0], [1, 1, 1]], [[0, 1, 0], [1, 0, 0], [1, 0, 0]]]`. Available on the entity as `entity.collisionMap`.
256
+ *
257
+ * @property collisionMap
258
+ * @type Array
259
+ * @default []
260
+ */
261
+ collisionMap: [],
262
+
263
+ /**
264
+ * The width of tiles in world coordinates. Available on the entity as `entity.tileWidth`.
265
+ *
266
+ * @property tileWidth
267
+ * @type number
268
+ * @default 10
269
+ */
270
+ tileWidth: 10,
271
+
272
+ /**
273
+ * The height of tiles in world coordinates. Available on the entity as `entity.tileHeight`.
274
+ *
275
+ * @property tileWidth
276
+ * @type number
277
+ * @default 10
278
+ */
279
+ tileHeight: 10
280
+ },
281
+
282
+ /**
283
+ * This component causes the tile-map to collide with other entities. It must be part of a collision group and will cause "hit-by-tile" messages to fire on colliding entities.
284
+ *
285
+ * @memberof platypus.components
286
+ * @uses platypus.Component
287
+ * @constructs
288
+ * @listens platypus.Entity#transform
289
+ * @listens platypus.Entity#translate
290
+ */
291
+ initialize: function () {
292
+ this.tileOffsetLeft = this.tileWidth / 2 + this.left;
293
+ this.tileOffsetTop = this.tileHeight / 2 + this.top;
294
+
295
+ this.columns = this.collisionMap[0].length;
296
+ this.rows = this.collisionMap[0][0].length;
297
+
298
+ this.shapeDefinition = Data.setUp(
299
+ "x", 0,
300
+ "y", 0,
301
+ "type", 'rectangle',
302
+ "width", this.tileWidth,
303
+ "height", this.tileHeight
304
+ );
305
+
306
+ this.storedTiles = arrayCache.setUp();
307
+ this.serveTiles = arrayCache.setUp();
308
+ this.storedTileIndex = 0;
309
+
310
+ this.aabb = AABB.setUp();
311
+ this.aabb.setBounds(this.left, this.top, this.tileWidth * this.columns + this.left, this.tileHeight * this.rows + this.top);
312
+
313
+ if (this.collisionTypeMap) {
314
+ this.getType = getCollisionType;
315
+ } else {
316
+ this.getType = getDefaultType;
317
+ }
318
+ },
319
+
320
+ events: {
321
+ "transform": function (transform) {
322
+ this.transform(transform);
323
+ },
324
+
325
+ "translate": function (translate) {
326
+ this.translate(translate);
327
+ },
328
+ /**
329
+ * This event adds a layer of tiles to the collision map.
330
+ *
331
+ * @event platypus.Entity#add-collision-tiles
332
+ * @param message.imageMap {Array} This is a 2D mapping of tile indexes to be added to the collision map.
333
+ */
334
+ "add-collision-tiles": function (definition) {
335
+ const map = definition.collisionMap[0],
336
+ typeMap = definition.collisionTypeMap;
337
+ let tileIndex = 0;
338
+
339
+ if (map) {
340
+ this.collisionMap.push(map);
341
+ }
342
+
343
+ if (typeMap) {
344
+ for (tileIndex in typeMap) {
345
+ if (this.collisionTypeMap[tileIndex]) {
346
+ console.warn('Overwriting existing typeMap.');
347
+ }
348
+ this.collisionTypeMap[tileIndex] = typeMap[tileIndex];
349
+ }
350
+ }
351
+ }
352
+ },
353
+
354
+ methods: {
355
+ getShape: function (x, y, type) {
356
+ const
357
+ {storedTileIndex: i, storedTiles} = this;
358
+ let shape = null;
359
+
360
+ if (i === storedTiles.length) {
361
+ shape = CollisionShape.setUp(null, this.shapeDefinition, type);
362
+ storedTiles.push(shape);
363
+ } else {
364
+ shape = storedTiles[i];
365
+ shape.collisionType = type;
366
+ }
367
+
368
+ shape.update(x * this.tileWidth + this.tileOffsetLeft, y * this.tileHeight + this.tileOffsetTop);
369
+
370
+ this.storedTileIndex += 1;
371
+
372
+ return shape;
373
+ },
374
+
375
+ addShape: function (shapes, prevAABB, layer, x, y, collisionType) {
376
+ const
377
+ xy = this.collisionMap[layer][x][y],
378
+ index = xy & maskIndex;
379
+
380
+ if (xy && (this.getType(index) === collisionType)) {
381
+ const
382
+ jumpThrough = maskJumpThrough & xy;
383
+
384
+ if (jumpThrough) {
385
+ const
386
+ rotation = maskRotation & xy,
387
+ xFlip = maskXFlip & xy,
388
+ yFlip = maskYFlip & xy;
389
+
390
+ if (rotation && xFlip) { // Right
391
+ if (prevAABB.left >= (x + 1) * this.tileWidth + this.left) {
392
+ shapes.push(this.getShape(x, y, collisionType));
393
+ }
394
+ } else if (rotation) { // Left
395
+ if (prevAABB.right <= x * this.tileWidth + this.left) {
396
+ shapes.push(this.getShape(x, y, collisionType));
397
+ }
398
+ } else if (yFlip) { // Bottom
399
+ if (prevAABB.top >= (y + 1) * this.tileHeight + this.top) {
400
+ shapes.push(this.getShape(x, y, collisionType));
401
+ }
402
+ } else if (prevAABB.bottom <= y * this.tileHeight + this.top) { // Top
403
+ shapes.push(this.getShape(x, y, collisionType));
404
+ }
405
+ } else {
406
+ shapes.push(this.getShape(x, y, collisionType));
407
+ }
408
+ }
409
+
410
+ return shapes;
411
+ },
412
+
413
+ destroy: function () {
414
+ const
415
+ store = this.storedTiles;
416
+ let i = store.length;
417
+
418
+ this.shapeDefinition.recycle();
419
+ this.shapeDefinition = null;
420
+
421
+ while (i--) {
422
+ store[i].recycle();
423
+ }
424
+ arrayCache.recycle(store);
425
+ this.storedTiles = null;
426
+
427
+ arrayCache.recycle(this.serveTiles);
428
+ this.serveTiles = null;
429
+
430
+ this.aabb.recycle();
431
+ this.aabb = null;
432
+ }
433
+ },
434
+
435
+ publicMethods: {
436
+ /**
437
+ * Returns the axis-aligned bounding box of the entire map.
438
+ *
439
+ * @method platypus.components.CollisionTiles#getAABB
440
+ * @return aabb {platypus.AABB} The returned object provides the top, left, width, and height of the collision map.
441
+ */
442
+ getAABB: function () {
443
+ return this.aabb;
444
+ },
445
+
446
+ /**
447
+ * Confirms whether a particular map grid coordinate contains a tile.
448
+ *
449
+ * @method platypus.components.CollisionTiles#isTile
450
+ * @param x {number} Integer specifying the column of tiles in the collision map to check.
451
+ * @param y {number} Integer specifying the row of tiles in the collision map to check.
452
+ * @return {boolean} Returns `true` if the coordinate contains a collision tile, `false` if it does not.
453
+ */
454
+ isTile: function (x, y) {
455
+ let z = 0;
456
+
457
+ if ((x < 0) || (y < 0) || (x >= this.columns) || (y >= this.rows)) {
458
+ return false;
459
+ }
460
+
461
+ for (z = 0; z < this.collisionMap.length; z++) {
462
+ if (this.collisionMap[z][x][y] !== -1) {
463
+ return true;
464
+ }
465
+ }
466
+
467
+ return false;
468
+ },
469
+
470
+ /**
471
+ * Returns all the collision tiles within the provided axis-aligned bounding box as an array of shapes.
472
+ *
473
+ * @method platypus.components.CollisionTiles#getTileShapes
474
+ * @param aabb {platypus.AABB} The axis-aligned bounding box for which tiles should be returned.
475
+ * @param prevAABB {platypus.AABB} The axis-aligned bounding box for a previous location to test for jump-through tiles.
476
+ * @param [collisionType] {String} The type of collision to check for. If not specified, "tiles" is used. (Since 0.8.3)
477
+ * @return {Array} Each returned object provides the [CollisionShape](CollisionShape.html) of a tile.
478
+ */
479
+ getTileShapes: function (aabb, prevAABB, collisionType) {
480
+ const
481
+ colType = collisionType || 'tiles',
482
+ l = this.left,
483
+ t = this.top,
484
+ th = this.tileHeight,
485
+ tw = this.tileWidth,
486
+ left = Math.max(Math.floor((aabb.left - l) / tw), 0),
487
+ top = Math.max(Math.floor((aabb.top - t) / th), 0),
488
+ right = Math.min(Math.ceil((aabb.right - l) / tw), this.columns),
489
+ bottom = Math.min(Math.ceil((aabb.bottom - t) / th), this.rows),
490
+ shapes = this.serveTiles;
491
+
492
+ shapes.length = 0;
493
+ this.storedTileIndex = 0;
494
+ for (let z = 0; z < this.collisionMap.length; z++) {
495
+ for (let x = left; x < right; x++) {
496
+ for (let y = top; y < bottom; y++) {
497
+ this.addShape(shapes, prevAABB, z, x, y, colType);
498
+ }
499
+ }
500
+ }
501
+
502
+
503
+ return shapes;
504
+ },
505
+
506
+ /**
507
+ * Performs a transform of a subset of the collision tile grid.
508
+ *
509
+ * @method platypus.components.CollisionTiles#transform
510
+ * @param [transform] {Object} A list of key/value pairs describing the transform.
511
+ * @param [transform.layers] {Array.<number>} The layer indexes on which to apply the transform, if not provided transforms all layers. Defaults to the 0th index.
512
+ * @param [transform.type="horizontal"] {String} The type of transform; one of the following: "horizontal", "vertical", "diagonal", "diagonal-inverse", "rotate-90", "rotate-180", "rotate-270". Height and width should match for diagonal flips and 90 degree rotations.
513
+ * @param [transform.left=0] {number} Grid coordinate for the left side of the bounding box.
514
+ * @param [transform.top=0] {number} Grid coordinate for the top of the bounding box.
515
+ * @param [transform.width=grid.width] {number} Cell width of the bounding box.
516
+ * @param [transform.height=grid.height] {number} Cell height of the bounding box.
517
+ */
518
+ transform: function (transform = {}) {
519
+ const {
520
+ layers = [0],
521
+ left: x = 0,
522
+ top: y = 0,
523
+ width = this.rows,
524
+ height = this.columns,
525
+ type = "horizontal"
526
+ } = transform;
527
+ let k = 0;
528
+
529
+ if (transforms[type]) {
530
+ for (k = 0; k < this.collisionMap.length; k++) {
531
+ if (layers.includes(k)) {
532
+ transforms[type](this.collisionMap[k], x, y, width, height);
533
+ }
534
+ }
535
+
536
+ return this.collisionMap;
537
+ } else {
538
+ return null;
539
+ }
540
+ },
541
+
542
+ /**
543
+ * Performs a translation of a subset of the collision tile grid.
544
+ *
545
+ * @method platypus.components.CollisionTiles#translate
546
+ * @param [translate] {Object} A list of key/value pairs describing the translation.
547
+ * @param [translate.layers] {Array.<number>} The layer indexes on which to apply the translate, if not provided translates all layers. Defaults to the 0th index.
548
+ * @param [translate.dx=0] {number} Movement in columns.
549
+ * @param [translate.dy=0] {number} Movement in rows.
550
+ * @param [translate.left=0] {number} Grid coordinate for the left side of the bounding box.
551
+ * @param [translate.top=0] {number} Grid coordinate for the top of the bounding box.
552
+ * @param [translate.width=grid.width] {number} Cell width of the bounding box.
553
+ * @param [translate.height=grid.height] {number} Cell height of the bounding box.
554
+ */
555
+ translate: function (translate = {}) {
556
+ const {
557
+ layers = [0],
558
+ left: x = 0,
559
+ top: y = 0,
560
+ width = this.rows,
561
+ height = this.columns,
562
+ dx = 0,
563
+ dy = 0
564
+ } = translate;
565
+ let k = 0;
566
+
567
+
568
+ for (k = 0; k < this.collisionMap.length; k++) {
569
+ if (!layers || layers.includes(k)) {
570
+ transforms.translate(this.collisionMap[k], x, y, width, height, dx, dy);
571
+ }
572
+ }
573
+
574
+ return this.collisionMap;
575
+ },
576
+
577
+ /**
578
+ * Gets a subset of the collision tile grid as a 2D array.
579
+ *
580
+ * @method platypus.components.CollisionTiles#getCollisionMatrix
581
+ * @param layer {number} The collision map index from which to copy.
582
+ * @param originX {number} Grid coordinate for the left side of the bounding box.
583
+ * @param originY {number} Grid coordinate for the top of the bounding box.
584
+ * @param width {number} Cell width of the bounding box.
585
+ * @param height {number} Cell height of the bounding box.
586
+ * @return {Array}
587
+ */
588
+ getCollisionMatrix: function (layer, originX, originY, width, height) {
589
+ return copySection(this.collisionMap[layer], originX, originY, width, height);
590
+ },
591
+
592
+ /**
593
+ * Sets a subset of the collision tile grid.
594
+ *
595
+ * @method platypus.components.CollisionTiles#setCollisionMatrix
596
+ * @param sourceArray {Array} A 2D array describing the collision tiles to insert into the collision tile grid.
597
+ * @param layer {number} The collision map index into which to paste the collision data.
598
+ * @param originX {number} Grid coordinate for the left side of the bounding box.
599
+ * @param originY {number} Grid coordinate for the top of the bounding box.
600
+ * @param width {number} Cell width of the bounding box.
601
+ * @param height {number} Cell height of the bounding box.
602
+ */
603
+ setCollisionMatrix: function (sourceArray, layer, originX, originY, width, height) {
604
+ return pasteSection(this.collisionMap[layer], sourceArray, originX, originY, width, height);
605
+ }
606
+ }
607
+ });
608
+ }());