@safe-engine/pixi 8.8.1 → 8.8.3

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 (146) hide show
  1. package/dist/app.d.ts +1 -0
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +20 -1
  4. package/dist/core/NodePool.d.ts +1 -1
  5. package/dist/core/Size.d.ts +0 -1
  6. package/dist/core/Size.d.ts.map +1 -1
  7. package/dist/dragonbones/DragonBonesComponent.d.ts +1 -1
  8. package/dist/dragonbones/DragonBonesComponent.d.ts.map +1 -1
  9. package/dist/dragonbones/DragonBonesComponent.js +1 -1
  10. package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
  11. package/dist/dragonbones/DragonBonesSystem.js +1 -1
  12. package/dist/dragonbones/db-pixi/PixiArmatureDisplay.d.ts +59 -0
  13. package/dist/dragonbones/db-pixi/PixiArmatureDisplay.d.ts.map +1 -0
  14. package/dist/dragonbones/db-pixi/PixiArmatureDisplay.js +180 -0
  15. package/dist/dragonbones/db-pixi/PixiFactory.d.ts +87 -0
  16. package/dist/dragonbones/db-pixi/PixiFactory.d.ts.map +1 -0
  17. package/dist/dragonbones/db-pixi/PixiFactory.js +159 -0
  18. package/dist/dragonbones/db-pixi/PixiSlot.d.ts +31 -0
  19. package/dist/dragonbones/db-pixi/PixiSlot.d.ts.map +1 -0
  20. package/dist/dragonbones/db-pixi/PixiSlot.js +332 -0
  21. package/dist/dragonbones/db-pixi/PixiTextureAtlasData.d.ts +38 -0
  22. package/dist/dragonbones/db-pixi/PixiTextureAtlasData.d.ts.map +1 -0
  23. package/dist/dragonbones/db-pixi/PixiTextureAtlasData.js +85 -0
  24. package/dist/dragonbones/db-pixi/index.d.ts +5 -0
  25. package/dist/dragonbones/db-pixi/index.d.ts.map +1 -0
  26. package/dist/dragonbones/db-pixi/index.js +4 -0
  27. package/dist/dragonbones/dragonBones/animation/Animation.d.ts +241 -0
  28. package/dist/dragonbones/dragonBones/animation/Animation.d.ts.map +1 -0
  29. package/dist/dragonbones/dragonBones/animation/Animation.js +692 -0
  30. package/dist/dragonbones/dragonBones/animation/AnimationState.d.ts +323 -0
  31. package/dist/dragonbones/dragonBones/animation/AnimationState.d.ts.map +1 -0
  32. package/dist/dragonbones/dragonBones/animation/AnimationState.js +1161 -0
  33. package/dist/dragonbones/dragonBones/animation/BaseTimelineState.d.ts +100 -0
  34. package/dist/dragonbones/dragonBones/animation/BaseTimelineState.d.ts.map +1 -0
  35. package/dist/dragonbones/dragonBones/animation/BaseTimelineState.js +479 -0
  36. package/dist/dragonbones/dragonBones/animation/IAnimatable.d.ts +38 -0
  37. package/dist/dragonbones/dragonBones/animation/IAnimatable.d.ts.map +1 -0
  38. package/dist/dragonbones/dragonBones/animation/IAnimatable.js +9 -0
  39. package/dist/dragonbones/dragonBones/animation/TimelineState.d.ts +159 -0
  40. package/dist/dragonbones/dragonBones/animation/TimelineState.d.ts.map +1 -0
  41. package/dist/dragonbones/dragonBones/animation/TimelineState.js +998 -0
  42. package/dist/dragonbones/dragonBones/animation/WorldClock.d.ts +74 -0
  43. package/dist/dragonbones/dragonBones/animation/WorldClock.d.ts.map +1 -0
  44. package/dist/dragonbones/dragonBones/animation/WorldClock.js +162 -0
  45. package/dist/dragonbones/dragonBones/armature/Armature.d.ts +314 -0
  46. package/dist/dragonbones/dragonBones/armature/Armature.d.ts.map +1 -0
  47. package/dist/dragonbones/dragonBones/armature/Armature.js +650 -0
  48. package/dist/dragonbones/dragonBones/armature/Bone.d.ts +123 -0
  49. package/dist/dragonbones/dragonBones/armature/Bone.d.ts.map +1 -0
  50. package/dist/dragonbones/dragonBones/armature/Bone.js +438 -0
  51. package/dist/dragonbones/dragonBones/armature/Constraint.d.ts +99 -0
  52. package/dist/dragonbones/dragonBones/armature/Constraint.d.ts.map +1 -0
  53. package/dist/dragonbones/dragonBones/armature/Constraint.js +672 -0
  54. package/dist/dragonbones/dragonBones/armature/IArmatureProxy.d.ts +47 -0
  55. package/dist/dragonbones/dragonBones/armature/IArmatureProxy.d.ts.map +1 -0
  56. package/dist/dragonbones/dragonBones/armature/IArmatureProxy.js +1 -0
  57. package/dist/dragonbones/dragonBones/armature/Slot.d.ts +357 -0
  58. package/dist/dragonbones/dragonBones/armature/Slot.d.ts.map +1 -0
  59. package/dist/dragonbones/dragonBones/armature/Slot.js +1009 -0
  60. package/dist/dragonbones/dragonBones/armature/Surface.d.ts +41 -0
  61. package/dist/dragonbones/dragonBones/armature/Surface.d.ts.map +1 -0
  62. package/dist/dragonbones/dragonBones/armature/Surface.js +463 -0
  63. package/dist/dragonbones/dragonBones/armature/TransformObject.d.ts +80 -0
  64. package/dist/dragonbones/dragonBones/armature/TransformObject.d.ts.map +1 -0
  65. package/dist/dragonbones/dragonBones/armature/TransformObject.js +77 -0
  66. package/dist/dragonbones/dragonBones/core/BaseObject.d.ts +53 -0
  67. package/dist/dragonbones/dragonBones/core/BaseObject.d.ts.map +1 -0
  68. package/dist/dragonbones/dragonBones/core/BaseObject.js +130 -0
  69. package/dist/dragonbones/dragonBones/core/DragonBones.d.ts +236 -0
  70. package/dist/dragonbones/dragonBones/core/DragonBones.d.ts.map +1 -0
  71. package/dist/dragonbones/dragonBones/core/DragonBones.js +61 -0
  72. package/dist/dragonbones/dragonBones/event/EventObject.d.ts +143 -0
  73. package/dist/dragonbones/dragonBones/event/EventObject.d.ts.map +1 -0
  74. package/dist/dragonbones/dragonBones/event/EventObject.js +99 -0
  75. package/dist/dragonbones/dragonBones/event/IEventDispatcher.d.ts +48 -0
  76. package/dist/dragonbones/dragonBones/event/IEventDispatcher.d.ts.map +1 -0
  77. package/dist/dragonbones/dragonBones/event/IEventDispatcher.js +1 -0
  78. package/dist/dragonbones/dragonBones/factory/BaseFactory.d.ts +292 -0
  79. package/dist/dragonbones/dragonBones/factory/BaseFactory.d.ts.map +1 -0
  80. package/dist/dragonbones/dragonBones/factory/BaseFactory.js +735 -0
  81. package/dist/dragonbones/dragonBones/geom/ColorTransform.d.ts +17 -0
  82. package/dist/dragonbones/dragonBones/geom/ColorTransform.d.ts.map +1 -0
  83. package/dist/dragonbones/dragonBones/geom/ColorTransform.js +33 -0
  84. package/dist/dragonbones/dragonBones/geom/Curve.d.ts +10 -0
  85. package/dist/dragonbones/dragonBones/geom/Curve.d.ts.map +1 -0
  86. package/dist/dragonbones/dragonBones/geom/Curve.js +26 -0
  87. package/dist/dragonbones/dragonBones/geom/Matrix.d.ts +105 -0
  88. package/dist/dragonbones/dragonBones/geom/Matrix.d.ts.map +1 -0
  89. package/dist/dragonbones/dragonBones/geom/Matrix.js +207 -0
  90. package/dist/dragonbones/dragonBones/geom/Point.d.ts +38 -0
  91. package/dist/dragonbones/dragonBones/geom/Point.d.ts.map +1 -0
  92. package/dist/dragonbones/dragonBones/geom/Point.js +31 -0
  93. package/dist/dragonbones/dragonBones/geom/Rectangle.d.ts +53 -0
  94. package/dist/dragonbones/dragonBones/geom/Rectangle.d.ts.map +1 -0
  95. package/dist/dragonbones/dragonBones/geom/Rectangle.js +37 -0
  96. package/dist/dragonbones/dragonBones/geom/Transform.d.ts +102 -0
  97. package/dist/dragonbones/dragonBones/geom/Transform.d.ts.map +1 -0
  98. package/dist/dragonbones/dragonBones/geom/Transform.js +170 -0
  99. package/dist/dragonbones/dragonBones/index.d.ts +37 -0
  100. package/dist/dragonbones/dragonBones/index.d.ts.map +1 -0
  101. package/dist/dragonbones/dragonBones/index.js +36 -0
  102. package/dist/dragonbones/dragonBones/model/AnimationConfig.d.ts +162 -0
  103. package/dist/dragonbones/dragonBones/model/AnimationConfig.d.ts.map +1 -0
  104. package/dist/dragonbones/dragonBones/model/AnimationConfig.js +81 -0
  105. package/dist/dragonbones/dragonBones/model/AnimationData.d.ts +174 -0
  106. package/dist/dragonbones/dragonBones/model/AnimationData.d.ts.map +1 -0
  107. package/dist/dragonbones/dragonBones/model/AnimationData.js +256 -0
  108. package/dist/dragonbones/dragonBones/model/ArmatureData.d.ts +319 -0
  109. package/dist/dragonbones/dragonBones/model/ArmatureData.d.ts.map +1 -0
  110. package/dist/dragonbones/dragonBones/model/ArmatureData.js +450 -0
  111. package/dist/dragonbones/dragonBones/model/BoundingBoxData.d.ts +188 -0
  112. package/dist/dragonbones/dragonBones/model/BoundingBoxData.d.ts.map +1 -0
  113. package/dist/dragonbones/dragonBones/model/BoundingBoxData.js +500 -0
  114. package/dist/dragonbones/dragonBones/model/CanvasData.d.ts +15 -0
  115. package/dist/dragonbones/dragonBones/model/CanvasData.d.ts.map +1 -0
  116. package/dist/dragonbones/dragonBones/model/CanvasData.js +17 -0
  117. package/dist/dragonbones/dragonBones/model/ConstraintData.d.ts +46 -0
  118. package/dist/dragonbones/dragonBones/model/ConstraintData.d.ts.map +1 -0
  119. package/dist/dragonbones/dragonBones/model/ConstraintData.js +57 -0
  120. package/dist/dragonbones/dragonBones/model/DisplayData.d.ts +98 -0
  121. package/dist/dragonbones/dragonBones/model/DisplayData.d.ts.map +1 -0
  122. package/dist/dragonbones/dragonBones/model/DisplayData.js +174 -0
  123. package/dist/dragonbones/dragonBones/model/DragonBonesData.d.ts +108 -0
  124. package/dist/dragonbones/dragonBones/model/DragonBonesData.d.ts.map +1 -0
  125. package/dist/dragonbones/dragonBones/model/DragonBonesData.js +86 -0
  126. package/dist/dragonbones/dragonBones/model/SkinData.d.ts +40 -0
  127. package/dist/dragonbones/dragonBones/model/SkinData.d.ts.map +1 -0
  128. package/dist/dragonbones/dragonBones/model/SkinData.js +68 -0
  129. package/dist/dragonbones/dragonBones/model/TextureAtlasData.d.ts +73 -0
  130. package/dist/dragonbones/dragonBones/model/TextureAtlasData.d.ts.map +1 -0
  131. package/dist/dragonbones/dragonBones/model/TextureAtlasData.js +102 -0
  132. package/dist/dragonbones/dragonBones/model/UserData.d.ts +73 -0
  133. package/dist/dragonbones/dragonBones/model/UserData.d.ts.map +1 -0
  134. package/dist/dragonbones/dragonBones/model/UserData.js +101 -0
  135. package/dist/dragonbones/dragonBones/parser/BinaryDataParser.d.ts +29 -0
  136. package/dist/dragonbones/dragonBones/parser/BinaryDataParser.d.ts.map +1 -0
  137. package/dist/dragonbones/dragonBones/parser/BinaryDataParser.js +356 -0
  138. package/dist/dragonbones/dragonBones/parser/DataParser.d.ts +153 -0
  139. package/dist/dragonbones/dragonBones/parser/DataParser.d.ts.map +1 -0
  140. package/dist/dragonbones/dragonBones/parser/DataParser.js +283 -0
  141. package/dist/dragonbones/dragonBones/parser/ObjectDataParser.d.ts +130 -0
  142. package/dist/dragonbones/dragonBones/parser/ObjectDataParser.d.ts.map +1 -0
  143. package/dist/dragonbones/dragonBones/parser/ObjectDataParser.js +2098 -0
  144. package/dist/dragonbones/index.js +1 -1
  145. package/dist/helper/utils.js +1 -1
  146. package/package.json +3 -4
@@ -0,0 +1,692 @@
1
+ import { BaseObject } from "../core/BaseObject";
2
+ import { AnimationConfig } from "../model/AnimationConfig";
3
+ import { AnimationState, BlendState } from "./AnimationState";
4
+ /**
5
+ * - The animation player is used to play the animation data and manage the animation states.
6
+ * @see dragonBones.AnimationData
7
+ * @see dragonBones.AnimationState
8
+ * @version DragonBones 3.0
9
+ * @language en_US
10
+ */
11
+ export class Animation extends BaseObject {
12
+ constructor() {
13
+ super(...arguments);
14
+ this._animationNames = [];
15
+ this._animationStates = [];
16
+ this._animations = {};
17
+ this._blendStates = {};
18
+ this._animationConfig = null; // Initial value.
19
+ }
20
+ static toString() {
21
+ return "[class dragonBones.Animation]";
22
+ }
23
+ _onClear() {
24
+ for (const animationState of this._animationStates) {
25
+ animationState.returnToPool();
26
+ }
27
+ for (let k in this._animations) {
28
+ delete this._animations[k];
29
+ }
30
+ for (let k in this._blendStates) {
31
+ const blendStates = this._blendStates[k];
32
+ for (let kB in blendStates) {
33
+ blendStates[kB].returnToPool();
34
+ }
35
+ delete this._blendStates[k];
36
+ }
37
+ if (this._animationConfig !== null) {
38
+ this._animationConfig.returnToPool();
39
+ }
40
+ this.timeScale = 1.0;
41
+ this._animationDirty = false;
42
+ this._inheritTimeScale = 1.0;
43
+ this._animationNames.length = 0;
44
+ this._animationStates.length = 0;
45
+ //this._animations.clear();
46
+ this._armature = null; //
47
+ this._animationConfig = null; //
48
+ this._lastAnimationState = null;
49
+ }
50
+ _fadeOut(animationConfig) {
51
+ switch (animationConfig.fadeOutMode) {
52
+ case 1 /* AnimationFadeOutMode.SameLayer */:
53
+ for (const animationState of this._animationStates) {
54
+ if (animationState._parent !== null) {
55
+ continue;
56
+ }
57
+ if (animationState.layer === animationConfig.layer) {
58
+ animationState.fadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
59
+ }
60
+ }
61
+ break;
62
+ case 2 /* AnimationFadeOutMode.SameGroup */:
63
+ for (const animationState of this._animationStates) {
64
+ if (animationState._parent !== null) {
65
+ continue;
66
+ }
67
+ if (animationState.group === animationConfig.group) {
68
+ animationState.fadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
69
+ }
70
+ }
71
+ break;
72
+ case 3 /* AnimationFadeOutMode.SameLayerAndGroup */:
73
+ for (const animationState of this._animationStates) {
74
+ if (animationState._parent !== null) {
75
+ continue;
76
+ }
77
+ if (animationState.layer === animationConfig.layer &&
78
+ animationState.group === animationConfig.group) {
79
+ animationState.fadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
80
+ }
81
+ }
82
+ break;
83
+ case 4 /* AnimationFadeOutMode.All */:
84
+ for (const animationState of this._animationStates) {
85
+ if (animationState._parent !== null) {
86
+ continue;
87
+ }
88
+ animationState.fadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
89
+ }
90
+ break;
91
+ case 5 /* AnimationFadeOutMode.Single */: // TODO
92
+ default:
93
+ break;
94
+ }
95
+ }
96
+ /**
97
+ * @internal
98
+ */
99
+ init(armature) {
100
+ if (this._armature !== null) {
101
+ return;
102
+ }
103
+ this._armature = armature;
104
+ this._animationConfig = BaseObject.borrowObject(AnimationConfig);
105
+ }
106
+ /**
107
+ * @internal
108
+ */
109
+ advanceTime(passedTime) {
110
+ if (passedTime < 0.0) {
111
+ // Only animationState can reverse play.
112
+ passedTime = -passedTime;
113
+ }
114
+ if (this._armature.inheritAnimation && this._armature._parent !== null) {
115
+ // Inherit parent animation timeScale.
116
+ this._inheritTimeScale =
117
+ this._armature._parent._armature.animation._inheritTimeScale *
118
+ this.timeScale;
119
+ }
120
+ else {
121
+ this._inheritTimeScale = this.timeScale;
122
+ }
123
+ if (this._inheritTimeScale !== 1.0) {
124
+ passedTime *= this._inheritTimeScale;
125
+ }
126
+ for (let k in this._blendStates) {
127
+ const blendStates = this._blendStates[k];
128
+ for (let kB in blendStates) {
129
+ blendStates[kB].reset();
130
+ }
131
+ }
132
+ const animationStateCount = this._animationStates.length;
133
+ if (animationStateCount === 1) {
134
+ const animationState = this._animationStates[0];
135
+ if (animationState._fadeState > 0 && animationState._subFadeState > 0) {
136
+ this._armature._dragonBones.bufferObject(animationState);
137
+ this._animationStates.length = 0;
138
+ this._lastAnimationState = null;
139
+ }
140
+ else {
141
+ const animationData = animationState.animationData;
142
+ const cacheFrameRate = animationData.cacheFrameRate;
143
+ if (this._animationDirty && cacheFrameRate > 0.0) {
144
+ // Update cachedFrameIndices.
145
+ this._animationDirty = false;
146
+ for (const bone of this._armature.getBones()) {
147
+ bone._cachedFrameIndices = animationData.getBoneCachedFrameIndices(bone.name);
148
+ }
149
+ for (const slot of this._armature.getSlots()) {
150
+ if (slot.displayFrameCount > 0) {
151
+ const rawDisplayData = slot.getDisplayFrameAt(0).rawDisplayData;
152
+ if (rawDisplayData !== null &&
153
+ rawDisplayData.parent ===
154
+ this._armature.armatureData.defaultSkin) {
155
+ slot._cachedFrameIndices =
156
+ animationData.getSlotCachedFrameIndices(slot.name);
157
+ continue;
158
+ }
159
+ }
160
+ slot._cachedFrameIndices = null;
161
+ }
162
+ }
163
+ animationState.advanceTime(passedTime, cacheFrameRate);
164
+ }
165
+ }
166
+ else if (animationStateCount > 1) {
167
+ for (let i = 0, r = 0; i < animationStateCount; ++i) {
168
+ const animationState = this._animationStates[i];
169
+ if (animationState._fadeState > 0 && animationState._subFadeState > 0) {
170
+ r++;
171
+ this._armature._dragonBones.bufferObject(animationState);
172
+ this._animationDirty = true;
173
+ if (this._lastAnimationState === animationState) {
174
+ // Update last animation state.
175
+ this._lastAnimationState = null;
176
+ }
177
+ }
178
+ else {
179
+ if (r > 0) {
180
+ this._animationStates[i - r] = animationState;
181
+ }
182
+ animationState.advanceTime(passedTime, 0.0);
183
+ }
184
+ if (i === animationStateCount - 1 && r > 0) {
185
+ // Modify animation states size.
186
+ this._animationStates.length -= r;
187
+ if (this._lastAnimationState === null &&
188
+ this._animationStates.length > 0) {
189
+ this._lastAnimationState =
190
+ this._animationStates[this._animationStates.length - 1];
191
+ }
192
+ }
193
+ }
194
+ this._armature._cacheFrameIndex = -1;
195
+ }
196
+ else {
197
+ this._armature._cacheFrameIndex = -1;
198
+ }
199
+ }
200
+ /**
201
+ * - Clear all animations states.
202
+ * @see dragonBones.AnimationState
203
+ * @version DragonBones 4.5
204
+ * @language en_US
205
+ */
206
+ reset() {
207
+ for (const animationState of this._animationStates) {
208
+ animationState.returnToPool();
209
+ }
210
+ this._animationDirty = false;
211
+ this._animationConfig.clear();
212
+ this._animationStates.length = 0;
213
+ this._lastAnimationState = null;
214
+ }
215
+ /**
216
+ * - Pause a specific animation state.
217
+ * @param animationName - The name of animation state. (If not set, it will pause all animations)
218
+ * @see dragonBones.AnimationState
219
+ * @version DragonBones 3.0
220
+ * @language en_US
221
+ */
222
+ stop(animationName = null) {
223
+ if (animationName !== null) {
224
+ const animationState = this.getState(animationName);
225
+ if (animationState !== null) {
226
+ animationState.stop();
227
+ }
228
+ }
229
+ else {
230
+ for (const animationState of this._animationStates) {
231
+ animationState.stop();
232
+ }
233
+ }
234
+ }
235
+ /**
236
+ * - Play animation with a specific animation config.
237
+ * The API is still in the experimental phase and may encounter bugs or stability or compatibility issues when used.
238
+ * @param animationConfig - The animation config.
239
+ * @returns The playing animation state.
240
+ * @see dragonBones.AnimationConfig
241
+ * @beta
242
+ * @version DragonBones 5.0
243
+ * @language en_US
244
+ */
245
+ playConfig(animationConfig) {
246
+ const animationName = animationConfig.animation;
247
+ if (!(animationName in this._animations)) {
248
+ console.warn("Non-existent animation.\n", "DragonBones name: " + this._armature.armatureData.parent.name, "Armature name: " + this._armature.name, "Animation name: " + animationName);
249
+ return null;
250
+ }
251
+ const animationData = this._animations[animationName];
252
+ if (animationConfig.fadeOutMode === 5 /* AnimationFadeOutMode.Single */) {
253
+ for (const animationState of this._animationStates) {
254
+ if (animationState._fadeState < 1 &&
255
+ animationState.layer === animationConfig.layer &&
256
+ animationState.animationData === animationData) {
257
+ return animationState;
258
+ }
259
+ }
260
+ }
261
+ if (this._animationStates.length === 0) {
262
+ animationConfig.fadeInTime = 0.0;
263
+ }
264
+ else if (animationConfig.fadeInTime < 0.0) {
265
+ animationConfig.fadeInTime = animationData.fadeInTime;
266
+ }
267
+ if (animationConfig.fadeOutTime < 0.0) {
268
+ animationConfig.fadeOutTime = animationConfig.fadeInTime;
269
+ }
270
+ if (animationConfig.timeScale <= -100.0) {
271
+ animationConfig.timeScale = 1.0 / animationData.scale;
272
+ }
273
+ if (animationData.frameCount > 0) {
274
+ if (animationConfig.position < 0.0) {
275
+ animationConfig.position %= animationData.duration;
276
+ animationConfig.position =
277
+ animationData.duration - animationConfig.position;
278
+ }
279
+ else if (animationConfig.position === animationData.duration) {
280
+ animationConfig.position -= 0.000001; // Play a little time before end.
281
+ }
282
+ else if (animationConfig.position > animationData.duration) {
283
+ animationConfig.position %= animationData.duration;
284
+ }
285
+ if (animationConfig.duration > 0.0 &&
286
+ animationConfig.position + animationConfig.duration >
287
+ animationData.duration) {
288
+ animationConfig.duration =
289
+ animationData.duration - animationConfig.position;
290
+ }
291
+ if (animationConfig.playTimes < 0) {
292
+ animationConfig.playTimes = animationData.playTimes;
293
+ }
294
+ }
295
+ else {
296
+ animationConfig.playTimes = 1;
297
+ animationConfig.position = 0.0;
298
+ if (animationConfig.duration > 0.0) {
299
+ animationConfig.duration = 0.0;
300
+ }
301
+ }
302
+ if (animationConfig.duration === 0.0) {
303
+ animationConfig.duration = -1.0;
304
+ }
305
+ this._fadeOut(animationConfig);
306
+ //
307
+ const animationState = BaseObject.borrowObject(AnimationState);
308
+ animationState.init(this._armature, animationData, animationConfig);
309
+ this._animationDirty = true;
310
+ this._armature._cacheFrameIndex = -1;
311
+ if (this._animationStates.length > 0) {
312
+ // Sort animation state.
313
+ let added = false;
314
+ for (let i = 0, l = this._animationStates.length; i < l; ++i) {
315
+ if (animationState.layer > this._animationStates[i].layer) {
316
+ added = true;
317
+ this._animationStates.splice(i, 0, animationState);
318
+ break;
319
+ }
320
+ else if (i !== l - 1 &&
321
+ animationState.layer > this._animationStates[i + 1].layer) {
322
+ added = true;
323
+ this._animationStates.splice(i + 1, 0, animationState);
324
+ break;
325
+ }
326
+ }
327
+ if (!added) {
328
+ this._animationStates.push(animationState);
329
+ }
330
+ }
331
+ else {
332
+ this._animationStates.push(animationState);
333
+ }
334
+ for (const slot of this._armature.getSlots()) {
335
+ // Child armature play same name animation.
336
+ const childArmature = slot.childArmature;
337
+ if (childArmature !== null &&
338
+ childArmature.inheritAnimation &&
339
+ childArmature.animation.hasAnimation(animationName) &&
340
+ childArmature.animation.getState(animationName) === null) {
341
+ childArmature.animation.fadeIn(animationName); //
342
+ }
343
+ }
344
+ for (let k in animationData.animationTimelines) {
345
+ // Blend animation node.
346
+ const childAnimationState = this.fadeIn(k, 0.0, 1, animationState.layer, "", 5 /* AnimationFadeOutMode.Single */);
347
+ if (childAnimationState === null) {
348
+ continue;
349
+ }
350
+ const timelines = animationData.animationTimelines[k];
351
+ childAnimationState.actionEnabled = false;
352
+ childAnimationState.resetToPose = false;
353
+ childAnimationState.stop();
354
+ animationState.addState(childAnimationState, timelines);
355
+ //
356
+ const index = this._animationStates.indexOf(animationState);
357
+ const childIndex = this._animationStates.indexOf(childAnimationState);
358
+ if (childIndex < index) {
359
+ this._animationStates.splice(index, 1);
360
+ this._animationStates.splice(childIndex, 0, animationState);
361
+ }
362
+ }
363
+ // if (!this._armature._lockUpdate && animationConfig.fadeInTime <= 0.0) { // Blend animation state, update armature.
364
+ // this._armature.advanceTime(0.0);
365
+ // }
366
+ this._lastAnimationState = animationState;
367
+ return animationState;
368
+ }
369
+ /**
370
+ * - Play a specific animation.
371
+ * @param animationName - The name of animation data. (If not set, The default animation will be played, or resume the animation playing from pause status, or replay the last playing animation)
372
+ * @param playTimes - Playing repeat times. [-1: Use default value of the animation data, 0: No end loop playing, [1~N]: Repeat N times] (default: -1)
373
+ * @returns The playing animation state.
374
+ * @example
375
+ * <pre>
376
+ * armature.animation.play("walk");
377
+ * </pre>
378
+ * @version DragonBones 3.0
379
+ * @language en_US
380
+ */
381
+ play(animationName = null, playTimes = -1) {
382
+ this._animationConfig.clear();
383
+ this._animationConfig.resetToPose = true;
384
+ this._animationConfig.playTimes = playTimes;
385
+ this._animationConfig.fadeInTime = 0.0;
386
+ this._animationConfig.animation =
387
+ animationName !== null ? animationName : "";
388
+ if (animationName !== null && animationName.length > 0) {
389
+ this.playConfig(this._animationConfig);
390
+ }
391
+ else if (this._lastAnimationState === null) {
392
+ const defaultAnimation = this._armature.armatureData.defaultAnimation;
393
+ if (defaultAnimation !== null) {
394
+ this._animationConfig.animation = defaultAnimation.name;
395
+ this.playConfig(this._animationConfig);
396
+ }
397
+ }
398
+ else if (!this._lastAnimationState.isPlaying &&
399
+ !this._lastAnimationState.isCompleted) {
400
+ this._lastAnimationState.play();
401
+ }
402
+ else {
403
+ this._animationConfig.animation = this._lastAnimationState.name;
404
+ this.playConfig(this._animationConfig);
405
+ }
406
+ return this._lastAnimationState;
407
+ }
408
+ /**
409
+ * - Fade in a specific animation.
410
+ * @param animationName - The name of animation data.
411
+ * @param fadeInTime - The fade in time. [-1: Use the default value of animation data, [0~N]: The fade in time (In seconds)] (Default: -1)
412
+ * @param playTimes - playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
413
+ * @param layer - The blending layer, the animation states in high level layer will get the blending weights with high priority, when the total blending weights are more than 1.0, there will be no more weights can be allocated to the other animation states. (Default: 0)
414
+ * @param group - The blending group name, it is typically used to specify the substitution of multiple animation states blending. (Default: null)
415
+ * @param fadeOutMode - The fade out mode, which is typically used to specify alternate mode of multiple animation states blending. (Default: AnimationFadeOutMode.SameLayerAndGroup)
416
+ * @returns The playing animation state.
417
+ * @example
418
+ * <pre>
419
+ * armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
420
+ * armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;
421
+ * </pre>
422
+ * @version DragonBones 4.5
423
+ * @language en_US
424
+ */
425
+ fadeIn(animationName, fadeInTime = -1.0, playTimes = -1, layer = 0, group = null, fadeOutMode = 3 /* AnimationFadeOutMode.SameLayerAndGroup */) {
426
+ this._animationConfig.clear();
427
+ this._animationConfig.fadeOutMode = fadeOutMode;
428
+ this._animationConfig.playTimes = playTimes;
429
+ this._animationConfig.layer = layer;
430
+ this._animationConfig.fadeInTime = fadeInTime;
431
+ this._animationConfig.animation = animationName;
432
+ this._animationConfig.group = group !== null ? group : "";
433
+ return this.playConfig(this._animationConfig);
434
+ }
435
+ /**
436
+ * - Play a specific animation from the specific time.
437
+ * @param animationName - The name of animation data.
438
+ * @param time - The start time point of playing. (In seconds)
439
+ * @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
440
+ * @returns The played animation state.
441
+ * @version DragonBones 4.5
442
+ * @language en_US
443
+ */
444
+ gotoAndPlayByTime(animationName, time = 0.0, playTimes = -1) {
445
+ this._animationConfig.clear();
446
+ this._animationConfig.resetToPose = true;
447
+ this._animationConfig.playTimes = playTimes;
448
+ this._animationConfig.position = time;
449
+ this._animationConfig.fadeInTime = 0.0;
450
+ this._animationConfig.animation = animationName;
451
+ return this.playConfig(this._animationConfig);
452
+ }
453
+ /**
454
+ * - Play a specific animation from the specific frame.
455
+ * @param animationName - The name of animation data.
456
+ * @param frame - The start frame of playing.
457
+ * @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
458
+ * @returns The played animation state.
459
+ * @version DragonBones 4.5
460
+ * @language en_US
461
+ */
462
+ gotoAndPlayByFrame(animationName, frame = 0, playTimes = -1) {
463
+ this._animationConfig.clear();
464
+ this._animationConfig.resetToPose = true;
465
+ this._animationConfig.playTimes = playTimes;
466
+ this._animationConfig.fadeInTime = 0.0;
467
+ this._animationConfig.animation = animationName;
468
+ const animationData = animationName in this._animations
469
+ ? this._animations[animationName]
470
+ : null;
471
+ if (animationData !== null) {
472
+ this._animationConfig.position =
473
+ animationData.frameCount > 0
474
+ ? (animationData.duration * frame) / animationData.frameCount
475
+ : 0.0;
476
+ }
477
+ return this.playConfig(this._animationConfig);
478
+ }
479
+ /**
480
+ * - Play a specific animation from the specific progress.
481
+ * @param animationName - The name of animation data.
482
+ * @param progress - The start progress value of playing.
483
+ * @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
484
+ * @returns The played animation state.
485
+ * @version DragonBones 4.5
486
+ * @language en_US
487
+ */
488
+ gotoAndPlayByProgress(animationName, progress = 0.0, playTimes = -1) {
489
+ this._animationConfig.clear();
490
+ this._animationConfig.resetToPose = true;
491
+ this._animationConfig.playTimes = playTimes;
492
+ this._animationConfig.fadeInTime = 0.0;
493
+ this._animationConfig.animation = animationName;
494
+ const animationData = animationName in this._animations
495
+ ? this._animations[animationName]
496
+ : null;
497
+ if (animationData !== null) {
498
+ this._animationConfig.position =
499
+ animationData.duration * (progress > 0.0 ? progress : 0.0);
500
+ }
501
+ return this.playConfig(this._animationConfig);
502
+ }
503
+ /**
504
+ * - Stop a specific animation at the specific time.
505
+ * @param animationName - The name of animation data.
506
+ * @param time - The stop time. (In seconds)
507
+ * @returns The played animation state.
508
+ * @version DragonBones 4.5
509
+ * @language en_US
510
+ */
511
+ gotoAndStopByTime(animationName, time = 0.0) {
512
+ const animationState = this.gotoAndPlayByTime(animationName, time, 1);
513
+ if (animationState !== null) {
514
+ animationState.stop();
515
+ }
516
+ return animationState;
517
+ }
518
+ /**
519
+ * - Stop a specific animation at the specific frame.
520
+ * @param animationName - The name of animation data.
521
+ * @param frame - The stop frame.
522
+ * @returns The played animation state.
523
+ * @version DragonBones 4.5
524
+ * @language en_US
525
+ */
526
+ gotoAndStopByFrame(animationName, frame = 0) {
527
+ const animationState = this.gotoAndPlayByFrame(animationName, frame, 1);
528
+ if (animationState !== null) {
529
+ animationState.stop();
530
+ }
531
+ return animationState;
532
+ }
533
+ /**
534
+ * - Stop a specific animation at the specific progress.
535
+ * @param animationName - The name of animation data.
536
+ * @param progress - The stop progress value.
537
+ * @returns The played animation state.
538
+ * @version DragonBones 4.5
539
+ * @language en_US
540
+ */
541
+ gotoAndStopByProgress(animationName, progress = 0.0) {
542
+ const animationState = this.gotoAndPlayByProgress(animationName, progress, 1);
543
+ if (animationState !== null) {
544
+ animationState.stop();
545
+ }
546
+ return animationState;
547
+ }
548
+ /**
549
+ * @internal
550
+ */
551
+ getBlendState(type, name, target) {
552
+ if (!(type in this._blendStates)) {
553
+ this._blendStates[type] = {};
554
+ }
555
+ const blendStates = this._blendStates[type];
556
+ if (!(name in blendStates)) {
557
+ const blendState = (blendStates[name] =
558
+ BaseObject.borrowObject(BlendState));
559
+ blendState.target = target;
560
+ }
561
+ return blendStates[name];
562
+ }
563
+ /**
564
+ * - Get a specific animation state.
565
+ * @param animationName - The name of animation state.
566
+ * @param layer - The layer of find animation states. [-1: Find all layers, [0~N]: Specified layer] (default: -1)
567
+ * @example
568
+ * <pre>
569
+ * armature.animation.play("walk");
570
+ * let walkState = armature.animation.getState("walk");
571
+ * walkState.timeScale = 0.5;
572
+ * </pre>
573
+ * @version DragonBones 3.0
574
+ * @language en_US
575
+ */
576
+ getState(animationName, layer = -1) {
577
+ let i = this._animationStates.length;
578
+ while (i--) {
579
+ const animationState = this._animationStates[i];
580
+ if (animationState.name === animationName &&
581
+ (layer < 0 || animationState.layer === layer)) {
582
+ return animationState;
583
+ }
584
+ }
585
+ return null;
586
+ }
587
+ /**
588
+ * - Check whether a specific animation data is included.
589
+ * @param animationName - The name of animation data.
590
+ * @see dragonBones.AnimationData
591
+ * @version DragonBones 3.0
592
+ * @language en_US
593
+ */
594
+ hasAnimation(animationName) {
595
+ return animationName in this._animations;
596
+ }
597
+ /**
598
+ * - Get all the animation states.
599
+ * @version DragonBones 5.1
600
+ * @language en_US
601
+ */
602
+ getStates() {
603
+ return this._animationStates;
604
+ }
605
+ /**
606
+ * - Check whether there is an animation state is playing
607
+ * @see dragonBones.AnimationState
608
+ * @version DragonBones 3.0
609
+ * @language en_US
610
+ */
611
+ get isPlaying() {
612
+ for (const animationState of this._animationStates) {
613
+ if (animationState.isPlaying) {
614
+ return true;
615
+ }
616
+ }
617
+ return false;
618
+ }
619
+ /**
620
+ * - Check whether all the animation states' playing were finished.
621
+ * @see dragonBones.AnimationState
622
+ * @version DragonBones 3.0
623
+ * @language en_US
624
+ */
625
+ get isCompleted() {
626
+ for (const animationState of this._animationStates) {
627
+ if (!animationState.isCompleted) {
628
+ return false;
629
+ }
630
+ }
631
+ return this._animationStates.length > 0;
632
+ }
633
+ /**
634
+ * - The name of the last playing animation state.
635
+ * @see #lastAnimationState
636
+ * @version DragonBones 3.0
637
+ * @language en_US
638
+ */
639
+ get lastAnimationName() {
640
+ return this._lastAnimationState !== null
641
+ ? this._lastAnimationState.name
642
+ : "";
643
+ }
644
+ /**
645
+ * - The name of all animation data
646
+ * @version DragonBones 4.5
647
+ * @language en_US
648
+ */
649
+ get animationNames() {
650
+ return this._animationNames;
651
+ }
652
+ /**
653
+ * - All animation data.
654
+ * @version DragonBones 4.5
655
+ * @language en_US
656
+ */
657
+ get animations() {
658
+ return this._animations;
659
+ }
660
+ set animations(value) {
661
+ if (this._animations === value) {
662
+ return;
663
+ }
664
+ this._animationNames.length = 0;
665
+ for (let k in this._animations) {
666
+ delete this._animations[k];
667
+ }
668
+ for (let k in value) {
669
+ this._animationNames.push(k);
670
+ this._animations[k] = value[k];
671
+ }
672
+ }
673
+ /**
674
+ * - An AnimationConfig instance that can be used quickly.
675
+ * @see dragonBones.AnimationConfig
676
+ * @version DragonBones 5.0
677
+ * @language en_US
678
+ */
679
+ get animationConfig() {
680
+ this._animationConfig.clear();
681
+ return this._animationConfig;
682
+ }
683
+ /**
684
+ * - The last playing animation state
685
+ * @see dragonBones.AnimationState
686
+ * @version DragonBones 3.0
687
+ * @language en_US
688
+ */
689
+ get lastAnimationState() {
690
+ return this._lastAnimationState;
691
+ }
692
+ }