@safe-engine/cocos 2.6.3 → 2.6.5

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