@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,178 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import RenderContainer from './RenderContainer.js';
|
|
3
|
+
import createComponentClass from '../factory.js';
|
|
4
|
+
import {Sprite, TilingSprite, AnimatedSprite, NineSliceSprite} from 'pixi.js';
|
|
5
|
+
|
|
6
|
+
const
|
|
7
|
+
spriteTypes = {Sprite, TilingSprite, AnimatedSprite, NineSliceSprite};
|
|
8
|
+
|
|
9
|
+
export default createComponentClass(/** @lends platypus.components.RenderSprite.prototype */{
|
|
10
|
+
|
|
11
|
+
id: 'Render',
|
|
12
|
+
|
|
13
|
+
properties: {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the image should auto-resize if the owner's size changes. For NineSliceSprite, this auto-adjusts to the entity's height and width changes. For other types, it modifies the sprite's scale to match the original sprite-to-entity size ratio.
|
|
16
|
+
*
|
|
17
|
+
* @property matchEntity
|
|
18
|
+
* @type Boolean
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
matchEntity: false,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The offset of the x-axis position of the sprite from the entity's x-axis position.
|
|
25
|
+
*
|
|
26
|
+
* @property offsetX
|
|
27
|
+
* @type Number
|
|
28
|
+
* @default 0
|
|
29
|
+
*/
|
|
30
|
+
offsetX: 0,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The offset of the y-axis position of the sprite from the entity's y-axis position.
|
|
34
|
+
*
|
|
35
|
+
* @property offsetY
|
|
36
|
+
* @type Number
|
|
37
|
+
* @default 0
|
|
38
|
+
*/
|
|
39
|
+
offsetY: 0,
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The z-index relative to other render components on the entity.
|
|
43
|
+
*
|
|
44
|
+
* @property offsetZ
|
|
45
|
+
* @type Number
|
|
46
|
+
* @default 0
|
|
47
|
+
*/
|
|
48
|
+
offsetZ: 0,
|
|
49
|
+
|
|
50
|
+
options: null,
|
|
51
|
+
|
|
52
|
+
image: null,
|
|
53
|
+
|
|
54
|
+
images: null,
|
|
55
|
+
|
|
56
|
+
spriteType: 'Sprite',
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The rotation for this sprite relative to the container.
|
|
60
|
+
*
|
|
61
|
+
* @property localRotation
|
|
62
|
+
* @type Number
|
|
63
|
+
* @default 0
|
|
64
|
+
*/
|
|
65
|
+
localRotation: 0,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The scaling factor for this sprite relative to the scale of the container.
|
|
69
|
+
*
|
|
70
|
+
* @property localScaleX
|
|
71
|
+
* @type Number|Array|Object
|
|
72
|
+
* @default 1
|
|
73
|
+
*/
|
|
74
|
+
localScaleX: 1,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The scaling factor for this sprite relative to the scale of the container.
|
|
78
|
+
*
|
|
79
|
+
* @property localScaleY
|
|
80
|
+
* @type Number|Array|Object
|
|
81
|
+
* @default 1
|
|
82
|
+
*/
|
|
83
|
+
localScaleY: 1
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 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.
|
|
88
|
+
*
|
|
89
|
+
* @memberof platypus.components
|
|
90
|
+
* @uses platypus.Component
|
|
91
|
+
* @constructs
|
|
92
|
+
* @listens platypus.Entity#handle-render
|
|
93
|
+
* @listens platypus.Entity#play-animation
|
|
94
|
+
* @listens platypus.Entity#stop-animation
|
|
95
|
+
* @fires platypus.Entity#animation-ended
|
|
96
|
+
* @fires platypus.Entity#update-animation
|
|
97
|
+
*/
|
|
98
|
+
initialize () {
|
|
99
|
+
const
|
|
100
|
+
{image, images, localRotation, localScaleX, localScaleY, offsetX, offsetY, offsetZ, options, owner, spriteType} = this,
|
|
101
|
+
sprite = this.sprite = new spriteTypes[spriteType === 'Sprite' && images && !images ? 'AnimatedSprite' : spriteType]({
|
|
102
|
+
...(image ? {texture: platypus.assetCache.get(image)} : {textures: images.map((image) => platypus.assetCache.get(image))}),
|
|
103
|
+
...options ?? {}
|
|
104
|
+
}),
|
|
105
|
+
matchEntity = this.matchEntity ? {
|
|
106
|
+
originalWidth: owner.width,
|
|
107
|
+
originalHeight: owner.height
|
|
108
|
+
} : null;
|
|
109
|
+
|
|
110
|
+
sprite.x = offsetX;
|
|
111
|
+
sprite.y = offsetY;
|
|
112
|
+
sprite.zIndex = offsetZ;
|
|
113
|
+
sprite.rotation = (localRotation / 180) * Math.PI;
|
|
114
|
+
sprite.scale.x = localScaleX;
|
|
115
|
+
sprite.scale.y = localScaleY;
|
|
116
|
+
|
|
117
|
+
if (!owner.container) {
|
|
118
|
+
const
|
|
119
|
+
{interactive, mask, mirror, flip, visible, cache, ignoreOpacity, scaleX, scaleY, skewX, skewY} = owner;
|
|
120
|
+
|
|
121
|
+
owner.addComponent(new RenderContainer(this.owner, {interactive, mask, mirror, flip, visible, cache, ignoreOpacity, scaleX, scaleY, skewX, skewY}, () => this.addToContainer()));
|
|
122
|
+
} else {
|
|
123
|
+
this.addToContainer();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (matchEntity) {
|
|
127
|
+
if (spriteType === 'NineSliceSprite') {
|
|
128
|
+
sprite.x = offsetX - owner.width / 2;
|
|
129
|
+
sprite.y = offsetY - owner.height / 2;
|
|
130
|
+
sprite.width = owner.width;
|
|
131
|
+
sprite.height = owner.height;
|
|
132
|
+
this.addEventListener('handle-render', (renderData) => {
|
|
133
|
+
sprite.x = offsetX - owner.width / 2;
|
|
134
|
+
sprite.y = offsetY - owner.height / 2;
|
|
135
|
+
sprite.width = owner.width;
|
|
136
|
+
sprite.height = owner.height;
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
this.addEventListener('handle-render', (renderData) => {
|
|
140
|
+
sprite.scale.x = localScaleX * owner.width / matchEntity.originalWidth;
|
|
141
|
+
sprite.scale.y = localScaleY * owner.height / matchEntity.originalHeight;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (sprite.update) {
|
|
147
|
+
this.addEventListener('handle-render', (renderData) => {
|
|
148
|
+
if (sprite.update) {
|
|
149
|
+
sprite.update(renderData.delta);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
methods: {
|
|
156
|
+
addToContainer: function () {
|
|
157
|
+
const container = this.owner.container;
|
|
158
|
+
|
|
159
|
+
container.addChild(this.sprite);
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
destroy: function () {
|
|
163
|
+
this.owner.container.removeChild(this.sprite);
|
|
164
|
+
this.sprite.destroy();
|
|
165
|
+
this.sprite = null;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
getAssetList (a, b, c) {
|
|
170
|
+
const
|
|
171
|
+
image = a?.image ?? b?.image ?? c?.image;
|
|
172
|
+
|
|
173
|
+
return (image ? [image] : a?.images ?? b?.images ?? c?.images ?? []).map((src) => ({
|
|
174
|
+
alias: [src],
|
|
175
|
+
src
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import StateMap from '../StateMap.js';
|
|
2
|
+
import {arrayCache} from '../utils/array.js';
|
|
3
|
+
import createComponentClass from '../factory.js';
|
|
4
|
+
|
|
5
|
+
const
|
|
6
|
+
createTest = function (testStates, animation) {
|
|
7
|
+
if (testStates === 'default') {
|
|
8
|
+
return () => animation;
|
|
9
|
+
} else {
|
|
10
|
+
//TODO: Better clean-up: Create a lot of these without removing them later... DDD 2/5/2016
|
|
11
|
+
const
|
|
12
|
+
states = StateMap.setUp(testStates);
|
|
13
|
+
|
|
14
|
+
return (ownerState) => ownerState.includes(states) ? animation : false;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
methodPlay = function (animation, loop, restart) {
|
|
18
|
+
this.component.playAnimation(animation, loop, restart);
|
|
19
|
+
},
|
|
20
|
+
methodStop = function (animation) {
|
|
21
|
+
this.component.stopAnimation(animation);
|
|
22
|
+
},
|
|
23
|
+
triggerPlay = function (animation, loop, restart) {
|
|
24
|
+
/**
|
|
25
|
+
* On entering a new animation-mapped state, this component triggers this event to play an animation.
|
|
26
|
+
*
|
|
27
|
+
* @event platypus.Entity#play-animation
|
|
28
|
+
* @param animation {String} Describes the animation to play.
|
|
29
|
+
* @param loop {Boolean} Whether to loop a playing animation.
|
|
30
|
+
* @param restart {Boolean} Whether to restart a playing animation.
|
|
31
|
+
*/
|
|
32
|
+
this.owner.triggerEvent('play-animation', animation, loop, restart);
|
|
33
|
+
},
|
|
34
|
+
triggerStop = function (animation) {
|
|
35
|
+
/**
|
|
36
|
+
* On attaining an animation-mapped state, this component triggers this event to stop a previous animation.
|
|
37
|
+
*
|
|
38
|
+
* @event platypus.Entity#stop-animation
|
|
39
|
+
* @param animation {String} Describes the animation to stop.
|
|
40
|
+
*/
|
|
41
|
+
this.owner.triggerEvent('stop-animation', animation);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default createComponentClass(/** @lends platypus.components.RenderAnimator.prototype */{
|
|
45
|
+
id: 'RenderAnimator',
|
|
46
|
+
|
|
47
|
+
properties: {
|
|
48
|
+
/**
|
|
49
|
+
* 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.
|
|
50
|
+
*
|
|
51
|
+
* "animationStates":{
|
|
52
|
+
* "standing": "default-animation" // On receiving a "standing" event, or when this.owner.state.standing === true, the "default" animation will begin playing.
|
|
53
|
+
* "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.
|
|
54
|
+
* "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.
|
|
55
|
+
* "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.
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* @property animationStates
|
|
59
|
+
* @type Object
|
|
60
|
+
* @default null
|
|
61
|
+
*/
|
|
62
|
+
animationStates: null,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* An object containg key-value pairs that define a mapping from triggered events to the animation that should play.
|
|
66
|
+
*
|
|
67
|
+
* "animationEvents":{
|
|
68
|
+
* "move": "walk-animation",
|
|
69
|
+
* "jump": "jumping-animation"
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* The above will create two event listeners on the entity, "move" and "jump", that will play their corresponding animations when the events are triggered.
|
|
73
|
+
*
|
|
74
|
+
* @property animationEvents
|
|
75
|
+
* @type Object
|
|
76
|
+
* @default null
|
|
77
|
+
*/
|
|
78
|
+
animationEvents: null,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sets a component that this component should be connected to.
|
|
82
|
+
*
|
|
83
|
+
* @property component
|
|
84
|
+
* @type Component
|
|
85
|
+
* @default null
|
|
86
|
+
*/
|
|
87
|
+
component: null,
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Optional. Forces animations to complete before starting a new animation. Defaults to `false`.
|
|
91
|
+
*
|
|
92
|
+
* @property forcePlayThrough
|
|
93
|
+
* @type Boolean
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
forcePlayThrough: false,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Whether to restart a playing animation on event.
|
|
100
|
+
*
|
|
101
|
+
* @property restart
|
|
102
|
+
* @type Boolean
|
|
103
|
+
* @default true
|
|
104
|
+
*/
|
|
105
|
+
restart: true,
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether to loop a playing animation on event.
|
|
109
|
+
*
|
|
110
|
+
* @property loop
|
|
111
|
+
* @type Boolean
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
loop: false
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* This component is typically added to an entity automatically by a render component. It handles mapping entity states and events to playable animations.
|
|
119
|
+
*
|
|
120
|
+
* @memberof platypus.components
|
|
121
|
+
* @uses platypus.Component
|
|
122
|
+
* @constructs
|
|
123
|
+
* @listens platypus.Entity#animation-ended
|
|
124
|
+
* @listens platypus.Entity#state-changed
|
|
125
|
+
* @listens platypus.Entity#update-animation
|
|
126
|
+
* @fires platypus.Entity#play-animation
|
|
127
|
+
* @fires platypus.Entity#stop-animation
|
|
128
|
+
*/
|
|
129
|
+
initialize: (function () {
|
|
130
|
+
const
|
|
131
|
+
trigger = function (animation, loop, restart) {
|
|
132
|
+
this.override = animation;
|
|
133
|
+
this.owner.triggerEvent('play-animation', animation, loop, restart);
|
|
134
|
+
},
|
|
135
|
+
method = function (animation, loop, restart) {
|
|
136
|
+
this.override = animation;
|
|
137
|
+
this.playAnimation(animation, loop, restart);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return function () {
|
|
141
|
+
const
|
|
142
|
+
events = this.animationEvents,
|
|
143
|
+
states = this.animationStates;
|
|
144
|
+
|
|
145
|
+
//Handle Events:
|
|
146
|
+
this.override = false;
|
|
147
|
+
if (events) {
|
|
148
|
+
const
|
|
149
|
+
keys = Object.keys(events),
|
|
150
|
+
{length} = keys,
|
|
151
|
+
component = this.component,
|
|
152
|
+
func = component ? method : trigger;
|
|
153
|
+
|
|
154
|
+
for (let i = 0; i < length; i++) {
|
|
155
|
+
const
|
|
156
|
+
key = keys[i];
|
|
157
|
+
|
|
158
|
+
this.addEventListener(key, func.bind(component ?? this, events[key], this.loop, this.restart));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//Handle States:
|
|
163
|
+
this.followThroughs = {};
|
|
164
|
+
this.checkStates = arrayCache.setUp();
|
|
165
|
+
this.state = this.owner.state;
|
|
166
|
+
this.stateChange = true; //Check state against entity's prior state to update animation if necessary on instantiation.
|
|
167
|
+
this.lastState = -1;
|
|
168
|
+
|
|
169
|
+
if (states) {
|
|
170
|
+
const
|
|
171
|
+
keys = Object.keys(states),
|
|
172
|
+
{length} = keys;
|
|
173
|
+
|
|
174
|
+
for (let i = 0; i < length; i++) {
|
|
175
|
+
const
|
|
176
|
+
key = keys[i],
|
|
177
|
+
animationLabel = states[key],
|
|
178
|
+
lastCharacter = animationLabel.length - 1,
|
|
179
|
+
isNot = animationLabel[lastCharacter] === '!',
|
|
180
|
+
animation = isNot ? animationLabel.substring(0, lastCharacter) : animationLabel;
|
|
181
|
+
|
|
182
|
+
//TODO: Should probably find a cleaner way to accomplish this. Maybe in the animationMap definition? - DDD
|
|
183
|
+
this.followThroughs[animation] = isNot;
|
|
184
|
+
this.checkStates.push(createTest(key, animation));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.waitingAnimation = false;
|
|
189
|
+
this.waitingState = 0;
|
|
190
|
+
this.playWaiting = false;
|
|
191
|
+
this.animationFinished = false;
|
|
192
|
+
|
|
193
|
+
if (this.component) {
|
|
194
|
+
this.playAnimation = methodPlay;
|
|
195
|
+
this.stopAnimation = methodStop;
|
|
196
|
+
} else {
|
|
197
|
+
this.playAnimation = triggerPlay;
|
|
198
|
+
this.stopAnimation = triggerStop;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
} ()),
|
|
202
|
+
|
|
203
|
+
events: {
|
|
204
|
+
"state-changed": function () {
|
|
205
|
+
this.stateChange = true;
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
"animation-ended": function (animation) {
|
|
209
|
+
if (animation === this.currentAnimation) {
|
|
210
|
+
if (this.override && (animation === this.override)) {
|
|
211
|
+
this.stateChange = true;
|
|
212
|
+
this.override = false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (this.waitingAnimation) {
|
|
216
|
+
this.currentAnimation = this.waitingAnimation;
|
|
217
|
+
this.waitingAnimation = false;
|
|
218
|
+
this.lastState = this.waitingState;
|
|
219
|
+
|
|
220
|
+
this.animationFinished = false;
|
|
221
|
+
this.playAnimation(this.currentAnimation);
|
|
222
|
+
} else {
|
|
223
|
+
this.animationFinished = true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
"update-animation": function (playing) {
|
|
229
|
+
if (this.stateChange && !this.override) {
|
|
230
|
+
if (this.state.has('visible')) {
|
|
231
|
+
this.visible = this.state.get('visible');
|
|
232
|
+
}
|
|
233
|
+
for (let i = 0; i < this.checkStates.length; i++) {
|
|
234
|
+
const
|
|
235
|
+
testCase = this.checkStates[i](this.state);
|
|
236
|
+
|
|
237
|
+
if (testCase) {
|
|
238
|
+
if (this.currentAnimation !== testCase) {
|
|
239
|
+
if (!this.followThroughs[this.currentAnimation] && (!this.forcePlaythrough || (this.animationFinished || (this.lastState >= +i)))) {
|
|
240
|
+
this.currentAnimation = testCase;
|
|
241
|
+
this.lastState = +i;
|
|
242
|
+
this.animationFinished = false;
|
|
243
|
+
if (playing) {
|
|
244
|
+
this.playAnimation(this.currentAnimation);
|
|
245
|
+
} else {
|
|
246
|
+
this.stopAnimation(this.currentAnimation);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
this.waitingAnimation = testCase;
|
|
250
|
+
this.waitingState = +i;
|
|
251
|
+
}
|
|
252
|
+
} else if (this.waitingAnimation && !this.followThroughs[this.currentAnimation]) {// keep animating this animation since this animation has already overlapped the waiting animation.
|
|
253
|
+
this.waitingAnimation = false;
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
this.stateChange = false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
methods: {
|
|
264
|
+
toJSON: function () { // This component is added by another component, so it shouldn't be returned for reconstruction.
|
|
265
|
+
return null;
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
destroy: function () {
|
|
269
|
+
arrayCache.recycle(this.checkStates);
|
|
270
|
+
this.checkStates = null;
|
|
271
|
+
this.followThroughs = null;
|
|
272
|
+
this.state = null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
});
|