@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,371 @@
1
+ import Vector from '../Vector.js';
2
+ import createComponentClass from '../factory.js';
3
+
4
+ const
5
+ isTrue = function () {
6
+ return true;
7
+ },
8
+ getState = function (state, stateName) {
9
+ return state.get(stateName);
10
+ },
11
+ instantUpdate = function (getInstantState, getActiveVelocityState, instantSuccess) {
12
+ const
13
+ state = getInstantState(),
14
+ vState = getActiveVelocityState();
15
+
16
+ if (this.activeVelocity) {
17
+ if (this.enact && !vState) { // Turn off ready if the state doesn't allow it.
18
+ this.ready = false;
19
+ }
20
+
21
+ if (this.ready && this.enact && state) {
22
+ this.ready = false; // to insure a single instance until things are reset
23
+ this.velocity.setVector(this.instant);
24
+ if (instantSuccess) {
25
+ this.owner.triggerEvent(instantSuccess);
26
+ }
27
+ } else if (!this.ready && !(this.enact && state)) {
28
+ this.ready = true;
29
+ this.decay();
30
+ } else if (vState) {
31
+ return null;
32
+ }
33
+ return this.velocity;
34
+ } else {
35
+ return null;
36
+ }
37
+ },
38
+ gradualUpdate = function (getActiveVelocityState, delta) {
39
+ if (this.activeVelocity && getActiveVelocityState()) {
40
+ if (this.activeAcceleration) {
41
+ this.move(delta);
42
+ }
43
+
44
+ return this.velocity;
45
+ } else {
46
+ return null;
47
+ }
48
+ },
49
+ createController = function (component, definition) {
50
+ const
51
+ state = component.owner.state,
52
+ getActiveVelocityState = (definition.controlState ? getState.bind(null, state, definition.controlState) : isTrue),
53
+ getInstantState = (definition.instantState ? getState.bind(null, state, definition.instantState) : isTrue);
54
+
55
+ if (component.instant || definition.instantState) {
56
+ component.instant = true;
57
+ component.update = instantUpdate.bind(component, getInstantState, getActiveVelocityState, definition.instantSuccess);
58
+ } else {
59
+ component.update = gradualUpdate.bind(component, getActiveVelocityState);
60
+ }
61
+ };
62
+
63
+ export default createComponentClass(/** @lends platypus.components.Motion.prototype */{
64
+
65
+ id: 'Motion',
66
+
67
+ properties: {
68
+ /**
69
+ * Whether this motion should automatically re-orient when the entity re-orients.
70
+ *
71
+ * @property orient
72
+ * @type boolean
73
+ * @default true
74
+ */
75
+ orient: true,
76
+
77
+ /**
78
+ * A vector, Array, or number specifying the acceleration of the motion. Numbers apply magnitude along the x-axis. Arrays map to [x, y, z] on the vector.
79
+ *
80
+ * @property acceleration
81
+ * @type platypus.Vector|Array|number
82
+ * @default Vector(0, 0, 0)
83
+ */
84
+ acceleration: 0,
85
+
86
+ /**
87
+ * Whether this motion should apply acceleration to the entity. Defaults to `true` unless an initial acceleration is left unset.
88
+ *
89
+ * @property activeAcceleration
90
+ * @type boolean
91
+ * @default true
92
+ */
93
+ activeAcceleration: true,
94
+
95
+ /**
96
+ * Whether this motion should apply acceleration to the entity.
97
+ *
98
+ * @property activeVelocity
99
+ * @type boolean
100
+ * @default true
101
+ */
102
+ activeVelocity: true,
103
+
104
+ /**
105
+ * This is the highest magnitude allowed for the motion vector.
106
+ *
107
+ * @property maxMagnitude
108
+ * @type number
109
+ * @default Infinity
110
+ */
111
+ maxMagnitude: Infinity,
112
+
113
+ /**
114
+ * When this state on the entity changes, this motion's active state is changed to match. If an "event" property is also set on this component, both the event and the state must be true for the motion to be active.
115
+ *
116
+ * @property controlState
117
+ * @type String
118
+ * @default ""
119
+ */
120
+ controlState: "",
121
+
122
+ /**
123
+ * If instant or instantState are set, the motion is only triggered for a single step and must be re-triggered to activate again. When the instantState on the entity becomes `true`, this motion's active state is changed to match. If an "instantState" property is also set on this component, both the event and the state must be true for the motion to be active.
124
+ *
125
+ * @property instant
126
+ * @type Boolean
127
+ * @default false
128
+ */
129
+ instant: false,
130
+
131
+ /**
132
+ * If instant or instantState are set, the motion is only triggered for a single step and must be re-triggered to activate again. When the instantState on the entity becomes `true`, this motion's active state is changed to match. If an "instant" property is also set on this component, both the event and the state must be true for the motion to be active. If "event" or "controlState" are also defined, they must also be `true` to trigger an instant motion on the entity.
133
+ *
134
+ * @property instantState
135
+ * @type String
136
+ * @default ""
137
+ */
138
+ instantState: "",
139
+
140
+ /**
141
+ * If instantState is set, this event is triggered when the intance of motion occurs on the entity.
142
+ *
143
+ * @property instantSuccess
144
+ * @type String
145
+ * @default ""
146
+ */
147
+ instantSuccess: "",
148
+
149
+ /**
150
+ * This determines if setting active to `false` (via the control event or state) should dampen velocity. This is a ratio applied to the vector magnitude between 0 and 1. This is useful for events like jumping where a longer keypress should jump farther than a shorter keypress.
151
+ *
152
+ * @property instantDecay
153
+ * @type number
154
+ * @default null
155
+ */
156
+ instantDecay: null,
157
+
158
+ /**
159
+ * A vector, Array, or number specifying the direction and magnitude of the motion. Numbers apply magnitude along the x-axis. Arrays map to [x, y, z] on the vector.
160
+ *
161
+ * @property velocity
162
+ * @type platypus.Vector|Array|number
163
+ * @default Vector(0, 0, 0)
164
+ */
165
+ velocity: 0,
166
+
167
+ stopOnCollision: true,
168
+
169
+ drag: -1,
170
+ friction: -1
171
+ },
172
+
173
+ /**
174
+ * This component works in tandem with the [Mover](platypus.components.Mover.html) component by adding a vector of motion to the entity. This component is typically created by `Mover` and doesn't need to be added separately.
175
+ *
176
+ * @memberof platypus.components
177
+ * @uses platypus.Component
178
+ * @constructs
179
+ * @listens platypus.Entity#control-velocity
180
+ * @listens platypus.Entity#stop-velocity
181
+ * @listens platypus.Entity#start-velocity
182
+ * @listens platypus.Entity#control-acceleration
183
+ * @listens platypus.Entity#stop-acceleration
184
+ * @listens platypus.Entity#start-acceleration
185
+ * @listens platypus.Entity#instant-motion
186
+ * @listens platypus.Entity#instant-begin
187
+ * @listens platypus.Entity#instant-end
188
+ * @listens platypus.Entity#set-motion
189
+ * @fires platypus.Entity#orient-vector
190
+ * @fires platypus.Entity#remove-vector
191
+ */
192
+ initialize: function (definition) {
193
+ if (!this.acceleration) {
194
+ this.activeAcceleration = false;
195
+ }
196
+ this.acceleration = Vector.setUp(this.acceleration);
197
+ this.velocity = Vector.setUp(this.velocity);
198
+
199
+ this.triggered = false;
200
+ this.ready = true;
201
+
202
+ if (typeof this.instantDecay === "number") {
203
+ this.capMagnitude = this.velocity.magnitude() * this.instantDecay;
204
+ } else {
205
+ this.capMagnitude = -1;
206
+ }
207
+
208
+ createController(this, definition);
209
+
210
+ if (this.instant) {
211
+ this.enact = false;
212
+ this.instant = Vector.setUp(this.velocity);
213
+ this.velocity.setXYZ(0, 0, 0);
214
+ }
215
+
216
+ if (this.orient) { // Orient vectors in case the entity is in a transformed position.
217
+ this.owner.triggerEvent('orient-vector', this.velocity);
218
+ this.owner.triggerEvent('orient-vector', this.acceleration);
219
+ }
220
+ },
221
+
222
+ events: {
223
+ /**
224
+ * This event controls whether this velocity is active or inactive.
225
+ *
226
+ * @event platypus.Entity#control-velocity
227
+ * @param control {Object|boolean} If `true`, this motion becomes active. If `false` or `{pressed: false}`, the motion becomes inactive.
228
+ */
229
+ "control-velocity": function (control) {
230
+ this.activeVelocity = (control && (control.pressed !== false));
231
+ },
232
+
233
+ /**
234
+ * This event sets the velocity to inactive.
235
+ *
236
+ * @event platypus.Entity#stop-velocity
237
+ */
238
+ "stop-velocity": function () {
239
+ this.activeVelocity = false;
240
+ },
241
+
242
+ /**
243
+ * This event sets the velocity to active.
244
+ *
245
+ * @event platypus.Entity#start-velocity
246
+ */
247
+ "start-velocity": function () {
248
+ this.activeVelocity = true;
249
+ },
250
+
251
+ /**
252
+ * This event controls whether the acceleration is active or inactive.
253
+ *
254
+ * @event platypus.Entity#control-acceleration
255
+ * @param control {Object|boolean} If `true`, this motion becomes active. If `false` or `{pressed: false}`, the motion becomes inactive.
256
+ */
257
+ "control-acceleration": function (control) {
258
+ this.activeAcceleration = (control && (control.pressed !== false));
259
+ },
260
+
261
+ /**
262
+ * This event sets the acceleration to inactive.
263
+ *
264
+ * @event platypus.Entity#stop-acceleration
265
+ */
266
+ "stop-acceleration": function () {
267
+ this.activeAcceleration = false;
268
+ },
269
+
270
+ /**
271
+ * This event sets the acceleration to active.
272
+ *
273
+ * @event platypus.Entity#start-acceleration
274
+ */
275
+ "start-acceleration": function () {
276
+ this.activeAcceleration = true;
277
+ },
278
+
279
+ /**
280
+ * This event triggers an instant motion.
281
+ *
282
+ * @event platypus.Entity#instant-motion
283
+ * @param control {Object|boolean} If `true`, this motion becomes active. If `false` or `{triggered: false}`, the motion becomes inactive.
284
+ */
285
+ "instant-motion": function (control) {
286
+ this.enact = (control && (control.triggered !== false));
287
+ },
288
+
289
+ /**
290
+ * This event triggers the beginning of an instant motion.
291
+ *
292
+ * @event platypus.Entity#instant-begin
293
+ */
294
+ "instant-begin": function () {
295
+ this.enact = true;
296
+ },
297
+
298
+ /**
299
+ * This event triggers the end of an instant motion.
300
+ *
301
+ * @event platypus.Entity#instant-end
302
+ */
303
+ "instant-end": function () {
304
+ this.enact = false;
305
+ },
306
+
307
+ /**
308
+ * This event modifies the properties of this Motion.
309
+ *
310
+ * @event platypus.Entity#set-motion
311
+ * @param motion {Object} A list of key/value pairs corresponding to motion values.
312
+ * @param [motion.maxMagnitude] {Number} A value describing the maximum velocity or acceleration the motion vector can exert on the Entity.
313
+ */
314
+ "set-motion": function (motion) {
315
+ if (motion.acceleration) {
316
+ this.acceleration.set(motion.acceleration);
317
+ }
318
+ if (motion.velocity) {
319
+ this.velocity.set(motion.velocity);
320
+ if (typeof this.instantDecay === "number") {
321
+ this.capMagnitude = this.velocity.magnitude() * this.instantDecay;
322
+ } else {
323
+ this.capMagnitude = -1;
324
+ }
325
+ }
326
+ if (typeof motion.maxMagnitude === "number") {
327
+ this.maxMagnitude = motion.maxMagnitude;
328
+ }
329
+ }
330
+ },
331
+
332
+ methods: {
333
+ move: function (delta) {
334
+ const
335
+ v = Vector.setUp(this.acceleration).multiply(delta);
336
+
337
+ this.velocity.add(v);
338
+ v.recycle();
339
+
340
+ if (this.velocity.magnitude() > this.maxMagnitude) {
341
+ this.velocity.normalize().multiply(this.maxMagnitude);
342
+ }
343
+ return this.velocity;
344
+ },
345
+
346
+ // This handles things like variable height jumping by adjusting the jump velocity to the pre-determined cap velocity for jump-button release.
347
+ decay: function () {
348
+ if ((this.capMagnitude >= 0) && (this.velocity.magnitude() > this.capMagnitude)) {
349
+ this.velocity.normalize().multiply(this.capMagnitude);
350
+ }
351
+ },
352
+
353
+ destroy: function () {
354
+ if (this.orient) {
355
+ /**
356
+ * On receiving this message, the maintained vector is immediately dropped from the list of maintained vectors.
357
+ *
358
+ * @event platypus.Entity#remove-vector
359
+ * @param vector {platypus.Vector} The vector to be removed.
360
+ */
361
+ this.owner.triggerEvent('remove-vector', this.acceleration);
362
+ this.owner.triggerEvent('remove-vector', this.velocity);
363
+ }
364
+ this.acceleration.recycle();
365
+ this.velocity.recycle();
366
+ if (this.instant) {
367
+ this.instant.recycle();
368
+ }
369
+ }
370
+ }
371
+ });