@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,319 @@
1
+ import {Container, Graphics} from 'pixi.js';
2
+ import {arrayCache} from '../utils/array.js';
3
+ import createComponentClass from '../factory.js';
4
+
5
+ const
6
+ collisionColors = {},
7
+ createCollisionColor = function (collisionType) {
8
+ let r = collisionType.charCodeAt(0) || 0,
9
+ g = collisionType.charCodeAt(1) || 0,
10
+ b = collisionType.charCodeAt(2) || 0,
11
+ min = 0,
12
+ max = 0;
13
+
14
+ min = Math.min(r, g, b);
15
+
16
+ r -= min;
17
+ g -= min;
18
+ b -= min;
19
+
20
+ max = Math.max(r, g, b, 1);
21
+
22
+ r = (0xCC * r / max) >> 0;
23
+ g = (0xCC * g / max) >> 0;
24
+ b = (0xCC * b / max) >> 0;
25
+
26
+ return (r << 8) + (g << 4) + b;
27
+ },
28
+ createShape = function ({radius, color, left, top, width, height, z, outline, points}) {
29
+ const
30
+ newShape = new Graphics();
31
+
32
+ if (radius) {
33
+ const
34
+ cx = width ? left + width / 2 : left + radius,
35
+ cy = height ? top + height / 2 : top + radius;
36
+
37
+ newShape.circle(cx, cy, radius);
38
+ } else if (points) {
39
+ newShape.poly(points);
40
+ } else if (width && height) {
41
+ newShape.rect(left, top, width, height);
42
+ }
43
+ newShape.z = z;
44
+ newShape.fill(color, 0.1);
45
+ if (outline) {
46
+ newShape.stroke({
47
+ width: outline,
48
+ color
49
+ });
50
+ }
51
+
52
+ return newShape;
53
+ },
54
+ standardizeColor = function (color) {
55
+ if (typeof color === 'string') {
56
+ return parseInt(color.replace('#', ''), 16);
57
+ } else {
58
+ return color;
59
+ }
60
+ };
61
+
62
+ export default createComponentClass(/** @lends platypus.components.RenderDebug.prototype */{
63
+
64
+ id: 'RenderDebug',
65
+
66
+ properties: {
67
+ /**
68
+ * The color to use to highlight an entity's AABB. For example, use `"#ffffff"` or `0xffffff` to set as white.
69
+ *
70
+ * @property aabbColor
71
+ * @type Number|String
72
+ * @default 0xff88ff
73
+ */
74
+ aabbColor: 0xff88ff,
75
+
76
+ /**
77
+ * The color to use to highlight an entity's collision shape. For example, use `"#ffffff"` or `0xffffff` to set as white. Will generate a color based on the collision type if not specified.
78
+ *
79
+ * @property collisionColor
80
+ * @type Number|String
81
+ * @default 0
82
+ */
83
+ collisionColor: 0,
84
+
85
+ /**
86
+ * The color to use to highlight the AABB for a group of entities attached to this entity. For example, use `"#ffffff"` or `0xffffff` to set as white.
87
+ *
88
+ * @property groupColor
89
+ * @type Number|String
90
+ * @default 0x00ff00
91
+ */
92
+ groupColor: 0x00ff00,
93
+
94
+ /**
95
+ * The color to use to highlight an entity. This property is only used if there is no `CollisionBasic` component attached to the entity: this component uses the entity's `width` and `height` properties if defined. For example, use `"#ffffff"` or `0xffffff` to set as white.
96
+ *
97
+ * @property renderColor
98
+ * @type Number|String
99
+ * @default 0x0000ff
100
+ */
101
+ renderColor: 0x0000ff,
102
+
103
+ /**
104
+ * The height of the entity.
105
+ *
106
+ * @property height
107
+ * @type Number
108
+ * @default 100
109
+ */
110
+ width: 100,
111
+
112
+ /**
113
+ * The width of the entity.
114
+ *
115
+ * @property width
116
+ * @type Number
117
+ * @default 100
118
+ */
119
+ height: 100,
120
+
121
+ /**
122
+ * The local offset in z-index for the rendered debug area.
123
+ *
124
+ * @property offsetZ
125
+ * @type Number
126
+ * @default 10000
127
+ */
128
+ offsetZ: 10000
129
+ },
130
+
131
+ /**
132
+ * This component is attached to entities that will appear in the game world. It serves two purposes. First, it displays a rectangle that indicates the location of the entity. By default it uses the specified position and dimensions of the object (in grey). If the object has a collision component it will display the AABB of the collision shape (in pink). If the entity has a LogicCarrier component and is/was carrying an object, a green rectangle will be drawn showing the collision group. The RenderDebug component also allows the developer to right-click on an entity and it will print the object in the debug console.
133
+ *
134
+ * @memberof platypus.components
135
+ * @uses platypus.Component
136
+ * @constructs
137
+ * @listens platypus.Entity#camera-update
138
+ * @listens platypus.Entity#collide-off
139
+ * @listens platypus.Entity#collide-on
140
+ * @listens platypus.Entity#handle-render
141
+ * @listens platypus.Entity#load
142
+ * @listens platypus.Entity#orientation-updated
143
+ */
144
+ initialize: function () {
145
+ this.container = new Container();
146
+ this.container.cullable = true;
147
+
148
+ this.parentContainer = this.owner.parent.worldContainer;
149
+ this.parentContainer.addChild(this.container);
150
+
151
+ this.shapes = arrayCache.setUp();
152
+ this.isOutdated = true;
153
+
154
+ this.aabbColor = standardizeColor(this.aabbColor);
155
+ this.collisionColor = this.collisionColor ? standardizeColor(this.collisionColor) : 0;
156
+ this.groupColor = standardizeColor(this.groupColor);
157
+ this.renderColor = standardizeColor(this.renderColor);
158
+ },
159
+
160
+ events: {
161
+ "load": function () {
162
+ if (!platypus.game.settings.debug) {
163
+ this.owner.removeComponent(this);
164
+ return;
165
+ }
166
+ },
167
+
168
+ "handle-render": function () {
169
+ if (this.isOutdated) {
170
+ this.updateSprites();
171
+ this.isOutdated = false;
172
+ }
173
+
174
+ if (this.owner.getCollisionGroupAABB) {
175
+ const
176
+ aabb = this.owner.getCollisionGroupAABB(),
177
+ offset = -0.5;
178
+
179
+ if (!this.groupShape) {
180
+ this.groupShape = createShape({
181
+ color: this.groupColor,
182
+ left: offset,
183
+ top: offset,
184
+ width: 1,
185
+ height: 1,
186
+ z: this.offsetZ
187
+ });
188
+ this.container.addChild(this.groupShape);
189
+ }
190
+ this.groupShape.scaleX = aabb.width;
191
+ this.groupShape.scaleY = aabb.height;
192
+ this.groupShape.x = aabb.x - this.owner.x;
193
+ this.groupShape.y = aabb.y - this.owner.y;
194
+ }
195
+
196
+ this.update();
197
+ },
198
+
199
+ "orientation-updated": function () {
200
+ this.isOutdated = true;
201
+ },
202
+
203
+ "collide-on": function () {
204
+ this.isOutdated = true;
205
+ },
206
+
207
+ "collide-off": function () {
208
+ this.isOutdated = true;
209
+ }
210
+ },
211
+
212
+ methods: {
213
+ addShape (properties) {
214
+ const
215
+ shape = createShape({
216
+ z: this.offsetZ,
217
+ ...properties
218
+ });
219
+
220
+ this.shapes.push(shape);
221
+ this.container.addChild(shape);
222
+ this.offsetZ -= 0.0001;
223
+ },
224
+
225
+ update () {
226
+ const
227
+ {container, owner} = this;
228
+
229
+ if (container.zIndex !== owner.z + 0.000001) {
230
+ container.zIndex = owner.z + 0.000001;
231
+ }
232
+
233
+ container.updateTransform({
234
+ x: owner.x,
235
+ y: owner.y
236
+ });
237
+ },
238
+
239
+ updateSprites: function () {
240
+ const
241
+ {owner} = this;
242
+
243
+ for (let i = 0; i < this.shapes.length; i++) {
244
+ this.container.removeChild(this.shapes[i]);
245
+ }
246
+ this.shapes.length = 0;
247
+
248
+ if (owner.getAABB) {
249
+ for (let j = 0; j < owner.collisionTypes.length; j++) {
250
+ const
251
+ collisionType = owner.collisionTypes[j],
252
+ aabb = owner.getAABB(collisionType),
253
+ lineWidth = 2,
254
+ shapes = owner.getShapes(collisionType),
255
+ width = this.initialWidth = aabb.width,
256
+ height = this.initialHeight = aabb.height;
257
+
258
+ let collisionColor = this.collisionColor || collisionColors[collisionType];
259
+
260
+ if (!collisionColor) {
261
+ collisionColor = collisionColors[collisionType] = createCollisionColor(collisionType);
262
+ }
263
+
264
+ this.addShape({
265
+ color: this.aabbColor,
266
+ left: aabb.left - owner.x,
267
+ top: aabb.top - owner.y,
268
+ width,
269
+ height
270
+ });
271
+
272
+ for (let i = 0; i < shapes.length; i++) {
273
+ const
274
+ shape = shapes[i],
275
+ shapeAabb = shape.aABB;
276
+
277
+ this.addShape({
278
+ color: collisionColor,
279
+ left: shapeAabb.left - owner.x,
280
+ top: shapeAabb.top - owner.y,
281
+ width: shapeAabb.width,
282
+ height: shapeAabb.height,
283
+ radius: shape.type === 'circle' ? shape.radius : 0,
284
+ outline: lineWidth
285
+ });
286
+ }
287
+ }
288
+ } else {
289
+ const
290
+ {height = 1, width = 1} = this;
291
+
292
+ this.addShape({
293
+ color: this.renderColor,
294
+ left: -width / 2,
295
+ top: -height / 2,
296
+ width,
297
+ height
298
+ });
299
+ }
300
+ this.addShape({
301
+ color: 0x000000,
302
+ left: -1,
303
+ outline: 1,
304
+ top: -1,
305
+ radius: 1
306
+ });
307
+ },
308
+
309
+ destroy: function () {
310
+ for (let i = 0; i < this.shapes.length; i++) {
311
+ this.container.removeChild(this.shapes[i]);
312
+ }
313
+ arrayCache.recycle(this.shapes);
314
+
315
+ this.parentContainer.removeChild(this.container);
316
+ this.container = null;
317
+ }
318
+ }
319
+ });
@@ -0,0 +1,59 @@
1
+ import {arrayCache, greenSlice} from '../utils/array.js';
2
+ import createComponentClass from '../factory.js';
3
+
4
+ export default createComponentClass(/** @lends platypus.components.RenderDestroyMe.prototype */{
5
+ id: 'RenderDestroyMe',
6
+
7
+ properties: {
8
+ /**
9
+ * This or animationIds required. This is a String identifying the animation that should destroy this entity on its completion.
10
+ *
11
+ * @property animationId
12
+ * @type String
13
+ * @default ''
14
+ */
15
+ animationId: '',
16
+
17
+ /**
18
+ * This or animationId required. This is an array of Strings identifying the animations that should destroy this entity on their completion.
19
+ *
20
+ * @property animationIds
21
+ * @type Array
22
+ * @default null
23
+ */
24
+ animationIds: null
25
+ },
26
+
27
+ /**
28
+ * This component will destroy the entity once an animation has finished. This is useful for explosions or similar animations where the entity is no longer needed once the animation completes.
29
+ *
30
+ * @memberof platypus.components
31
+ * @uses platypus.Component
32
+ * @constructs
33
+ * @listens platypus.Entity#animation-ended
34
+ */
35
+ initialize: function (definition) {
36
+ if (this.animationId) {
37
+ this.animationIds = arrayCache.setUp(definition.animationId);
38
+ } else if (this.animationIds) {
39
+ this.animationIds = greenSlice(this.animationIds);
40
+ }
41
+ },
42
+
43
+ events: {// These are messages that this component listens for
44
+ "animation-ended": function (animation) {
45
+ if (!this.animationIds || (this.animationIds.indexOf(animation) >= 0)) {
46
+ this.owner.parent.removeEntity(this.owner);
47
+ }
48
+ }
49
+ },
50
+
51
+ methods: {
52
+ destroy: function () {
53
+ if (this.animationIds) {
54
+ arrayCache.recycle(this.animationIds);
55
+ this.animationIds = null;
56
+ }
57
+ }
58
+ }
59
+ });
@@ -0,0 +1,149 @@
1
+ import {LottieSprite} from '@qva/pixi-lottie';
2
+ import createComponentClass from '../factory.js';
3
+ import RenderContainer from './RenderContainer.js';
4
+
5
+ export default createComponentClass(/** @lends platypus.components.RenderSprite.prototype */{
6
+
7
+ id: 'RenderLottie',
8
+
9
+ properties: {
10
+ /**
11
+ * The offset of the x-axis position of the sprite from the entity's x-axis position.
12
+ *
13
+ * @property offsetX
14
+ * @type Number
15
+ * @default 0
16
+ */
17
+ offsetX: 0,
18
+
19
+ /**
20
+ * The offset of the y-axis position of the sprite from the entity's y-axis position.
21
+ *
22
+ * @property offsetY
23
+ * @type Number
24
+ * @default 0
25
+ */
26
+ offsetY: 0,
27
+
28
+ /**
29
+ * The z-index relative to other render components on the entity.
30
+ *
31
+ * @property offsetZ
32
+ * @type Number
33
+ * @default 0
34
+ */
35
+ offsetZ: 0,
36
+
37
+ /**
38
+ {
39
+ asset: string | Uint8Array;
40
+
41
+ autoplay?: boolean;
42
+
43
+ loop?: boolean;
44
+
45
+ width?: number;
46
+
47
+ height?: number;
48
+
49
+ speed?: number;
50
+ }
51
+ */
52
+ options: null,
53
+
54
+ /**
55
+ * The rotation for this sprite relative to the container.
56
+ *
57
+ * @property localRotation
58
+ * @type Number
59
+ * @default 0
60
+ */
61
+ localRotation: 0,
62
+
63
+ /**
64
+ * The scaling factor for this sprite relative to the scale of the container.
65
+ *
66
+ * @property localScaleX
67
+ * @type Number|Array|Object
68
+ * @default 1
69
+ */
70
+ localScaleX: 1,
71
+
72
+ /**
73
+ * The scaling factor for this sprite relative to the scale of the container.
74
+ *
75
+ * @property localScaleY
76
+ * @type Number|Array|Object
77
+ * @default 1
78
+ */
79
+ localScaleY: 1
80
+ },
81
+
82
+ /**
83
+ * 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.
84
+ *
85
+ * @memberof platypus.components
86
+ * @uses platypus.Component
87
+ * @constructs
88
+ * @listens platypus.Entity#handle-render
89
+ * @listens platypus.Entity#play-animation
90
+ * @listens platypus.Entity#stop-animation
91
+ * @fires platypus.Entity#animation-ended
92
+ * @fires platypus.Entity#update-animation
93
+ */
94
+ initialize () {
95
+ const
96
+ {localRotation, localScaleX, localScaleY, offsetX, offsetY, offsetZ, options, owner} = this,
97
+ sprite = this.sprite = new LottieSprite(options ?? {});
98
+
99
+ sprite.x = offsetX;
100
+ sprite.y = offsetY;
101
+ sprite.zIndex = offsetZ;
102
+ sprite.rotation = (localRotation / 180) * Math.PI;
103
+ sprite.scale.x = localScaleX;
104
+ sprite.scale.y = localScaleY;
105
+
106
+ if (!owner.container) {
107
+ const
108
+ {interactive, mask, mirror, flip, visible, cache, ignoreOpacity, scaleX, scaleY, skewX, skewY} = owner;
109
+
110
+ owner.addComponent(new RenderContainer(this.owner, {interactive, mask, mirror, flip, visible, cache, ignoreOpacity, scaleX, scaleY, skewX, skewY}, () => this.addToContainer()));
111
+ } else {
112
+ this.addToContainer();
113
+ }
114
+
115
+ if (sprite.update) {
116
+ this.addEventListener('handle-render', (renderData) => {
117
+ if (sprite.update) {
118
+ sprite.update(renderData.delta);
119
+ }
120
+ });
121
+ }
122
+
123
+ sprite.play();
124
+ },
125
+
126
+ methods: {
127
+ addToContainer: function () {
128
+ const container = this.owner.container;
129
+
130
+ container.addChild(this.sprite);
131
+ },
132
+
133
+ destroy: function () {
134
+ this.owner.container.removeChild(this.sprite);
135
+ this.sprite.destroy();
136
+ this.sprite = null;
137
+ }
138
+ },
139
+
140
+ getAssetList (/*a, b, c*/) {
141
+ //const
142
+ // image = a?.image ?? b?.image ?? c?.image;
143
+ //
144
+ //return (image ? [image] : a?.images ?? b?.images ?? c?.images ?? []).map((src) => ({
145
+ // alias: [src],
146
+ // src
147
+ //}));
148
+ }
149
+ });
@@ -0,0 +1,120 @@
1
+ /* global platypus */
2
+ import {Container, Graphics, Point} from 'pixi.js';
3
+ import createComponentClass from '../factory.js';
4
+
5
+ export default createComponentClass(/** @lends platypus.components.RenderProgress.prototype */{
6
+
7
+ id: 'RenderProgress',
8
+
9
+ properties: {
10
+ //TODO: Document!
11
+ backgroundColor: 0x000000,
12
+
13
+ color: 0xffffff,
14
+
15
+ mirror: false,
16
+
17
+ flip: false,
18
+
19
+ width: 100,
20
+
21
+ height: 20,
22
+
23
+ regX: 0,
24
+
25
+ regY: 0
26
+ },
27
+
28
+ publicProperties: {
29
+ x: 0,
30
+
31
+ y: 0,
32
+
33
+ z: 0
34
+ },
35
+
36
+ /**
37
+ * This component creates a visual progress bar that can be used for loading assets or showing other types of progress changes.
38
+ *
39
+ * @memberof platypus.components
40
+ * @uses platypus.Component
41
+ * @constructs
42
+ * @listens platypus.Entity#handle-render
43
+ * @listens platypus.Entity#handle-render-load
44
+ */
45
+ initialize: function () {
46
+ const
47
+ b = new Graphics(),
48
+ f = new Graphics(),
49
+ con = new Container();
50
+
51
+ this.parentContainer = null;
52
+ this.background = b;
53
+ this.progress = f;
54
+ this.container = con;
55
+
56
+ if (typeof this.backgroundColor === 'string') {
57
+ this.backgroundColor = +this.backgroundColor.replace('#', '0x');
58
+ }
59
+ if (typeof this.color === 'string') {
60
+ this.color = +this.color.replace('#', '0x');
61
+ }
62
+
63
+ b.f(this.backgroundColor).rect(-this.regX, -this.regY, this.width, this.height);
64
+ f.f(this.color).rect(-this.regX, -this.regY, this.width, this.height);
65
+ f.scale = new Point(0.0001, 1);
66
+ con.addChild(b);
67
+ con.addChild(f);
68
+ },
69
+
70
+ events: {
71
+ "handle-render-load": function (resp) {
72
+ if (!this.parentContainer && resp && resp.container) {
73
+ this.parentContainer = resp.container;
74
+ this.parentContainer.addChild(this.container);
75
+ }
76
+ },
77
+
78
+ "handle-render": function (resp) {
79
+ if (!this.container) { // If this component's removal is pending
80
+ return;
81
+ }
82
+
83
+ if (!this.parentContainer) {
84
+ if (resp && resp.container) {
85
+ this.parentContainer = resp.container;
86
+ this.parentContainer.addChild(this.container);
87
+ } else {
88
+ platypus.debug.warn('No PIXI Stage, removing ProgressRender component from "' + this.owner.type + '".');
89
+ this.owner.removeComponent(this);
90
+ }
91
+ }
92
+
93
+ this.container.x = this.x;
94
+ this.container.y = this.y;
95
+ this.container.z = this.z;
96
+ },
97
+
98
+ "update-progress": function (progress) {
99
+ if (isNaN(progress)) {
100
+ if (typeof progress.fraction === 'number') {
101
+ this.progress.scale.x = progress.fraction;
102
+ } else if ((typeof progress.total === 'number') && (typeof progress.progress === 'number')) {
103
+ this.progress.scale.x = progress.progress / progress.total;
104
+ }
105
+ } else {
106
+ this.progress.scale.x = progress;
107
+ }
108
+ }
109
+ },
110
+
111
+ methods: {
112
+ destroy: function () {
113
+ if (this.parentContainer) {
114
+ this.parentContainer.removeChild(this.container);
115
+ this.parentContainer = null;
116
+ }
117
+ this.container = null;
118
+ }
119
+ }
120
+ });