@safe-engine/cocos 2.2.8 → 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 (104) hide show
  1. package/@types/index.d.ts +0 -59
  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/collider/CollideComponent.d.ts +21 -3
  6. package/dist/collider/CollideComponent.d.ts.map +1 -1
  7. package/dist/core/NodeComp.d.ts +1 -1
  8. package/dist/core/NodeComp.d.ts.map +1 -1
  9. package/dist/dragonbones/DragonBonesComp.d.ts +4 -6
  10. package/dist/dragonbones/DragonBonesComp.d.ts.map +1 -1
  11. package/dist/dragonbones/DragonBonesComp.js +15 -13
  12. package/dist/dragonbones/DragonBonesSystem.d.ts +1 -1
  13. package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
  14. package/dist/dragonbones/DragonBonesSystem.js +42 -35
  15. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts +87 -0
  16. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts.map +1 -0
  17. package/dist/dragonbones/db-cocos/CocosArmatureDisplay.js +240 -0
  18. package/dist/dragonbones/db-cocos/CocosFactory.d.ts +128 -0
  19. package/dist/dragonbones/db-cocos/CocosFactory.d.ts.map +1 -0
  20. package/dist/dragonbones/db-cocos/CocosFactory.js +190 -0
  21. package/dist/dragonbones/db-cocos/CocosSlot.d.ts +49 -0
  22. package/dist/dragonbones/db-cocos/CocosSlot.d.ts.map +1 -0
  23. package/dist/dragonbones/db-cocos/CocosSlot.js +368 -0
  24. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts +53 -0
  25. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts.map +1 -0
  26. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.js +121 -0
  27. package/dist/dragonbones/index.d.ts +0 -1
  28. package/dist/dragonbones/index.d.ts.map +1 -1
  29. package/dist/dragonbones/index.js +0 -1
  30. package/dist/polyfills.d.ts +1 -1
  31. package/dist/polyfills.d.ts.map +1 -1
  32. package/dist/polyfills.js +1 -2
  33. package/dist/render/RenderComponent.d.ts.map +1 -1
  34. package/dist/render/RenderComponent.js +1 -0
  35. package/dist/render/RenderSystem.d.ts.map +1 -1
  36. package/dist/render/RenderSystem.js +34 -2
  37. package/dist/richtext/RichTextComp.js +1 -1
  38. package/dist/spine/SpineSkeleton.d.ts +5 -3
  39. package/dist/spine/SpineSkeleton.d.ts.map +1 -1
  40. package/dist/spine/SpineSkeleton.js +12 -5
  41. package/dist/spine/SpineSystem.d.ts +1 -2
  42. package/dist/spine/SpineSystem.d.ts.map +1 -1
  43. package/dist/spine/SpineSystem.js +22 -24
  44. package/dist/spine/index.d.ts +0 -1
  45. package/dist/spine/index.d.ts.map +1 -1
  46. package/dist/spine/index.js +14 -2
  47. package/dist/spine/spine-cocos/CCSkeleton.d.ts +86 -0
  48. package/dist/spine/spine-cocos/CCSkeleton.d.ts.map +1 -0
  49. package/dist/spine/{CCSkeleton.js → spine-cocos/CCSkeleton.js} +39 -128
  50. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts +87 -0
  51. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts.map +1 -0
  52. package/dist/spine/{CCSkeletonAnimation.js → spine-cocos/CCSkeletonAnimation.js} +37 -97
  53. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts +28 -0
  54. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
  55. package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.js +224 -0
  56. package/dist/spine/{CCSkeletonTexture.d.ts → spine-cocos/CCSkeletonTexture.d.ts} +1 -1
  57. package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts.map +1 -0
  58. package/dist/spine/{CCSkeletonTexture.js → spine-cocos/CCSkeletonTexture.js} +5 -5
  59. package/dist/spine/spine-cocos/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
  60. package/dist/spine/{CCSkeletonWebGLRenderCmd.js → spine-cocos/CCSkeletonWebGLRenderCmd.js} +13 -13
  61. package/package.json +5 -6
  62. package/dist/core/index.d.ts +0 -6
  63. package/dist/core/index.d.ts.map +0 -1
  64. package/dist/core/index.js +0 -5
  65. package/dist/dragonbones/PixiDragonBonesSprite.d.ts +0 -19
  66. package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +0 -1
  67. package/dist/dragonbones/PixiDragonBonesSprite.js +0 -75
  68. package/dist/gworld/EnhancedComponent.d.ts +0 -22
  69. package/dist/gworld/EnhancedComponent.d.ts.map +0 -1
  70. package/dist/gworld/EnhancedComponent.js +0 -44
  71. package/dist/gworld/NodeComp.d.ts +0 -153
  72. package/dist/gworld/NodeComp.d.ts.map +0 -1
  73. package/dist/gworld/NodeComp.js +0 -337
  74. package/dist/gworld/NodePool.d.ts +0 -9
  75. package/dist/gworld/NodePool.d.ts.map +0 -1
  76. package/dist/gworld/NodePool.js +0 -23
  77. package/dist/gworld/Scene.d.ts +0 -5
  78. package/dist/gworld/Scene.d.ts.map +0 -1
  79. package/dist/gworld/Scene.js +0 -14
  80. package/dist/gworld/decorator.d.ts +0 -8
  81. package/dist/gworld/decorator.d.ts.map +0 -1
  82. package/dist/gworld/decorator.js +0 -12
  83. package/dist/gworld/index.d.ts +0 -8
  84. package/dist/gworld/index.d.ts.map +0 -1
  85. package/dist/gworld/index.js +0 -14
  86. package/dist/render/TiledSprite.d.ts +0 -13
  87. package/dist/render/TiledSprite.d.ts.map +0 -1
  88. package/dist/render/TiledSprite.js +0 -69
  89. package/dist/safex.d.ts +0 -10
  90. package/dist/safex.d.ts.map +0 -1
  91. package/dist/safex.js +0 -1
  92. package/dist/spine/CCSkeleton.d.ts +0 -189
  93. package/dist/spine/CCSkeleton.d.ts.map +0 -1
  94. package/dist/spine/CCSkeletonAnimation.d.ts +0 -146
  95. package/dist/spine/CCSkeletonAnimation.d.ts.map +0 -1
  96. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +0 -2
  97. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +0 -1
  98. package/dist/spine/CCSkeletonCanvasRenderCmd.js +0 -228
  99. package/dist/spine/CCSkeletonTexture.d.ts.map +0 -1
  100. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +0 -1
  101. package/dist/spine/PixiSpineSprite.d.ts +0 -19
  102. package/dist/spine/PixiSpineSprite.d.ts.map +0 -1
  103. package/dist/spine/PixiSpineSprite.js +0 -72
  104. /package/dist/spine/{CCSkeletonWebGLRenderCmd.d.ts → spine-cocos/CCSkeletonWebGLRenderCmd.d.ts} +0 -0
@@ -2,7 +2,6 @@ import { EventTypes } from 'entityx-ts';
2
2
  import { NodeComp } from '../core/NodeComp';
3
3
  import { BLUE, RED } from '../polyfills';
4
4
  import { GraphicsRender, MaskRender, MotionStreakComp, NodeRender, ParticleComp, SpriteRender, TiledMap } from './RenderComponent';
5
- import { TiledSprite } from './TiledSprite';
6
5
  export var SpriteTypes;
7
6
  (function (SpriteTypes) {
8
7
  SpriteTypes[SpriteTypes["SIMPLE"] = 0] = "SIMPLE";
@@ -12,6 +11,39 @@ export var SpriteTypes;
12
11
  SpriteTypes[SpriteTypes["MESH"] = 4] = "MESH";
13
12
  SpriteTypes[SpriteTypes["ANIMATION"] = 5] = "ANIMATION";
14
13
  })(SpriteTypes || (SpriteTypes = {}));
14
+ function createTiledSprite(src, totalW, totalH) {
15
+ // tạo sprite từ input
16
+ const tileSprite = new cc.Sprite(src);
17
+ // lấy kích thước gốc của texture
18
+ const frame = tileSprite.getSpriteFrame();
19
+ const tileW = frame ? frame.getRect().width : tileSprite.getContentSize().width;
20
+ const tileH = frame ? frame.getRect().height : tileSprite.getContentSize().height;
21
+ // tạo renderTexture với kích thước cần phủ
22
+ const rt = new cc.RenderTexture(totalW, totalH);
23
+ rt.beginWithClear(0, 0, 0, 0);
24
+ const drawSprite = new cc.Sprite(tileSprite.getTexture());
25
+ // if (frame) {
26
+ // drawSprite.setSpriteFrame(frame)
27
+ // }
28
+ drawSprite.setAnchorPoint(0, 0);
29
+ // số tile theo trục x,y
30
+ const cols = Math.ceil(totalW / tileW);
31
+ const rows = Math.ceil(totalH / tileH);
32
+ for (let r = 0; r < rows; r++) {
33
+ for (let c = 0; c < cols; c++) {
34
+ const s = new cc.Sprite(frame);
35
+ s.setAnchorPoint(0, 0);
36
+ s.setPosition(c * tileW, r * tileH);
37
+ s.visit(rt);
38
+ }
39
+ }
40
+ rt.end();
41
+ const finalSprite = rt.sprite;
42
+ finalSprite.setFlippedY(true); // RenderTexture bị lật
43
+ finalSprite.setAnchorPoint(0, 0);
44
+ finalSprite.setContentSize(cc.size(totalW, totalH));
45
+ return new cc.Sprite(finalSprite.texture);
46
+ }
15
47
  export class RenderSystem {
16
48
  configure(event_manager) {
17
49
  event_manager.subscribe(EventTypes.ComponentAdded, NodeRender, this.onAddNodeRender);
@@ -35,7 +67,7 @@ export class RenderSystem {
35
67
  // console.log('frame', spriteFrame, frame)
36
68
  let node;
37
69
  if (tiledSize) {
38
- node = new TiledSprite({ texture: spriteFrame, width: tiledSize.width, height: tiledSize.height });
70
+ node = createTiledSprite(spriteFrame, tiledSize.width, tiledSize.height);
39
71
  }
40
72
  else if (capInsets) {
41
73
  const rect = cc.rect(...capInsets);
@@ -22,7 +22,7 @@ export class RichTextComp extends ComponentX {
22
22
  // console.log('richText', richText, (ccui as any).RichElementCustomNode)
23
23
  const label = new ccui.Text(text, fontName, fontSize);
24
24
  label.enableOutline(cc.hexToColor(style.outline.color), style.outline.width || 3);
25
- const customElem = new ccui.RichElementCustomNode.create(1, cc.color(255, 0, 0), 255, label);
25
+ const customElem = ccui.RichElementCustomNode.create(1, cc.color(255, 0, 0), 255, label);
26
26
  this.node.instance.pushBackElement(customElem);
27
27
  }
28
28
  else {
@@ -1,5 +1,5 @@
1
1
  import { BaseComponentProps, ComponentX } from '..';
2
- import { PixiSpineSprite } from './PixiSpineSprite';
2
+ import { SkeletonAnimation } from './spine-cocos/CCSkeletonAnimation';
3
3
  export interface SpineData {
4
4
  atlas: string;
5
5
  skeleton: string;
@@ -11,9 +11,11 @@ interface SpineSkeletonProps {
11
11
  animation?: string;
12
12
  timeScale?: number;
13
13
  loop?: boolean;
14
+ onAnimationComplete?: any;
14
15
  }
15
- export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps & BaseComponentProps<SpineSkeleton>, cc.Node> {
16
- spine: PixiSpineSprite;
16
+ export declare class SpineSkeleton extends ComponentX<SpineSkeletonProps & BaseComponentProps<SpineSkeleton>, SkeletonAnimation> {
17
+ set scaleX(flip: number);
18
+ getAnimationName(): string;
17
19
  setAnimation(name: string, loop?: boolean): void;
18
20
  }
19
21
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"SpineSkeleton.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSkeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAU,MAAM,IAAI,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;IAC5G,KAAK,EAAE,eAAe,CAAA;IAEtB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAO;CAYvC"}
1
+ {"version":3,"file":"SpineSkeleton.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSkeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAU,MAAM,IAAI,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErE,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,mBAAmB,CAAC,MAAA;CACrB;AACD,qBAAa,aAAc,SAAQ,UAAU,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IACtH,IAAI,MAAM,CAAC,IAAI,EAAE,MAAM,EAGtB;IACD,gBAAgB;IAIhB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ;CAYxC"}
@@ -1,10 +1,17 @@
1
1
  import { ComponentX, render } from '..';
2
2
  export class SpineSkeleton extends ComponentX {
3
- spine;
4
- setAnimation(name, loop = true) {
5
- const skel = this.spine;
6
- if (skel._armatureDisplay.state.setAnimation) {
7
- skel._armatureDisplay.state.setAnimation(0, name, loop);
3
+ set scaleX(flip) {
4
+ const skel = this.node.instance;
5
+ skel._skeleton.scaleX = flip;
6
+ }
7
+ getAnimationName() {
8
+ const skel = this.node.instance;
9
+ return skel.getState().getCurrent(0).animation.name;
10
+ }
11
+ setAnimation(name, loop = false) {
12
+ const skel = this.node.instance;
13
+ if (skel.setAnimation) {
14
+ skel.setAnimation(0, name, loop);
8
15
  }
9
16
  }
10
17
  }
@@ -1,7 +1,6 @@
1
- import { EntityManager, EventManager, System } from 'entityx-ts';
1
+ import { EventManager, System } from 'entityx-ts';
2
2
  export declare class SpineSystem implements System {
3
3
  configure(event_manager: EventManager): void;
4
4
  private onAddSpineSkeleton;
5
- update(entities: EntityManager): void;
6
5
  }
7
6
  //# sourceMappingURL=SpineSystem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpineSystem.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAMlG,qBAAa,WAAY,YAAW,MAAM;IACxC,SAAS,CAAC,aAAa,EAAE,YAAY;IAGrC,OAAO,CAAC,kBAAkB,CAiBzB;IACD,MAAM,CAAC,QAAQ,EAAE,aAAa;CAS/B"}
1
+ {"version":3,"file":"SpineSystem.d.ts","sourceRoot":"","sources":["../../src/spine/SpineSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAMnF,qBAAa,WAAY,YAAW,MAAM;IACxC,SAAS,CAAC,aAAa,EAAE,YAAY;IAGrC,OAAO,CAAC,kBAAkB,CAuBzB;CAUF"}
@@ -1,36 +1,34 @@
1
1
  import { EventTypes } from 'entityx-ts';
2
2
  import { NodeComp } from '../core/NodeComp';
3
- import { PixiSpineSprite } from './PixiSpineSprite';
4
3
  import { SpineSkeleton } from './SpineSkeleton';
4
+ import { SkeletonAnimation } from './spine-cocos/CCSkeletonAnimation';
5
5
  export class SpineSystem {
6
6
  configure(event_manager) {
7
7
  event_manager.subscribe(EventTypes.ComponentAdded, SpineSkeleton, this.onAddSpineSkeleton);
8
8
  }
9
9
  onAddSpineSkeleton = async ({ entity, component: spineComp }) => {
10
- const { data, skin, animation, loop = true, timeScale = 1 } = spineComp.props;
11
- const { atlas, skeleton, texture } = data;
10
+ const { data, skin, animation, loop = true, timeScale = 1, onAnimationComplete } = spineComp.props;
11
+ const { atlas: argAtlasFile, skeleton } = data;
12
12
  // console.log('spineComp', data)
13
- const spine = new PixiSpineSprite({
14
- skeleton,
15
- atlas,
16
- texture,
17
- animationName: animation,
18
- loop,
19
- skin,
20
- timeScale,
21
- });
22
- const node = new cc.Node();
23
- node.addChild(spine);
24
- spineComp.spine = spine;
13
+ let node;
14
+ if (skeleton.endsWith('.json')) {
15
+ node = SkeletonAnimation.createWithJsonFile(skeleton, argAtlasFile, timeScale);
16
+ }
17
+ else {
18
+ node = SkeletonAnimation.createWithBinaryFile(skeleton, argAtlasFile, timeScale);
19
+ }
20
+ if (skin) {
21
+ node.setSkin(skin);
22
+ }
23
+ if (animation) {
24
+ node.setAnimation(0, animation, loop);
25
+ }
25
26
  spineComp.node = entity.assign(new NodeComp(node, entity));
27
+ if (onAnimationComplete) {
28
+ node.setCompleteListener((track, loopCount) => {
29
+ // console.log(track, loopCount)
30
+ onAnimationComplete(track, loopCount);
31
+ });
32
+ }
26
33
  };
27
- update(entities) {
28
- const animations = entities.entities_with_components(SpineSkeleton);
29
- animations.forEach((ett) => {
30
- const spine = ett.getComponent(SpineSkeleton);
31
- if (spine.node && spine.node.active) {
32
- spine.spine.updateTexture();
33
- }
34
- });
35
- }
36
34
  }
@@ -1,4 +1,3 @@
1
- export * from './PixiSpineSprite';
2
1
  export * from './SpineSkeleton';
3
2
  export declare function setupSpine(): void;
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spine/index.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,UAAU,SAEzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spine/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,UAAU,SAEzB"}
@@ -1,7 +1,19 @@
1
1
  import { GameWorld } from '..';
2
2
  import { SpineSystem } from './SpineSystem';
3
- export * from './PixiSpineSprite';
4
3
  export * from './SpineSkeleton';
5
4
  export function setupSpine() {
6
- GameWorld.Instance.addSystemAndUpdate(SpineSystem);
5
+ GameWorld.Instance.systems.addThenConfigure(SpineSystem);
7
6
  }
7
+ cc.loader.register(['skel'], {
8
+ TYPE: { skel: 'binary' },
9
+ load: function (realUrl, url, res, callback) {
10
+ cc.loader.loadBinary(url, function (err, data) {
11
+ // console.log('loadBinary Skeleton', realUrl, url, res, data, callback)
12
+ if (err) {
13
+ callback(err);
14
+ return;
15
+ }
16
+ callback(null, data);
17
+ });
18
+ },
19
+ });
@@ -0,0 +1,86 @@
1
+ import { AnimationState, Bone, Skeleton } from '@esotericsoftware/spine-core';
2
+ /****************************************************************************
3
+ Copyright (c) 2011-2012 cocos2d-x.org
4
+ Copyright (c) 2013-2014 Chukong Technologies Inc.
5
+ Copyright (c) 2014 Shengxiang Chen (Nero Chan)
6
+
7
+ http://www.cocos2d-x.org
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ ****************************************************************************/
27
+ /**
28
+ * The main namespace of Spine, all classes, functions, properties and constants of Spine are defined in this namespace
29
+ * @namespace
30
+ * @name gworld
31
+ */
32
+ /**
33
+ * <p>
34
+ * The skeleton of <br/>
35
+ * Skeleton has a reference to a SkeletonData and stores the state for skeleton instance,
36
+ * which consists of the current pose's bone SRT, slot colors, and which slot attachments are visible. <br/>
37
+ * Multiple skeletons can use the same SkeletonData (which includes all animations, skins, and attachments). <br/>
38
+ * </p>
39
+ * @class
40
+ * @extends cc.Node
41
+ */
42
+ export declare class CCSkeleton extends cc.Node {
43
+ _skeleton: Skeleton;
44
+ _rootBone: Bone;
45
+ _timeScale: number;
46
+ _debugSlots: boolean;
47
+ _debugBones: boolean;
48
+ _premultipliedAlpha: boolean;
49
+ _ownsSkeletonData: any;
50
+ _renderCmd: any;
51
+ _state: AnimationState;
52
+ _ownsAnimationStateData: boolean;
53
+ _listener: any;
54
+ constructor(skeletonDataFile?: any, atlasFile?: any, scale?: any);
55
+ _createRenderCmd(): any;
56
+ init(): boolean;
57
+ onEnter(): void;
58
+ onExit(): void;
59
+ setDebugSolots(enable: boolean): void;
60
+ setDebugBones(enable: boolean): void;
61
+ setDebugSlotsEnabled(enabled: boolean): void;
62
+ getDebugSlotsEnabled(): boolean;
63
+ setDebugBonesEnabled(enabled: boolean): void;
64
+ getDebugBonesEnabled(): boolean;
65
+ setTimeScale(scale: number): void;
66
+ getTimeScale(): number;
67
+ initWithArgs(skeletonDataFile: any, atlasFile: any, scale: any): void;
68
+ getBoundingBox(): cc.Rect;
69
+ updateWorldTransform(): void;
70
+ setToSetupPose(): void;
71
+ setBonesToSetupPose(): void;
72
+ setSlotsToSetupPose(): void;
73
+ findBone(boneName: string): Bone;
74
+ findSlot(slotName: string): import("@esotericsoftware/spine-core").Slot;
75
+ setSkin(skinName: string): void;
76
+ getAttachment(slotName: string, attachmentName: string): import("@esotericsoftware/spine-core").Attachment;
77
+ setAttachment(slotName: string, attachmentName: string): void;
78
+ setPremultipliedAlpha(premultiplied: boolean): void;
79
+ isPremultipliedAlpha(): boolean;
80
+ setSkeletonData(skeletonData: any, ownsSkeletonData: any): void;
81
+ getTextureAtlas(regionAttachment: any): any;
82
+ getBlendFunc(): any;
83
+ setBlendFunc(): void;
84
+ update(dt: any): void;
85
+ }
86
+ //# sourceMappingURL=CCSkeleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CCSkeleton.d.ts","sourceRoot":"","sources":["../../../src/spine/spine-cocos/CCSkeleton.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,IAAI,EAGJ,QAAQ,EAIT,MAAM,8BAA8B,CAAA;AAKrC;;;;;;;;;;;;;;;;;;;;;;;;8EAwB8E;AAE9E;;;;GAIG;AACH;;;;;;;;;GASG;AACH,qBAAa,UAAW,SAAQ,EAAE,CAAC,IAAI;IACrC,SAAS,EAAE,QAAQ,CAAO;IAC1B,SAAS,EAAE,IAAI,CAAO;IACtB,UAAU,SAAI;IACd,WAAW,UAAQ;IACnB,WAAW,UAAQ;IACnB,mBAAmB,UAAQ;IAC3B,iBAAiB,EAAE,GAAG,CAAO;IAC7B,UAAU,EAAE,GAAG,CAAA;IACf,MAAM,EAAE,cAAc,CAAA;IACtB,uBAAuB,UAAQ;IAC/B,SAAS,EAAE,GAAG,CAAA;gBAEF,gBAAgB,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG;IAWhE,gBAAgB;IAKhB,IAAI,IAAI,OAAO;IAMf,OAAO;IAKP,MAAM;IAKN,cAAc,CAAC,MAAM,EAAE,OAAO;IAI9B,aAAa,CAAC,MAAM,EAAE,OAAO;IAI7B,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC,oBAAoB;IAIpB,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC,oBAAoB;IAIpB,YAAY,CAAC,KAAK,EAAE,MAAM;IAI1B,YAAY;IAIZ,YAAY,CAAC,gBAAgB,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAiC9D,cAAc;IAkDd,oBAAoB;IAIpB,cAAc;IAId,mBAAmB;IAInB,mBAAmB;IAInB,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAIzB,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAIzB,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAItD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAItD,qBAAqB,CAAC,aAAa,EAAE,OAAO;IAI5C,oBAAoB;IAIpB,eAAe,CAAC,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG;IAiBxD,eAAe,CAAC,gBAAgB,EAAE,GAAG;IAIrC,YAAY;IAaZ,YAAY;IAIZ,MAAM,CAAC,EAAE,EAAE,GAAG;CAGf"}
@@ -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
  });