@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,301 @@
1
+ /*global platypus */
2
+ import Data from '../Data.js';
3
+ import {arrayCache} from '../utils/array.js';
4
+ import createComponentClass from '../factory.js';
5
+ import TimeEventList from '../TimeEventList.js';
6
+
7
+ const
8
+ formatPath = (path) => {
9
+ if (path.indexOf('.mp3') === -1) {
10
+ return `${path}.mp3`;
11
+ } else {
12
+ return path;
13
+ }
14
+ };
15
+
16
+ export default createComponentClass(/** @lends platypus.components.AudioVO.prototype */{
17
+ id: 'AudioVO',
18
+
19
+ properties: {
20
+ /**
21
+ * Use the audioMap property object to map messages triggered with audio clips to play. At least one audio mapping should be included for audio to play. Here is an example audioMap object:
22
+ *
23
+ * {
24
+ * "message-triggered": "audio-id",
25
+ * // This simple form is useful to listen for "message-triggered" and play "audio-id" using default audio properties.
26
+ *
27
+ * "another-message": {
28
+ * // To specify audio properties, instead of mapping the message to an audio id string, map it to an object with one or more of the properties shown below. Many of these properties directly correspond to SoundJS play parameters.
29
+ *
30
+ * "sound": "another-audio-id",
31
+ * // Required. This is the audio clip to play when "another-message" is triggered.
32
+ *
33
+ * "events": [{
34
+ * "event": "walk-to-the-left",
35
+ * "time": 1500,
36
+ * "interruptable": true // If `false`, event will trigger immediately when VO is interrupted or otherwise ended before event's time is reached. If `true`, event is not triggered if VO stops before time is reached. Defaults to `false`.
37
+ * }]
38
+ * // Optional. Used to specify a list of events to play once the VO begins.
39
+ * }
40
+ * }
41
+ *
42
+ * @property audioMap
43
+ * @type Object
44
+ * @default null
45
+ */
46
+ audioMap: null,
47
+
48
+ /**
49
+ * Whether VO may be interrupted by new requests to play VO
50
+ *
51
+ * @property interrupt
52
+ * @type boolean
53
+ * @default true
54
+ */
55
+ interrupt: true,
56
+
57
+ /**
58
+ * Whether all audio should be preloaded. 'none' preloads no audio, 'events' preloads audio with events attached, and 'all' preloads all audio.
59
+ *
60
+ * @property preloadAudio
61
+ * @type Object
62
+ * @default 'events'
63
+ */
64
+ preloadAudio: 'events'
65
+ },
66
+
67
+ /**
68
+ * This component plays audio using the SpringRoll VOPlayer instance. Audio is played by triggering specific messages defined in the audio component definition.
69
+ *
70
+ * @memberof platypus.components
71
+ * @uses platypus.Component
72
+ * @constructs
73
+ * @listens platypus.Entity#handle-render
74
+ * @listens platypus.Entity#stop-audio
75
+ * @fires platypus.Entity#sequence-complete
76
+ */
77
+ initialize: function () {
78
+ const
79
+ audioMap = this.audioMap;
80
+
81
+ this.eventList = TimeEventList.setUp();
82
+
83
+ this.playingAudio = 0;
84
+ this.stopping = false;
85
+ this.player = platypus.game.voPlayer;
86
+
87
+ if (audioMap) {
88
+ const
89
+ keys = Object.keys(audioMap),
90
+ {length} = keys;
91
+
92
+ for (let i = 0; i < length; i++) {
93
+ const
94
+ key = keys[i];
95
+
96
+ // Listens for messages specified by the `audioMap` and on receiving them, begins playing corresponding audio clips.
97
+ this.addEventListener(key, this.playSound.bind(this, audioMap[key]));
98
+ }
99
+ }
100
+
101
+ this.paused = false;
102
+ },
103
+
104
+ events: {
105
+ "handle-render": function () {
106
+ if (!this.paused && this.eventList) {
107
+ this.checkTimeEvents(false);
108
+ }
109
+ },
110
+
111
+ /**
112
+ * Plays voice-over directly without using a predefined mapping from `audioMap`. This event accepts the same syntax as individual items in the `audioMap`.
113
+ *
114
+ * @param {String|Array|Object} vo Voice-over track or tracks to play.
115
+ */
116
+ "play-voice-over": function (vo) {
117
+ this.playSound(vo);
118
+ },
119
+
120
+ "stop-audio": function () {
121
+ this.player.stop();
122
+ this.player.voList = []; // Workaround to prevent a Springroll bug wherein stopping throws an error due to `voList` being `null`.
123
+ }
124
+ },
125
+
126
+ methods: {
127
+ checkTimeEvents: function (finished, completed) {
128
+ const
129
+ {eventList, owner} = this;
130
+
131
+ if (eventList) {
132
+ const
133
+ currentTime = finished ? Infinity : this.player.getElapsed(),
134
+ events = eventList.getEvents(currentTime);
135
+
136
+ events.forEach((event) => {
137
+ if (!finished || completed || !event.interruptable) {
138
+ owner.trigger(event);
139
+ }
140
+ event.recycle();
141
+ });
142
+
143
+ arrayCache.recycle(events);
144
+ }
145
+ },
146
+
147
+ destroy: function () {
148
+ if (this.playingAudio > 0) {
149
+ this.stopping = true; // used to make sure events don't start new plays
150
+ this.player.stop(true);
151
+ this.player.voList = []; // Workaround to prevent a Springroll bug wherein stopping throws an error due to `voList` being `null`.
152
+ }
153
+ if (this.eventList) {
154
+ this.eventList.recycle();
155
+ this.eventList = null;
156
+ }
157
+ },
158
+
159
+ playSound: function (soundDefinition, value) {
160
+ if (!this.stopping) {
161
+ const
162
+ {owner, player} = this,
163
+ onComplete = (completed) => {
164
+ this.playingAudio -= 1;
165
+ if (!owner.destroyed) {
166
+ this.checkTimeEvents(true, completed);
167
+
168
+ eventList.recycle();
169
+ if (this.eventList === eventList) {
170
+ this.eventList = null;
171
+ }
172
+
173
+ /**
174
+ * When an audio sequence is finished playing, this event is triggered.
175
+ *
176
+ * @event platypus.Entity#sequence-complete
177
+ */
178
+ owner.triggerEvent('sequence-complete');
179
+ }
180
+ arrayCache.recycle(soundList);
181
+ },
182
+ eventList = TimeEventList.setUp(); // Create a new copy so the old one can run its course if needed.
183
+ let soundList = null;
184
+
185
+ if (typeof soundDefinition === 'string') {
186
+ soundList = arrayCache.setUp(soundDefinition);
187
+ } else if (Array.isArray(soundDefinition)) {
188
+ soundList = this.setupEventList(soundDefinition, eventList);
189
+ } else {
190
+ if (soundDefinition.events) {
191
+ eventList.addEvents(soundDefinition.events);
192
+ }
193
+ if (Array.isArray(soundDefinition.sound)) {
194
+ soundList = this.setupEventList(soundDefinition.sound, eventList);
195
+ } else {
196
+ soundList = arrayCache.setUp(soundDefinition.sound);
197
+ }
198
+ }
199
+
200
+ if (value && value.events) {
201
+ eventList.addEvents(value.events);
202
+ }
203
+
204
+ player.play(soundList, onComplete.bind(this, true), onComplete.bind(this, false), this.interrupt);
205
+
206
+ this.eventList = eventList; // setting this after play so that cancelled audio still references original event list.
207
+ this.playingAudio += 1;
208
+ }
209
+ },
210
+
211
+ setupEventList (sounds, eventList) { // This function merges events from individual sounds into a full list queued to sync with the SpringRoll voPlayer.
212
+ const
213
+ {owner, player} = this,
214
+ soundList = arrayCache.setUp();
215
+
216
+ // Create alias-only sound list.
217
+ for (let i = 0; i < sounds.length; i++) {
218
+ if (sounds[i].sound) {
219
+ const
220
+ events = sounds[i].events;
221
+ let timeEvents = null;
222
+
223
+ if (events) {
224
+ // Add audio-segment events
225
+ soundList.push(() => timeEvents = eventList.addEvents(events, player.getElapsed()));
226
+ }
227
+ soundList.push(sounds[i].sound);
228
+ if (events) {
229
+ // Make sure audio-segment events not yet triggered are triggered.
230
+ soundList.push(() => eventList.clear(timeEvents).forEach((event) => {
231
+ owner.trigger(event);
232
+ event.recycle();
233
+ }));
234
+ }
235
+ } else {
236
+ soundList.push(sounds[i]);
237
+ }
238
+ }
239
+ return soundList;
240
+ }
241
+ },
242
+
243
+ getAssetList: function (component, props, defaultProps) {
244
+ const
245
+ preloadAudio = component?.preloadAudio ?? props?.preloadAudio ?? defaultProps?.preloadAudio,
246
+ audioMap = component?.audioMap ?? props?.audioMap ?? defaultProps?.audioMap;
247
+
248
+ if (audioMap && preloadAudio !== 'none') {
249
+ const
250
+ preloadOptions = {
251
+ all: () => true,
252
+ events: (sound) => {
253
+ if (Array.isArray(sound)) {
254
+ for (let i = 0; i < sound.length; i++) {
255
+ if (shouldPreload(sound[i])) {
256
+ return true;
257
+ }
258
+ }
259
+ } else if (sound) {
260
+ return shouldPreload(sound?.sound) || sound?.events?.length > 0;
261
+ } else {
262
+ return false;
263
+ }
264
+ }
265
+ },
266
+ shouldPreload = preloadOptions[preloadAudio] ?? preloadOptions.events,
267
+ getTracks = (sound) => {
268
+ if (typeof sound === 'string') {
269
+ return {
270
+ [formatPath(sound)]: true
271
+ };
272
+ } else if (Array.isArray(sound)) {
273
+ return sound.reduce((obj, value) => ({
274
+ ...obj,
275
+ ...getTracks(value)
276
+ }), {});
277
+ } else if (sound.sound) {
278
+ return getTracks(sound.sound);
279
+ } else {
280
+ return {};
281
+ }
282
+ };
283
+
284
+ return Object.keys(Object.keys(audioMap).reduce((obj, key) => {
285
+ const
286
+ audio = audioMap[key];
287
+
288
+ if (shouldPreload(audio)) {
289
+ return {
290
+ ...obj,
291
+ ...getTracks(audio)
292
+ };
293
+ } else {
294
+ return obj;
295
+ }
296
+ }, {}));
297
+ } else {
298
+ return [];
299
+ }
300
+ }
301
+ });