@makefully/platypus 4.1.4 → 4.1.6

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 (134) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +4 -2
  3. package/lib/platypus.js +1 -1
  4. package/package.json +7 -2
  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 +833 -0
  98. package/src/components/RenderSprite.js +527 -0
  99. package/src/components/RenderText.js +147 -0
  100. package/src/components/RenderTiles.js +1391 -0
  101. package/src/components/SceneChanger.js +128 -0
  102. package/src/components/TiledLoader.js +1451 -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
@@ -0,0 +1,121 @@
1
+ import Data from './Data.js';
2
+ import StateMap from './StateMap.js';
3
+ import {arrayCache} from './utils/array.js';
4
+ import recycle from 'recycle';
5
+
6
+ const
7
+ /**
8
+ * This class defines an action state based on one or more inputs. This is used by [EntityController](platypus.components.EntityController.html) to produce event messages listing whether a particular action is "triggered", "pressed", and/or "released".
9
+ *
10
+ * @memberof platypus
11
+ * @class ActionState
12
+ * @param event {string} The name of the event to trigger on the Entity.
13
+ * @param states {Object} A list of key/value pairs describing what states should be `true` or `false` on the Entity for this action to be triggered.
14
+ * @param trigger {Function} The function to be called if one or more inputs are active and the current state of the Entity is valid.
15
+ * @property {string} [event] The name of the event to trigger on the Entity.
16
+ * @property {Function} [trigger] The function to call if the ActionState is active.
17
+ * @property {boolean} [active] Whether any of the ActionState's inputs are active.
18
+ * @property {boolean} [wasActive] Whether any of the ActionState's inputs were active last update.
19
+ * @property {boolean} [valid] Whether the Entity's state is valid for this ActionState.
20
+ * @property {boolean} [wasValid] Whether the Entity's state was valid for this ActionState last update.
21
+ * @property {platypus.StateMap} [states] The state of the Entity that is valid for this ActionState.
22
+ * @property {Array} [inputs] The list of input toggles to track control input.
23
+ * @property {platypus.Data} [stateSummary] The message that is passed to the Entity if the ActionState is active.
24
+ * @return {ActionState} Returns the new ActionState object.
25
+ */
26
+ ActionState = function (event, states, trigger) {
27
+ this.event = event;
28
+ this.trigger = trigger;
29
+ this.active = false;
30
+ this.wasActive = false;
31
+ this.valid = true;
32
+ this.wasValid = true;
33
+ this.states = StateMap.setUp(states);
34
+ this.inputs = arrayCache.setUp();
35
+
36
+ this.stateSummary = Data.setUp(
37
+ "pressed", false,
38
+ "released", false,
39
+ "triggered", false
40
+ );
41
+ },
42
+ orArray = function (element) {
43
+ return element;
44
+ },
45
+ proto = ActionState.prototype;
46
+
47
+ /**
48
+ * Updates the state of the action by checking the state of the Entity and whether any inputs are active.
49
+ *
50
+ * @method platypus.ActionState#update
51
+ * @param state {Object} The Entity's `state` property to compare against the ActionState's valid state.
52
+ * @return {Boolean} Whether the ActionState is triggered, pressed, or released.
53
+ */
54
+ proto.update = function (state) {
55
+ const
56
+ ss = this.stateSummary;
57
+
58
+ this.valid = state.includes(this.states);
59
+ this.active = this.inputs.some(orArray);
60
+
61
+ ss.pressed = this.valid && this.active;
62
+ ss.released = this.wasActive && ((!this.valid && this.wasValid) || (this.valid && !this.active));
63
+ ss.triggered = this.valid && this.active && !this.wasActive;
64
+
65
+ this.wasValid = this.valid;
66
+ this.wasActive = this.active;
67
+
68
+ return ss.pressed || ss.released || ss.triggered;
69
+ };
70
+
71
+ /**
72
+ * Triggers events on the Entity related to the ActionState's state. This is necessarily separate from the `update` method since triggered events could affect entity state. The messages have the following form and are only triggered if one of the values is `true`:
73
+ *
74
+ * {
75
+ * "triggered": true,
76
+ * "pressed": true,
77
+ * "released": false
78
+ * }
79
+ *
80
+ * Here is a mapping of the various event messages depending on the ActionState's state.
81
+ *
82
+ * ActionState State:
83
+ * wasValid: 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
84
+ * valid: 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
85
+ * wasActive: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
86
+ * active: 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
87
+ * Events:
88
+ * triggered: 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
89
+ * pressed: 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1
90
+ * released: 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0
91
+ *
92
+ * @method platypus.ActionState#resolve
93
+ */
94
+ proto.resolve = function () {
95
+ this.trigger(this.event, this.stateSummary);
96
+ };
97
+
98
+ /**
99
+ * Returns an ActionState from cache or creates a new one if none are available.
100
+ *
101
+ * @method platypus.ActionState.setUp
102
+ * @return {platypus.ActionState} The instantiated ActionState.
103
+ */
104
+ /**
105
+ * Returns an ActionState back to the cache. Prefer the ActionState's recycle method since it recycles property objects as well.
106
+ *
107
+ * @method platypus.ActionState.recycle
108
+ * @param {platypus.ActionState} actionState The ActionState to be recycled.
109
+ */
110
+ /**
111
+ * Relinquishes properties of the ActionState and recycles it.
112
+ *
113
+ * @method platypus.ActionState#recycle
114
+ */
115
+ recycle.add(ActionState, 'ActionState', ActionState, function () {
116
+ this.states.recycle();
117
+ this.stateSummary.recycle();
118
+ arrayCache.recycle(this.inputs);
119
+ }, true);
120
+
121
+ export default ActionState;
@@ -0,0 +1,206 @@
1
+ /**
2
+ * This class is instantiated by Platypus at `platypus.assetCache` to track assets: loading assets needed for particular layers and unloading assets once they're no longer needed.
3
+ *
4
+ * @memberof platypus
5
+ * @class AssetManager
6
+ **/
7
+ /* global platypus, setTimeout */
8
+ import Data from './Data.js';
9
+ import DataMap from './DataMap.js';
10
+ import {Assets} from 'pixi.js';
11
+ import {arrayCache} from './utils/array.js';
12
+
13
+ const
14
+ fn = /^(?:\w+:\/{2}\w+(?:\.\w+)*\/?)?(?:[\/.]*?(?:[^?]+)?\/)?(?:([^\/?]+?)(?:\.(\w+|{\w+(?:,\w+)*}))?)(?:\?\S*)?$/,
15
+ formatAsset = function (asset) { //TODO: Make this behavior less opaque.
16
+ const
17
+ path = asset.src ?? asset,
18
+ match = path.match(fn);
19
+
20
+ if (asset.id) {
21
+ platypus.debug.warn(`AssetManager: Use "alias" instead of "id" for asset identification. (${asset.id})`);
22
+ }
23
+
24
+ return Data.setUp(
25
+ 'alias', asset.alias ?? [asset.id ?? (match ? match[1] : path)],
26
+ 'src', path,
27
+ 'data', asset.data ?? null
28
+ );
29
+ };
30
+
31
+ export default class AssetManager {
32
+ constructor () {
33
+ this.assets = DataMap.setUp();
34
+ this.counts = Data.setUp();
35
+ }
36
+
37
+ /**
38
+ * This method removes an asset from memory if it's the last needed instance of the asset.
39
+ *
40
+ * @method platypus.AssetManager#delete
41
+ * @param {*} alias
42
+ * @return {Boolean} Returns `true` if asset was removed from asset cache.
43
+ */
44
+ delete (alias) {
45
+ const assets = this.assets;
46
+
47
+ if (assets.has(alias)) {
48
+ const counts = this.counts;
49
+
50
+ counts[alias] -= 1;
51
+ if (counts[alias] === 0) {
52
+ const asset = assets.get(alias);
53
+
54
+ if (asset && asset.src) {
55
+ asset.src = '';
56
+ }
57
+ assets.delete(alias);
58
+ }
59
+
60
+ return !counts[alias];
61
+ } else {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Returns a loaded instance of a given asset.
68
+ *
69
+ * @method platypus.AssetManager#get
70
+ * @param {*} alias
71
+ * @return {Object} Returns the asset if defined.
72
+ */
73
+ get (alias) {
74
+ return this.assets.get(alias);
75
+ }
76
+
77
+ /**
78
+ * Returns alias for given path.
79
+ *
80
+ * @method platypus.AssetManager#getFileId
81
+ * @param {*} path
82
+ * @return {String} Returns alias generated from path.
83
+ */
84
+ getFileId (path) {
85
+ const match = path.match(fn);
86
+
87
+ return match ? match[1] : path;
88
+ }
89
+
90
+ /**
91
+ * Returns whether a given asset is currently loaded by the AssetManager.
92
+ *
93
+ * @method platypus.AssetManager#has
94
+ * @param {*} alias
95
+ * @return {Object} Returns `true` if the asset is loaded and `false` if not.
96
+ */
97
+ has (alias) {
98
+ return this.assets.has(alias);
99
+ }
100
+
101
+ /**
102
+ * Sets a mapping between an alias and a loaded asset. If the mapping already exists, simply increment the count for a given alias.
103
+ *
104
+ * @method platypus.AssetManager#set
105
+ * @param {*} alias
106
+ * @param {*} value The loaded asset.
107
+ * @param {Number} count The number of assets needed.
108
+ */
109
+ set (alias, value, count = 1) {
110
+ const
111
+ assets = this.assets,
112
+ counts = this.counts;
113
+
114
+ if (assets.has(alias)) {
115
+ counts[alias] += count;
116
+ } else {
117
+ assets.set(alias, value);
118
+ counts[alias] = count;
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Loads a list of assets.
124
+ *
125
+ * @method platypus.AssetManager#load
126
+ * @param {Array} list A list of assets to load.
127
+ * @param {Function} one This function is called as each asset is loaded.
128
+ * @param {Function} all This function is called once all assets in the list are loaded.
129
+ */
130
+ async load (list, one, all) {
131
+ const
132
+ counts = this.counts,
133
+ needsLoading = arrayCache.setUp(),
134
+ adds = Data.setUp();
135
+
136
+ if (platypus.game?.options?.images ?? platypus.game?.options?.audio) {
137
+ platypus.debug.warn('AssetManager: Default asset folders are no longer specified via game options. Include pathing in asset imports.');
138
+ }
139
+
140
+ // work-around for Pixi v7 Spine PMA issue https://github.com/pixijs/pixijs/issues/9141
141
+ Assets.setPreferences({
142
+ preferCreateImageBitmap: false,
143
+ preferWorker: false
144
+ });
145
+
146
+ for (let i = 0; i < list.length; i++) {
147
+ const
148
+ item = formatAsset(list[i]),
149
+ alias = item.alias?.[0] ?? item.id ?? item.src ?? item;
150
+
151
+ if (this.has(alias)) {
152
+ counts[alias] += 1;
153
+ } else if (adds.hasOwnProperty(alias)) {
154
+ adds[alias] += 1;
155
+ } else {
156
+ adds[alias] = 1;
157
+ needsLoading.push(item);
158
+ }
159
+ }
160
+
161
+ if (needsLoading.length) {
162
+ // Do this first to pass `data` property if needed
163
+ needsLoading.forEach((asset) => Assets.add(asset));
164
+
165
+ const
166
+ aliases = needsLoading.map((asset) => asset.alias[0]),
167
+ loadedList = await Assets.load(aliases, one);
168
+
169
+ aliases.forEach((alias) => {
170
+ const
171
+ response = loadedList[alias];
172
+
173
+ this.set(alias, response, adds[alias]);
174
+ });
175
+
176
+ if (all) {
177
+ all();
178
+ }
179
+ } else {
180
+ setTimeout(() => { // To run in same async sequence as above.
181
+ if (one) {
182
+ one(1);
183
+ }
184
+ if (all) {
185
+ all();
186
+ }
187
+ }, 1);
188
+ }
189
+
190
+ arrayCache.recycle(needsLoading);
191
+ }
192
+
193
+ /**
194
+ * Unloads a list of assets. This is identical to passing each item in the list to `.delete()`.
195
+ *
196
+ * @method platypus.AssetManager#unload
197
+ * @param {Array} list A list of assets to unload.
198
+ */
199
+ unload (list) {
200
+ let i = list.length;
201
+
202
+ while (i--) {
203
+ this.delete(list[i].alias?.[0] ?? list[i].id ?? list[i]);
204
+ }
205
+ }
206
+ }
@@ -0,0 +1,96 @@
1
+ import Vector from './Vector.js';
2
+ import recycle from 'recycle';
3
+
4
+ /**
5
+ * CollisionData holds collision data passed to entities during collisions with other entities. This class is primarily used by the ["HandlerCollision"]("HandlerCollision"%20Component.html) Component to trigger messages on child entities as collision occur.
6
+ *
7
+ * @memberof platypus
8
+ * @class CollisionData
9
+ * @param occurredOrData {Boolean|CollisionData} Whether this represents an actual collision between two shapes. If a CollisionData instance is provided, the instance's full set of values are copied.
10
+ * @param direction {Number} 1 or -1 to define the direction of the collision.
11
+ * @param position {Number} A positive number describing position along the line of collision direction.
12
+ * @param deltaMovement {Number} A positive number describing the magnitude of overlap.
13
+ * @param aABB {platypus.AABB} An AABB of the colliding shape.
14
+ * @param thisShape {platypus.Shape} The moving shape.
15
+ * @param thatShape {platypus.Shape} The stationary shape being collided with.
16
+ * @param vector {platypus.Vector} The vector describing the contact point.
17
+ * @param stuck {Number} The amount of unwarranted overlap if shapes start in a collided position before moving.
18
+ * @return {platypus.CollisionData} Returns the new CollisionData object.
19
+ */
20
+ const
21
+ CollisionData = function (occurredOrData) {
22
+ if (!this.vector) {
23
+ this.vector = Vector.setUp();
24
+ }
25
+ if (occurredOrData instanceof CollisionData) {
26
+ this.copy(occurredOrData);
27
+ } else {
28
+ this.set.apply(this, arguments);
29
+ }
30
+ },
31
+ proto = CollisionData.prototype;
32
+
33
+ /**
34
+ * Sets all of the properties of the CollisionData.
35
+ *
36
+ * @method platypus.CollisionData#set
37
+ * @param occurred {Boolean} Whether this represents an actual collision between two shapes.
38
+ * @param direction {Number} 1 or -1 to define the direction of the collision.
39
+ * @param position {Number} A positive number describing position along the line of collision direction.
40
+ * @param deltaMovement {Number} A positive number describing the magnitude of overlap.
41
+ * @param aABB {platypus.AABB} An AABB of the colliding shape.
42
+ * @param thisShape {platypus.Shape} The moving shape.
43
+ * @param thatShape {platypus.Shape} The stationary shape being collided with.
44
+ * @param vector {platypus.Vector} The vector describing the contact point.
45
+ * @param stuck {Number} The amount of unwarranted overlap if shapes start in a collided position before moving.
46
+ */
47
+ proto.set = function (occurred, direction, position, deltaMovement, aABB, thisShape, thatShape, vector, stuck) {
48
+ this.occurred = occurred || false;
49
+ this.direction = direction || null;
50
+ this.position = position || null;
51
+ this.deltaMovement = deltaMovement || null;
52
+ this.aABB = aABB || null;
53
+ this.thisShape = thisShape || null;
54
+ this.thatShape = thatShape || null;
55
+ this.vector.set(vector);
56
+ this.stuck = stuck || 0;
57
+ };
58
+
59
+ /**
60
+ * Sets all of the properties of the CollisionData to match those of the provided CollisionData object.
61
+ *
62
+ * @method platypus.CollisionData#copy
63
+ * @param dataToCopy {CollisionData} The object values to copy.
64
+ */
65
+ proto.copy = function (dataToCopy) {
66
+ this.occurred = dataToCopy.occurred;
67
+ this.direction = dataToCopy.direction;
68
+ this.position = dataToCopy.position;
69
+ this.deltaMovement = dataToCopy.deltaMovement;
70
+ this.aABB = dataToCopy.aABB;
71
+ this.thisShape = dataToCopy.thisShape;
72
+ this.thatShape = dataToCopy.thatShape;
73
+ this.vector.setVector(dataToCopy.vector);
74
+ this.stuck = dataToCopy.stuck;
75
+ };
76
+
77
+ /**
78
+ * Returns an collisionData from cache or creates a new one if none are available.
79
+ *
80
+ * @method platypus.CollisionData.setUp
81
+ * @return {platypus.CollisionData} The instantiated CollisionData.
82
+ */
83
+ /**
84
+ * Returns a collisionData back to the cache.
85
+ *
86
+ * @method platypus.CollisionData.recycle
87
+ * @param collisionData {platypus.CollisionData} The collisionData to be recycled.
88
+ */
89
+ /**
90
+ * Relinquishes properties of the collisionData and recycles it.
91
+ *
92
+ * @method platypus.CollisionData#recycle
93
+ */
94
+ recycle.add(CollisionData, 'CollisionData', CollisionData, null, true);
95
+
96
+ export default CollisionData;
@@ -0,0 +1,127 @@
1
+ import {arrayCache} from './utils/array.js';
2
+ import recycle from 'recycle';
3
+
4
+ /**
5
+ * CollisionDataContainer holds lists of CollisionData passed to entities during collisions with other entities. This class is primarily used by the ["HandlerCollision"]("HandlerCollision"%20Component.html) Component to trigger messages on child entities as collisions occur.
6
+ *
7
+ * @memberof platypus
8
+ * @class CollisionDataContainer
9
+ * @return {platypus.CollisionDataContainer} Returns the new aabb object.
10
+ */
11
+ const
12
+ CollisionDataContainer = function () {
13
+ if (!this.xData && !this.yData) {
14
+ this.xData = arrayCache.setUp();
15
+ this.yData = arrayCache.setUp();
16
+ this.xDeltaMovement = Infinity;
17
+ this.yDeltaMovement = Infinity;
18
+ } else {
19
+ this.reset();
20
+ }
21
+ },
22
+ proto = CollisionDataContainer.prototype;
23
+
24
+ /**
25
+ * Adds a CollisionData object to the container's X-axis if the movement distance is less than or equal to collision data collected so far.
26
+ *
27
+ * @method platypus.CollisionDataContainer#tryToAddX
28
+ * @param collisionData {platypus.CollisionData} The collision data to add.
29
+ * @return {Boolean} Whether the collision data was added.
30
+ */
31
+ proto.tryToAddX = function (collisionData) {
32
+ if (collisionData.deltaMovement > this.xDeltaMovement) {
33
+ return false;
34
+ } else if (collisionData.deltaMovement < this.xDeltaMovement) {
35
+ this.resetX(collisionData.deltaMovement);
36
+ }
37
+
38
+ this.xData.push(collisionData);
39
+
40
+ return true;
41
+ };
42
+
43
+ /**
44
+ * Adds a CollisionData object to the container's Y-axis if the movement distance is less than or equal to collision data collected so far.
45
+ *
46
+ * @method platypus.CollisionDataContainer#tryToAddY
47
+ * @param collisionData {platypus.CollisionData} The collision data to add.
48
+ * @return {Boolean} Whether the collision data was added.
49
+ */
50
+ proto.tryToAddY = function (collisionData) {
51
+ if (collisionData.deltaMovement > this.yDeltaMovement) {
52
+ return false;
53
+ } else if (collisionData.deltaMovement < this.yDeltaMovement) {
54
+ this.resetY(collisionData.deltaMovement);
55
+ }
56
+
57
+ this.yData.push(collisionData);
58
+
59
+ return true;
60
+ };
61
+
62
+ /**
63
+ * Resets the X and Y axes.
64
+ *
65
+ * @method platypus.CollisionDataContainer#reset
66
+ */
67
+ proto.reset = function () {
68
+ this.resetX(Infinity);
69
+ this.resetY(Infinity);
70
+ };
71
+
72
+ /**
73
+ * Resets the X axis.
74
+ *
75
+ * @param delta {Number} The delta value of the X-axis.
76
+ * @method platypus.CollisionDataContainer#resetX
77
+ */
78
+ proto.resetX = function (delta) {
79
+ const
80
+ {xData} = this;
81
+ let i = xData.length;
82
+
83
+ while (i--) {
84
+ xData[i].recycle();
85
+ }
86
+ xData.length = 0;
87
+ this.xDeltaMovement = delta;
88
+ };
89
+
90
+ /**
91
+ * Resets the Y axis.
92
+ *
93
+ * @param delta {Number} The delta value of the Y-axis.
94
+ * @method platypus.CollisionDataContainer#resetY
95
+ */
96
+ proto.resetY = function (delta) {
97
+ const
98
+ {yData} = this;
99
+ let i = yData.length;
100
+
101
+ while (i--) {
102
+ yData[i].recycle();
103
+ }
104
+ yData.length = 0;
105
+ this.yDeltaMovement = delta;
106
+ };
107
+
108
+ /**
109
+ * Returns an CollisionDataContainer from cache or creates a new one if none are available.
110
+ *
111
+ * @method platypus.CollisionDataContainer.setUp
112
+ * @return {platypus.CollisionDataContainer} The instantiated CollisionDataContainer.
113
+ */
114
+ /**
115
+ * Returns a CollisionDataContainer back to the cache.
116
+ *
117
+ * @method platypus.CollisionDataContainer.recycle
118
+ * @param CollisionDataContainer {platypus.CollisionDataContainer} The CollisionDataContainer to be recycled.
119
+ */
120
+ /**
121
+ * Relinquishes properties of the CollisionDataContainer and recycles it.
122
+ *
123
+ * @method platypus.CollisionDataContainer#recycle
124
+ */
125
+ recycle.add(CollisionDataContainer, 'CollisionDataContainer', CollisionDataContainer, null, true);
126
+
127
+ export default CollisionDataContainer;