@safe-engine/cocos 2.2.7 → 2.3.4

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 (118) hide show
  1. package/@types/index.d.ts +0 -61
  2. package/dist/app.d.ts +1 -1
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +25 -23
  5. package/dist/box2d-wasm/PhysicsComponent.d.ts +1 -1
  6. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  7. package/dist/collider/CollideComponent.d.ts +21 -3
  8. package/dist/collider/CollideComponent.d.ts.map +1 -1
  9. package/dist/collider/CollideSystem.d.ts.map +1 -1
  10. package/dist/collider/CollideSystem.js +6 -5
  11. package/dist/core/EnhancedComponent.d.ts +1 -1
  12. package/dist/core/EnhancedComponent.d.ts.map +1 -1
  13. package/dist/core/NodeComp.d.ts +1 -1
  14. package/dist/core/NodeComp.d.ts.map +1 -1
  15. package/dist/dragonbones/DragonBonesComp.d.ts +27 -0
  16. package/dist/dragonbones/DragonBonesComp.d.ts.map +1 -0
  17. package/dist/dragonbones/DragonBonesComp.js +29 -0
  18. package/dist/dragonbones/DragonBonesSystem.d.ts +9 -0
  19. package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -0
  20. package/dist/dragonbones/DragonBonesSystem.js +69 -0
  21. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts +87 -0
  22. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts.map +1 -0
  23. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.js +240 -0
  24. package/dist/dragonbones/db-cocos/CocosFactory.d.ts +128 -0
  25. package/dist/dragonbones/db-cocos/CocosFactory.d.ts.map +1 -0
  26. package/dist/dragonbones/db-cocos/CocosFactory.js +190 -0
  27. package/dist/dragonbones/db-cocos/CocosSlot.d.ts +49 -0
  28. package/dist/dragonbones/db-cocos/CocosSlot.d.ts.map +1 -0
  29. package/dist/dragonbones/db-cocos/CocosSlot.js +368 -0
  30. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts +53 -0
  31. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts.map +1 -0
  32. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.js +121 -0
  33. package/dist/dragonbones/index.d.ts +1 -35
  34. package/dist/dragonbones/index.d.ts.map +1 -1
  35. package/dist/dragonbones/index.js +2 -83
  36. package/dist/gui/GUIComponent.d.ts +1 -1
  37. package/dist/gui/GUIComponent.d.ts.map +1 -1
  38. package/dist/index.d.ts +9 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +0 -2
  41. package/dist/polyfills.d.ts +1 -1
  42. package/dist/polyfills.d.ts.map +1 -1
  43. package/dist/polyfills.js +1 -2
  44. package/dist/render/RenderComponent.d.ts +1 -1
  45. package/dist/render/RenderComponent.d.ts.map +1 -1
  46. package/dist/render/RenderComponent.js +1 -0
  47. package/dist/render/RenderSystem.d.ts.map +1 -1
  48. package/dist/render/RenderSystem.js +34 -2
  49. package/dist/richtext/RichTextComp.d.ts +1 -1
  50. package/dist/richtext/RichTextComp.d.ts.map +1 -1
  51. package/dist/richtext/RichTextComp.js +1 -1
  52. package/dist/spine/SpineSkeleton.d.ts +22 -0
  53. package/dist/spine/SpineSkeleton.d.ts.map +1 -0
  54. package/dist/spine/SpineSkeleton.js +18 -0
  55. package/dist/spine/SpineSystem.d.ts +6 -0
  56. package/dist/spine/SpineSystem.d.ts.map +1 -0
  57. package/dist/spine/SpineSystem.js +34 -0
  58. package/dist/spine/index.d.ts +1 -24
  59. package/dist/spine/index.d.ts.map +1 -1
  60. package/dist/spine/index.js +16 -42
  61. package/dist/spine/spine-cocos/CCSkeleton.d.ts +86 -0
  62. package/dist/spine/spine-cocos/CCSkeleton.d.ts.map +1 -0
  63. package/dist/spine/{CCSkeleton.js → spine-cocos/CCSkeleton.js} +39 -128
  64. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts +87 -0
  65. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts.map +1 -0
  66. package/dist/spine/{CCSkeletonAnimation.js → spine-cocos/CCSkeletonAnimation.js} +37 -97
  67. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts +28 -0
  68. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
  69. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.js +224 -0
  70. package/dist/spine/{CCSkeletonTexture.d.ts → spine-cocos/CCSkeletonTexture.d.ts} +1 -1
  71. package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts.map +1 -0
  72. package/dist/spine/{CCSkeletonTexture.js → spine-cocos/CCSkeletonTexture.js} +5 -5
  73. package/dist/spine/spine-cocos/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
  74. package/dist/spine/{CCSkeletonWebGLRenderCmd.js → spine-cocos/CCSkeletonWebGLRenderCmd.js} +13 -13
  75. package/package.json +5 -6
  76. package/dist/core/index.d.ts +0 -6
  77. package/dist/core/index.d.ts.map +0 -1
  78. package/dist/core/index.js +0 -5
  79. package/dist/dragonbones/PixiDragonBonesSprite.d.ts +0 -15
  80. package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +0 -1
  81. package/dist/dragonbones/PixiDragonBonesSprite.js +0 -71
  82. package/dist/gworld/EnhancedComponent.d.ts +0 -22
  83. package/dist/gworld/EnhancedComponent.d.ts.map +0 -1
  84. package/dist/gworld/EnhancedComponent.js +0 -44
  85. package/dist/gworld/NodeComp.d.ts +0 -153
  86. package/dist/gworld/NodeComp.d.ts.map +0 -1
  87. package/dist/gworld/NodeComp.js +0 -337
  88. package/dist/gworld/NodePool.d.ts +0 -9
  89. package/dist/gworld/NodePool.d.ts.map +0 -1
  90. package/dist/gworld/NodePool.js +0 -23
  91. package/dist/gworld/Scene.d.ts +0 -5
  92. package/dist/gworld/Scene.d.ts.map +0 -1
  93. package/dist/gworld/Scene.js +0 -14
  94. package/dist/gworld/decorator.d.ts +0 -8
  95. package/dist/gworld/decorator.d.ts.map +0 -1
  96. package/dist/gworld/decorator.js +0 -12
  97. package/dist/gworld/index.d.ts +0 -8
  98. package/dist/gworld/index.d.ts.map +0 -1
  99. package/dist/gworld/index.js +0 -14
  100. package/dist/render/TiledSprite.d.ts +0 -13
  101. package/dist/render/TiledSprite.d.ts.map +0 -1
  102. package/dist/render/TiledSprite.js +0 -69
  103. package/dist/safex.d.ts +0 -10
  104. package/dist/safex.d.ts.map +0 -1
  105. package/dist/safex.js +0 -25
  106. package/dist/spine/CCSkeleton.d.ts +0 -189
  107. package/dist/spine/CCSkeleton.d.ts.map +0 -1
  108. package/dist/spine/CCSkeletonAnimation.d.ts +0 -146
  109. package/dist/spine/CCSkeletonAnimation.d.ts.map +0 -1
  110. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +0 -2
  111. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +0 -1
  112. package/dist/spine/CCSkeletonCanvasRenderCmd.js +0 -228
  113. package/dist/spine/CCSkeletonTexture.d.ts.map +0 -1
  114. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +0 -1
  115. package/dist/spine/PixiSpineSprite.d.ts +0 -15
  116. package/dist/spine/PixiSpineSprite.d.ts.map +0 -1
  117. package/dist/spine/PixiSpineSprite.js +0 -70
  118. /package/dist/spine/{CCSkeletonWebGLRenderCmd.d.ts → spine-cocos/CCSkeletonWebGLRenderCmd.d.ts} +0 -0
@@ -1,5 +1,4 @@
1
- import * as spine from '@esotericsoftware/spine-core';
2
- import { AtlasAttachmentLoader, SkeletonJson, TextureAtlas } from '@esotericsoftware/spine-core';
1
+ import { AtlasAttachmentLoader, Physics, RegionAttachment, Skeleton, SkeletonJson, TextureAtlas, Utils, } from '@esotericsoftware/spine-core';
3
2
  import { _atlasLoader } from './CCSkeletonAnimation';
4
3
  import { CanvasRenderCmd } from './CCSkeletonCanvasRenderCmd';
5
4
  import { WebGLRenderCmd } from './CCSkeletonWebGLRenderCmd';
@@ -31,11 +30,11 @@ import { WebGLRenderCmd } from './CCSkeletonWebGLRenderCmd';
31
30
  /**
32
31
  * The main namespace of Spine, all classes, functions, properties and constants of Spine are defined in this namespace
33
32
  * @namespace
34
- * @name
33
+ * @name gworld
35
34
  */
36
35
  /**
37
36
  * <p>
38
- * The skeleton of Spine. <br/>
37
+ * The skeleton of <br/>
39
38
  * Skeleton has a reference to a SkeletonData and stores the state for skeleton instance,
40
39
  * which consists of the current pose's bone SRT, slot colors, and which slot attachments are visible. <br/>
41
40
  * Multiple skeletons can use the same SkeletonData (which includes all animations, skins, and attachments). <br/>
@@ -43,20 +42,28 @@ import { WebGLRenderCmd } from './CCSkeletonWebGLRenderCmd';
43
42
  * @class
44
43
  * @extends cc.Node
45
44
  */
46
- export class Skeleton extends cc.Node {
45
+ export class CCSkeleton extends cc.Node {
47
46
  _skeleton = null;
48
47
  _rootBone = null;
49
48
  _timeScale = 1;
50
49
  _debugSlots = false;
51
50
  _debugBones = false;
52
- _premultipliedAlpha;
51
+ _premultipliedAlpha = false;
53
52
  _ownsSkeletonData = null;
54
- _atlas = null;
53
+ _renderCmd;
54
+ _state;
55
+ _ownsAnimationStateData = false;
56
+ _listener;
55
57
  constructor(skeletonDataFile, atlasFile, scale) {
56
58
  super();
57
- super.init();
58
- this._premultipliedAlpha = cc._renderType === cc.game.RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA;
59
- this.initWithArgs(skeletonDataFile, atlasFile, scale);
59
+ super.ctor();
60
+ this._renderCmd = this._createRenderCmd();
61
+ if (arguments.length === 0) {
62
+ this.init();
63
+ }
64
+ else {
65
+ this.initWithArgs(skeletonDataFile, atlasFile, scale);
66
+ }
60
67
  }
61
68
  _createRenderCmd() {
62
69
  if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
@@ -64,6 +71,11 @@ export class Skeleton extends cc.Node {
64
71
  else
65
72
  return new WebGLRenderCmd(this);
66
73
  }
74
+ init() {
75
+ super.init();
76
+ this._premultipliedAlpha = !!(cc._renderType === cc.game.RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA);
77
+ return true;
78
+ }
67
79
  onEnter() {
68
80
  super.onEnter();
69
81
  this.scheduleUpdate();
@@ -72,66 +84,33 @@ export class Skeleton extends cc.Node {
72
84
  this.unscheduleUpdate();
73
85
  super.onExit();
74
86
  }
75
- /**
76
- * Sets whether open debug slots.
77
- * @param {boolean} enable true to open, false to close.
78
- */
79
87
  setDebugSolots(enable) {
80
88
  this._debugSlots = enable;
81
89
  }
82
- /**
83
- * Sets whether open debug bones.
84
- * @param {boolean} enable
85
- */
86
90
  setDebugBones(enable) {
87
91
  this._debugBones = enable;
88
92
  }
89
- /**
90
- * Sets whether open debug slots.
91
- * @param {boolean} enabled true to open, false to close.
92
- */
93
93
  setDebugSlotsEnabled(enabled) {
94
94
  this._debugSlots = enabled;
95
95
  }
96
- /**
97
- * Gets whether open debug slots.
98
- * @returns {boolean} true to open, false to close.
99
- */
100
96
  getDebugSlotsEnabled() {
101
97
  return this._debugSlots;
102
98
  }
103
- /**
104
- * Sets whether open debug bones.
105
- * @param {boolean} enabled
106
- */
107
99
  setDebugBonesEnabled(enabled) {
108
100
  this._debugBones = enabled;
109
101
  }
110
- /**
111
- * Gets whether open debug bones.
112
- * @returns {boolean} true to open, false to close.
113
- */
114
102
  getDebugBonesEnabled() {
115
103
  return this._debugBones;
116
104
  }
117
- /**
118
- * Sets the time scale of Skeleton.
119
- * @param {Number} scale
120
- */
121
105
  setTimeScale(scale) {
122
106
  this._timeScale = scale;
123
107
  }
124
108
  getTimeScale() {
125
109
  return this._timeScale;
126
110
  }
127
- /**
128
- * Initializes Skeleton with Data.
129
- * @param {.spine.SkeletonData|String} skeletonDataFile
130
- * @param {String|spine.Atlas|spine.SkeletonData} atlasFile atlas filename or atlas data or owns SkeletonData
131
- * @param {Number} [scale] scale can be specified on the JSON or binary loader which will scale the bone positions, image sizes, and animation translations.
132
- */
133
111
  initWithArgs(skeletonDataFile, atlasFile, scale) {
134
- const argSkeletonFile = skeletonDataFile, argAtlasFile = atlasFile;
112
+ const argSkeletonFile = skeletonDataFile;
113
+ const argAtlasFile = atlasFile;
135
114
  let skeletonData, atlas, ownsSkeletonData;
136
115
  if (cc.isString(argSkeletonFile)) {
137
116
  if (cc.isString(argAtlasFile)) {
@@ -159,20 +138,16 @@ export class Skeleton extends cc.Node {
159
138
  this.setSkeletonData(skeletonData, ownsSkeletonData);
160
139
  this.init();
161
140
  }
162
- /**
163
- * Returns the bounding box of Skeleton.
164
- * @returns {cc.Rect}
165
- */
166
141
  getBoundingBox() {
167
142
  let minX = cc.FLT_MAX, minY = cc.FLT_MAX, maxX = cc.FLT_MIN, maxY = cc.FLT_MIN;
168
- const scaleX = this.getScaleX(), scaleY = this.getScaleY(), slots = this._skeleton.slots, VERTEX = spine.RegionAttachment;
143
+ const scaleX = this.getScaleX(), scaleY = this.getScaleY(), slots = this._skeleton.slots, VERTEX = RegionAttachment;
169
144
  let vertices;
170
145
  for (let i = 0, slotCount = slots.length; i < slotCount; ++i) {
171
146
  const slot = slots[i];
172
147
  const attachment = slot.attachment;
173
- if (!attachment || !(attachment instanceof spine.RegionAttachment))
148
+ if (!attachment || !(attachment instanceof RegionAttachment))
174
149
  continue;
175
- vertices = spine.Utils.setArraySize([], 8, 0);
150
+ vertices = Utils.setArraySize([], 8, 0);
176
151
  attachment.computeWorldVertices(slot, vertices, 0, 2);
177
152
  minX = Math.min(minX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
178
153
  minY = Math.min(minY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
@@ -182,115 +157,59 @@ export class Skeleton extends cc.Node {
182
157
  const position = this.getPosition();
183
158
  return cc.rect(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
184
159
  }
185
- /**
186
- * Computes the world SRT from the local SRT for each bone.
187
- */
188
160
  updateWorldTransform() {
189
- this._skeleton.updateWorldTransform(true);
161
+ this._skeleton.updateWorldTransform(Physics.pose);
190
162
  }
191
- /**
192
- * Sets the bones and slots to the setup pose.
193
- */
194
163
  setToSetupPose() {
195
164
  this._skeleton.setToSetupPose();
196
165
  }
197
- /**
198
- * Sets the bones to the setup pose, using the values from the `BoneData` list in the `SkeletonData`.
199
- */
200
166
  setBonesToSetupPose() {
201
167
  this._skeleton.setBonesToSetupPose();
202
168
  }
203
- /**
204
- * Sets the slots to the setup pose, using the values from the `SlotData` list in the `SkeletonData`.
205
- */
206
169
  setSlotsToSetupPose() {
207
170
  this._skeleton.setSlotsToSetupPose();
208
171
  }
209
- /**
210
- * Finds a bone by name. This does a string comparison for every bone.
211
- * @param {String} boneName
212
- * @returns {.spine.Bone}
213
- */
214
172
  findBone(boneName) {
215
173
  return this._skeleton.findBone(boneName);
216
174
  }
217
- /**
218
- * Finds a slot by name. This does a string comparison for every slot.
219
- * @param {String} slotName
220
- * @returns {.spine.Slot}
221
- */
222
175
  findSlot(slotName) {
223
176
  return this._skeleton.findSlot(slotName);
224
177
  }
225
- /**
226
- * Finds a skin by name and makes it the active skin. This does a string comparison for every skin. Note that setting the skin does not change which attachments are visible.
227
- * @param {string} skinName
228
- * @returns {.spine.Skin}
229
- */
230
178
  setSkin(skinName) {
231
179
  return this._skeleton.setSkinByName(skinName);
232
180
  }
233
- /**
234
- * Returns the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
235
- * @param {String} slotName
236
- * @param {String} attachmentName
237
- * @returns {.spine.Attachment}
238
- */
239
181
  getAttachment(slotName, attachmentName) {
240
182
  return this._skeleton.getAttachmentByName(slotName, attachmentName);
241
183
  }
242
- /**
243
- * Sets the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
244
- * @param {String} slotName
245
- * @param {String} attachmentName
246
- */
247
184
  setAttachment(slotName, attachmentName) {
248
185
  this._skeleton.setAttachment(slotName, attachmentName);
249
186
  }
250
- /**
251
- * Sets the premultiplied alpha value to Skeleton.
252
- * @param {Number} alpha
253
- */
254
187
  setPremultipliedAlpha(premultiplied) {
255
188
  this._premultipliedAlpha = premultiplied;
256
189
  }
257
- /**
258
- * Returns whether to enable premultiplied alpha.
259
- * @returns {boolean}
260
- */
261
190
  isPremultipliedAlpha() {
262
191
  return this._premultipliedAlpha;
263
192
  }
264
- /**
265
- * Sets skeleton data to Skeleton.
266
- * @param {.spine.SkeletonData} skeletonData
267
- * @param {.spine.SkeletonData} ownsSkeletonData
268
- */
269
193
  setSkeletonData(skeletonData, ownsSkeletonData) {
270
194
  if (skeletonData.width != null && skeletonData.height != null)
271
195
  this.setContentSize(skeletonData.width / cc.director.getContentScaleFactor(), skeletonData.height / cc.director.getContentScaleFactor());
272
- this._skeleton = new spine.Skeleton(skeletonData);
273
- this._skeleton.updateWorldTransform(true);
196
+ this._skeleton = new Skeleton(skeletonData);
197
+ this._skeleton.updateWorldTransform(Physics.pose);
274
198
  this._rootBone = this._skeleton.getRootBone();
275
199
  this._ownsSkeletonData = ownsSkeletonData;
276
- this._renderCmd._createChildFormSkeletonData();
200
+ if (this._renderCmd && typeof this._renderCmd._createChildFormSkeletonData === 'function') {
201
+ this._renderCmd._createChildFormSkeletonData();
202
+ }
277
203
  }
278
- /**
279
- * Return the renderer of attachment.
280
- * @param {.spine.RegionAttachment|.spine.BoundingBoxAttachment} regionAttachment
281
- * @returns {.spine.TextureAtlasRegion}
282
- */
283
204
  getTextureAtlas(regionAttachment) {
284
205
  return regionAttachment.region;
285
206
  }
286
- /**
287
- * Returns the blendFunc of Skeleton.
288
- * @returns {cc.BlendFunc}
289
- */
290
207
  getBlendFunc() {
291
208
  const slot = this._skeleton.drawOrder[0];
292
209
  if (slot) {
293
- const blend = this._renderCmd._getBlendFunc(slot.data.blendMode, this._premultipliedAlpha);
210
+ const blend = this._renderCmd && typeof this._renderCmd._getBlendFunc === 'function'
211
+ ? this._renderCmd._getBlendFunc(slot.data.blendMode, this._premultipliedAlpha)
212
+ : {};
294
213
  return blend;
295
214
  }
296
215
  else {
@@ -300,21 +219,13 @@ export class Skeleton extends cc.Node {
300
219
  setBlendFunc() {
301
220
  return;
302
221
  }
303
- /**
304
- * Update will be called automatically every frame if "scheduleUpdate" is called when the node is "live".
305
- * @param {Number} dt Delta time since last update
306
- */
307
222
  update(dt) {
308
223
  this._skeleton.update(dt);
309
224
  }
310
- // Static create method
311
- static create(skeletonDataFile, atlasFile, scale) {
312
- return new Skeleton(skeletonDataFile, atlasFile, scale);
313
- }
314
225
  }
315
- cc.defineGetterSetter(Skeleton.prototype, 'opacityModifyRGB', Skeleton.prototype.isOpacityModifyRGB);
226
+ cc.defineGetterSetter(CCSkeleton.prototype, 'opacityModifyRGB', CCSkeleton.prototype.isOpacityModifyRGB);
316
227
  // For renderer webgl to identify skeleton's default texture and blend function
317
- cc.defineGetterSetter(Skeleton.prototype, '_blendFunc', Skeleton.prototype.getBlendFunc);
318
- cc.defineGetterSetter(Skeleton.prototype, '_texture', function () {
228
+ cc.defineGetterSetter(CCSkeleton.prototype, '_blendFunc', CCSkeleton.prototype.getBlendFunc);
229
+ cc.defineGetterSetter(CCSkeleton.prototype, '_texture', function () {
319
230
  return this._renderCmd._currTexture;
320
231
  });
@@ -0,0 +1,87 @@
1
+ import { Animation, AnimationState, AnimationStateData } from '@esotericsoftware/spine-core';
2
+ import { CCSkeleton } from './CCSkeleton';
3
+ /****************************************************************************
4
+ Copyright (c) 2011-2012 cocos2d-x.org
5
+ Copyright (c) 2013-2014 Chukong Technologies Inc.
6
+ Copyright (c) 2014 Shengxiang Chen (Nero Chan)
7
+
8
+ http://www.cocos2d-x.org
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+ ****************************************************************************/
28
+ export declare const _atlasLoader: {
29
+ spAtlasFile: any;
30
+ setAtlasFile: (spAtlasFile: any) => void;
31
+ load: (line: any) => any;
32
+ unload: () => void;
33
+ };
34
+ /**
35
+ * The event type of spine skeleton animation. It contains event types: START(0), END(1), COMPLETE(2), EVENT(3).
36
+ * @constant
37
+ * @type {{START: number, END: number, COMPLETE: number, EVENT: number}}
38
+ */
39
+ export declare const ANIMATION_EVENT_TYPE: {
40
+ START: number;
41
+ INTERRUPT: number;
42
+ END: number;
43
+ DISPOSE: number;
44
+ COMPLETE: number;
45
+ EVENT: number;
46
+ };
47
+ export declare const TrackEntryListeners: {
48
+ (startListener?: any, endListener?: any, completeListener?: any, eventListener?: any, interruptListener?: any, disposeListener?: any): void;
49
+ getListeners(entry: any): any;
50
+ };
51
+ /**
52
+ * The skeleton animation of It updates animation's state and skeleton's world transform.
53
+ * @class
54
+ * @extends Skeleton
55
+ * @example
56
+ * var spineBoy = new SkeletonAnimation('res/skeletons/spineboy.json', 'res/skeletons/spineboy.atlas');
57
+ * this.addChild(spineBoy, 4);
58
+ */
59
+ export declare class SkeletonAnimation extends CCSkeleton {
60
+ init(): boolean;
61
+ setAnimationStateData(stateData: AnimationStateData): void;
62
+ setMix(fromAnimation: Animation, toAnimation: Animation, duration: number): void;
63
+ setAnimationListener(target: any, callback: Function): void;
64
+ setAnimation(trackIndex: number, name: string, loop: boolean): import("@esotericsoftware/spine-core").TrackEntry;
65
+ addAnimation(trackIndex: number, name: string, loop: boolean, delay?: number): import("@esotericsoftware/spine-core").TrackEntry;
66
+ findAnimation(name: string): Animation;
67
+ getCurrent(trackIndex: number): import("@esotericsoftware/spine-core").TrackEntry;
68
+ clearTracks(): void;
69
+ clearTrack(trackIndex: number): void;
70
+ update(dt: number): void;
71
+ setStartListener(listener: Function): void;
72
+ setInterruptListener(listener: Function): void;
73
+ setEndListener(listener: Function): void;
74
+ setDisposeListener(listener: Function): void;
75
+ setCompleteListener(listener: Function): void;
76
+ setEventListener(listener: Function): void;
77
+ setTrackStartListener(entry: any, listener: Function): void;
78
+ setTrackInterruptListener(entry: any, listener: Function): void;
79
+ setTrackEndListener(entry: any, listener: Function): void;
80
+ setTrackDisposeListener(entry: any, listener: Function): void;
81
+ setTrackCompleteListener(entry: any, listener: Function): void;
82
+ setTrackEventListener(entry: any, listener: Function): void;
83
+ getState(): AnimationState;
84
+ static createWithJsonFile(skeletonDataFile: any, atlasFile: any, scale?: any): SkeletonAnimation;
85
+ static createWithBinaryFile(skeletonDataFile: any, atlasFile: any, scale?: any): SkeletonAnimation;
86
+ }
87
+ //# sourceMappingURL=CCSkeletonAnimation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CCSkeletonAnimation.d.ts","sourceRoot":"","sources":["../../../src/spine/spine-cocos/CCSkeletonAnimation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,cAAc,EACd,kBAAkB,EAKnB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;8EAwB8E;AAE9E,eAAO,MAAM,YAAY;;;;;CAaxB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;CAOhC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;CAiB/B,CAAA;AAiED;;;;;;;GAOG;AAEH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,IAAI,IAAI,OAAO;IAOf,qBAAqB,CAAC,SAAS,EAAE,kBAAkB;IAOnD,MAAM,CAAC,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM;IAIzE,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAMpD,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAS5D,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM;IAU5E,aAAa,CAAC,IAAI,EAAE,MAAM;IAI1B,UAAU,CAAC,UAAU,EAAE,MAAM;IAI7B,WAAW;IAIX,UAAU,CAAC,UAAU,EAAE,MAAM;IAI7B,MAAM,CAAC,EAAE,EAAE,MAAM;IAcjB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ;IAInC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ;IAIvC,cAAc,CAAC,QAAQ,EAAE,QAAQ;IAIjC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ;IAIrC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ;IAItC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ;IAInC,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAIpD,yBAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAIxD,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAIlD,uBAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAItD,wBAAwB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAIvD,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ;IAIpD,QAAQ;IAIR,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG;IAI5E,MAAM,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG;CAc/E"}
@@ -1,5 +1,6 @@
1
- import * as spine from '@esotericsoftware/spine-core';
2
- import { Skeleton } from './CCSkeleton';
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ import { AnimationState, AnimationStateData, AtlasAttachmentLoader, Physics, SkeletonBinary, TextureAtlas, } from '@esotericsoftware/spine-core';
3
+ import { CCSkeleton } from './CCSkeleton';
3
4
  import { SkeletonTexture } from './CCSkeletonTexture';
4
5
  /****************************************************************************
5
6
  Copyright (c) 2011-2012 cocos2d-x.org
@@ -34,7 +35,7 @@ export const _atlasLoader = {
34
35
  load: function (line) {
35
36
  const texturePath = cc.path.join(cc.path.dirname(this.spAtlasFile), line);
36
37
  const texture = cc.textureCache.addImage(texturePath);
37
- const tex = new SkeletonTexture({ width: texture.getPixelsWide(), height: texture.getPixelsHigh() });
38
+ const tex = new SkeletonTexture();
38
39
  tex.setRealTexture(texture);
39
40
  return tex;
40
41
  },
@@ -45,7 +46,7 @@ export const _atlasLoader = {
45
46
  * @constant
46
47
  * @type {{START: number, END: number, COMPLETE: number, EVENT: number}}
47
48
  */
48
- const ANIMATION_EVENT_TYPE = {
49
+ export const ANIMATION_EVENT_TYPE = {
49
50
  START: 0,
50
51
  INTERRUPT: 1,
51
52
  END: 2,
@@ -53,7 +54,7 @@ const ANIMATION_EVENT_TYPE = {
53
54
  COMPLETE: 4,
54
55
  EVENT: 5,
55
56
  };
56
- const TrackEntryListeners = function (startListener, endListener, completeListener, eventListener, interruptListener, disposeListener) {
57
+ export const TrackEntryListeners = function (startListener, endListener, completeListener, eventListener, interruptListener, disposeListener) {
57
58
  this.startListener = startListener || null;
58
59
  this.endListener = endListener || null;
59
60
  this.completeListener = completeListener || null;
@@ -121,71 +122,42 @@ TrackEntryListeners.getListeners = function (entry) {
121
122
  return entry.listener;
122
123
  };
123
124
  /**
124
- * The skeleton animation of spine. It updates animation's state and skeleton's world transform.
125
+ * The skeleton animation of It updates animation's state and skeleton's world transform.
125
126
  * @class
126
127
  * @extends Skeleton
128
+ * @example
129
+ * var spineBoy = new SkeletonAnimation('res/skeletons/spineboy.json', 'res/skeletons/spineboy.atlas');
130
+ * this.addChild(spineBoy, 4);
127
131
  */
128
- export class SkeletonAnimation extends Skeleton {
129
- _state = null;
130
- _ownsAnimationStateData = false;
131
- _listener = null;
132
- constructor(skeletonDataFile, atlasFile, scale) {
133
- super(skeletonDataFile, atlasFile, scale);
132
+ export class SkeletonAnimation extends CCSkeleton {
133
+ init() {
134
+ super.init();
134
135
  this._ownsAnimationStateData = true;
135
- this.setAnimationStateData(new spine.AnimationStateData(this._skeleton.data));
136
+ this.setAnimationStateData(new AnimationStateData(this._skeleton.data));
137
+ return true;
136
138
  }
137
- /**
138
- * Sets animation state data to SkeletonAnimation.
139
- * @param {spine.AnimationStateData} stateData
140
- */
141
139
  setAnimationStateData(stateData) {
142
- const state = new spine.AnimationState(stateData);
140
+ const state = new AnimationState(stateData);
143
141
  this._listener = new TrackEntryListeners();
144
142
  state.addListener(this._listener);
145
143
  this._state = state;
146
144
  }
147
- /**
148
- * Mix applies all keyframe values, interpolated for the specified time and mixed with the current values.
149
- * @param {String} fromAnimation
150
- * @param {String} toAnimation
151
- * @param {Number} duration
152
- */
153
145
  setMix(fromAnimation, toAnimation, duration) {
154
146
  this._state.data.setMixWith(fromAnimation, toAnimation, duration);
155
147
  }
156
- /**
157
- * Sets event listener of SkeletonAnimation.
158
- * @param {Object} target
159
- * @param {Function} callback
160
- */
161
148
  setAnimationListener(target, callback) {
162
149
  this._listener.callbackTarget = target;
163
150
  this._listener.callback = callback;
164
151
  this._listener.skeletonNode = this;
165
152
  }
166
- /**
167
- * Set the current animation. Any queued animations are cleared.
168
- * @param {Number} trackIndex
169
- * @param {String} name
170
- * @param {Boolean} loop
171
- * @returns {spine.TrackEntry|null}
172
- */
173
153
  setAnimation(trackIndex, name, loop) {
174
154
  const animation = this._skeleton.data.findAnimation(name);
175
155
  if (!animation) {
176
- cc.log(`Spine: Animation not found: ${name}`);
156
+ cc.log(`Spine: Animation not found: ${name}/${this._skeleton.data.animations.map((a) => a.name)} `);
177
157
  return null;
178
158
  }
179
159
  return this._state.setAnimationWith(trackIndex, animation, loop);
180
160
  }
181
- /**
182
- * Adds an animation to be played delay seconds after the current or last queued animation.
183
- * @param {Number} trackIndex
184
- * @param {String} name
185
- * @param {Boolean} loop
186
- * @param {Number} [delay=0]
187
- * @returns {spine.TrackEntry|null}
188
- */
189
161
  addAnimation(trackIndex, name, loop, delay) {
190
162
  delay = delay == null ? 0 : delay;
191
163
  const animation = this._skeleton.data.findAnimation(name);
@@ -195,75 +167,40 @@ export class SkeletonAnimation extends Skeleton {
195
167
  }
196
168
  return this._state.addAnimationWith(trackIndex, animation, loop, delay);
197
169
  }
198
- /**
199
- * Find animation with specified name
200
- * @param {String} name
201
- * @returns {spine.Animation|null}
202
- */
203
170
  findAnimation(name) {
204
171
  return this._skeleton.data.findAnimation(name);
205
172
  }
206
- /**
207
- * Returns track entry by trackIndex.
208
- * @param trackIndex
209
- * @returns {spine.TrackEntry|null}
210
- */
211
173
  getCurrent(trackIndex) {
212
174
  return this._state.getCurrent(trackIndex);
213
175
  }
214
- /**
215
- * Clears all tracks of animation state.
216
- */
217
176
  clearTracks() {
218
177
  this._state.clearTracks();
219
178
  }
220
- /**
221
- * Clears track of animation state by trackIndex.
222
- * @param {Number} trackIndex
223
- */
224
179
  clearTrack(trackIndex) {
225
180
  this._state.clearTrack(trackIndex);
226
181
  }
227
- /**
228
- * Update will be called automatically every frame if "scheduleUpdate" is called when the node is "live".
229
- * It updates animation's state and skeleton's world transform.
230
- * @param {Number} dt Delta time since last update
231
- * @override
232
- */
233
182
  update(dt) {
234
183
  super.update(dt);
235
184
  dt *= this._timeScale;
236
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.contentDirty);
185
+ if (this._renderCmd && typeof this._renderCmd.setDirtyFlag === 'function') {
186
+ this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.contentDirty);
187
+ }
237
188
  this._state.update(dt);
238
189
  this._state.apply(this._skeleton);
239
- this._skeleton.updateWorldTransform(true);
240
- this._renderCmd._updateChild();
190
+ this._skeleton.updateWorldTransform(Physics.pose);
191
+ if (this._renderCmd && typeof this._renderCmd._updateChild === 'function') {
192
+ this._renderCmd._updateChild();
193
+ }
241
194
  }
242
- /**
243
- * Set the start event listener.
244
- * @param {function} listener
245
- */
246
195
  setStartListener(listener) {
247
196
  this._listener.startListener = listener;
248
197
  }
249
- /**
250
- * Set the interrupt listener
251
- * @param {function} listener
252
- */
253
198
  setInterruptListener(listener) {
254
199
  this._listener.interruptListener = listener;
255
200
  }
256
- /**
257
- * Set the end event listener.
258
- * @param {function} listener
259
- */
260
201
  setEndListener(listener) {
261
202
  this._listener.endListener = listener;
262
203
  }
263
- /**
264
- * Set the dispose listener
265
- * @param {function} listener
266
- */
267
204
  setDisposeListener(listener) {
268
205
  this._listener.disposeListener = listener;
269
206
  }
@@ -294,18 +231,21 @@ export class SkeletonAnimation extends Skeleton {
294
231
  getState() {
295
232
  return this._state;
296
233
  }
297
- /**
298
- * Creates a skeleton animation object.
299
- * @deprecated since v3.0, please use new SkeletonAnimation(skeletonDataFile, atlasFile, scale) instead.
300
- * @param {spine.SkeletonData|String} skeletonDataFile
301
- * @param {String|spine.Atlas|spine.SkeletonData} atlasFile atlas filename or atlas data or owns SkeletonData
302
- * @param {Number} [scale]
303
- * @returns {SkeletonAnimation}
304
- */
305
234
  static createWithJsonFile(skeletonDataFile, atlasFile, scale) {
306
235
  return new SkeletonAnimation(skeletonDataFile, atlasFile, scale);
307
236
  }
308
- static create(skeletonDataFile, atlasFile, scale) {
309
- return new SkeletonAnimation(skeletonDataFile, atlasFile, scale);
237
+ static createWithBinaryFile(skeletonDataFile, atlasFile, scale) {
238
+ const dataTex = cc.loader.getRes(atlasFile);
239
+ _atlasLoader.setAtlasFile(atlasFile);
240
+ const atlas = new TextureAtlas(dataTex);
241
+ for (const page of atlas.pages) {
242
+ const texture = _atlasLoader.load(page.name);
243
+ page.setTexture(texture);
244
+ }
245
+ const attachmentLoader = new AtlasAttachmentLoader(atlas);
246
+ const skeletonBinaryReader = new SkeletonBinary(attachmentLoader);
247
+ const skeletonBinary = cc.loader.getRes(skeletonDataFile);
248
+ const skeletonData = skeletonBinaryReader.readSkeletonData(skeletonBinary);
249
+ return new SkeletonAnimation(skeletonData, true, scale);
310
250
  }
311
251
  }
@@ -0,0 +1,28 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2013-2014 Chukong Technologies Inc.
3
+
4
+ http://www.cocos2d-x.org
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
+ ****************************************************************************/
24
+ export declare const CanvasRenderCmd: {
25
+ (renderableObject: any): void;
26
+ prototype: any;
27
+ };
28
+ //# sourceMappingURL=CCSkeletonCanvasRenderCmd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CCSkeletonCanvasRenderCmd.d.ts","sourceRoot":"","sources":["../../../src/spine/spine-cocos/CCSkeletonCanvasRenderCmd.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;8EAsB8E;AAI9E,eAAO,MAAM,eAAe;;;CAG3B,CAAA"}