@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,527 @@
1
+ /* global platypus */
2
+ import {arrayCache, greenSlice, union} from '../utils/array.js';
3
+ import Data from '../Data.js';
4
+ import PIXIAnimation from '../PIXIAnimation.js';
5
+ import RenderAnimator from './RenderAnimator.js';
6
+ import RenderContainer from './RenderContainer.js';
7
+ import createComponentClass from '../factory.js';
8
+
9
+ export default createComponentClass(/** @lends platypus.components.RenderSprite.prototype */{
10
+
11
+ id: 'RenderSprite',
12
+
13
+ properties: {
14
+ /**
15
+ * An object containg key-value pairs that define a mapping from entity states to the animation that should play. The list is processed from top to bottom, so the most important actions should be listed first (for example, a jumping animation might take precedence over an idle animation). If not specified, an 1-to-1 animation map is created from the list of animations in the sprite sheet definition using the animation names as the keys.
16
+ *
17
+ * "animationStates":{
18
+ * "standing": "default-animation" // On receiving a "standing" event, or when this.owner.state.standing === true, the "default" animation will begin playing.
19
+ * "ground,moving": "walking", // Comma separated values have a special meaning when evaluating "state-changed" messages. The above example will cause the "walking" animation to play ONLY if the entity's state includes both "moving" and "ground" equal to true.
20
+ * "ground,striking": "swing!", // Putting an exclamation after an animation name causes this animation to complete before going to the next animation. This is useful for animations that would look poorly if interrupted.
21
+ * "default": "default-animation" // Optional. "default" is a special property that matches all states. If none of the above states are valid for the entity, it will use the default animation listed here.
22
+ * }
23
+ *
24
+ * If `stateBased` is `true` and this property is not set, this component will use the `animationMap` property value to define state mappings.
25
+ *
26
+ * @property animationStates
27
+ * @type Object
28
+ * @default animationMap
29
+ */
30
+ animationStates: null,
31
+
32
+ /**
33
+ * An object containg key-value pairs that define a mapping from triggered events to the animation that should play.
34
+ *
35
+ * "animationEvents":{
36
+ * "move": "walk-animation",
37
+ * "jump": "jumping-animation"
38
+ * }
39
+ *
40
+ * The above will create two event listeners on the entity, "move" and "jump", that will play their corresponding animations when the events are triggered.
41
+ *
42
+ * If `eventBased` is `true` and this property is not set, this component will use the `animationMap` property value to define event mappings.
43
+ *
44
+ * @property animationEvents
45
+ * @type Object
46
+ * @default animationMap
47
+ */
48
+ animationEvents: null,
49
+
50
+ /**
51
+ * spriteSheet can either be a String or an object. If a string, the spritesheet data will be loaded from the file with a matching name in the spritesheet folder. Otherwise the definition is in full here. That spritesheet data defines an EaselJS sprite sheet to use for rendering. See https://createjs.com/docs/easeljs/classes/SpriteSheet.html for the full specification.
52
+ *
53
+ * "spriteSheet": 'hero-image'
54
+ *
55
+ * -OR-
56
+ *
57
+ * "spriteSheet": {
58
+ *
59
+ * "images": ["example0", "example1"], //Can also define 'image' and give the
60
+ * "frames": {
61
+ * "width": 100,
62
+ * "height": 100,
63
+ * "regY": 100,
64
+ * "regX": 50
65
+ * },
66
+ * "animations":{
67
+ * "default-animation":[2],
68
+ * "walking": {"frames": [0, 1, 2], "speed": 4},
69
+ * "swing": {"frames": [3, 4, 5], "speed": 4}
70
+ * }
71
+ * }
72
+ *
73
+ * -OR- an Array of the above (since 0.8.4)
74
+ *
75
+ * @property spriteSheet
76
+ * @type String|Array|Object
77
+ * @default null
78
+ */
79
+ spriteSheet: null,
80
+
81
+ /**
82
+ * Optional. An object containg key-value pairs that define a mapping from triggered events or entity states to the animation that should play. The list is processed from top to bottom, so the most important actions should be listed first (for example, a jumping animation might take precedence over an idle animation). If not specified, an 1-to-1 animation map is created from the list of animations in the sprite sheet definition using the animation names as the keys.
83
+ *
84
+ * "animationMap":{
85
+ * "standing": "default-animation" // On receiving a "standing" event, or when this.owner.state.standing === true, the "default" animation will begin playing.
86
+ * "ground,moving": "walking", // Comma separated values have a special meaning when evaluating "state-changed" messages. The above example will cause the "walking" animation to play ONLY if the entity's state includes both "moving" and "ground" equal to true.
87
+ * "ground,striking": "swing!", // Putting an exclamation after an animation name causes this animation to complete before going to the next animation. This is useful for animations that would look poorly if interrupted.
88
+ * "default": "default-animation" // Optional. "default" is a special property that matches all states. If none of the above states are valid for the entity, it will use the default animation listed here.
89
+ * }
90
+ *
91
+ * This data may also be used to create a RenderAnimator component on the entity if the `eventBased` or `stateBased` properties are set to `true`.
92
+ *
93
+ * @property animationMap
94
+ * @type Object
95
+ * @default null
96
+ */
97
+ animationMap: null,
98
+
99
+ /**
100
+ * Optional. A mask definition that determines where the image should clip. A string can also be used to create more complex shapes via the PIXI graphics API like: "mask": "r(10,20,40,40).circle(30,10,12)". Defaults to no mask or, if simply set to true, a rectangle using the entity's dimensions.
101
+ *
102
+ * "mask": {
103
+ * "x": 10,
104
+ * "y": 10,
105
+ * "width": 40,
106
+ * "height": 40
107
+ * },
108
+ *
109
+ * -OR-
110
+ *
111
+ * "mask": "r(10,20,40,40).circle(30,10,12)"
112
+ *
113
+ * @property mask
114
+ * @type Object
115
+ * @default null
116
+ */
117
+ mask: null,
118
+
119
+ /**
120
+ * Defines whether the entity will respond to touch and click events. Setting this value will create an Interactive component on this entity with these properties. For example:
121
+ *
122
+ * "interactive": {
123
+ * "hover": false,
124
+ * "hitArea": {
125
+ * "x": 10,
126
+ * "y": 10,
127
+ * "width": 40,
128
+ * "height": 40
129
+ * }
130
+ * }
131
+ *
132
+ * @property interactive
133
+ * @type Boolean|Object
134
+ * @default false
135
+ */
136
+ interactive: false,
137
+
138
+ /**
139
+ * The offset of the x-axis position of the sprite from the entity's x-axis position.
140
+ *
141
+ * @property offsetX
142
+ * @type Number
143
+ * @default 0
144
+ */
145
+ offsetX: 0,
146
+
147
+ /**
148
+ * The offset of the y-axis position of the sprite from the entity's y-axis position.
149
+ *
150
+ * @property offsetY
151
+ * @type Number
152
+ * @default 0
153
+ */
154
+ offsetY: 0,
155
+
156
+ /**
157
+ * The z-index relative to other render components on the entity.
158
+ *
159
+ * @property offsetZ
160
+ * @type Number
161
+ * @default 0
162
+ */
163
+ offsetZ: 0,
164
+
165
+ /**
166
+ * Whether to restart a playing animation on event.
167
+ *
168
+ * @property restart
169
+ * @type Boolean
170
+ * @default true
171
+ */
172
+ restart: true,
173
+
174
+ /**
175
+ * Whether this object can be mirrored over X. To mirror it over X set the this.owner.rotation value to be > 90 and < 270.
176
+ *
177
+ * @property mirror
178
+ * @type Boolean
179
+ * @default false
180
+ */
181
+ mirror: false,
182
+
183
+ /**
184
+ * Optional. Whether this object can be flipped over Y. To flip it over Y set the this.owner.rotation to be > 180.
185
+ *
186
+ * @property flip
187
+ * @type Boolean
188
+ * @default false
189
+ */
190
+ flip: false,
191
+
192
+ /**
193
+ * Optional. Whether this object is visible or not. To change the visible value dynamically set this.owner.state.visible to true or false.
194
+ *
195
+ * @property visible
196
+ * @type Boolean
197
+ * @default false
198
+ */
199
+ visible: true,
200
+
201
+ /**
202
+ * Optional. Specifies whether this component should create an RenderAnimator component to listen to events matching the animationMap to animate. Set this to true if the component should animate for on events. Default is `false`.
203
+ *
204
+ * @property eventBased
205
+ * @type Boolean
206
+ * @default false
207
+ */
208
+ eventBased: false,
209
+
210
+ /**
211
+ * Optional. Specifies whether this component should create a RenderAnimator component to handle changes in the entity's state that match the animationMap to animate. Set this to true if the component should animate based on `this.owner.state`. Default is `true`.
212
+ *
213
+ * @property stateBased
214
+ * @type Boolean
215
+ * @default true
216
+ */
217
+ stateBased: true,
218
+
219
+ /**
220
+ * Optional. Whether this sprite should be cached into an entity with a `RenderTiles` component (like "render-layer"). The `RenderTiles` component must have its "entityCache" property set to `true`. Warning! This is a one-direction setting and will remove this component from the entity once the current frame has been cached.
221
+ *
222
+ * @property cache
223
+ * @type Boolean
224
+ * @default false
225
+ */
226
+ cache: false,
227
+
228
+ /**
229
+ * Optional. When using state-based animations, forces animations to complete before starting a new animation. Defaults to false.
230
+ *
231
+ * @property forcePlayThrough
232
+ * @type Boolean
233
+ * @default false
234
+ */
235
+ forcePlayThrough: false,
236
+
237
+ /**
238
+ * Optional. Ignores the opacity of the owner. Used when multiple RenderSprite components are on the same entity.
239
+ *
240
+ * @property ignoreOpacity
241
+ * @type Boolean
242
+ * @default false
243
+ */
244
+ ignoreOpacity: false,
245
+
246
+ /**
247
+ * The scaling factor for this component.
248
+ *
249
+ * @property scale
250
+ * @type Number|Array|Object
251
+ * @default 1
252
+ */
253
+ scale: 1,
254
+
255
+ /**
256
+ * Optional. The X scaling factor for the image. Defaults to 1.
257
+ *
258
+ * @property scaleX
259
+ * @type Number
260
+ * @default 1
261
+ */
262
+ scaleX: 1,
263
+
264
+ /**
265
+ * Optional. The Y scaling factor for the entity. Defaults to 1.
266
+ *
267
+ * @property scaleY
268
+ * @type Number
269
+ * @default 1
270
+ */
271
+ scaleY: 1,
272
+
273
+ /**
274
+ * The rotation for this sprite relative to the container.
275
+ *
276
+ * @property localRotation
277
+ * @type Number
278
+ * @default 0
279
+ */
280
+ localRotation: 0,
281
+
282
+ /**
283
+ * The scaling factor for this sprite relative to the scale of the container.
284
+ *
285
+ * @property localScaleX
286
+ * @type Number|Array|Object
287
+ * @default 1
288
+ */
289
+ localScaleX: 1,
290
+
291
+ /**
292
+ * The scaling factor for this sprite relative to the scale of the container.
293
+ *
294
+ * @property localScaleY
295
+ * @type Number|Array|Object
296
+ * @default 1
297
+ */
298
+ localScaleY: 1,
299
+
300
+ /**
301
+ * The skew factor for this component.
302
+ *
303
+ * @property skew
304
+ * @type Number|Array|Object
305
+ * @default 0
306
+ */
307
+ skew: 0,
308
+
309
+ /**
310
+ * Optional. The X skew factor of the entity. Defaults to 0.
311
+ *
312
+ * @property skewX
313
+ * @type Number
314
+ * @default 0
315
+ */
316
+ skewX: 0,
317
+
318
+ /**
319
+ * Optional. The Y skew factor for the entity. Defaults to 0.
320
+ *
321
+ * @property skewY
322
+ * @type Number
323
+ * @default 0
324
+ */
325
+ skewY: 0
326
+ },
327
+
328
+ /**
329
+ * This component is attached to entities that will appear in the game world. It renders a static or animated image. It listens for messages triggered on the entity or changes in the logical state of the entity to play a corresponding animation.
330
+ *
331
+ * @memberof platypus.components
332
+ * @uses platypus.Component
333
+ * @constructs
334
+ * @listens platypus.Entity#handle-render
335
+ * @listens platypus.Entity#play-animation
336
+ * @listens platypus.Entity#stop-animation
337
+ * @fires platypus.Entity#animation-ended
338
+ * @fires platypus.Entity#update-animation
339
+ */
340
+ initialize: (function () {
341
+ const
342
+ createAnimationMap = function (animationMap, ss) {
343
+ if (animationMap) {
344
+ return animationMap;
345
+ } else if (Array.isArray(ss.frames) && (ss.frames.length === 1)) {
346
+ // This is a single frame animation, so no mapping is necessary
347
+ return null;
348
+ } else {
349
+ // Create 1-to-1 animation map since none was defined
350
+ return Object.keys(ss.animations).reduce((map, value) => {
351
+ map[value] = value;
352
+ return map;
353
+ }, {});
354
+ }
355
+ };
356
+
357
+ return function () {
358
+ const
359
+ ss = PIXIAnimation.formatSpriteSheet(this.spriteSheet),
360
+ map = createAnimationMap(this.animationMap, ss),
361
+ animation = map?.default ?? '';
362
+
363
+ if (ss === PIXIAnimation.EmptySpriteSheet) {
364
+ platypus.debug.warn('Entity "' + this.owner.type + '": RenderSprite sprite sheet not defined.');
365
+ }
366
+
367
+ this.stateBased = map && this.stateBased;
368
+ this.eventBased = map && this.eventBased;
369
+
370
+ if (map) {
371
+ const
372
+ definition = Data.setUp(
373
+ 'animationEvents', this.eventBased ? this.animationEvents || map : null,
374
+ 'animationStates', this.stateBased ? this.animationStates || map : null,
375
+ 'forcePlayThrough', this.forcePlayThrough,
376
+ 'restart', this.restart,
377
+ 'component', this
378
+ );
379
+
380
+ this.owner.addComponent(new RenderAnimator(this.owner, definition));
381
+ definition.recycle();
382
+ }
383
+
384
+ /*
385
+ * PIXIAnimation created here:
386
+ */
387
+ this.sprite = new PIXIAnimation(ss, animation);
388
+ this.sprite.onComplete = (animation) => {
389
+ /**
390
+ * This event fires each time an animation completes.
391
+ *
392
+ * @event platypus.Entity#animation-ended
393
+ * @param animation {String} The id of the animation that ended.
394
+ */
395
+ this.owner.triggerEvent('animation-ended', animation);
396
+ };
397
+ this.sprite.x = this.offsetX;
398
+ this.sprite.y = this.offsetY;
399
+ this.sprite.zIndex = this.offsetZ;
400
+ this.sprite.rotation = (this.localRotation / 180) * Math.PI;
401
+ this.sprite.scale.x = this.localScaleX;
402
+ this.sprite.scale.y = this.localScaleY;
403
+
404
+ if (!this.owner.container) {
405
+ const
406
+ definition = Data.setUp(
407
+ 'interactive', this.interactive,
408
+ 'mask', this.mask,
409
+ 'mirror', this.mirror,
410
+ 'flip', this.flip,
411
+ 'visible', this.visible,
412
+ 'cache', this.cache,
413
+ 'ignoreOpacity', this.ignoreOpacity,
414
+ 'scaleX', this.scaleX,
415
+ 'scaleY', this.scaleY,
416
+ 'skewX', this.skewX,
417
+ 'skewY', this.skewY
418
+ );
419
+
420
+ this.owner.addComponent(new RenderContainer(this.owner, definition, () => this.addToContainer()));
421
+ definition.recycle();
422
+ } else {
423
+ this.addToContainer();
424
+ }
425
+
426
+ ss.recycleSpriteSheet();
427
+ };
428
+ }()),
429
+
430
+ events: {
431
+ "handle-render": function (renderData) {
432
+ if (this.sprite) {
433
+ /**
434
+ * This event is triggered each tick to check for animation updates.
435
+ *
436
+ * @event platypus.Entity#update-animation
437
+ * @param playing {Boolean} Whether the animation is in a playing or paused state.
438
+ */
439
+ this.owner.triggerEvent('update-animation', true);
440
+
441
+ this.sprite.update(renderData.delta);
442
+ }
443
+ },
444
+
445
+ "stop-animation": function (animation) {
446
+ this.stopAnimation(animation);
447
+ },
448
+
449
+ "play-animation": function (animation, loop, restart) {
450
+ this.playAnimation(animation, loop, restart);
451
+ }
452
+ },
453
+
454
+ methods: {
455
+ addToContainer: function () {
456
+ const container = this.owner.container;
457
+
458
+ container.addChild(this.sprite);
459
+ },
460
+
461
+ playAnimation: function (animation, loop, restart) {
462
+ const
463
+ {sprite} = this;
464
+
465
+ if (animation && sprite.has(animation)) {
466
+ sprite.gotoAndPlay(animation, loop, restart);
467
+ } else {
468
+ sprite.play();
469
+ }
470
+ },
471
+
472
+ stopAnimation: function (animation) {
473
+ const
474
+ {sprite} = this;
475
+
476
+ if (animation && sprite.has(animation)) {
477
+ sprite.gotoAndStop(animation);
478
+ } else {
479
+ sprite.stop();
480
+ }
481
+ },
482
+
483
+ destroy: function () {
484
+ this.owner.container.removeChild(this.sprite);
485
+ this.sprite.destroy();
486
+ this.sprite = null;
487
+ }
488
+ },
489
+
490
+ getAssetList: (function () {
491
+ const
492
+ getImages = function (ss, spriteSheets) {
493
+ if (ss) {
494
+ if (typeof ss === 'string') {
495
+ return getImages(spriteSheets[ss], spriteSheets);
496
+ } else if (ss.images) {
497
+ return greenSlice(ss.images);
498
+ }
499
+ }
500
+
501
+ return arrayCache.setUp();
502
+ };
503
+
504
+ return function (component, props, defaultProps) {
505
+ const
506
+ spriteSheets = platypus.game.settings.spriteSheets,
507
+ ss = component?.spriteSheet ?? props?.spriteSheet ?? defaultProps?.spriteSheet;
508
+
509
+ if (Array.isArray(ss)) {
510
+ const
511
+ images = arrayCache.setUp();
512
+ let i = ss.length;
513
+
514
+ while (i--) {
515
+ const
516
+ arr = getImages(ss[i], spriteSheets);
517
+
518
+ union(images, arr);
519
+ arrayCache.recycle(arr);
520
+ }
521
+ return images;
522
+ } else {
523
+ return getImages(ss, spriteSheets);
524
+ }
525
+ };
526
+ }())
527
+ });
@@ -0,0 +1,147 @@
1
+ import RenderContainer from './RenderContainer.js';
2
+ import {Text} from 'pixi.js';
3
+ import createComponentClass from '../factory.js';
4
+
5
+ const
6
+ DEFAULT_ALIGNMENT = 0.5,
7
+ alignments = {
8
+ horizontal: {
9
+ left: 0,
10
+ middle: DEFAULT_ALIGNMENT,
11
+ center: DEFAULT_ALIGNMENT,
12
+ right: 1
13
+ },
14
+ vertical: {
15
+ top: 0,
16
+ middle: DEFAULT_ALIGNMENT,
17
+ center: DEFAULT_ALIGNMENT,
18
+ bottom: 1
19
+ }
20
+ };
21
+
22
+ export default createComponentClass(/** @lends platypus.components.RenderText.prototype */{
23
+
24
+ id: 'RenderText',
25
+
26
+ properties: {
27
+ /**
28
+ * The offset of the x-axis position of the text from the entity's x-axis position.
29
+ *
30
+ * @property offsetX
31
+ * @type Number
32
+ * @default 0
33
+ */
34
+ offsetX: 0,
35
+
36
+ /**
37
+ * The offset of the y-axis position of the text from the entity's y-axis position.
38
+ *
39
+ * @property offsetY
40
+ * @type Number
41
+ * @default 0
42
+ */
43
+ offsetY: 0,
44
+
45
+ /**
46
+ * The z-index relative to other render components on the entity.
47
+ *
48
+ * @property offsetZ
49
+ * @type Number
50
+ * @default 0
51
+ */
52
+ offsetZ: 0,
53
+
54
+ /**
55
+ * This is the text to display.
56
+ *
57
+ * @property text
58
+ * @type String
59
+ * @default ""
60
+ */
61
+ text: "",
62
+
63
+ /**
64
+ * This is the text style to use. Use the following specification to define the style:
65
+ *
66
+ * {
67
+ * "fontSize": "64px",
68
+ * "fill": "#ffffff",
69
+ * "align": "center", // Can be `left`, `center`, or `right`
70
+ * "fontFamily": "arial", // Any CSS font that has been loaded by the browser
71
+ * "fontWeight": 700, //Numerical weight of the font.
72
+ * "verticalAlign": "bottom" // Can be `top`, `center`, or `bottom`
73
+ * }
74
+ *
75
+ * See [PIXI.TextStyle documentation](http://pixijs.download/dev/docs/PIXI.TextStyle.html) for a full list of available options.
76
+ *
77
+ * @property style
78
+ * @type Object
79
+ * @default null
80
+ */
81
+ style: null
82
+ },
83
+
84
+ /**
85
+ * This component is attached to entities that should display text.
86
+ *
87
+ * @memberof platypus.components
88
+ * @uses platypus.Component
89
+ * @constructs
90
+ * @listens platypus.Entity#set-text
91
+ */
92
+ initialize: function (definition) {
93
+ const
94
+ {offsetX, offsetY, offsetZ, owner, style = {}, text = ''} = this,
95
+ hAlign = alignments.horizontal[style?.align] ?? DEFAULT_ALIGNMENT,
96
+ vAlign = alignments.vertical[style?.verticalAlign] ?? DEFAULT_ALIGNMENT,
97
+ sprite = this.sprite = new Text({text, style});
98
+
99
+ sprite.anchor.x = hAlign;
100
+ sprite.anchor.y = vAlign;
101
+ sprite.x = offsetX;
102
+ sprite.y = offsetY;
103
+ sprite.zIndex = offsetZ;
104
+
105
+ if (!owner.container) {
106
+ owner.addComponent(new RenderContainer(owner, definition, () => this.addToContainer()));
107
+ } else {
108
+ this.addToContainer();
109
+ }
110
+ },
111
+
112
+ events: {
113
+ /**
114
+ * Sets the copy of the text.
115
+ *
116
+ * @event platypus.Entity#set-text
117
+ * @param text {String} The text to insert.
118
+ */
119
+ "set-text": function (text) {
120
+ const
121
+ {sprite} = this;
122
+
123
+ if (typeof text === 'string') {
124
+ sprite.text = text;
125
+ } else {
126
+ if (text.style) {
127
+ Object.keys(text.style).forEach((key) => sprite.style[key] = text.style[key])
128
+ }
129
+ if (typeof text.text === 'string') {
130
+ sprite.text = text.text;
131
+ }
132
+ }
133
+ }
134
+ },
135
+
136
+ methods: {
137
+ addToContainer: function () {
138
+ this.owner.container.addChild(this.sprite);
139
+ },
140
+
141
+ destroy: function () {
142
+ this.owner.container.removeChild(this.sprite);
143
+ this.sprite.destroy();
144
+ this.sprite = null;
145
+ }
146
+ }
147
+ });