@eva/plugin-renderer-spine 1.2.2-alpha.1 → 1.2.2-alpha.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.
@@ -1,51 +1,14 @@
1
- import { Component } from '@eva/eva.js';
2
- import { ComponentChanged } from '@eva/eva.js';
3
- import { ContainerManager } from '@eva/plugin-renderer';
4
- import { DisplayObject } from 'pixi.js';
5
- import { Renderer } from '@eva/plugin-renderer';
6
- import { RendererManager } from '@eva/plugin-renderer';
7
- import { RendererSystem } from '@eva/plugin-renderer';
8
- import { UpdateParams } from '@eva/eva.js';
1
+ import { Spine as Spine_2 } from '@eva/spine-base';
2
+ import { SpineParams } from '@eva/spine-base';
3
+ import { SpineSystem as SpineSystem_2 } from '@eva/spine-base';
9
4
 
10
- export declare class Spine extends Component<SpineParams> {
11
- static componentName: string;
12
- resource: string;
13
- animationName: string;
14
- autoPlay: boolean;
15
- armature: any;
16
- destroied: boolean;
17
- addHandler: any;
18
- lastResource: string;
19
- init(obj?: SpineParams): void;
20
- onDestroy(): void;
21
- play(name?: string, loop?: boolean, track?: number): void;
22
- stop(track?: number): void;
23
- addAnimation(name?: string, delay?: number, loop?: boolean, track?: number): void;
24
- setMix(from: string, to: string, duration: number): void;
25
- getAnim(track?: number): any;
26
- setDefaultMix(duration: number): void;
27
- setAttachment(slotName: string, attachmentName: string): void;
28
- getBone(boneName: string): any;
5
+ export declare class Spine extends Spine_2 {
29
6
  }
30
7
 
31
- export declare interface SpineParams {
32
- resource: string;
33
- animationName?: string;
34
- autoPlay?: boolean;
35
- }
8
+ export { SpineParams }
36
9
 
37
- export declare class SpineSystem extends Renderer {
38
- static systemName: string;
39
- armatures: Record<number, DisplayObject>;
40
- renderSystem: RendererSystem;
41
- rendererManager: RendererManager;
42
- containerManager: ContainerManager;
10
+ export declare class SpineSystem extends SpineSystem_2 {
43
11
  init(): void;
44
- update(e: UpdateParams): void;
45
- componentChanged(changed: ComponentChanged): Promise<void>;
46
- add(changed: ComponentChanged, count?: number): Promise<void>;
47
- change(changed: ComponentChanged): void;
48
- remove(changed: ComponentChanged): Promise<void>;
49
12
  }
50
13
 
51
14
  export { }
@@ -1,6 +1,4 @@
1
- import { Component, resource, OBSERVER_TYPE, decorators } from '@eva/eva.js';
2
- import { RendererSystem, Renderer } from '@eva/plugin-renderer';
3
- import { type } from '@eva/inspector-decorator';
1
+ import { SpineSystem as SpineSystem$2, Spine as Spine$2 } from '@eva/spine-base';
4
2
  import { loaders, Texture, Rectangle, Sprite, Graphics, mesh, Matrix, Container, SCALE_MODES, utils, TransformBase, TransformStatic, DisplayObject, Polygon, BaseTexture } from 'pixi.js';
5
3
 
6
4
  /*! *****************************************************************************
@@ -30,168 +28,14 @@ function __extends$1(d, b) {
30
28
  extendStatics(d, b);
31
29
  function __() { this.constructor = d; }
32
30
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
33
- }
34
-
35
- function __decorate(decorators, target, key, desc) {
36
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
37
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
38
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
39
- return c > 3 && r && Object.defineProperty(target, key, r), r;
40
- }
41
-
42
- function __awaiter(thisArg, _arguments, P, generator) {
43
- return new (P || (P = Promise))(function (resolve, reject) {
44
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
47
- step((generator = generator.apply(thisArg, _arguments || [])).next());
48
- });
49
- }
50
-
51
- function __generator(thisArg, body) {
52
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
53
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
54
- function verb(n) { return function (v) { return step([n, v]); }; }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while (_) try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [op[0] & 2, t.value];
60
- switch (op[0]) {
61
- case 0: case 1: t = op; break;
62
- case 4: _.label++; return { value: op[1], done: false };
63
- case 5: _.label++; y = op[1]; op = [0]; continue;
64
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
65
- default:
66
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
67
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
68
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
69
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
70
- if (t[2]) _.ops.pop();
71
- _.trys.pop(); continue;
72
- }
73
- op = body.call(thisArg, _);
74
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
75
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
76
- }
77
31
  }
78
32
 
79
- var Spine = (function (_super) {
80
- __extends$1(Spine, _super);
81
- function Spine() {
82
- var _this = _super !== null && _super.apply(this, arguments) || this;
83
- _this.resource = '';
84
- _this.animationName = '';
85
- _this.autoPlay = true;
86
- return _this;
87
- }
88
- Spine.prototype.init = function (obj) {
89
- if (!obj)
90
- return;
91
- Object.assign(this, obj);
92
- if (this.autoPlay) {
93
- this.play(this.animationName);
94
- }
95
- };
96
- Spine.prototype.onDestroy = function () {
97
- this.destroied = true;
98
- };
99
- Spine.prototype.play = function (name, loop, track) {
100
- try {
101
- if (name)
102
- this.animationName = name;
103
- if (!this.armature) {
104
- }
105
- else {
106
- if (track === undefined) {
107
- track = 0;
108
- }
109
- this.armature.state.setAnimation(track, this.animationName, loop);
110
- }
111
- }
112
- catch (e) {
113
- console.log(e);
114
- }
115
- };
116
- Spine.prototype.stop = function (track) {
117
- if (!this.armature) {
118
- return;
119
- }
120
- if (track === undefined) {
121
- track = 0;
122
- }
123
- this.armature.state.setEmptyAnimation(track, 0);
124
- };
125
- Spine.prototype.addAnimation = function (name, delay, loop, track) {
126
- try {
127
- if (!this.armature) {
128
- }
129
- else {
130
- if (track === undefined) {
131
- track = 0;
132
- }
133
- this.armature.state.addAnimation(track, name, loop, delay);
134
- }
135
- }
136
- catch (e) {
137
- console.log(e);
138
- }
139
- };
140
- Spine.prototype.setMix = function (from, to, duration) {
141
- if (!this.armature) ;
142
- else {
143
- this.armature.stateData.setMix(from, to, duration);
144
- }
145
- };
146
- Spine.prototype.getAnim = function (track) {
147
- if (track === void 0) { track = 0; }
148
- try {
149
- if (!this.armature) {
150
- }
151
- else {
152
- return this.armature.state.tracks[track].animation.name;
153
- }
154
- }
155
- catch (e) {
156
- console.log(e);
157
- }
158
- };
159
- Spine.prototype.setDefaultMix = function (duration) {
160
- if (!this.armature) ;
161
- else {
162
- this.armature.stateData.defaultMix = duration;
163
- }
164
- };
165
- Spine.prototype.setAttachment = function (slotName, attachmentName) {
166
- if (!this.armature) {
167
- return;
168
- }
169
- this.armature.skeleton.setAttachment(slotName, attachmentName);
170
- };
171
- Spine.prototype.getBone = function (boneName) {
172
- if (!this.armature) {
173
- return;
174
- }
175
- return this.armature.skeleton.findBone(boneName);
176
- };
177
- Spine.componentName = 'Spine';
178
- __decorate([
179
- type('string')
180
- ], Spine.prototype, "resource", void 0);
181
- __decorate([
182
- type('string')
183
- ], Spine.prototype, "animationName", void 0);
184
- __decorate([
185
- type('boolean')
186
- ], Spine.prototype, "autoPlay", void 0);
187
- return Spine;
188
- }(Component));
189
- var Spine$1 = Spine;
33
+ // https://github.com/pixijs/spine/tree/pixi4
190
34
 
191
- const VERSION = '4.8.9';
192
- const loader = loaders.shared;
35
+ var VERSION = '4.8.9';
36
+ var loader = loaders.shared;
193
37
 
194
- const PIXI = {
38
+ var PIXI = {
195
39
  Texture,
196
40
  Rectangle,
197
41
  Sprite,
@@ -7826,308 +7670,27 @@ var pixi_spine;
7826
7670
  }
7827
7671
  })(pixi_spine || (pixi_spine = {}));
7828
7672
 
7829
- var pixispine = pixi_spine;
7830
-
7831
- var texCache = {};
7832
- function cacheImage(data) {
7833
- var oldImg = data.image;
7834
- return {
7835
- tex: Texture.from(oldImg),
7836
- count: 0,
7837
- };
7838
- }
7839
- function retainTexture(name, data) {
7840
- var cache = texCache[name];
7841
- if (!cache) {
7842
- cache = cacheImage(data);
7843
- texCache[name] = cache;
7844
- }
7845
- cache.count++;
7846
- return cache.tex;
7847
- }
7848
- function getTexture(imageSrc, data) {
7849
- var cache = texCache[imageSrc];
7850
- if (!cache) {
7851
- cache = cacheImage(data);
7852
- texCache[imageSrc] = cache;
7853
- }
7854
- return cache.tex;
7855
- }
7856
- function releaseTexture(imageSrc) {
7857
- if (!imageSrc)
7858
- return;
7859
- setTimeout(function () {
7860
- var cache = texCache[imageSrc];
7861
- if (cache) {
7862
- cache.count--;
7863
- if (cache.count <= 0) {
7864
- if (cache.tex) {
7865
- cache.tex.destroy(true);
7866
- cache.tex = null;
7867
- }
7868
- delete texCache[imageSrc];
7869
- }
7870
- }
7871
- }, 100);
7872
- }
7673
+ var pixiSpine = pixi_spine;
7873
7674
 
7874
- var dataMap = {};
7875
- function createSpineData(name, data, scale) {
7876
- var spineData = null;
7877
- var img = getTexture(data.image.src, data);
7878
- new pixispine.core.TextureAtlas(data.atlas, function (line, callback) {
7879
- callback(img.baseTexture);
7880
- }, function (spineAtlas) {
7881
- if (spineAtlas) {
7882
- var attachmentLoader = new pixispine.core.AtlasAttachmentLoader(spineAtlas);
7883
- var spineJsonParser = new pixispine.core.SkeletonJson(attachmentLoader);
7884
- if (scale) {
7885
- spineJsonParser.scale = scale;
7886
- }
7887
- spineData = spineJsonParser.readSkeletonData(data.ske);
7888
- }
7889
- });
7890
- var obj = { spineData: spineData, ref: 0, imageSrc: data.image.src };
7891
- dataMap[name] = obj;
7892
- return obj;
7893
- }
7894
- resource.registerInstance('SPINE', function (info) {
7895
- return createSpineData(info.name, info.data, info.scale);
7896
- });
7897
- resource.registerDestroy('SPINE', function (info) {
7898
- if (info.instance) {
7899
- releaseTexture(info.data.image.src);
7900
- info.instance = null;
7901
- }
7902
- });
7903
- function getSpineData(res) {
7904
- return __awaiter(this, void 0, void 0, function () {
7905
- var data;
7906
- return __generator(this, function (_a) {
7907
- data = dataMap[res.name];
7908
- if (!data) {
7909
- if (res.complete) {
7910
- data = createSpineData(res.name, res.data, res.scale);
7911
- }
7912
- else if (!data) {
7913
- return [2];
7914
- }
7915
- }
7916
- retainTexture(res.data.image.src, res.data);
7917
- data.ref++;
7918
- return [2, data.spineData];
7919
- });
7920
- });
7921
- }
7922
- function releaseSpineData(resourceName, imageSrc) {
7923
- var data = dataMap[resourceName];
7924
- if (!data) {
7925
- return;
7926
- }
7927
- data.ref--;
7928
- if (data.ref <= 0) {
7929
- releaseTexture(imageSrc);
7930
- delete dataMap[resourceName];
7931
- }
7932
- }
7933
-
7934
- var MaxRetryCount = 20;
7935
7675
  var SpineSystem = (function (_super) {
7936
7676
  __extends$1(SpineSystem, _super);
7937
7677
  function SpineSystem() {
7938
- var _this = _super !== null && _super.apply(this, arguments) || this;
7939
- _this.armatures = {};
7940
- return _this;
7678
+ return _super !== null && _super.apply(this, arguments) || this;
7941
7679
  }
7942
7680
  SpineSystem.prototype.init = function () {
7943
- var _this = this;
7944
- this.renderSystem = this.game.getSystem(RendererSystem);
7945
- this.renderSystem.rendererManager.register(this);
7946
- this.game.canvas.addEventListener('webglcontextrestored', function () {
7947
- var objs = _this.game.gameObjects;
7948
- var toAdd = [];
7949
- for (var k in _this.armatures) {
7950
- var id = +k;
7951
- for (var i = 0; i < objs.length; ++i) {
7952
- var obj = objs[i];
7953
- if (obj.id === id) {
7954
- var sp = obj.getComponent(Spine$1);
7955
- if (sp) {
7956
- _this.remove({
7957
- type: OBSERVER_TYPE.REMOVE,
7958
- gameObject: obj,
7959
- component: sp,
7960
- componentName: Spine$1.componentName,
7961
- });
7962
- toAdd.push({
7963
- type: OBSERVER_TYPE.ADD,
7964
- gameObject: obj,
7965
- component: sp,
7966
- componentName: Spine$1.componentName,
7967
- });
7968
- }
7969
- break;
7970
- }
7971
- }
7972
- }
7973
- setTimeout(function () {
7974
- toAdd.forEach(function (obj) {
7975
- _this.add(obj);
7976
- });
7977
- }, 1000);
7978
- }, false);
7979
- };
7980
- SpineSystem.prototype.update = function (e) {
7981
- for (var key in this.armatures) {
7982
- this.armatures[key].update(e.deltaTime * 0.001);
7983
- this.armatures[key].updateTransform();
7984
- }
7985
- _super.prototype.update.call(this);
7986
- };
7987
- SpineSystem.prototype.componentChanged = function (changed) {
7988
- return __awaiter(this, void 0, void 0, function () {
7989
- return __generator(this, function (_a) {
7990
- if (changed.componentName === 'Spine') {
7991
- if (changed.type === OBSERVER_TYPE.ADD) {
7992
- this.add(changed);
7993
- }
7994
- else if (changed.type === OBSERVER_TYPE.CHANGE) {
7995
- switch (changed.prop.prop[0]) {
7996
- case 'resource':
7997
- this.change(changed);
7998
- break;
7999
- }
8000
- }
8001
- else if (changed.type === OBSERVER_TYPE.REMOVE) {
8002
- this.remove(changed);
8003
- }
8004
- }
8005
- return [2];
8006
- });
8007
- });
7681
+ _super.prototype.init.call(this, { pixiSpine: pixiSpine });
8008
7682
  };
8009
- SpineSystem.prototype.add = function (changed, count) {
8010
- return __awaiter(this, void 0, void 0, function () {
8011
- var component, res, spineData, container, armature, tran;
8012
- var _this = this;
8013
- return __generator(this, function (_a) {
8014
- switch (_a.label) {
8015
- case 0:
8016
- component = changed.component;
8017
- clearTimeout(component.addHandler);
8018
- return [4, resource.getResource(component.resource)];
8019
- case 1:
8020
- res = _a.sent();
8021
- return [4, getSpineData(res)];
8022
- case 2:
8023
- spineData = _a.sent();
8024
- if (!spineData) {
8025
- component.addHandler = setTimeout(function () {
8026
- if (!component.destroied) {
8027
- if (count === undefined) {
8028
- count = MaxRetryCount;
8029
- }
8030
- count--;
8031
- if (count > 0) {
8032
- _this.add(changed, count);
8033
- }
8034
- else {
8035
- console.log('retry exceed max times', component.resource);
8036
- }
8037
- }
8038
- }, 1000);
8039
- return [2];
8040
- }
8041
- this.remove(changed);
8042
- container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
8043
- if (!container) {
8044
- return [2];
8045
- }
8046
- component.lastResource = component.resource;
8047
- armature = new pixispine.Spine(spineData);
8048
- this.armatures[changed.gameObject.id] = armature;
8049
- if (changed.gameObject && changed.gameObject.transform) {
8050
- tran = changed.gameObject.transform;
8051
- armature.x = tran.size.width * tran.origin.x;
8052
- armature.y = tran.size.height * tran.origin.y;
8053
- }
8054
- container.addChildAt(armature, 0);
8055
- armature.update();
8056
- armature.updateTransform();
8057
- component.armature = armature;
8058
- if (component.autoPlay) {
8059
- try {
8060
- armature.state.setAnimation(0, component.animationName, true);
8061
- }
8062
- catch (e) {
8063
- console.log(e);
8064
- }
8065
- }
8066
- component.emit('loaded', { resource: component.resource });
8067
- armature.state.addListener({
8068
- start: function (track, event) {
8069
- component.emit('start', { track: track, name: track.animation.name });
8070
- },
8071
- complete: function (track, event) {
8072
- component.emit('complete', { track: track, name: track.animation.name });
8073
- },
8074
- interrupt: function (track, event) {
8075
- component.emit('interrupt', { track: track, name: track.animation.name });
8076
- },
8077
- end: function (track, event) {
8078
- component.emit('end', { track: track, name: track.animation.name });
8079
- },
8080
- event: function (track, event) {
8081
- component.emit('event', track, event);
8082
- },
8083
- });
8084
- return [2];
8085
- }
8086
- });
8087
- });
8088
- };
8089
- SpineSystem.prototype.change = function (changed) {
8090
- this.remove(changed);
8091
- this.add(changed);
8092
- };
8093
- SpineSystem.prototype.remove = function (changed) {
8094
- var _a, _b;
8095
- return __awaiter(this, void 0, void 0, function () {
8096
- var component, armature, container, res;
8097
- return __generator(this, function (_c) {
8098
- switch (_c.label) {
8099
- case 0:
8100
- component = changed.component;
8101
- clearTimeout(component.addHandler);
8102
- armature = this.armatures[changed.gameObject.id];
8103
- container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
8104
- if (container && armature) {
8105
- container.removeChild(armature);
8106
- }
8107
- if (!component.armature) return [3, 2];
8108
- component.armature.destroy({ children: true });
8109
- return [4, resource.getResource(component.lastResource)];
8110
- case 1:
8111
- res = _c.sent();
8112
- releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
8113
- _c.label = 2;
8114
- case 2:
8115
- component.armature = null;
8116
- delete this.armatures[changed.gameObject.id];
8117
- if (changed.type === OBSERVER_TYPE.CHANGE) ;
8118
- return [2];
8119
- }
8120
- });
8121
- });
8122
- };
8123
- SpineSystem.systemName = 'SpineSystem';
8124
- SpineSystem = __decorate([
8125
- decorators.componentObserver({
8126
- Spine: ['resource'],
8127
- })
8128
- ], SpineSystem);
8129
7683
  return SpineSystem;
8130
- }(Renderer));
7684
+ }(SpineSystem$2));
8131
7685
  var SpineSystem$1 = SpineSystem;
8132
7686
 
7687
+ var Spine = (function (_super) {
7688
+ __extends$1(Spine, _super);
7689
+ function Spine() {
7690
+ return _super !== null && _super.apply(this, arguments) || this;
7691
+ }
7692
+ return Spine;
7693
+ }(Spine$2));
7694
+ var Spine$1 = Spine;
7695
+
8133
7696
  export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-spine",
3
- "version": "1.2.2-alpha.1",
3
+ "version": "1.2.2-alpha.5",
4
4
  "description": "@eva/plugin-renderer-spine",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-spine.esm.js",
@@ -19,8 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.2.2-alpha.1",
23
- "@eva/eva.js": "1.2.2-alpha.1",
22
+ "@eva/plugin-renderer": "1.2.2-alpha.5",
23
+ "@eva/eva.js": "1.2.2-alpha.5",
24
+ "@eva/spine-base": "1.2.2-alpha.5",
24
25
  "pixi.js": "^4.8.7"
25
26
  }
26
27
  }