@eva/spine-base 1.2.2-mini.1
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.
- package/README.md +6 -0
- package/dist/EVA.plugin.spineBase.js +705 -0
- package/dist/EVA.plugin.spineBase.min.js +1 -0
- package/dist/global.d.ts +6 -0
- package/dist/miniprogram.js +499 -0
- package/dist/spine-base.cjs.js +493 -0
- package/dist/spine-base.cjs.prod.js +1 -0
- package/dist/spine-base.d.ts +55 -0
- package/dist/spine-base.esm.js +488 -0
- package/index.js +7 -0
- package/package.json +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}var _EVA_IIFE_spineBase=function(t,e,n,r){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function i(t,e,n,r){var o,a=arguments.length,i=a<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(i=(a<3?o(i):a>3?o(e,n,i):o(e,n))||i);return a>3&&i&&Object.defineProperty(e,n,i),i}function s(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{c(r.next(t))}catch(t){a(t)}}function s(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,s)}c((r=r.apply(t,e||[])).next())}))}function c(t,e){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function u(t){return function(e,n){var r=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);r.key=n,r.type=t}}var m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.animationName="",e.autoPlay=!0,e}return a(e,t),e.prototype.init=function(t){t&&(_extends(this,t),this.autoPlay&&this.play(this.animationName))},e.prototype.onDestroy=function(){this.destroied=!0},e.prototype.play=function(t,e,n){try{t&&(this.animationName=t),this.armature&&(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,e))}catch(t){console.log(t)}},e.prototype.stop=function(t){this.armature&&(void 0===t&&(t=0),this.armature.state.setEmptyAnimation(t,0))},e.prototype.addAnimation=function(t,e,n,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,t,n,e))}catch(t){console.log(t)}},e.prototype.setMix=function(t,e,n){this.armature&&this.armature.stateData.setMix(t,e,n)},e.prototype.getAnim=function(t){void 0===t&&(t=0);try{if(this.armature)return this.armature.state.tracks[t].animation.name}catch(t){console.log(t)}},e.prototype.setDefaultMix=function(t){this.armature&&(this.armature.stateData.defaultMix=t)},e.prototype.setAttachment=function(t,e){this.armature&&this.armature.skeleton.setAttachment(t,e)},e.prototype.getBone=function(t){if(this.armature)return this.armature.skeleton.findBone(t)},e.componentName="Spine",i([u("string")],e.prototype,"resource",void 0),i([u("string")],e.prototype,"animationName",void 0),i([u("boolean")],e.prototype,"autoPlay",void 0),e}(e.Component),p={};function f(t){var e=t.image;return{tex:r.Texture.from(e),count:0}}var l={};function d(t,e,n,r){var o=null,a=function(t,e){var n=p[t];return n||(n=f(e),p[t]=n),n.tex}(e.image.src,e);new r.core.TextureAtlas(e.atlas,(function(t,e){e(a.baseTexture)}),(function(t){if(t){var a=new r.core.AtlasAttachmentLoader(t),i=new r.core.SkeletonJson(a);n&&(i.scale=n),o=i.readSkeletonData(e.ske)}}));var i={spineData:o,ref:0,imageSrc:e.image.src};return l[t]=i,i}function h(t,e){return s(this,void 0,void 0,(function(){var n;return c(this,(function(r){if(!(n=l[t.name]))if(t.complete)n=d(t.name,t.data,t.scale,e);else if(!n)return[2];return function(t,e){var n=p[t];n||(n=f(e),p[t]=n),n.count++,n.tex}(t.data.image.src,t.data),n.ref++,[2,n.spineData]}))}))}function y(t,e){var n=l[t];n&&(n.ref--,n.ref<=0&&(!function(t){t&&setTimeout((function(){var e=p[t];e&&(e.count--,e.count<=0&&(e.tex&&(e.tex.destroy(!0),e.tex=null),delete p[t]))}),100)}(e),delete l[t]))}var v=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.armatures={},e}return a(r,t),r.prototype.init=function(t){var r=this,o=t.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=r.game.gameObjects,n=[];for(var o in r.armatures)for(var a=+o,i=0;i<t.length;++i){var s=t[i];if(s.id===a){var c=s.getComponent(m);c&&(r.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:c,componentName:m.componentName}),n.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:c,componentName:m.componentName}));break}}setTimeout((function(){n.forEach((function(t){r.add(t)}))}),1e3)}),!1)},r.prototype.update=function(e){for(var n in this.armatures)this.armatures[n].update(.001*e.deltaTime),this.armatures[n].updateTransform();t.prototype.update.call(this)},r.prototype.componentChanged=function(t){return s(this,void 0,void 0,(function(){return c(this,(function(n){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE)switch(t.prop.prop[0]){case"resource":this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t);return[2]}))}))},r.prototype.add=function(t,n){return s(this,void 0,void 0,(function(){var r,o,a,i,s,u=this;return c(this,(function(c){switch(c.label){case 0:return r=t.component,clearTimeout(r.addHandler),[4,e.resource.getResource(r.resource)];case 1:return[4,h(c.sent(),this.pixiSpine)];case 2:if(!(o=c.sent()))return r.addHandler=setTimeout((function(){r.destroied||(void 0===n&&(n=20),--n>0?u.add(t,n):console.log("retry exceed max times",r.resource))}),1e3),[2];if(this.remove(t),!(a=this.renderSystem.containerManager.getContainer(t.gameObject.id)))return[2];if(r.lastResource=r.resource,i=new this.pixiSpine.Spine(o),this.armatures[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform&&(s=t.gameObject.transform,i.x=s.size.width*s.origin.x,i.y=s.size.height*s.origin.y),a.addChildAt(i,0),i.update(),i.updateTransform(),r.armature=i,r.autoPlay)try{i.state.setAnimation(0,r.animationName,!0)}catch(t){console.log(t)}return r.emit("loaded",{resource:r.resource}),i.state.addListener({start:function(t,e){r.emit("start",{track:t,name:t.animation.name})},complete:function(t,e){r.emit("complete",{track:t,name:t.animation.name})},interrupt:function(t,e){r.emit("interrupt",{track:t,name:t.animation.name})},end:function(t,e){r.emit("end",{track:t,name:t.animation.name})},event:function(t,e){r.emit("event",t,e)}}),[2]}}))}))},r.prototype.change=function(t){this.remove(t),this.add(t)},r.prototype.remove=function(t){var n,r;return s(this,void 0,void 0,(function(){var o,a,i,s;return c(this,(function(c){switch(c.label){case 0:return o=t.component,clearTimeout(o.addHandler),a=this.armatures[t.gameObject.id],(i=this.renderSystem.containerManager.getContainer(t.gameObject.id))&&a&&i.removeChild(a),o.armature?(o.armature.destroy({children:!0}),[4,e.resource.getResource(o.lastResource)]):[3,2];case 1:y((s=c.sent()).name,null===(r=null===(n=s.data)||void 0===n?void 0:n.image)||void 0===r?void 0:r.src),c.label=2;case 2:return o.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([e.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer);return e.resource.registerResourceType("SPINE"),t.Spine=m,t.SpineSystem=v,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,PIXI);
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
4
|
+
import { __extends, __decorate, __awaiter, __generator } from 'tslib';
|
|
5
|
+
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
6
|
+
import { type } from '@eva/inspector-decorator';
|
|
7
|
+
import { Texture } from '@eva/miniprogram-pixi';
|
|
8
|
+
|
|
9
|
+
var Spine = function (_super) {
|
|
10
|
+
__extends(Spine, _super);
|
|
11
|
+
|
|
12
|
+
function Spine() {
|
|
13
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
14
|
+
|
|
15
|
+
_this.resource = '';
|
|
16
|
+
_this.animationName = '';
|
|
17
|
+
_this.autoPlay = true;
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Spine.prototype.init = function (obj) {
|
|
22
|
+
if (!obj) return;
|
|
23
|
+
|
|
24
|
+
_extends(this, obj);
|
|
25
|
+
|
|
26
|
+
if (this.autoPlay) {
|
|
27
|
+
this.play(this.animationName);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
Spine.prototype.onDestroy = function () {
|
|
32
|
+
this.destroied = true;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Spine.prototype.play = function (name, loop, track) {
|
|
36
|
+
try {
|
|
37
|
+
if (name) this.animationName = name;
|
|
38
|
+
|
|
39
|
+
if (!this.armature) {} else {
|
|
40
|
+
if (track === undefined) {
|
|
41
|
+
track = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.log(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Spine.prototype.stop = function (track) {
|
|
52
|
+
if (!this.armature) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (track === undefined) {
|
|
57
|
+
track = 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.armature.state.setEmptyAnimation(track, 0);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
64
|
+
try {
|
|
65
|
+
if (!this.armature) {} else {
|
|
66
|
+
if (track === undefined) {
|
|
67
|
+
track = 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.armature.state.addAnimation(track, name, loop, delay);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.log(e);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
Spine.prototype.setMix = function (from, to, duration) {
|
|
78
|
+
if (!this.armature) ;else {
|
|
79
|
+
this.armature.stateData.setMix(from, to, duration);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
Spine.prototype.getAnim = function (track) {
|
|
84
|
+
if (track === void 0) {
|
|
85
|
+
track = 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
if (!this.armature) {} else {
|
|
90
|
+
return this.armature.state.tracks[track].animation.name;
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.log(e);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Spine.prototype.setDefaultMix = function (duration) {
|
|
98
|
+
if (!this.armature) ;else {
|
|
99
|
+
this.armature.stateData.defaultMix = duration;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
104
|
+
if (!this.armature) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
Spine.prototype.getBone = function (boneName) {
|
|
112
|
+
if (!this.armature) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return this.armature.skeleton.findBone(boneName);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
Spine.componentName = 'Spine';
|
|
120
|
+
|
|
121
|
+
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
122
|
+
|
|
123
|
+
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
124
|
+
|
|
125
|
+
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
126
|
+
|
|
127
|
+
return Spine;
|
|
128
|
+
}(Component);
|
|
129
|
+
|
|
130
|
+
var Spine$1 = Spine;
|
|
131
|
+
var texCache = {};
|
|
132
|
+
|
|
133
|
+
function cacheImage(data) {
|
|
134
|
+
var oldImg = data.image;
|
|
135
|
+
return {
|
|
136
|
+
tex: Texture.from(oldImg),
|
|
137
|
+
count: 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function retainTexture(name, data) {
|
|
142
|
+
var cache = texCache[name];
|
|
143
|
+
|
|
144
|
+
if (!cache) {
|
|
145
|
+
cache = cacheImage(data);
|
|
146
|
+
texCache[name] = cache;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
cache.count++;
|
|
150
|
+
return cache.tex;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function getTexture(imageSrc, data) {
|
|
154
|
+
var cache = texCache[imageSrc];
|
|
155
|
+
|
|
156
|
+
if (!cache) {
|
|
157
|
+
cache = cacheImage(data);
|
|
158
|
+
texCache[imageSrc] = cache;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return cache.tex;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function releaseTexture(imageSrc) {
|
|
165
|
+
if (!imageSrc) return;
|
|
166
|
+
setTimeout(function () {
|
|
167
|
+
var cache = texCache[imageSrc];
|
|
168
|
+
|
|
169
|
+
if (cache) {
|
|
170
|
+
cache.count--;
|
|
171
|
+
|
|
172
|
+
if (cache.count <= 0) {
|
|
173
|
+
if (cache.tex) {
|
|
174
|
+
cache.tex.destroy(true);
|
|
175
|
+
cache.tex = null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
delete texCache[imageSrc];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}, 100);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var dataMap = {};
|
|
185
|
+
|
|
186
|
+
function createSpineData(name, data, scale, pixiSpine) {
|
|
187
|
+
var spineData = null;
|
|
188
|
+
var img = getTexture(data.image.src, data);
|
|
189
|
+
new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
|
|
190
|
+
callback(img.baseTexture);
|
|
191
|
+
}, function (spineAtlas) {
|
|
192
|
+
if (spineAtlas) {
|
|
193
|
+
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
194
|
+
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
195
|
+
|
|
196
|
+
if (scale) {
|
|
197
|
+
spineJsonParser.scale = scale;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
var obj = {
|
|
204
|
+
spineData: spineData,
|
|
205
|
+
ref: 0,
|
|
206
|
+
imageSrc: data.image.src
|
|
207
|
+
};
|
|
208
|
+
dataMap[name] = obj;
|
|
209
|
+
return obj;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function getSpineData(res, pixiSpine) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
var data;
|
|
215
|
+
return __generator(this, function (_a) {
|
|
216
|
+
data = dataMap[res.name];
|
|
217
|
+
|
|
218
|
+
if (!data) {
|
|
219
|
+
if (res.complete) {
|
|
220
|
+
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
221
|
+
} else if (!data) {
|
|
222
|
+
return [2];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
retainTexture(res.data.image.src, res.data);
|
|
227
|
+
data.ref++;
|
|
228
|
+
return [2, data.spineData];
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function releaseSpineData(resourceName, imageSrc) {
|
|
234
|
+
var data = dataMap[resourceName];
|
|
235
|
+
|
|
236
|
+
if (!data) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
data.ref--;
|
|
241
|
+
|
|
242
|
+
if (data.ref <= 0) {
|
|
243
|
+
releaseTexture(imageSrc);
|
|
244
|
+
delete dataMap[resourceName];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var MaxRetryCount = 20;
|
|
249
|
+
|
|
250
|
+
var SpineSystem = function (_super) {
|
|
251
|
+
__extends(SpineSystem, _super);
|
|
252
|
+
|
|
253
|
+
function SpineSystem() {
|
|
254
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
255
|
+
|
|
256
|
+
_this.armatures = {};
|
|
257
|
+
return _this;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
SpineSystem.prototype.init = function (_a) {
|
|
261
|
+
var _this = this;
|
|
262
|
+
|
|
263
|
+
var pixiSpine = _a.pixiSpine;
|
|
264
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
265
|
+
this.renderSystem.rendererManager.register(this);
|
|
266
|
+
this.pixiSpine = pixiSpine;
|
|
267
|
+
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
268
|
+
var objs = _this.game.gameObjects;
|
|
269
|
+
var toAdd = [];
|
|
270
|
+
|
|
271
|
+
for (var k in _this.armatures) {
|
|
272
|
+
var id = +k;
|
|
273
|
+
|
|
274
|
+
for (var i = 0; i < objs.length; ++i) {
|
|
275
|
+
var obj = objs[i];
|
|
276
|
+
|
|
277
|
+
if (obj.id === id) {
|
|
278
|
+
var sp = obj.getComponent(Spine$1);
|
|
279
|
+
|
|
280
|
+
if (sp) {
|
|
281
|
+
_this.remove({
|
|
282
|
+
type: OBSERVER_TYPE.REMOVE,
|
|
283
|
+
gameObject: obj,
|
|
284
|
+
component: sp,
|
|
285
|
+
componentName: Spine$1.componentName
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
toAdd.push({
|
|
289
|
+
type: OBSERVER_TYPE.ADD,
|
|
290
|
+
gameObject: obj,
|
|
291
|
+
component: sp,
|
|
292
|
+
componentName: Spine$1.componentName
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
setTimeout(function () {
|
|
302
|
+
toAdd.forEach(function (obj) {
|
|
303
|
+
_this.add(obj);
|
|
304
|
+
});
|
|
305
|
+
}, 1000);
|
|
306
|
+
}, false);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
SpineSystem.prototype.update = function (e) {
|
|
310
|
+
for (var key in this.armatures) {
|
|
311
|
+
this.armatures[key].update(e.deltaTime * 0.001);
|
|
312
|
+
this.armatures[key].updateTransform();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
_super.prototype.update.call(this);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
SpineSystem.prototype.componentChanged = function (changed) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
320
|
+
return __generator(this, function (_a) {
|
|
321
|
+
if (changed.componentName === 'Spine') {
|
|
322
|
+
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
323
|
+
this.add(changed);
|
|
324
|
+
} else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
325
|
+
switch (changed.prop.prop[0]) {
|
|
326
|
+
case 'resource':
|
|
327
|
+
this.change(changed);
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
} else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
331
|
+
this.remove(changed);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return [2];
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
SpineSystem.prototype.add = function (changed, count) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
342
|
+
var component, res, spineData, container, armature, tran;
|
|
343
|
+
|
|
344
|
+
var _this = this;
|
|
345
|
+
|
|
346
|
+
return __generator(this, function (_a) {
|
|
347
|
+
switch (_a.label) {
|
|
348
|
+
case 0:
|
|
349
|
+
component = changed.component;
|
|
350
|
+
clearTimeout(component.addHandler);
|
|
351
|
+
return [4, resource.getResource(component.resource)];
|
|
352
|
+
|
|
353
|
+
case 1:
|
|
354
|
+
res = _a.sent();
|
|
355
|
+
return [4, getSpineData(res, this.pixiSpine)];
|
|
356
|
+
|
|
357
|
+
case 2:
|
|
358
|
+
spineData = _a.sent();
|
|
359
|
+
|
|
360
|
+
if (!spineData) {
|
|
361
|
+
component.addHandler = setTimeout(function () {
|
|
362
|
+
if (!component.destroied) {
|
|
363
|
+
if (count === undefined) {
|
|
364
|
+
count = MaxRetryCount;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
count--;
|
|
368
|
+
|
|
369
|
+
if (count > 0) {
|
|
370
|
+
_this.add(changed, count);
|
|
371
|
+
} else {
|
|
372
|
+
console.log('retry exceed max times', component.resource);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}, 1000);
|
|
376
|
+
return [2];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
this.remove(changed);
|
|
380
|
+
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
381
|
+
|
|
382
|
+
if (!container) {
|
|
383
|
+
return [2];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
component.lastResource = component.resource;
|
|
387
|
+
armature = new this.pixiSpine.Spine(spineData);
|
|
388
|
+
this.armatures[changed.gameObject.id] = armature;
|
|
389
|
+
|
|
390
|
+
if (changed.gameObject && changed.gameObject.transform) {
|
|
391
|
+
tran = changed.gameObject.transform;
|
|
392
|
+
armature.x = tran.size.width * tran.origin.x;
|
|
393
|
+
armature.y = tran.size.height * tran.origin.y;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
container.addChildAt(armature, 0);
|
|
397
|
+
armature.update();
|
|
398
|
+
armature.updateTransform();
|
|
399
|
+
component.armature = armature;
|
|
400
|
+
|
|
401
|
+
if (component.autoPlay) {
|
|
402
|
+
try {
|
|
403
|
+
armature.state.setAnimation(0, component.animationName, true);
|
|
404
|
+
} catch (e) {
|
|
405
|
+
console.log(e);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
component.emit('loaded', {
|
|
410
|
+
resource: component.resource
|
|
411
|
+
});
|
|
412
|
+
armature.state.addListener({
|
|
413
|
+
start: function start(track, event) {
|
|
414
|
+
component.emit('start', {
|
|
415
|
+
track: track,
|
|
416
|
+
name: track.animation.name
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
complete: function complete(track, event) {
|
|
420
|
+
component.emit('complete', {
|
|
421
|
+
track: track,
|
|
422
|
+
name: track.animation.name
|
|
423
|
+
});
|
|
424
|
+
},
|
|
425
|
+
interrupt: function interrupt(track, event) {
|
|
426
|
+
component.emit('interrupt', {
|
|
427
|
+
track: track,
|
|
428
|
+
name: track.animation.name
|
|
429
|
+
});
|
|
430
|
+
},
|
|
431
|
+
end: function end(track, event) {
|
|
432
|
+
component.emit('end', {
|
|
433
|
+
track: track,
|
|
434
|
+
name: track.animation.name
|
|
435
|
+
});
|
|
436
|
+
},
|
|
437
|
+
event: function event(track, _event) {
|
|
438
|
+
component.emit('event', track, _event);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
return [2];
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
SpineSystem.prototype.change = function (changed) {
|
|
448
|
+
this.remove(changed);
|
|
449
|
+
this.add(changed);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
SpineSystem.prototype.remove = function (changed) {
|
|
453
|
+
var _a, _b;
|
|
454
|
+
|
|
455
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
456
|
+
var component, armature, container, res;
|
|
457
|
+
return __generator(this, function (_c) {
|
|
458
|
+
switch (_c.label) {
|
|
459
|
+
case 0:
|
|
460
|
+
component = changed.component;
|
|
461
|
+
clearTimeout(component.addHandler);
|
|
462
|
+
armature = this.armatures[changed.gameObject.id];
|
|
463
|
+
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
464
|
+
|
|
465
|
+
if (container && armature) {
|
|
466
|
+
container.removeChild(armature);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!component.armature) return [3, 2];
|
|
470
|
+
component.armature.destroy({
|
|
471
|
+
children: true
|
|
472
|
+
});
|
|
473
|
+
return [4, resource.getResource(component.lastResource)];
|
|
474
|
+
|
|
475
|
+
case 1:
|
|
476
|
+
res = _c.sent();
|
|
477
|
+
releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
|
|
478
|
+
_c.label = 2;
|
|
479
|
+
|
|
480
|
+
case 2:
|
|
481
|
+
component.armature = null;
|
|
482
|
+
delete this.armatures[changed.gameObject.id];
|
|
483
|
+
if (changed.type === OBSERVER_TYPE.CHANGE) ;
|
|
484
|
+
return [2];
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
SpineSystem.systemName = 'SpineSystem';
|
|
491
|
+
SpineSystem = __decorate([decorators.componentObserver({
|
|
492
|
+
Spine: ['resource']
|
|
493
|
+
})], SpineSystem);
|
|
494
|
+
return SpineSystem;
|
|
495
|
+
}(Renderer);
|
|
496
|
+
|
|
497
|
+
var SpineSystem$1 = SpineSystem;
|
|
498
|
+
resource.registerResourceType('SPINE');
|
|
499
|
+
export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
|