@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.
- package/CHANGELOG.md +10 -0
- package/README.md +3 -3
- package/lib/platypus.js +1 -1
- package/package.json +6 -5
- package/src/AABB.js +685 -0
- package/src/ActionState.js +121 -0
- package/src/AssetManager.js +206 -0
- package/src/CollisionData.js +96 -0
- package/src/CollisionDataContainer.js +127 -0
- package/src/CollisionShape.js +315 -0
- package/src/Component.js +231 -0
- package/src/Data.js +64 -0
- package/src/DataMap.js +204 -0
- package/src/Entity.js +404 -0
- package/src/EntityLinker.js +113 -0
- package/src/EventHandler.js +115 -0
- package/src/EventHandlerList.js +251 -0
- package/src/Game.js +840 -0
- package/src/Gamepad.js +175 -0
- package/src/ID3CaptionPlayer.js +61 -0
- package/src/Messenger.js +365 -0
- package/src/PIXIAnimation.js +622 -0
- package/src/RandomSet.js +140 -0
- package/src/SFXPlayer.js +120 -0
- package/src/StateMap.js +252 -0
- package/src/Storage.js +152 -0
- package/src/TickerClient.js +48 -0
- package/src/TickerServer.js +23 -0
- package/src/TimeEvent.js +50 -0
- package/src/TimeEventList.js +100 -0
- package/src/VOPlayer.js +684 -0
- package/src/Vector.js +702 -0
- package/src/components/AIChaser.js +161 -0
- package/src/components/AIPacer.js +107 -0
- package/src/components/AudioMusic.js +151 -0
- package/src/components/AudioSFX.js +673 -0
- package/src/components/AudioVO.js +301 -0
- package/src/components/CollisionBasic.js +826 -0
- package/src/components/CollisionFilter.js +74 -0
- package/src/components/CollisionGroup.js +448 -0
- package/src/components/CollisionTiles.js +608 -0
- package/src/components/ComponentSwitcher.js +173 -0
- package/src/components/ControllerInput.js +65 -0
- package/src/components/Counter.js +165 -0
- package/src/components/EntityCamera.js +215 -0
- package/src/components/EntityContainer.js +549 -0
- package/src/components/EntityController.js +541 -0
- package/src/components/HandlerCamera.js +1052 -0
- package/src/components/HandlerCollision.js +1318 -0
- package/src/components/HandlerController.js +291 -0
- package/src/components/HandlerLogic.js +394 -0
- package/src/components/HandlerRender.js +217 -0
- package/src/components/Interactive.js +502 -0
- package/src/components/LevelBuilder.js +524 -0
- package/src/components/LogicAngularMovement.js +154 -0
- package/src/components/LogicAttachment.js +265 -0
- package/src/components/LogicButton.js +466 -0
- package/src/components/LogicCarrier.js +39 -0
- package/src/components/LogicDestroyMe.js +58 -0
- package/src/components/LogicDirectionalMovement.js +325 -0
- package/src/components/LogicDragDrop.js +371 -0
- package/src/components/LogicImpactLaunch.js +144 -0
- package/src/components/LogicPacingPlatform.js +64 -0
- package/src/components/LogicPortable.js +112 -0
- package/src/components/LogicPortal.js +115 -0
- package/src/components/LogicPushable.js +98 -0
- package/src/components/LogicRebounder.js +136 -0
- package/src/components/LogicRegionSpawner.js +139 -0
- package/src/components/LogicRotationalMovement.js +205 -0
- package/src/components/LogicSpawner.js +159 -0
- package/src/components/LogicStateMachine.js +382 -0
- package/src/components/LogicSwitch.js +77 -0
- package/src/components/LogicTeleportee.js +68 -0
- package/src/components/LogicTeleporter.js +93 -0
- package/src/components/LogicTimer.js +178 -0
- package/src/components/LogicWindUpRacer.js +179 -0
- package/src/components/Motion.js +371 -0
- package/src/components/Mover.js +566 -0
- package/src/components/Node.js +289 -0
- package/src/components/NodeMap.js +295 -0
- package/src/components/NodeResident.js +636 -0
- package/src/components/Orientation.js +697 -0
- package/src/components/RandomEvents.js +73 -0
- package/src/components/RelativePosition.js +204 -0
- package/src/components/RelayFamily.js +106 -0
- package/src/components/RelayGame.js +53 -0
- package/src/components/RelayLinker.js +94 -0
- package/src/components/RelayParent.js +57 -0
- package/src/components/RelaySelf.js +55 -0
- package/src/components/Render.js +178 -0
- package/src/components/RenderAnimator.js +275 -0
- package/src/components/RenderContainer.js +646 -0
- package/src/components/RenderDebug.js +319 -0
- package/src/components/RenderDestroyMe.js +59 -0
- package/src/components/RenderLottie.js +149 -0
- package/src/components/RenderProgress.js +120 -0
- package/src/components/RenderSpine.js +833 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1391 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1451 -0
- package/src/components/Timeline.js +314 -0
- package/src/components/Tutorial.js +267 -0
- package/src/components/Tween.js +296 -0
- package/src/components/VoiceOver.js +373 -0
- package/src/components/XHR.js +129 -0
- package/src/components/index.js +79 -0
- package/src/factory.js +305 -0
- package/src/index.js +159 -0
- package/src/mixins/PIXI.Graphics.js +41 -0
- package/src/platypus.css +68 -0
- package/src/sayHello.js +50 -0
- package/src/shapes/Capsule.js +74 -0
- package/src/shapes/Circle.js +43 -0
- package/src/shapes/Ellipse.js +117 -0
- package/src/shapes/Point.js +191 -0
- package/src/shapes/Polygon.js +112 -0
- package/src/shapes/Polyline.js +97 -0
- package/src/shapes/Rectangle.js +78 -0
- package/src/shapes/RoundedRectangle.js +33 -0
- package/src/shapes/Segment.js +346 -0
- package/src/shapes/adjustedXY.js +19 -0
- package/src/shapes/castFromBox2D.js +92 -0
- package/src/shapes/castFromObject.js +53 -0
- package/src/shapes/castFromPixiGraphics.js +6 -0
- package/src/shapes/castFromPixiShape.js +89 -0
- package/src/shapes/castToBox2D.js +190 -0
- package/src/shapes/castToPixiGraphics.js +100 -0
- package/src/shapes/castToPixiShape.js +61 -0
- package/src/shapes/checkPointsMap.js +313 -0
- package/src/shapes/index.js +35 -0
- package/src/utils/array.js +73 -0
- package/src/utils/string.js +39 -0
- package/lib/243.platypus.mjs +0 -1
- package/lib/platypus.mjs +0 -1
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import {Container, Graphics, Matrix} from 'pixi.js';
|
|
3
|
+
import AABB from '../AABB.js';
|
|
4
|
+
import Data from '../Data.js';
|
|
5
|
+
import Entity from '../Entity.js';
|
|
6
|
+
import Interactive from './Interactive.js';
|
|
7
|
+
import {arrayCache} from '../utils/array.js';
|
|
8
|
+
import createComponentClass from '../factory.js';
|
|
9
|
+
import {greenSplit} from '../utils/string.js';
|
|
10
|
+
|
|
11
|
+
const
|
|
12
|
+
pixiMatrix = new Matrix(),
|
|
13
|
+
magSqr = function (x, y) {
|
|
14
|
+
return x * x + y * y;
|
|
15
|
+
},
|
|
16
|
+
process = function (gfx, value) {
|
|
17
|
+
const
|
|
18
|
+
paren = value.indexOf('('),
|
|
19
|
+
func = value.substring(0, paren);
|
|
20
|
+
let values = value.substring(paren + 1, value.indexOf(')'));
|
|
21
|
+
|
|
22
|
+
if (values.length) {
|
|
23
|
+
let i = 0,
|
|
24
|
+
polyRay = false;
|
|
25
|
+
|
|
26
|
+
if (values[0] === '[') {
|
|
27
|
+
values = values.substring(1, values.length - 1);
|
|
28
|
+
polyRay = true;
|
|
29
|
+
}
|
|
30
|
+
values = greenSplit(values, ',');
|
|
31
|
+
i = values.length;
|
|
32
|
+
while (i--) {
|
|
33
|
+
values[i] = +values[i];
|
|
34
|
+
}
|
|
35
|
+
if (polyRay) {
|
|
36
|
+
gfx[func](values);
|
|
37
|
+
} else {
|
|
38
|
+
gfx[func].apply(gfx, values);
|
|
39
|
+
arrayCache.recycle(values); // cannot recycle polygon above since it's used by the polygon shape.
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
gfx[func]();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
processGraphics = function (gfx, value) {
|
|
46
|
+
const
|
|
47
|
+
arr = greenSplit(value, '.');
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < arr.length; i++) {
|
|
50
|
+
process(gfx, arr[i]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
arrayCache.recycle(arr);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default createComponentClass(/** @lends platypus.components.RenderContainer.prototype */{
|
|
57
|
+
|
|
58
|
+
id: 'RenderContainer',
|
|
59
|
+
|
|
60
|
+
properties: {
|
|
61
|
+
/**
|
|
62
|
+
* 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. Note that the mask is in world coordinates by default. To make the mask local to the entity's coordinates, set `localMask` to `true` in the RenderContainer properties.
|
|
63
|
+
*
|
|
64
|
+
* "mask": {
|
|
65
|
+
* "x": 10,
|
|
66
|
+
* "y": 10,
|
|
67
|
+
* "width": 40,
|
|
68
|
+
* "height": 40
|
|
69
|
+
* },
|
|
70
|
+
*
|
|
71
|
+
* -OR-
|
|
72
|
+
*
|
|
73
|
+
* "mask": "r(10,20,40,40).circle(30,10,12)"
|
|
74
|
+
*
|
|
75
|
+
* @property mask
|
|
76
|
+
* @type Object
|
|
77
|
+
* @default null
|
|
78
|
+
*/
|
|
79
|
+
mask: null,
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 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:
|
|
83
|
+
*
|
|
84
|
+
* "interactive": {
|
|
85
|
+
* "hover": false,
|
|
86
|
+
* "hitArea": {
|
|
87
|
+
* "x": 10,
|
|
88
|
+
* "y": 10,
|
|
89
|
+
* "width": 40,
|
|
90
|
+
* "height": 40
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* @property interactive
|
|
95
|
+
* @type Boolean|Object
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
interactive: false,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether to render objects to their new position over time instead of instantaneously if there has been a time adjustment. Time is in milliseconds.
|
|
102
|
+
*
|
|
103
|
+
* @property interpolation
|
|
104
|
+
* @type Number
|
|
105
|
+
* @default 0
|
|
106
|
+
*/
|
|
107
|
+
interpolation: 0,
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Optional. What field this object should use to rotate.
|
|
111
|
+
*
|
|
112
|
+
* @property rotate
|
|
113
|
+
* @type String
|
|
114
|
+
* @default 'rotation'
|
|
115
|
+
*/
|
|
116
|
+
rotate: 'rotation',
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Whether this object can be mirrored over X. To mirror it over X set the this.owner.rotation value to be > 90 and < 270.
|
|
120
|
+
*
|
|
121
|
+
* @property mirror
|
|
122
|
+
* @type Boolean
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
mirror: false,
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Optional. Whether this object can be flipped over Y. To flip it over Y set the this.owner.rotation to be > 180.
|
|
129
|
+
*
|
|
130
|
+
* @property flip
|
|
131
|
+
* @type Boolean
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
flip: false,
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Optional. Whether this object is visible or not. To change the visible value dynamically set this.owner.state.visible to true or false.
|
|
138
|
+
*
|
|
139
|
+
* @property visible
|
|
140
|
+
* @type Boolean
|
|
141
|
+
* @default true
|
|
142
|
+
*/
|
|
143
|
+
visible: true,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 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.
|
|
147
|
+
*
|
|
148
|
+
* @property cache
|
|
149
|
+
* @type Boolean
|
|
150
|
+
* @default false
|
|
151
|
+
*/
|
|
152
|
+
cache: false,
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Sets the PIXI Container's `cullable` property.
|
|
156
|
+
*
|
|
157
|
+
* @property cullable
|
|
158
|
+
* @type Boolean
|
|
159
|
+
* @default true
|
|
160
|
+
*/
|
|
161
|
+
cullable: true,
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Optional. Ignores the opacity of the owner.
|
|
165
|
+
*
|
|
166
|
+
* @property ignoreOpacity
|
|
167
|
+
* @type Boolean
|
|
168
|
+
* @default false
|
|
169
|
+
*/
|
|
170
|
+
ignoreOpacity: false,
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Whether the mask should be relative to the entity's coordinates.
|
|
174
|
+
*
|
|
175
|
+
* @property localMask
|
|
176
|
+
* @type boolean
|
|
177
|
+
* @default false
|
|
178
|
+
*/
|
|
179
|
+
localMask: false
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
publicProperties: {
|
|
183
|
+
/**
|
|
184
|
+
* Prevents sprite from becoming invisible out of frame and losing mouse input connection.
|
|
185
|
+
*
|
|
186
|
+
* @property dragMode
|
|
187
|
+
* @type Boolean
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
dragMode: false,
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The entity or id of the entity that will act as the parent container. If not set, the entity will be rendered in the layer's container. If set to `true`, adds to parent's world container.
|
|
194
|
+
*
|
|
195
|
+
* @property renderParent
|
|
196
|
+
* @type String|Object
|
|
197
|
+
* @default true
|
|
198
|
+
*/
|
|
199
|
+
renderParent: true,
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Optional. The rotation of the sprite in degrees. All sprites on the same entity are rotated the same amount unless they ignore the rotation value by setting 'rotate' to "".
|
|
203
|
+
*
|
|
204
|
+
* Boolean values for the "rotate" property has been deprecated. Use "rotation" or "orientationMatrix" to specify the source of rotation for the render container.
|
|
205
|
+
*
|
|
206
|
+
* @property rotation
|
|
207
|
+
* @type Number
|
|
208
|
+
* @default 0
|
|
209
|
+
*/
|
|
210
|
+
rotation: 0,
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Optional. The X scaling factor for the image. Defaults to 1.
|
|
214
|
+
*
|
|
215
|
+
* @property scaleX
|
|
216
|
+
* @type Number
|
|
217
|
+
* @default 1
|
|
218
|
+
*/
|
|
219
|
+
scaleX: 1,
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Optional. The Y scaling factor for the image. Defaults to 1.
|
|
223
|
+
*
|
|
224
|
+
* @property scaleY
|
|
225
|
+
* @type Number
|
|
226
|
+
* @default 1
|
|
227
|
+
*/
|
|
228
|
+
scaleY: 1,
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Optional. The X skew factor of the sprite. Defaults to 0.
|
|
232
|
+
*
|
|
233
|
+
* @property skewX
|
|
234
|
+
* @type Number
|
|
235
|
+
* @default 0
|
|
236
|
+
*/
|
|
237
|
+
skewX: 0,
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Optional. The Y skew factor for the image. Defaults to 0.
|
|
241
|
+
*
|
|
242
|
+
* @property skewY
|
|
243
|
+
* @type Number
|
|
244
|
+
* @default 0
|
|
245
|
+
*/
|
|
246
|
+
skewY: 0,
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Optional. The tint applied to the sprite. Tint may be specified by number or text. For example, to give the sprite a red tint, set to 0xff0000 or "#ff0000". Tint will be stored as a number even when set using text. Defaults to no tint.
|
|
250
|
+
*
|
|
251
|
+
* @property tint
|
|
252
|
+
* @type Number|String
|
|
253
|
+
* @default null
|
|
254
|
+
*/
|
|
255
|
+
tint: null,
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Optional. The x position of the entity. Defaults to 0.
|
|
259
|
+
*
|
|
260
|
+
* @property x
|
|
261
|
+
* @type Number
|
|
262
|
+
* @default 0
|
|
263
|
+
*/
|
|
264
|
+
x: 0,
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Optional. The y position of the entity. Defaults to 0.
|
|
268
|
+
*
|
|
269
|
+
* @property y
|
|
270
|
+
* @type Number
|
|
271
|
+
* @default 0
|
|
272
|
+
*/
|
|
273
|
+
y: 0,
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Optional. The z position of the entity. Defaults to 0.
|
|
277
|
+
*
|
|
278
|
+
* @property z
|
|
279
|
+
* @type Number
|
|
280
|
+
* @default 0
|
|
281
|
+
*/
|
|
282
|
+
z: 0
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* This component is attached to entities that will appear in the game world. It creates a PIXI Container to contain all other display objects on the entity and keeps the container updates with the entity's location and other dynamic properties.
|
|
287
|
+
*
|
|
288
|
+
* @memberof platypus.components
|
|
289
|
+
* @uses platypus.Component
|
|
290
|
+
* @constructs
|
|
291
|
+
* @listens platypus.Entity#cache
|
|
292
|
+
* @listens platypus.Entity#camera-update
|
|
293
|
+
* @listens platypus.Entity#handle-render
|
|
294
|
+
* @listens platypus.Entity#handle-render-load
|
|
295
|
+
* @listens platypus.Entity#hide-sprite
|
|
296
|
+
* @listens platypus.Entity#set-mask
|
|
297
|
+
* @listens platypus.Entity#show-sprite
|
|
298
|
+
* @fires platypus.Entity#cache-sprite
|
|
299
|
+
* @fires platypus.Entity#input-on
|
|
300
|
+
*/
|
|
301
|
+
initialize: function () {
|
|
302
|
+
const
|
|
303
|
+
{owner} = this,
|
|
304
|
+
container = this.container = owner.container = new Container(),
|
|
305
|
+
initialTint = this.tint;
|
|
306
|
+
|
|
307
|
+
container.sortableChildren = true;
|
|
308
|
+
container.cullable = this.cullable;
|
|
309
|
+
container.label = owner.id;
|
|
310
|
+
|
|
311
|
+
if (this.rotate === true) {
|
|
312
|
+
this.rotate = 'rotation';
|
|
313
|
+
platypus.debug.warn('RenderContainer: Boolean values for the "rotate" property has been deprecated. Use "rotation", "orientationMatrix", or "" to specify the source of rotation for the render container. This property defaults to "rotation".');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
this.parentContainer = null;
|
|
317
|
+
this.wasVisible = this.visible;
|
|
318
|
+
this.lastX = owner.x;
|
|
319
|
+
this.lastY = owner.y;
|
|
320
|
+
|
|
321
|
+
if (this.interpolation) { // handle interpolation if timeline changes.
|
|
322
|
+
const
|
|
323
|
+
updateUsingOwnerXY = () => {
|
|
324
|
+
this.updateSprite(true, this.owner.x, this.owner.y);
|
|
325
|
+
},
|
|
326
|
+
updateUsingInterpolationXY = () => {
|
|
327
|
+
const
|
|
328
|
+
owner = this.owner,
|
|
329
|
+
interpolationDist = magSqr(this.lastX - owner.x, this.lastY - owner.y);
|
|
330
|
+
|
|
331
|
+
if (!interpolationTime || interpolationDist < 1.5) {
|
|
332
|
+
interpolationTime = 0;
|
|
333
|
+
update = updateUsingOwnerXY;
|
|
334
|
+
update();
|
|
335
|
+
} else {
|
|
336
|
+
const
|
|
337
|
+
ratio = Math.min((interpolationTime / interpolation), (lastInterpolationDistance / interpolationDist)),
|
|
338
|
+
alt = 1 - ratio;
|
|
339
|
+
|
|
340
|
+
interpolationTime = Math.max(0, interpolationTime - 5);
|
|
341
|
+
fromX = this.lastX;
|
|
342
|
+
fromY = this.lastY;
|
|
343
|
+
lastInterpolationDistance = interpolationDist;
|
|
344
|
+
|
|
345
|
+
this.updateSprite(true, owner.x * alt + fromX * ratio, owner.y * alt + fromY * ratio);
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
interpolation = this.interpolation;
|
|
349
|
+
let interpolationTime = 0,
|
|
350
|
+
lastInterpolationDistance = 0,
|
|
351
|
+
fromX = 0,
|
|
352
|
+
fromY = 0,
|
|
353
|
+
update = updateUsingOwnerXY;
|
|
354
|
+
|
|
355
|
+
this.addEventListener('handle-render', function (tick) {
|
|
356
|
+
if (tick.tick.timeShift) {
|
|
357
|
+
fromX = this.lastX;
|
|
358
|
+
fromY = this.lastY;
|
|
359
|
+
lastInterpolationDistance = magSqr(this.lastX - this.owner.x, this.lastY - this.owner.y);
|
|
360
|
+
interpolationTime = lastInterpolationDistance > 1.5 ? interpolation : 0;
|
|
361
|
+
update = updateUsingInterpolationXY;
|
|
362
|
+
} else {
|
|
363
|
+
update();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
} else {
|
|
367
|
+
this.addEventListener('handle-render', function () {
|
|
368
|
+
this.updateSprite(true, this.owner.x, this.owner.y);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
this.interpolate = Data.setUp(
|
|
372
|
+
'x', 0,
|
|
373
|
+
'y', 0
|
|
374
|
+
);
|
|
375
|
+
this.interpolationTime = 0;
|
|
376
|
+
|
|
377
|
+
Object.defineProperty(owner, 'tint', {
|
|
378
|
+
get: function () {
|
|
379
|
+
return container.tint;
|
|
380
|
+
}.bind(this),
|
|
381
|
+
set: function (value) {
|
|
382
|
+
container.tint = value;
|
|
383
|
+
}.bind(this)
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
if (initialTint !== null) {
|
|
387
|
+
this.tint = initialTint; // feed initial tint through setter.
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (this.interactive) {
|
|
391
|
+
const
|
|
392
|
+
definition = Data.setUp(
|
|
393
|
+
'container', container,
|
|
394
|
+
'hitArea', this.interactive.hitArea,
|
|
395
|
+
'hover', this.interactive.hover
|
|
396
|
+
);
|
|
397
|
+
owner.addComponent(new Interactive(owner, definition));
|
|
398
|
+
definition.recycle();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (this.cache) {
|
|
402
|
+
this.updateSprite(false, owner.x, owner.y);
|
|
403
|
+
this.owner.cacheRender = this.container;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (this.mask && this.localMask) {
|
|
407
|
+
this.setMask(this.mask);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (this.renderParent) {
|
|
411
|
+
this.addToParentContainer(this.renderParent);
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
events: {
|
|
416
|
+
/**
|
|
417
|
+
* On receiving a "cache" event, this component triggers "cache-sprite" to cache its rendering into the background. This is an optimization for static images to reduce render calls.
|
|
418
|
+
*
|
|
419
|
+
* @event platypus.Entity#cache
|
|
420
|
+
*/
|
|
421
|
+
"cache": function () {
|
|
422
|
+
const owner = this.owner;
|
|
423
|
+
|
|
424
|
+
this.updateSprite(false, owner.x, owner.y);
|
|
425
|
+
owner.cacheRender = this.container;
|
|
426
|
+
this.cache = true;
|
|
427
|
+
if (owner.parent.triggerEventOnChildren) {
|
|
428
|
+
/**
|
|
429
|
+
* On receiving a "cache" event, this component triggers "cache-sprite" to cache its rendering into the background. This is an optimization for static images to reduce render calls.
|
|
430
|
+
*
|
|
431
|
+
* @event platypus.Entity#cache-sprite
|
|
432
|
+
* @param entity {platypus.Entity} This component's owner.
|
|
433
|
+
*/
|
|
434
|
+
owner.parent.triggerEventOnChildren('cache-sprite', owner);
|
|
435
|
+
} else {
|
|
436
|
+
platypus.debug.warn('Unable to cache sprite for ' + owner.type);
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
"handle-render-load": function () {
|
|
441
|
+
const owner = this.owner;
|
|
442
|
+
|
|
443
|
+
owner.triggerEvent('input-on');
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* This event makes the sprite invisible.
|
|
448
|
+
*
|
|
449
|
+
* @event platypus.Entity#hide-sprite
|
|
450
|
+
*/
|
|
451
|
+
"hide-sprite": function () {
|
|
452
|
+
this.visible = false;
|
|
453
|
+
},
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* This event makes the sprite visible.
|
|
457
|
+
*
|
|
458
|
+
* @event platypus.Entity#show-sprite
|
|
459
|
+
*/
|
|
460
|
+
"show-sprite": function () {
|
|
461
|
+
this.visible = true;
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Defines the mask on the container/sprite. If no mask is specified, the mask is set to null.
|
|
466
|
+
*
|
|
467
|
+
* @event platypus.Entity#set-mask
|
|
468
|
+
* @param mask {Object} The mask. This can specified the same way as the 'mask' parameter on the component.
|
|
469
|
+
*/
|
|
470
|
+
"set-mask": function (mask) {
|
|
471
|
+
this.setMask(mask);
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
methods: {
|
|
476
|
+
updateSprite: function (uncached, x, y) {
|
|
477
|
+
const
|
|
478
|
+
{container, dragMode, owner, scaleX, scaleY, skewX, skewY, visible} = this,
|
|
479
|
+
matrix = pixiMatrix,
|
|
480
|
+
rotation = (this.rotate === 'rotation') && this.rotation || 0;
|
|
481
|
+
let mirrored = 1,
|
|
482
|
+
flipped = 1;
|
|
483
|
+
|
|
484
|
+
if (container.zIndex !== owner.z) {
|
|
485
|
+
container.zIndex = owner.z;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (!this.ignoreOpacity && (owner.opacity || (owner.opacity === 0))) {
|
|
489
|
+
container.alpha = owner.opacity;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (this.mirror || this.flip) {
|
|
493
|
+
const angle = this.rotation % 360;
|
|
494
|
+
|
|
495
|
+
if (this.mirror && (angle > 90) && (angle < 270)) {
|
|
496
|
+
mirrored = -1;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (this.flip && (angle < 180)) {
|
|
500
|
+
flipped = -1;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (this.rotate === 'orientationMatrix') { // This is a 3x3 2D matrix describing an affine transformation.
|
|
505
|
+
const o = this.owner.orientationMatrix;
|
|
506
|
+
|
|
507
|
+
matrix.a = o[0][0];
|
|
508
|
+
matrix.b = o[1][0];
|
|
509
|
+
matrix.tx = x + o[0][2];
|
|
510
|
+
matrix.c = o[0][1];
|
|
511
|
+
matrix.d = o[1][1];
|
|
512
|
+
matrix.ty = y + o[1][2];
|
|
513
|
+
container.transform.setFromMatrix(matrix);
|
|
514
|
+
} else {
|
|
515
|
+
container.updateTransform({
|
|
516
|
+
x,
|
|
517
|
+
y,
|
|
518
|
+
scaleX: scaleX * mirrored,
|
|
519
|
+
scaleY: scaleY * flipped,
|
|
520
|
+
rotation: (rotation ? (rotation / 180) * Math.PI : 0),
|
|
521
|
+
skewX: skewX,
|
|
522
|
+
skewY: skewY
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
this.lastX = x;
|
|
527
|
+
this.lastY = y;
|
|
528
|
+
this.wasVisible = visible;
|
|
529
|
+
container.visible = visible || dragMode;
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
setMask: function (shape) {
|
|
533
|
+
let gfx = null;
|
|
534
|
+
|
|
535
|
+
if (this.mask) {
|
|
536
|
+
if (this.localMask) {
|
|
537
|
+
this.container.removeChild(this.mask);
|
|
538
|
+
} else if (this.parentContainer) {
|
|
539
|
+
this.parentContainer.removeChild(this.mask);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (!shape) {
|
|
544
|
+
this.mask = this.container.mask = null;
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (shape.isMask || (shape instanceof Graphics)) {
|
|
549
|
+
gfx = shape;
|
|
550
|
+
} else {
|
|
551
|
+
gfx = new Graphics();
|
|
552
|
+
if (typeof shape === 'string') {
|
|
553
|
+
processGraphics(gfx, shape);
|
|
554
|
+
} else if (shape.radius) {
|
|
555
|
+
gfx.circle(shape.x || 0, shape.y || 0, shape.radius);
|
|
556
|
+
} else if (shape instanceof AABB) {
|
|
557
|
+
gfx.rect(shape.left, shape.top, shape.width, shape.height);
|
|
558
|
+
} else if (shape.width && shape.height) {
|
|
559
|
+
gfx.rect(shape.x || 0, shape.y || 0, shape.width, shape.height);
|
|
560
|
+
}
|
|
561
|
+
gfx.fill(0x000000, 1);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
gfx.isMask = true;
|
|
565
|
+
|
|
566
|
+
this.mask = this.container.mask = gfx;
|
|
567
|
+
this.mask.z = 0; //TML 12-4-16 - Masks don't need a Z, but this makes it play nice with the Z-ordering in HandlerRender.
|
|
568
|
+
|
|
569
|
+
if (this.localMask) {
|
|
570
|
+
this.container.addChild(this.mask);
|
|
571
|
+
} else if (this.parentContainer) {
|
|
572
|
+
this.parentContainer.addChild(this.mask);
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
|
|
576
|
+
destroy: function () {
|
|
577
|
+
if (this.parentContainer && !this.container.mouseTarget) {
|
|
578
|
+
this.parentContainer.removeChild(this.container);
|
|
579
|
+
this.parentContainer = null;
|
|
580
|
+
} else if (!this.cache) {
|
|
581
|
+
this.container.destroy();
|
|
582
|
+
}
|
|
583
|
+
this.container = null;
|
|
584
|
+
|
|
585
|
+
this.interpolate.recycle();
|
|
586
|
+
this.interpolate = null;
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
|
|
590
|
+
publicMethods: {
|
|
591
|
+
/**
|
|
592
|
+
* Remove this entity's container from the containing rendering container.
|
|
593
|
+
*
|
|
594
|
+
* @method platypus.components.RenderContainer#removeFromParentContainer
|
|
595
|
+
*/
|
|
596
|
+
removeFromParentContainer: function () {
|
|
597
|
+
if (this.parentContainer) {
|
|
598
|
+
if (this.mask && !this.localMask) {
|
|
599
|
+
this.setMask();
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
this.parentContainer.removeChild(this.container);
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Add this entity's container to a rendering container.
|
|
608
|
+
*
|
|
609
|
+
* @method platypus.components.RenderContainer#addToParentContainer
|
|
610
|
+
* @param {Container} newContainer Container to add this to.
|
|
611
|
+
*/
|
|
612
|
+
addToParentContainer: function (newContainer) {
|
|
613
|
+
this.removeFromParentContainer();
|
|
614
|
+
|
|
615
|
+
if (!this.cache) {
|
|
616
|
+
const
|
|
617
|
+
{parent, x, y} = this.owner;
|
|
618
|
+
let container = newContainer === true ? parent.worldContainer : newContainer?.container ?? newContainer ?? parent.worldContainer;
|
|
619
|
+
|
|
620
|
+
if (typeof newContainer === "string") {
|
|
621
|
+
const
|
|
622
|
+
otherEntity = parent.getEntityById(newContainer);
|
|
623
|
+
|
|
624
|
+
container = otherEntity?.container;
|
|
625
|
+
if (!container) {
|
|
626
|
+
//Didn't find group.
|
|
627
|
+
platypus.debug.warn(`Trying to add to non-existent entity "${newContainer}", added to World container instead.`);
|
|
628
|
+
container = parent.worldContainer;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (container instanceof Entity) { // wait for entity to get a container.
|
|
633
|
+
container.on('load', () => this.addToParentContainer(container));
|
|
634
|
+
} else {
|
|
635
|
+
this.parentContainer = container;
|
|
636
|
+
this.parentContainer.addChild(this.container);
|
|
637
|
+
this.updateSprite(true, x, y);
|
|
638
|
+
|
|
639
|
+
if (this.mask && !this.localMask) {
|
|
640
|
+
this.setMask(this.mask);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
});
|