@makefully/platypus 4.1.5 → 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 (136) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +3 -3
  3. package/lib/platypus.js +1 -1
  4. package/package.json +6 -5
  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
  135. package/lib/243.platypus.mjs +0 -1
  136. package/lib/platypus.mjs +0 -1
@@ -0,0 +1,541 @@
1
+ import ActionState from '../ActionState.js';
2
+ import Data from '../Data.js';
3
+ import DataMap from '../DataMap.js';
4
+ import StateMap from '../StateMap.js';
5
+ import {arrayCache} from '../utils/array.js';
6
+ import createComponentClass from '../factory.js';
7
+
8
+ const
9
+ distance = function (origin, destination) {
10
+ const
11
+ x = destination.x - origin.x,
12
+ y = destination.y - origin.y;
13
+
14
+ return Math.sqrt((x * x) + (y * y));
15
+ },
16
+ angle = function (origin, destination, distance) {
17
+ const
18
+ x = destination.x - origin.x,
19
+ y = destination.y - origin.y,
20
+ circle = Math.PI * 2;
21
+ let a = 0;
22
+
23
+ if (!distance) {
24
+ return a;
25
+ }
26
+
27
+ a = Math.acos(x / distance);
28
+ if (y < 0) {
29
+ a = circle - a;
30
+ }
31
+ return a;
32
+ },
33
+ directions = [null, null, null, null, //joystick directions
34
+ ['east', 'south', 'west', 'north'], null, null, null,
35
+ ['east', 'southeast', 'south', 'southwest', 'west', 'northwest', 'north', 'northeast'], null, null, null, null, null, null, null,
36
+ ['east', 'east-southeast', 'southeast', 'south-southeast', 'south', 'south-southwest', 'southwest', 'west-southwest', 'west', 'west-northwest', 'northwest', 'north-northwest', 'north', 'north-northeast', 'northeast', 'east-northeast']
37
+ ],
38
+ mouseMap = ['left-button', 'middle-button', 'right-button'],
39
+ trigger = function (event, message) {
40
+ if (!this.paused) {
41
+ this.owner.trigger(event, message);
42
+ }
43
+ },
44
+ filteredTrigger = function (state, event, message) {
45
+ if (!this.paused && message[state]) {
46
+ this.owner.trigger(event, message);
47
+ }
48
+ };
49
+
50
+ export default createComponentClass(/** @lends platypus.components.EntityController.prototype */{
51
+ id: 'EntityController',
52
+
53
+ properties: {
54
+ /**
55
+ * Use the controlMap property object to map inputs to messages that should be triggered. At least one control mapping should be included. The following are a few examples:
56
+ *
57
+ * {
58
+ * "key:x": "run-left",
59
+ * // This causes an "x" keypress to fire "run-left" on the entity. For a full listing of key names, check out the `HandlerController` component.
60
+ *
61
+ * "button-pressed": "throw-block",
62
+ * // custom input messages can be fired on this entity from other entities, allowing for on-screen input buttons to run through the same controller channel as other inputs.
63
+ *
64
+ * "mouse:left-button"
65
+ * // The controller can also handle mouse events on the entity if the entity's render component triggers mouse events on the entity (for example, the `RenderSprite` component).
66
+ * }
67
+ *
68
+ * @property controlMap
69
+ * @type Object
70
+ * @default {}
71
+ */
72
+ controlMap: {},
73
+
74
+ /**
75
+ * Determines whether this entity should listen for mouse events to trigger directional events. Can be set simply to "true" to accept all joystick defaults.
76
+ *
77
+ * "joystick": {
78
+ * "directions": 8, // Optional: 4, 8, or 16. Determines how many directions to broadcast. Default is 4 ("north", "east", "south", and "west").
79
+ * "innerRadius": 30, // Optional. Number determining how far the mouse must be from the entity's position before joystick events should be triggered. Default is 0.
80
+ * "outerRadius": 60 // Optional. Number determining how far the mouse can move away from the entity's position before the joystick stops triggering events. Default is Infinity.
81
+ * }
82
+ *
83
+ * @property joystick
84
+ * @type Object
85
+ * @default null
86
+ */
87
+ joystick: null,
88
+
89
+ /**
90
+ * The stateMaps property can hold multiple control maps. Use this if certain controls should only be available for certain states. The controller finds the first valid state and falls back to the base `controlMap` as default if no matches are found.
91
+ *
92
+ * @property stateMaps
93
+ * @type Object
94
+ * @default {}
95
+ */
96
+ stateMaps: {}
97
+ },
98
+
99
+ publicProperties: {
100
+ /**
101
+ * Whether input controls should be deactivated.
102
+ *
103
+ * @property paused
104
+ * @type Boolean
105
+ * @default false
106
+ */
107
+ paused: false
108
+ },
109
+
110
+ /**
111
+ * This component listens for input messages triggered on the entity and updates the state of any controller inputs it is listening for. It then broadcasts messages on the entity corresponding to the input it received.
112
+ *
113
+ * @memberof platypus.components
114
+ * @uses platypus.Component
115
+ * @constructs
116
+ * @listens platypus.Entity#[event.code]:down
117
+ * @listens platypus.Entity#[event.code]:up
118
+ * @listens platypus.Entity#handle-controller
119
+ * @listens platypus.Entity#pause-controls
120
+ * @listens platypus.Entity#pointerdown
121
+ * @listens platypus.Entity#pressmove
122
+ * @listens platypus.Entity#pressup
123
+ * @listens platypus.Entity#unpause-controls
124
+ * @fires platypus.Entity#[active-state]
125
+ * @fires platypus.Entity#joystick:down
126
+ * @fires platypus.Entity#joystick:up
127
+ * @fires platypus.Entity#mouse:mouse-left:down
128
+ * @fires platypus.Entity#mouse:mouse-middle:down
129
+ * @fires platypus.Entity#mouse:mouse-right:down
130
+ * @fires platypus.Entity#mouse:mouse-left:up
131
+ * @fires platypus.Entity#mouse:mouse-middle:up
132
+ * @fires platypus.Entity#mouse:mouse-right:up
133
+ * @fires platypus.Entity#north
134
+ * @fires platypus.Entity#north-northeast
135
+ * @fires platypus.Entity#northeast
136
+ * @fires platypus.Entity#east-northeast
137
+ * @fires platypus.Entity#east
138
+ * @fires platypus.Entity#east-southeast
139
+ * @fires platypus.Entity#southeast
140
+ * @fires platypus.Entity#south-southeast
141
+ * @fires platypus.Entity#south
142
+ * @fires platypus.Entity#south-southwest
143
+ * @fires platypus.Entity#southwest
144
+ * @fires platypus.Entity#west-southwest
145
+ * @fires platypus.Entity#west
146
+ * @fires platypus.Entity#west-northwest
147
+ * @fires platypus.Entity#northwest
148
+ * @fires platypus.Entity#north-northwest
149
+ * @fires platypus.Entity#joystick-orientation
150
+ * @fires platypus.Entity#stop
151
+ */
152
+ initialize: function (definition) {
153
+ const
154
+ stateMaps = this.stateMaps;
155
+
156
+ this.actions = DataMap.setUp();
157
+
158
+ if (stateMaps) {
159
+ const
160
+ keys = Object.keys(stateMaps),
161
+ {length} = keys;
162
+
163
+ for (let i = 0; i < length; i++) {
164
+ const
165
+ key = keys[i],
166
+ filter = StateMap.setUp(key);
167
+
168
+ this.addMap(stateMaps[key], key, filter);
169
+ filter.recycle();
170
+ }
171
+ }
172
+
173
+ this.addMap(this.controlMap, 'default');
174
+
175
+ if (definition.joystick) {
176
+ this.joystick = Data.setUp(
177
+ "directions", definition.joystick.directions || 4, // 4 = n,e,s,w; 8 = n,ne,e,se,s,sw,w,nw; 16 = n,nne,ene,e...
178
+ "handleEdge", definition.joystick.handleEdge || false,
179
+ "innerRadius", definition.joystick.innerRadius || 0,
180
+ "outerRadius", definition.joystick.outerRadius || Infinity
181
+ );
182
+ }
183
+ },
184
+
185
+ events: {
186
+ "handle-controller": function () {
187
+ const
188
+ actions = this.actions,
189
+ keys = actions.keys,
190
+ resolution = arrayCache.setUp(),
191
+ state = this.owner.state;
192
+ let i = keys.length,
193
+ j = 0;
194
+
195
+ while (i--) {
196
+ const
197
+ action = actions.get(keys[i]);
198
+
199
+ if (action.update(state)) {
200
+ resolution.push(action);
201
+ }
202
+ }
203
+
204
+ j = resolution.length;
205
+ while (j--) {
206
+ resolution[j].resolve();
207
+ }
208
+
209
+ arrayCache.recycle(resolution);
210
+ },
211
+
212
+ "pointerdown": function (value) {
213
+ if (value.pixiEvent.data.pointerType === 'mouse') {
214
+ /**
215
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input.
216
+ *
217
+ * @event platypus.Entity#mouse:mouse-left:down
218
+ * @param message {Event} The original mouse event object is passed along with the control message.
219
+ */
220
+ /**
221
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).
222
+ *
223
+ * @event platypus.Entity#mouse:mouse-middle:down
224
+ * @param message {Event} The original mouse event object is passed along with the control message.
225
+ */
226
+ /**
227
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).
228
+ *
229
+ * @event platypus.Entity#mouse:mouse-right:down
230
+ * @param message {Event} The original mouse event object is passed along with the control message.
231
+ */
232
+ this.owner.triggerEvent('mouse:' + mouseMap[value.event.button || 0] + ':down', value.event);
233
+ }
234
+
235
+ if (this.joystick) {
236
+ /**
237
+ * This event is triggered when there is an active touch in the joystick area.
238
+ *
239
+ * @event platypus.Entity#joystick:down
240
+ * @param message {Event} The original pointer event object is passed along with the control message.
241
+ */
242
+ this.owner.triggerEvent('joystick:down', value.event);
243
+ this.handleJoy(value);
244
+ }
245
+ },
246
+
247
+ "pressup": function (value) {
248
+ const
249
+ owner = this.owner;
250
+
251
+ if (value.pixiEvent.data.pointerType === 'mouse') {
252
+ /**
253
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).
254
+ *
255
+ * @event platypus.Entity#mouse:mouse-left:up
256
+ * @param message {Event} The original mouse event object is passed along with the control message.
257
+ */
258
+ /**
259
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).
260
+ *
261
+ * @event platypus.Entity#mouse:mouse-middle:up
262
+ * @param message {Event} The original mouse event object is passed along with the control message.
263
+ */
264
+ /**
265
+ * This component triggers the state of mouse inputs on the entity if a render component of the entity accepts mouse input (for example [[Render-Animation]]).
266
+ *
267
+ * @event platypus.Entity#mouse:mouse-right:up
268
+ * @param message {Event} The original mouse event object is passed along with the control message.
269
+ */
270
+ owner.triggerEvent('mouse:' + mouseMap[value.event.button || 0] + ':up', value.event);
271
+ }
272
+
273
+ if (this.joystick) {
274
+ /**
275
+ * This event is triggered when there is an active touch is released from the joystick area.
276
+ *
277
+ * @event platypus.Entity#joystick:up
278
+ * @param message {Event} The original pointer event object is passed along with the control message.
279
+ */
280
+ owner.triggerEvent('joystick:up', value.event);
281
+
282
+ owner.triggerEvent('stop');
283
+ }
284
+ },
285
+
286
+ "pressmove": function (value) {
287
+ if (this.joystick) {
288
+ this.handleJoy(value);
289
+ }
290
+ },
291
+
292
+ /**
293
+ * This message will stop the controller from triggering messages until "unpause-controls" is triggered on the entity.
294
+ *
295
+ * @event platypus.Entity#pause-controls
296
+ */
297
+ "pause-controls": function () {
298
+ this.paused = true;
299
+ },
300
+
301
+ /**
302
+ * This message will allow the controller to trigger messages until "pause-controls" is triggered on the entity.
303
+ *
304
+ * @event platypus.Entity#unpause-controls
305
+ */
306
+ "unpause-controls": function () {
307
+ this.paused = false;
308
+ }
309
+ },
310
+
311
+ methods: {
312
+ handleJoy: function (event) {
313
+ // The following translate mouse and touch events into messages that this controller can handle in a systematic way
314
+ const
315
+ joystick = this.joystick,
316
+ dist = distance(owner, event);
317
+
318
+ if ((dist > joystick.outerRadius) || (dist < joystick.innerRadius)) {
319
+ return;
320
+ } else if (!this.paused) {
321
+ const
322
+ owner = this.owner,
323
+ divisions = Math.PI / (joystick.directions / 2),
324
+ orientation = angle(owner, event, dist),
325
+ direction = directions[joystick.directions][Math.floor(((orientation + divisions / 2) % (Math.PI * 2)) / divisions)];
326
+
327
+ if (joystick.handleEdge) {
328
+ const
329
+ segment = Math.PI / joystick.directions,
330
+ accuracy = directions[joystick.directions * 2][Math.floor(((orientation + segment / 2) % (Math.PI * 2)) / segment)];
331
+
332
+ if (accuracy !== direction) {
333
+ owner.triggerEvent(accuracy.replace(direction, '').replace('-', ''), event); //There's probably a better way to perform this, but the current method is functional. - DDD
334
+ }
335
+ }
336
+
337
+ owner.triggerEvent('stop');
338
+
339
+ /**
340
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north.
341
+ *
342
+ * @event platypus.Entity#north
343
+ * @param message {Event} The original pointer event object is passed along with the control message.
344
+ */
345
+ /**
346
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north-northeast.
347
+ *
348
+ * @event platypus.Entity#north-northeast
349
+ * @param message {Event} The original pointer event object is passed along with the control message.
350
+ */
351
+ /**
352
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due northeast.
353
+ *
354
+ * @event platypus.Entity#northeast
355
+ * @param message {Event} The original pointer event object is passed along with the control message.
356
+ */
357
+ /**
358
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east-northeast.
359
+ *
360
+ * @event platypus.Entity#east-northeast
361
+ * @param message {Event} The original pointer event object is passed along with the control message.
362
+ */
363
+ /**
364
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east.
365
+ *
366
+ * @event platypus.Entity#east
367
+ * @param message {Event} The original pointer event object is passed along with the control message.
368
+ */
369
+ /**
370
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due east-southeast.
371
+ *
372
+ * @event platypus.Entity#east-southeast
373
+ * @param message {Event} The original pointer event object is passed along with the control message.
374
+ */
375
+ /**
376
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due southeast.
377
+ *
378
+ * @event platypus.Entity#southeast
379
+ * @param message {Event} The original pointer event object is passed along with the control message.
380
+ */
381
+ /**
382
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south-southeast.
383
+ *
384
+ * @event platypus.Entity#south-southeast
385
+ * @param message {Event} The original pointer event object is passed along with the control message.
386
+ */
387
+ /**
388
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south.
389
+ *
390
+ * @event platypus.Entity#south
391
+ * @param message {Event} The original pointer event object is passed along with the control message.
392
+ */
393
+ /**
394
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due south-southwest.
395
+ *
396
+ * @event platypus.Entity#south-southwest
397
+ * @param message {Event} The original pointer event object is passed along with the control message.
398
+ */
399
+ /**
400
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due southwest.
401
+ *
402
+ * @event platypus.Entity#southwest
403
+ * @param message {Event} The original pointer event object is passed along with the control message.
404
+ */
405
+ /**
406
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west-southwest.
407
+ *
408
+ * @event platypus.Entity#west-southwest
409
+ * @param message {Event} The original pointer event object is passed along with the control message.
410
+ */
411
+ /**
412
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west.
413
+ *
414
+ * @event platypus.Entity#west
415
+ * @param message {Event} The original pointer event object is passed along with the control message.
416
+ */
417
+ /**
418
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due west-northwest.
419
+ *
420
+ * @event platypus.Entity#west-northwest
421
+ * @param message {Event} The original pointer event object is passed along with the control message.
422
+ */
423
+ /**
424
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due northwest.
425
+ *
426
+ * @event platypus.Entity#northwest
427
+ * @param message {Event} The original pointer event object is passed along with the control message.
428
+ */
429
+ /**
430
+ * If the soft joystick is enabled on this component, it will broadcast this directional message if the joystick is dragged due north-northwest.
431
+ *
432
+ * @event platypus.Entity#north-northwest
433
+ * @param message {Event} The original pointer event object is passed along with the control message.
434
+ */
435
+ owner.triggerEvent(direction, event);
436
+
437
+ /**
438
+ * If the soft joystick is enabled on this component, this message will trigger to provide the current orientation of the joystick.
439
+ *
440
+ * @event platypus.Entity#joystick-orientation
441
+ * @param orientation (number) - A number in radians representing the orientation of the joystick.
442
+ */
443
+ owner.triggerEvent("joystick-orientation", orientation);
444
+ }
445
+ },
446
+
447
+ addController: (function () {
448
+ const
449
+ up = function (index) {
450
+ this.inputs[index] = false;
451
+ },
452
+ down = function (index) {
453
+ this.inputs[index] = true;
454
+ };
455
+
456
+ return function (key, stateId, controller, states, controllerState) {
457
+ const
458
+ actions = this.actions,
459
+ id = `${stateId}-${controller}-${controllerState || 'all'}`;
460
+ let actionState = actions.get(id); // If there's already a state storage object for this action, reuse it: there are multiple keys mapped to the same action.
461
+
462
+ // Otherwise create a new state storage object
463
+ if (!actionState) {
464
+
465
+ /**
466
+ * Broadcasts active states using the JSON-defined message on each `handle-controller` message. Active states include `pressed` being true or `released` being true. If both of these states are false, the message is not broadcasted.
467
+ *
468
+ * @event platypus.Entity#[active-state]
469
+ * @param message.pressed {Boolean} Whether the current input is active.
470
+ * @param message.released {Boolean} Whether the current input was active last tick but is no longer active.
471
+ * @param message.triggered {Boolean} Whether the current input is active but was not active last tick.
472
+ * @param message.over {Boolean} Whether the mouse was over the entity when pressed, released, or triggered. This value is always false for non-mouse input messages.
473
+ */
474
+ if (controllerState) {
475
+ actionState = actions.set(id, ActionState.setUp(controller, states, filteredTrigger.bind(this, controllerState)));
476
+ } else {
477
+ actionState = actions.set(id, ActionState.setUp(controller, states, trigger.bind(this)));
478
+ }
479
+ }
480
+
481
+ // Set up listeners and input flag.
482
+ this.addEventListener(key + ':up', up.bind(actionState, actionState.inputs.length));
483
+ this.addEventListener(key + ':down', down.bind(actionState, actionState.inputs.length));
484
+ actionState.inputs.push(false);
485
+ };
486
+ }()),
487
+
488
+ addMap: function (map, id, states) {
489
+ const
490
+ keys = Object.keys(map),
491
+ {length} = keys;
492
+
493
+ for (let i = 0; i < length; i++) {
494
+ const
495
+ key = keys[i],
496
+ controller = map[key];
497
+
498
+ if (typeof controller === 'string') {
499
+ this.addController(key, id, controller, states);
500
+ } else if (Array.isArray(controller)) {
501
+ for (let j = 0; j < controller.length; j++) {
502
+ this.addController(key, id, controller[j], states);
503
+ }
504
+ } else {
505
+ const
506
+ controllerKeys = Object.keys(controller),
507
+ {length} = controllerKeys;
508
+
509
+ for (let j = 0; j < length; j++) {
510
+ const
511
+ controllerKey = controllerKeys[j],
512
+ subcontroller = controller[controllerKey];
513
+
514
+ if (typeof subcontroller === 'string') {
515
+ this.addController(key, id, subcontroller, states, controllerKey);
516
+ } else {
517
+ for (let k = 0; k < subcontroller.length; k++) {
518
+ this.addController(key, id, subcontroller[k], states, controllerKey);
519
+ }
520
+ }
521
+ }
522
+ }
523
+ }
524
+ },
525
+
526
+ destroy: function () {
527
+ const
528
+ actions = this.actions,
529
+ keys = actions.keys;
530
+ let i = keys.length;
531
+
532
+ while (i--) {
533
+ actions.get(keys[i]).recycle();
534
+ }
535
+ actions.recycle();
536
+ if (this.joystick) {
537
+ this.joystick.recycle();
538
+ }
539
+ }
540
+ }
541
+ });