@eva/spine-base 1.2.7-fix.4 → 1.2.7-fix.6
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,6 +1,8 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
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
|
+
|
|
2
3
|
window.EVA = window.EVA || {};
|
|
3
4
|
window.EVA.plugin = window.EVA.plugin || {};
|
|
5
|
+
|
|
4
6
|
var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
5
7
|
'use strict';
|
|
6
8
|
|
|
@@ -14,30 +16,37 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
14
16
|
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
15
17
|
}
|
|
16
18
|
};
|
|
19
|
+
|
|
17
20
|
return _extendStatics(d, b);
|
|
18
21
|
};
|
|
22
|
+
|
|
19
23
|
function __extends(d, b) {
|
|
20
24
|
_extendStatics(d, b);
|
|
25
|
+
|
|
21
26
|
function __() {
|
|
22
27
|
this.constructor = d;
|
|
23
28
|
}
|
|
29
|
+
|
|
24
30
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
25
31
|
}
|
|
32
|
+
|
|
26
33
|
function __decorate(decorators, target, key, desc) {
|
|
27
34
|
var c = arguments.length,
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
36
|
+
d;
|
|
30
37
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
|
|
31
38
|
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
32
39
|
}
|
|
33
40
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
34
41
|
}
|
|
42
|
+
|
|
35
43
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
36
44
|
function adopt(value) {
|
|
37
45
|
return value instanceof P ? value : new P(function (resolve) {
|
|
38
46
|
resolve(value);
|
|
39
47
|
});
|
|
40
48
|
}
|
|
49
|
+
|
|
41
50
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
51
|
function fulfilled(value) {
|
|
43
52
|
try {
|
|
@@ -46,6 +55,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
46
55
|
reject(e);
|
|
47
56
|
}
|
|
48
57
|
}
|
|
58
|
+
|
|
49
59
|
function rejected(value) {
|
|
50
60
|
try {
|
|
51
61
|
step(generator["throw"](value));
|
|
@@ -53,26 +63,29 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
53
63
|
reject(e);
|
|
54
64
|
}
|
|
55
65
|
}
|
|
66
|
+
|
|
56
67
|
function step(result) {
|
|
57
68
|
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
58
69
|
}
|
|
70
|
+
|
|
59
71
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
60
72
|
});
|
|
61
73
|
}
|
|
74
|
+
|
|
62
75
|
function __generator(thisArg, body) {
|
|
63
76
|
var _ = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
trys: [],
|
|
70
|
-
ops: []
|
|
77
|
+
label: 0,
|
|
78
|
+
sent: function sent() {
|
|
79
|
+
if (t[0] & 1) throw t[1];
|
|
80
|
+
return t[1];
|
|
71
81
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
82
|
+
trys: [],
|
|
83
|
+
ops: []
|
|
84
|
+
},
|
|
85
|
+
f,
|
|
86
|
+
y,
|
|
87
|
+
t,
|
|
88
|
+
g;
|
|
76
89
|
return g = {
|
|
77
90
|
next: verb(0),
|
|
78
91
|
"throw": verb(1),
|
|
@@ -80,60 +93,79 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
80
93
|
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
81
94
|
return this;
|
|
82
95
|
}), g;
|
|
96
|
+
|
|
83
97
|
function verb(n) {
|
|
84
98
|
return function (v) {
|
|
85
99
|
return step([n, v]);
|
|
86
100
|
};
|
|
87
101
|
}
|
|
102
|
+
|
|
88
103
|
function step(op) {
|
|
89
104
|
if (f) throw new TypeError("Generator is already executing.");
|
|
105
|
+
|
|
90
106
|
while (_) {
|
|
91
107
|
try {
|
|
92
108
|
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;
|
|
93
109
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
110
|
+
|
|
94
111
|
switch (op[0]) {
|
|
95
112
|
case 0:
|
|
96
113
|
case 1:
|
|
97
114
|
t = op;
|
|
98
115
|
break;
|
|
116
|
+
|
|
99
117
|
case 4:
|
|
100
118
|
_.label++;
|
|
101
119
|
return {
|
|
102
120
|
value: op[1],
|
|
103
121
|
done: false
|
|
104
122
|
};
|
|
123
|
+
|
|
105
124
|
case 5:
|
|
106
125
|
_.label++;
|
|
107
126
|
y = op[1];
|
|
108
127
|
op = [0];
|
|
109
128
|
continue;
|
|
129
|
+
|
|
110
130
|
case 7:
|
|
111
131
|
op = _.ops.pop();
|
|
132
|
+
|
|
112
133
|
_.trys.pop();
|
|
134
|
+
|
|
113
135
|
continue;
|
|
136
|
+
|
|
114
137
|
default:
|
|
115
138
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
116
139
|
_ = 0;
|
|
117
140
|
continue;
|
|
118
141
|
}
|
|
142
|
+
|
|
119
143
|
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
120
144
|
_.label = op[1];
|
|
121
145
|
break;
|
|
122
146
|
}
|
|
147
|
+
|
|
123
148
|
if (op[0] === 6 && _.label < t[1]) {
|
|
124
149
|
_.label = t[1];
|
|
125
150
|
t = op;
|
|
126
151
|
break;
|
|
127
152
|
}
|
|
153
|
+
|
|
128
154
|
if (t && _.label < t[2]) {
|
|
129
155
|
_.label = t[2];
|
|
156
|
+
|
|
130
157
|
_.ops.push(op);
|
|
158
|
+
|
|
131
159
|
break;
|
|
132
160
|
}
|
|
161
|
+
|
|
133
162
|
if (t[2]) _.ops.pop();
|
|
163
|
+
|
|
134
164
|
_.trys.pop();
|
|
165
|
+
|
|
135
166
|
continue;
|
|
136
167
|
}
|
|
168
|
+
|
|
137
169
|
op = body.call(thisArg, _);
|
|
138
170
|
} catch (e) {
|
|
139
171
|
op = [6, e];
|
|
@@ -142,6 +174,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
142
174
|
f = t = 0;
|
|
143
175
|
}
|
|
144
176
|
}
|
|
177
|
+
|
|
145
178
|
if (op[0] & 5) throw op[1];
|
|
146
179
|
return {
|
|
147
180
|
value: op[0] ? op[1] : void 0,
|
|
@@ -149,10 +182,11 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
149
182
|
};
|
|
150
183
|
}
|
|
151
184
|
}
|
|
185
|
+
|
|
152
186
|
function __values(o) {
|
|
153
187
|
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
154
|
-
|
|
155
|
-
|
|
188
|
+
m = s && o[s],
|
|
189
|
+
i = 0;
|
|
156
190
|
if (m) return m.call(o);
|
|
157
191
|
if (o && typeof o.length === "number") return {
|
|
158
192
|
next: function next() {
|
|
@@ -165,16 +199,20 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
165
199
|
};
|
|
166
200
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
167
201
|
}
|
|
202
|
+
|
|
168
203
|
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
169
204
|
if (!target.constructor.IDEProps) {
|
|
170
205
|
target.constructor.IDEProps = {};
|
|
171
206
|
}
|
|
207
|
+
|
|
172
208
|
if (!target.constructor.IDEProps[propertyKey]) {
|
|
173
209
|
target.constructor.IDEProps[propertyKey] = {};
|
|
174
210
|
}
|
|
211
|
+
|
|
175
212
|
var propertyObj = target.constructor.IDEProps[propertyKey];
|
|
176
213
|
return propertyObj;
|
|
177
214
|
}
|
|
215
|
+
|
|
178
216
|
function type(type) {
|
|
179
217
|
return function (target, propertyKey) {
|
|
180
218
|
var prop = getIDEPropsPropertyObj(target, propertyKey);
|
|
@@ -182,34 +220,42 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
182
220
|
prop.type = type;
|
|
183
221
|
};
|
|
184
222
|
}
|
|
223
|
+
|
|
185
224
|
var Spine = function (_super) {
|
|
186
225
|
__extends(Spine, _super);
|
|
226
|
+
|
|
187
227
|
function Spine() {
|
|
188
228
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
229
|
+
|
|
189
230
|
_this.resource = '';
|
|
190
231
|
_this.animationName = '';
|
|
191
232
|
_this.autoPlay = true;
|
|
192
233
|
_this.waitExecuteInfos = [];
|
|
193
234
|
return _this;
|
|
194
235
|
}
|
|
236
|
+
|
|
195
237
|
Object.defineProperty(Spine.prototype, "armature", {
|
|
196
238
|
get: function get() {
|
|
197
239
|
return this._armature;
|
|
198
240
|
},
|
|
199
241
|
set: function set(val) {
|
|
200
242
|
var e_1, _a;
|
|
243
|
+
|
|
201
244
|
this._armature = val;
|
|
202
245
|
if (!val) return;
|
|
246
|
+
|
|
203
247
|
if (this.autoPlay) {
|
|
204
248
|
this.play(this.animationName);
|
|
205
249
|
}
|
|
250
|
+
|
|
206
251
|
try {
|
|
207
252
|
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
208
253
|
var info = _c.value;
|
|
254
|
+
|
|
209
255
|
if (info.playType) {
|
|
210
256
|
var name_1 = info.name,
|
|
211
|
-
|
|
212
|
-
|
|
257
|
+
loop = info.loop,
|
|
258
|
+
track = info.track;
|
|
213
259
|
this.play(name_1, loop, track);
|
|
214
260
|
} else {
|
|
215
261
|
this.stop(info.track);
|
|
@@ -226,21 +272,27 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
226
272
|
if (e_1) throw e_1.error;
|
|
227
273
|
}
|
|
228
274
|
}
|
|
275
|
+
|
|
229
276
|
this.waitExecuteInfos = [];
|
|
230
277
|
},
|
|
231
278
|
enumerable: false,
|
|
232
279
|
configurable: true
|
|
233
280
|
});
|
|
281
|
+
|
|
234
282
|
Spine.prototype.init = function (obj) {
|
|
235
283
|
if (!obj) return;
|
|
284
|
+
|
|
236
285
|
_extends(this, obj);
|
|
237
286
|
};
|
|
287
|
+
|
|
238
288
|
Spine.prototype.onDestroy = function () {
|
|
239
289
|
this.destroied = true;
|
|
240
290
|
};
|
|
291
|
+
|
|
241
292
|
Spine.prototype.play = function (name, loop, track) {
|
|
242
293
|
try {
|
|
243
294
|
if (name) this.animationName = name;
|
|
295
|
+
|
|
244
296
|
if (!this.armature) {
|
|
245
297
|
this.waitExecuteInfos.push({
|
|
246
298
|
playType: true,
|
|
@@ -252,12 +304,14 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
252
304
|
if (track === undefined) {
|
|
253
305
|
track = 0;
|
|
254
306
|
}
|
|
307
|
+
|
|
255
308
|
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
256
309
|
}
|
|
257
310
|
} catch (e) {
|
|
258
311
|
console.log(e);
|
|
259
312
|
}
|
|
260
313
|
};
|
|
314
|
+
|
|
261
315
|
Spine.prototype.stop = function (track) {
|
|
262
316
|
if (!this.armature) {
|
|
263
317
|
this.waitExecuteInfos.push({
|
|
@@ -266,32 +320,39 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
266
320
|
});
|
|
267
321
|
return;
|
|
268
322
|
}
|
|
323
|
+
|
|
269
324
|
if (track === undefined) {
|
|
270
325
|
track = 0;
|
|
271
326
|
}
|
|
327
|
+
|
|
272
328
|
this.armature.state.setEmptyAnimation(track, 0);
|
|
273
329
|
};
|
|
330
|
+
|
|
274
331
|
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
275
332
|
try {
|
|
276
333
|
if (!this.armature) {} else {
|
|
277
334
|
if (track === undefined) {
|
|
278
335
|
track = 0;
|
|
279
336
|
}
|
|
337
|
+
|
|
280
338
|
this.armature.state.addAnimation(track, name, loop, delay);
|
|
281
339
|
}
|
|
282
340
|
} catch (e) {
|
|
283
341
|
console.log(e);
|
|
284
342
|
}
|
|
285
343
|
};
|
|
344
|
+
|
|
286
345
|
Spine.prototype.setMix = function (from, to, duration) {
|
|
287
346
|
if (!this.armature) ;else {
|
|
288
347
|
this.armature.stateData.setMix(from, to, duration);
|
|
289
348
|
}
|
|
290
349
|
};
|
|
350
|
+
|
|
291
351
|
Spine.prototype.getAnim = function (track) {
|
|
292
352
|
if (track === void 0) {
|
|
293
353
|
track = 0;
|
|
294
354
|
}
|
|
355
|
+
|
|
295
356
|
try {
|
|
296
357
|
if (!this.armature) {} else {
|
|
297
358
|
return this.armature.state.tracks[track].animation.name;
|
|
@@ -300,31 +361,43 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
300
361
|
console.log(e);
|
|
301
362
|
}
|
|
302
363
|
};
|
|
364
|
+
|
|
303
365
|
Spine.prototype.setDefaultMix = function (duration) {
|
|
304
366
|
if (!this.armature) ;else {
|
|
305
367
|
this.armature.stateData.defaultMix = duration;
|
|
306
368
|
}
|
|
307
369
|
};
|
|
370
|
+
|
|
308
371
|
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
309
372
|
if (!this.armature) {
|
|
310
373
|
return;
|
|
311
374
|
}
|
|
375
|
+
|
|
312
376
|
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
313
377
|
};
|
|
378
|
+
|
|
314
379
|
Spine.prototype.getBone = function (boneName) {
|
|
315
380
|
if (!this.armature) {
|
|
316
381
|
return;
|
|
317
382
|
}
|
|
383
|
+
|
|
318
384
|
return this.armature.skeleton.findBone(boneName);
|
|
319
385
|
};
|
|
386
|
+
|
|
320
387
|
Spine.componentName = 'Spine';
|
|
388
|
+
|
|
321
389
|
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
390
|
+
|
|
322
391
|
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
392
|
+
|
|
323
393
|
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
394
|
+
|
|
324
395
|
return Spine;
|
|
325
396
|
}(eva_js.Component);
|
|
397
|
+
|
|
326
398
|
var Spine$1 = Spine;
|
|
327
399
|
var texCache = {};
|
|
400
|
+
|
|
328
401
|
function cacheImage(data) {
|
|
329
402
|
var oldImg = data.image;
|
|
330
403
|
return {
|
|
@@ -332,40 +405,52 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
332
405
|
count: 0
|
|
333
406
|
};
|
|
334
407
|
}
|
|
408
|
+
|
|
335
409
|
function retainTexture(name, data) {
|
|
336
410
|
var cache = texCache[name];
|
|
411
|
+
|
|
337
412
|
if (!cache) {
|
|
338
413
|
cache = cacheImage(data);
|
|
339
414
|
texCache[name] = cache;
|
|
340
415
|
}
|
|
416
|
+
|
|
341
417
|
cache.count++;
|
|
342
418
|
return cache.tex;
|
|
343
419
|
}
|
|
420
|
+
|
|
344
421
|
function getTexture(imageSrc, data) {
|
|
345
422
|
var cache = texCache[imageSrc];
|
|
423
|
+
|
|
346
424
|
if (!cache) {
|
|
347
425
|
cache = cacheImage(data);
|
|
348
426
|
texCache[imageSrc] = cache;
|
|
349
427
|
}
|
|
428
|
+
|
|
350
429
|
return cache.tex;
|
|
351
430
|
}
|
|
431
|
+
|
|
352
432
|
function releaseTexture(imageSrc) {
|
|
353
433
|
if (!imageSrc) return;
|
|
354
434
|
setTimeout(function () {
|
|
355
435
|
var cache = texCache[imageSrc];
|
|
436
|
+
|
|
356
437
|
if (cache) {
|
|
357
438
|
cache.count--;
|
|
439
|
+
|
|
358
440
|
if (cache.count <= 0) {
|
|
359
441
|
if (cache.tex) {
|
|
360
442
|
cache.tex.destroy(true);
|
|
361
443
|
cache.tex = null;
|
|
362
444
|
}
|
|
445
|
+
|
|
363
446
|
delete texCache[imageSrc];
|
|
364
447
|
}
|
|
365
448
|
}
|
|
366
449
|
}, 100);
|
|
367
450
|
}
|
|
451
|
+
|
|
368
452
|
var dataMap = {};
|
|
453
|
+
|
|
369
454
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
370
455
|
var spineData = null;
|
|
371
456
|
var img = getTexture(data.image.src, data);
|
|
@@ -375,9 +460,11 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
375
460
|
if (spineAtlas) {
|
|
376
461
|
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
377
462
|
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
463
|
+
|
|
378
464
|
if (scale) {
|
|
379
465
|
spineJsonParser.scale = scale;
|
|
380
466
|
}
|
|
467
|
+
|
|
381
468
|
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
382
469
|
}
|
|
383
470
|
});
|
|
@@ -389,11 +476,13 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
389
476
|
dataMap[name] = obj;
|
|
390
477
|
return obj;
|
|
391
478
|
}
|
|
479
|
+
|
|
392
480
|
function getSpineData(res, pixiSpine) {
|
|
393
481
|
return __awaiter(this, void 0, void 0, function () {
|
|
394
482
|
var data;
|
|
395
483
|
return __generator(this, function (_a) {
|
|
396
484
|
data = dataMap[res.name];
|
|
485
|
+
|
|
397
486
|
if (!data) {
|
|
398
487
|
if (res.complete) {
|
|
399
488
|
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
@@ -401,33 +490,44 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
401
490
|
return [2];
|
|
402
491
|
}
|
|
403
492
|
}
|
|
493
|
+
|
|
404
494
|
retainTexture(res.data.image.src, res.data);
|
|
405
495
|
data.ref++;
|
|
406
496
|
return [2, data.spineData];
|
|
407
497
|
});
|
|
408
498
|
});
|
|
409
499
|
}
|
|
500
|
+
|
|
410
501
|
function releaseSpineData(resourceName, imageSrc) {
|
|
411
502
|
var data = dataMap[resourceName];
|
|
503
|
+
|
|
412
504
|
if (!data) {
|
|
413
505
|
return;
|
|
414
506
|
}
|
|
507
|
+
|
|
415
508
|
data.ref--;
|
|
509
|
+
|
|
416
510
|
if (data.ref <= 0) {
|
|
417
511
|
releaseTexture(imageSrc);
|
|
418
512
|
delete dataMap[resourceName];
|
|
419
513
|
}
|
|
420
514
|
}
|
|
515
|
+
|
|
421
516
|
var MaxRetryCount = 20;
|
|
517
|
+
|
|
422
518
|
var SpineSystem = function (_super) {
|
|
423
519
|
__extends(SpineSystem, _super);
|
|
520
|
+
|
|
424
521
|
function SpineSystem() {
|
|
425
522
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
523
|
+
|
|
426
524
|
_this.armatures = {};
|
|
427
525
|
return _this;
|
|
428
526
|
}
|
|
527
|
+
|
|
429
528
|
SpineSystem.prototype.init = function (_a) {
|
|
430
529
|
var _this = this;
|
|
530
|
+
|
|
431
531
|
var pixiSpine = _a.pixiSpine;
|
|
432
532
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
433
533
|
this.renderSystem.rendererManager.register(this);
|
|
@@ -435,12 +535,16 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
435
535
|
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
436
536
|
var objs = _this.game.gameObjects;
|
|
437
537
|
var toAdd = [];
|
|
538
|
+
|
|
438
539
|
for (var k in _this.armatures) {
|
|
439
540
|
var id = +k;
|
|
541
|
+
|
|
440
542
|
for (var i = 0; i < objs.length; ++i) {
|
|
441
543
|
var obj = objs[i];
|
|
544
|
+
|
|
442
545
|
if (obj.id === id) {
|
|
443
546
|
var sp = obj.getComponent(Spine$1);
|
|
547
|
+
|
|
444
548
|
if (sp) {
|
|
445
549
|
_this.remove({
|
|
446
550
|
type: eva_js.OBSERVER_TYPE.REMOVE,
|
|
@@ -448,6 +552,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
448
552
|
component: sp,
|
|
449
553
|
componentName: Spine$1.componentName
|
|
450
554
|
});
|
|
555
|
+
|
|
451
556
|
toAdd.push({
|
|
452
557
|
type: eva_js.OBSERVER_TYPE.ADD,
|
|
453
558
|
gameObject: obj,
|
|
@@ -455,10 +560,12 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
455
560
|
componentName: Spine$1.componentName
|
|
456
561
|
});
|
|
457
562
|
}
|
|
563
|
+
|
|
458
564
|
break;
|
|
459
565
|
}
|
|
460
566
|
}
|
|
461
567
|
}
|
|
568
|
+
|
|
462
569
|
setTimeout(function () {
|
|
463
570
|
toAdd.forEach(function (obj) {
|
|
464
571
|
_this.add(obj);
|
|
@@ -466,13 +573,16 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
466
573
|
}, 1000);
|
|
467
574
|
}, false);
|
|
468
575
|
};
|
|
576
|
+
|
|
469
577
|
SpineSystem.prototype.update = function (e) {
|
|
470
578
|
for (var key in this.armatures) {
|
|
471
579
|
this.armatures[key].update(e.deltaTime * 0.001);
|
|
472
580
|
this.armatures[key].updateTransform();
|
|
473
581
|
}
|
|
582
|
+
|
|
474
583
|
_super.prototype.update.call(this);
|
|
475
584
|
};
|
|
585
|
+
|
|
476
586
|
SpineSystem.prototype.componentChanged = function (changed) {
|
|
477
587
|
return __awaiter(this, void 0, void 0, function () {
|
|
478
588
|
return __generator(this, function (_a) {
|
|
@@ -489,15 +599,20 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
489
599
|
this.remove(changed);
|
|
490
600
|
}
|
|
491
601
|
}
|
|
602
|
+
|
|
492
603
|
return [2];
|
|
493
604
|
});
|
|
494
605
|
});
|
|
495
606
|
};
|
|
607
|
+
|
|
496
608
|
SpineSystem.prototype.add = function (changed, count) {
|
|
497
609
|
var _a, _b;
|
|
610
|
+
|
|
498
611
|
return __awaiter(this, void 0, void 0, function () {
|
|
499
612
|
var component, gameObjectId, asyncId, res, spineData, container, armature, tran;
|
|
613
|
+
|
|
500
614
|
var _this = this;
|
|
615
|
+
|
|
501
616
|
return __generator(this, function (_c) {
|
|
502
617
|
switch (_c.label) {
|
|
503
618
|
case 0:
|
|
@@ -506,20 +621,25 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
506
621
|
gameObjectId = changed.gameObject.id;
|
|
507
622
|
asyncId = this.increaseAsyncId(gameObjectId);
|
|
508
623
|
return [4, eva_js.resource.getResource(component.resource)];
|
|
624
|
+
|
|
509
625
|
case 1:
|
|
510
626
|
res = _c.sent();
|
|
511
627
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
512
628
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
629
|
+
|
|
513
630
|
case 2:
|
|
514
631
|
spineData = _c.sent();
|
|
515
632
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
633
|
+
|
|
516
634
|
if (!spineData) {
|
|
517
635
|
component.addHandler = setTimeout(function () {
|
|
518
636
|
if (!component.destroied) {
|
|
519
637
|
if (count === undefined) {
|
|
520
638
|
count = MaxRetryCount;
|
|
521
639
|
}
|
|
640
|
+
|
|
522
641
|
count--;
|
|
642
|
+
|
|
523
643
|
if (count > 0) {
|
|
524
644
|
_this.add(changed, count);
|
|
525
645
|
} else {
|
|
@@ -529,19 +649,24 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
529
649
|
}, 1000);
|
|
530
650
|
return [2];
|
|
531
651
|
}
|
|
652
|
+
|
|
532
653
|
this.remove(changed);
|
|
533
654
|
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
655
|
+
|
|
534
656
|
if (!container) {
|
|
535
657
|
return [2];
|
|
536
658
|
}
|
|
659
|
+
|
|
537
660
|
component.lastResource = component.resource;
|
|
538
661
|
armature = new this.pixiSpine.Spine(spineData);
|
|
539
662
|
this.armatures[changed.gameObject.id] = armature;
|
|
663
|
+
|
|
540
664
|
if (changed.gameObject && changed.gameObject.transform) {
|
|
541
665
|
tran = changed.gameObject.transform;
|
|
542
666
|
armature.x = tran.size.width * tran.origin.x;
|
|
543
667
|
armature.y = tran.size.height * tran.origin.y;
|
|
544
668
|
}
|
|
669
|
+
|
|
545
670
|
container.addChildAt(armature, 0);
|
|
546
671
|
armature.update();
|
|
547
672
|
armature.updateTransform();
|
|
@@ -583,12 +708,15 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
583
708
|
});
|
|
584
709
|
});
|
|
585
710
|
};
|
|
711
|
+
|
|
586
712
|
SpineSystem.prototype.change = function (changed) {
|
|
587
713
|
this.remove(changed);
|
|
588
714
|
this.add(changed);
|
|
589
715
|
};
|
|
716
|
+
|
|
590
717
|
SpineSystem.prototype.remove = function (changed) {
|
|
591
718
|
var _a, _b, _c, _d;
|
|
719
|
+
|
|
592
720
|
return __awaiter(this, void 0, void 0, function () {
|
|
593
721
|
var component, armature, container, res;
|
|
594
722
|
return __generator(this, function (_e) {
|
|
@@ -599,18 +727,22 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
599
727
|
clearTimeout(component.addHandler);
|
|
600
728
|
armature = this.armatures[changed.gameObject.id];
|
|
601
729
|
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
730
|
+
|
|
602
731
|
if (container && armature) {
|
|
603
732
|
container.removeChild(armature);
|
|
604
733
|
}
|
|
734
|
+
|
|
605
735
|
if (!component.armature) return [3, 2];
|
|
606
736
|
component.armature.destroy({
|
|
607
737
|
children: true
|
|
608
738
|
});
|
|
609
739
|
return [4, eva_js.resource.getResource(component.lastResource)];
|
|
740
|
+
|
|
610
741
|
case 1:
|
|
611
742
|
res = _e.sent();
|
|
612
743
|
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
613
744
|
_e.label = 2;
|
|
745
|
+
|
|
614
746
|
case 2:
|
|
615
747
|
component.armature = null;
|
|
616
748
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -620,12 +752,14 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
620
752
|
});
|
|
621
753
|
});
|
|
622
754
|
};
|
|
755
|
+
|
|
623
756
|
SpineSystem.systemName = 'SpineSystem';
|
|
624
757
|
SpineSystem = __decorate([eva_js.decorators.componentObserver({
|
|
625
758
|
Spine: ['resource']
|
|
626
759
|
})], SpineSystem);
|
|
627
760
|
return SpineSystem;
|
|
628
761
|
}(pluginRenderer.Renderer);
|
|
762
|
+
|
|
629
763
|
var SpineSystem$1 = SpineSystem;
|
|
630
764
|
eva_js.resource.registerResourceType('SPINE');
|
|
631
765
|
exports.Spine = Spine$1;
|
|
@@ -635,4 +769,5 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
635
769
|
});
|
|
636
770
|
return exports;
|
|
637
771
|
}({}, EVA, EVA.plugin.renderer, PIXI);
|
|
772
|
+
|
|
638
773
|
window.EVA.plugin.spineBase = window.EVA.plugin.spineBase || _EVA_IIFE_spineBase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return
|
|
1
|
+
function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function a(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t,n,r){var o,a=arguments.length,i=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,n,i):o(t,n))||i);return a>3&&i&&Object.defineProperty(t,n,i),i}function s(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{u(r.next(e))}catch(e){a(e)}}function s(e){try{u(r.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){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=t.call(e,i)}catch(e){a=[6,e],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 c(e){return function(t,n){var r=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);r.key=n,r.type=e}}var p=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return a(t,e),Object.defineProperty(t.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,n;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var r=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.waitExecuteInfos),o=r.next();!o.done;o=r.next()){var a=o.value;if(a.playType){var i=a.name,s=a.loop,u=a.track;this.play(i,s,u)}else this.stop(a.track)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&_extends(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,n){try{e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:n})}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(e,t,n,r){try{this.armature&&(void 0===r&&(r=0),this.armature.state.addAnimation(r,e,n,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,n){this.armature&&this.armature.stateData.setMix(e,t,n)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([c("string")],t.prototype,"resource",void 0),i([c("string")],t.prototype,"animationName",void 0),i([c("boolean")],t.prototype,"autoPlay",void 0),t}(t.Component),l={};function m(e){var t=e.image;return{tex:r.Texture.from(t),count:0}}var f={};function d(e,t,n,r){var o=null,a=function(e,t){var n=l[e];return n||(n=m(t),l[e]=n),n.tex}(t.image.src,t);new r.core.TextureAtlas(t.atlas,(function(e,t){t(a.baseTexture)}),(function(e){if(e){var a=new r.core.AtlasAttachmentLoader(e),i=new r.core.SkeletonJson(a);n&&(i.scale=n),o=i.readSkeletonData(t.ske)}}));var i={spineData:o,ref:0,imageSrc:t.image.src};return f[e]=i,i}function h(e,t){return s(this,void 0,void 0,(function(){var n;return u(this,(function(r){if(!(n=f[e.name]))if(e.complete)n=d(e.name,e.data,e.scale,t);else if(!n)return[2];return function(e,t){var n=l[e];n||(n=m(t),l[e]=n),n.count++,n.tex}(e.data.image.src,e.data),n.ref++,[2,n.spineData]}))}))}function y(e,t){var n=f[e];n&&(n.ref--,n.ref<=0&&(!function(e){e&&setTimeout((function(){var t=l[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete l[e]))}),100)}(t),delete f[e]))}var v=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.armatures={},t}return a(r,e),r.prototype.init=function(e){var r=this,o=e.pixiSpine;this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=o,this.game.canvas.addEventListener("webglcontextrestored",(function(){var e=r.game.gameObjects,n=[];for(var o in r.armatures)for(var a=+o,i=0;i<e.length;++i){var s=e[i];if(s.id===a){var u=s.getComponent(p);u&&(r.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:p.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:p.componentName}));break}}setTimeout((function(){n.forEach((function(e){r.add(e)}))}),1e3)}),!1)},r.prototype.update=function(t){for(var n in this.armatures)this.armatures[n].update(.001*t.deltaTime),this.armatures[n].updateTransform();e.prototype.update.call(this)},r.prototype.componentChanged=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(n){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE)switch(e.prop.prop[0]){case"resource":this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e);return[2]}))}))},r.prototype.add=function(e,n){var r,o;return s(this,void 0,void 0,(function(){var a,i,s,c,p,l,m,f,d=this;return u(this,(function(u){switch(u.label){case 0:return a=e.component,clearTimeout(a.addHandler),i=e.gameObject.id,s=this.increaseAsyncId(i),[4,t.resource.getResource(a.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,h(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(e),(l=null===(o=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===o?void 0:o.getContainer(e.gameObject.id))?(a.lastResource=a.resource,m=new this.pixiSpine.Spine(p),this.armatures[e.gameObject.id]=m,e.gameObject&&e.gameObject.transform&&(f=e.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),a.armature=m,a.emit("loaded",{resource:a.resource}),m.state.addListener({start:function(e,t){a.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){a.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){a.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){a.emit("end",{track:e,name:e.animation.name})},event:function(e,t){a.emit("event",e,t)}}),[2]):[2]):(a.addHandler=setTimeout((function(){a.destroied||(void 0===n&&(n=20),--n>0?d.add(e,n):console.log("retry exceed max times",a.resource))}),1e3),[2]):[2]}}))}))},r.prototype.change=function(e){this.remove(e),this.add(e)},r.prototype.remove=function(e){var n,r,o,a;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(e.gameObject.id),i=e.component,clearTimeout(i.addHandler),s=this.armatures[e.gameObject.id],(c=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,t.resource.getResource(i.lastResource)]):[3,2];case 1:y((p=u.sent()).name,null===(a=null===(o=p.data)||void 0===o?void 0:o.image)||void 0===a?void 0:a.src),u.label=2;case 2:return i.armature=null,delete this.armatures[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([t.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer);return t.resource.registerResourceType("SPINE"),e.Spine=p,e.SpineSystem=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);window.EVA.plugin.spineBase=window.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
|
package/dist/miniprogram.js
CHANGED
|
@@ -1,37 +1,46 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
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
|
+
|
|
2
3
|
import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
|
|
3
4
|
import { __extends, __values, __decorate, __awaiter, __generator } from 'tslib';
|
|
4
5
|
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
5
6
|
import { type } from '@eva/inspector-decorator';
|
|
6
7
|
import { Texture } from '@eva/miniprogram-pixi';
|
|
8
|
+
|
|
7
9
|
var Spine = function (_super) {
|
|
8
10
|
__extends(Spine, _super);
|
|
11
|
+
|
|
9
12
|
function Spine() {
|
|
10
13
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
14
|
+
|
|
11
15
|
_this.resource = '';
|
|
12
16
|
_this.animationName = '';
|
|
13
17
|
_this.autoPlay = true;
|
|
14
18
|
_this.waitExecuteInfos = [];
|
|
15
19
|
return _this;
|
|
16
20
|
}
|
|
21
|
+
|
|
17
22
|
Object.defineProperty(Spine.prototype, "armature", {
|
|
18
23
|
get: function get() {
|
|
19
24
|
return this._armature;
|
|
20
25
|
},
|
|
21
26
|
set: function set(val) {
|
|
22
27
|
var e_1, _a;
|
|
28
|
+
|
|
23
29
|
this._armature = val;
|
|
24
30
|
if (!val) return;
|
|
31
|
+
|
|
25
32
|
if (this.autoPlay) {
|
|
26
33
|
this.play(this.animationName);
|
|
27
34
|
}
|
|
35
|
+
|
|
28
36
|
try {
|
|
29
37
|
for (var _b = __values(this.waitExecuteInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
30
38
|
var info = _c.value;
|
|
39
|
+
|
|
31
40
|
if (info.playType) {
|
|
32
41
|
var name_1 = info.name,
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
loop = info.loop,
|
|
43
|
+
track = info.track;
|
|
35
44
|
this.play(name_1, loop, track);
|
|
36
45
|
} else {
|
|
37
46
|
this.stop(info.track);
|
|
@@ -48,21 +57,27 @@ var Spine = function (_super) {
|
|
|
48
57
|
if (e_1) throw e_1.error;
|
|
49
58
|
}
|
|
50
59
|
}
|
|
60
|
+
|
|
51
61
|
this.waitExecuteInfos = [];
|
|
52
62
|
},
|
|
53
63
|
enumerable: false,
|
|
54
64
|
configurable: true
|
|
55
65
|
});
|
|
66
|
+
|
|
56
67
|
Spine.prototype.init = function (obj) {
|
|
57
68
|
if (!obj) return;
|
|
69
|
+
|
|
58
70
|
_extends(this, obj);
|
|
59
71
|
};
|
|
72
|
+
|
|
60
73
|
Spine.prototype.onDestroy = function () {
|
|
61
74
|
this.destroied = true;
|
|
62
75
|
};
|
|
76
|
+
|
|
63
77
|
Spine.prototype.play = function (name, loop, track) {
|
|
64
78
|
try {
|
|
65
79
|
if (name) this.animationName = name;
|
|
80
|
+
|
|
66
81
|
if (!this.armature) {
|
|
67
82
|
this.waitExecuteInfos.push({
|
|
68
83
|
playType: true,
|
|
@@ -74,12 +89,14 @@ var Spine = function (_super) {
|
|
|
74
89
|
if (track === undefined) {
|
|
75
90
|
track = 0;
|
|
76
91
|
}
|
|
92
|
+
|
|
77
93
|
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
78
94
|
}
|
|
79
95
|
} catch (e) {
|
|
80
96
|
console.log(e);
|
|
81
97
|
}
|
|
82
98
|
};
|
|
99
|
+
|
|
83
100
|
Spine.prototype.stop = function (track) {
|
|
84
101
|
if (!this.armature) {
|
|
85
102
|
this.waitExecuteInfos.push({
|
|
@@ -88,32 +105,39 @@ var Spine = function (_super) {
|
|
|
88
105
|
});
|
|
89
106
|
return;
|
|
90
107
|
}
|
|
108
|
+
|
|
91
109
|
if (track === undefined) {
|
|
92
110
|
track = 0;
|
|
93
111
|
}
|
|
112
|
+
|
|
94
113
|
this.armature.state.setEmptyAnimation(track, 0);
|
|
95
114
|
};
|
|
115
|
+
|
|
96
116
|
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
97
117
|
try {
|
|
98
118
|
if (!this.armature) {} else {
|
|
99
119
|
if (track === undefined) {
|
|
100
120
|
track = 0;
|
|
101
121
|
}
|
|
122
|
+
|
|
102
123
|
this.armature.state.addAnimation(track, name, loop, delay);
|
|
103
124
|
}
|
|
104
125
|
} catch (e) {
|
|
105
126
|
console.log(e);
|
|
106
127
|
}
|
|
107
128
|
};
|
|
129
|
+
|
|
108
130
|
Spine.prototype.setMix = function (from, to, duration) {
|
|
109
131
|
if (!this.armature) ;else {
|
|
110
132
|
this.armature.stateData.setMix(from, to, duration);
|
|
111
133
|
}
|
|
112
134
|
};
|
|
135
|
+
|
|
113
136
|
Spine.prototype.getAnim = function (track) {
|
|
114
137
|
if (track === void 0) {
|
|
115
138
|
track = 0;
|
|
116
139
|
}
|
|
140
|
+
|
|
117
141
|
try {
|
|
118
142
|
if (!this.armature) {} else {
|
|
119
143
|
return this.armature.state.tracks[track].animation.name;
|
|
@@ -122,31 +146,43 @@ var Spine = function (_super) {
|
|
|
122
146
|
console.log(e);
|
|
123
147
|
}
|
|
124
148
|
};
|
|
149
|
+
|
|
125
150
|
Spine.prototype.setDefaultMix = function (duration) {
|
|
126
151
|
if (!this.armature) ;else {
|
|
127
152
|
this.armature.stateData.defaultMix = duration;
|
|
128
153
|
}
|
|
129
154
|
};
|
|
155
|
+
|
|
130
156
|
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
131
157
|
if (!this.armature) {
|
|
132
158
|
return;
|
|
133
159
|
}
|
|
160
|
+
|
|
134
161
|
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
135
162
|
};
|
|
163
|
+
|
|
136
164
|
Spine.prototype.getBone = function (boneName) {
|
|
137
165
|
if (!this.armature) {
|
|
138
166
|
return;
|
|
139
167
|
}
|
|
168
|
+
|
|
140
169
|
return this.armature.skeleton.findBone(boneName);
|
|
141
170
|
};
|
|
171
|
+
|
|
142
172
|
Spine.componentName = 'Spine';
|
|
173
|
+
|
|
143
174
|
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
175
|
+
|
|
144
176
|
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
177
|
+
|
|
145
178
|
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
179
|
+
|
|
146
180
|
return Spine;
|
|
147
181
|
}(Component);
|
|
182
|
+
|
|
148
183
|
var Spine$1 = Spine;
|
|
149
184
|
var texCache = {};
|
|
185
|
+
|
|
150
186
|
function cacheImage(data) {
|
|
151
187
|
var oldImg = data.image;
|
|
152
188
|
return {
|
|
@@ -154,40 +190,52 @@ function cacheImage(data) {
|
|
|
154
190
|
count: 0
|
|
155
191
|
};
|
|
156
192
|
}
|
|
193
|
+
|
|
157
194
|
function retainTexture(name, data) {
|
|
158
195
|
var cache = texCache[name];
|
|
196
|
+
|
|
159
197
|
if (!cache) {
|
|
160
198
|
cache = cacheImage(data);
|
|
161
199
|
texCache[name] = cache;
|
|
162
200
|
}
|
|
201
|
+
|
|
163
202
|
cache.count++;
|
|
164
203
|
return cache.tex;
|
|
165
204
|
}
|
|
205
|
+
|
|
166
206
|
function getTexture(imageSrc, data) {
|
|
167
207
|
var cache = texCache[imageSrc];
|
|
208
|
+
|
|
168
209
|
if (!cache) {
|
|
169
210
|
cache = cacheImage(data);
|
|
170
211
|
texCache[imageSrc] = cache;
|
|
171
212
|
}
|
|
213
|
+
|
|
172
214
|
return cache.tex;
|
|
173
215
|
}
|
|
216
|
+
|
|
174
217
|
function releaseTexture(imageSrc) {
|
|
175
218
|
if (!imageSrc) return;
|
|
176
219
|
setTimeout(function () {
|
|
177
220
|
var cache = texCache[imageSrc];
|
|
221
|
+
|
|
178
222
|
if (cache) {
|
|
179
223
|
cache.count--;
|
|
224
|
+
|
|
180
225
|
if (cache.count <= 0) {
|
|
181
226
|
if (cache.tex) {
|
|
182
227
|
cache.tex.destroy(true);
|
|
183
228
|
cache.tex = null;
|
|
184
229
|
}
|
|
230
|
+
|
|
185
231
|
delete texCache[imageSrc];
|
|
186
232
|
}
|
|
187
233
|
}
|
|
188
234
|
}, 100);
|
|
189
235
|
}
|
|
236
|
+
|
|
190
237
|
var dataMap = {};
|
|
238
|
+
|
|
191
239
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
192
240
|
var spineData = null;
|
|
193
241
|
var img = getTexture(data.image.src, data);
|
|
@@ -197,9 +245,11 @@ function createSpineData(name, data, scale, pixiSpine) {
|
|
|
197
245
|
if (spineAtlas) {
|
|
198
246
|
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
199
247
|
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
248
|
+
|
|
200
249
|
if (scale) {
|
|
201
250
|
spineJsonParser.scale = scale;
|
|
202
251
|
}
|
|
252
|
+
|
|
203
253
|
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
204
254
|
}
|
|
205
255
|
});
|
|
@@ -211,11 +261,13 @@ function createSpineData(name, data, scale, pixiSpine) {
|
|
|
211
261
|
dataMap[name] = obj;
|
|
212
262
|
return obj;
|
|
213
263
|
}
|
|
264
|
+
|
|
214
265
|
function getSpineData(res, pixiSpine) {
|
|
215
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
216
267
|
var data;
|
|
217
268
|
return __generator(this, function (_a) {
|
|
218
269
|
data = dataMap[res.name];
|
|
270
|
+
|
|
219
271
|
if (!data) {
|
|
220
272
|
if (res.complete) {
|
|
221
273
|
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
@@ -223,33 +275,44 @@ function getSpineData(res, pixiSpine) {
|
|
|
223
275
|
return [2];
|
|
224
276
|
}
|
|
225
277
|
}
|
|
278
|
+
|
|
226
279
|
retainTexture(res.data.image.src, res.data);
|
|
227
280
|
data.ref++;
|
|
228
281
|
return [2, data.spineData];
|
|
229
282
|
});
|
|
230
283
|
});
|
|
231
284
|
}
|
|
285
|
+
|
|
232
286
|
function releaseSpineData(resourceName, imageSrc) {
|
|
233
287
|
var data = dataMap[resourceName];
|
|
288
|
+
|
|
234
289
|
if (!data) {
|
|
235
290
|
return;
|
|
236
291
|
}
|
|
292
|
+
|
|
237
293
|
data.ref--;
|
|
294
|
+
|
|
238
295
|
if (data.ref <= 0) {
|
|
239
296
|
releaseTexture(imageSrc);
|
|
240
297
|
delete dataMap[resourceName];
|
|
241
298
|
}
|
|
242
299
|
}
|
|
300
|
+
|
|
243
301
|
var MaxRetryCount = 20;
|
|
302
|
+
|
|
244
303
|
var SpineSystem = function (_super) {
|
|
245
304
|
__extends(SpineSystem, _super);
|
|
305
|
+
|
|
246
306
|
function SpineSystem() {
|
|
247
307
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
308
|
+
|
|
248
309
|
_this.armatures = {};
|
|
249
310
|
return _this;
|
|
250
311
|
}
|
|
312
|
+
|
|
251
313
|
SpineSystem.prototype.init = function (_a) {
|
|
252
314
|
var _this = this;
|
|
315
|
+
|
|
253
316
|
var pixiSpine = _a.pixiSpine;
|
|
254
317
|
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
255
318
|
this.renderSystem.rendererManager.register(this);
|
|
@@ -257,12 +320,16 @@ var SpineSystem = function (_super) {
|
|
|
257
320
|
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
258
321
|
var objs = _this.game.gameObjects;
|
|
259
322
|
var toAdd = [];
|
|
323
|
+
|
|
260
324
|
for (var k in _this.armatures) {
|
|
261
325
|
var id = +k;
|
|
326
|
+
|
|
262
327
|
for (var i = 0; i < objs.length; ++i) {
|
|
263
328
|
var obj = objs[i];
|
|
329
|
+
|
|
264
330
|
if (obj.id === id) {
|
|
265
331
|
var sp = obj.getComponent(Spine$1);
|
|
332
|
+
|
|
266
333
|
if (sp) {
|
|
267
334
|
_this.remove({
|
|
268
335
|
type: OBSERVER_TYPE.REMOVE,
|
|
@@ -270,6 +337,7 @@ var SpineSystem = function (_super) {
|
|
|
270
337
|
component: sp,
|
|
271
338
|
componentName: Spine$1.componentName
|
|
272
339
|
});
|
|
340
|
+
|
|
273
341
|
toAdd.push({
|
|
274
342
|
type: OBSERVER_TYPE.ADD,
|
|
275
343
|
gameObject: obj,
|
|
@@ -277,10 +345,12 @@ var SpineSystem = function (_super) {
|
|
|
277
345
|
componentName: Spine$1.componentName
|
|
278
346
|
});
|
|
279
347
|
}
|
|
348
|
+
|
|
280
349
|
break;
|
|
281
350
|
}
|
|
282
351
|
}
|
|
283
352
|
}
|
|
353
|
+
|
|
284
354
|
setTimeout(function () {
|
|
285
355
|
toAdd.forEach(function (obj) {
|
|
286
356
|
_this.add(obj);
|
|
@@ -288,13 +358,16 @@ var SpineSystem = function (_super) {
|
|
|
288
358
|
}, 1000);
|
|
289
359
|
}, false);
|
|
290
360
|
};
|
|
361
|
+
|
|
291
362
|
SpineSystem.prototype.update = function (e) {
|
|
292
363
|
for (var key in this.armatures) {
|
|
293
364
|
this.armatures[key].update(e.deltaTime * 0.001);
|
|
294
365
|
this.armatures[key].updateTransform();
|
|
295
366
|
}
|
|
367
|
+
|
|
296
368
|
_super.prototype.update.call(this);
|
|
297
369
|
};
|
|
370
|
+
|
|
298
371
|
SpineSystem.prototype.componentChanged = function (changed) {
|
|
299
372
|
return __awaiter(this, void 0, void 0, function () {
|
|
300
373
|
return __generator(this, function (_a) {
|
|
@@ -311,15 +384,20 @@ var SpineSystem = function (_super) {
|
|
|
311
384
|
this.remove(changed);
|
|
312
385
|
}
|
|
313
386
|
}
|
|
387
|
+
|
|
314
388
|
return [2];
|
|
315
389
|
});
|
|
316
390
|
});
|
|
317
391
|
};
|
|
392
|
+
|
|
318
393
|
SpineSystem.prototype.add = function (changed, count) {
|
|
319
394
|
var _a, _b;
|
|
395
|
+
|
|
320
396
|
return __awaiter(this, void 0, void 0, function () {
|
|
321
397
|
var component, gameObjectId, asyncId, res, spineData, container, armature, tran;
|
|
398
|
+
|
|
322
399
|
var _this = this;
|
|
400
|
+
|
|
323
401
|
return __generator(this, function (_c) {
|
|
324
402
|
switch (_c.label) {
|
|
325
403
|
case 0:
|
|
@@ -328,20 +406,25 @@ var SpineSystem = function (_super) {
|
|
|
328
406
|
gameObjectId = changed.gameObject.id;
|
|
329
407
|
asyncId = this.increaseAsyncId(gameObjectId);
|
|
330
408
|
return [4, resource.getResource(component.resource)];
|
|
409
|
+
|
|
331
410
|
case 1:
|
|
332
411
|
res = _c.sent();
|
|
333
412
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
334
413
|
return [4, getSpineData(res, this.pixiSpine)];
|
|
414
|
+
|
|
335
415
|
case 2:
|
|
336
416
|
spineData = _c.sent();
|
|
337
417
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
|
|
418
|
+
|
|
338
419
|
if (!spineData) {
|
|
339
420
|
component.addHandler = setTimeout(function () {
|
|
340
421
|
if (!component.destroied) {
|
|
341
422
|
if (count === undefined) {
|
|
342
423
|
count = MaxRetryCount;
|
|
343
424
|
}
|
|
425
|
+
|
|
344
426
|
count--;
|
|
427
|
+
|
|
345
428
|
if (count > 0) {
|
|
346
429
|
_this.add(changed, count);
|
|
347
430
|
} else {
|
|
@@ -351,19 +434,24 @@ var SpineSystem = function (_super) {
|
|
|
351
434
|
}, 1000);
|
|
352
435
|
return [2];
|
|
353
436
|
}
|
|
437
|
+
|
|
354
438
|
this.remove(changed);
|
|
355
439
|
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
440
|
+
|
|
356
441
|
if (!container) {
|
|
357
442
|
return [2];
|
|
358
443
|
}
|
|
444
|
+
|
|
359
445
|
component.lastResource = component.resource;
|
|
360
446
|
armature = new this.pixiSpine.Spine(spineData);
|
|
361
447
|
this.armatures[changed.gameObject.id] = armature;
|
|
448
|
+
|
|
362
449
|
if (changed.gameObject && changed.gameObject.transform) {
|
|
363
450
|
tran = changed.gameObject.transform;
|
|
364
451
|
armature.x = tran.size.width * tran.origin.x;
|
|
365
452
|
armature.y = tran.size.height * tran.origin.y;
|
|
366
453
|
}
|
|
454
|
+
|
|
367
455
|
container.addChildAt(armature, 0);
|
|
368
456
|
armature.update();
|
|
369
457
|
armature.updateTransform();
|
|
@@ -405,12 +493,15 @@ var SpineSystem = function (_super) {
|
|
|
405
493
|
});
|
|
406
494
|
});
|
|
407
495
|
};
|
|
496
|
+
|
|
408
497
|
SpineSystem.prototype.change = function (changed) {
|
|
409
498
|
this.remove(changed);
|
|
410
499
|
this.add(changed);
|
|
411
500
|
};
|
|
501
|
+
|
|
412
502
|
SpineSystem.prototype.remove = function (changed) {
|
|
413
503
|
var _a, _b, _c, _d;
|
|
504
|
+
|
|
414
505
|
return __awaiter(this, void 0, void 0, function () {
|
|
415
506
|
var component, armature, container, res;
|
|
416
507
|
return __generator(this, function (_e) {
|
|
@@ -421,18 +512,22 @@ var SpineSystem = function (_super) {
|
|
|
421
512
|
clearTimeout(component.addHandler);
|
|
422
513
|
armature = this.armatures[changed.gameObject.id];
|
|
423
514
|
container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(changed.gameObject.id);
|
|
515
|
+
|
|
424
516
|
if (container && armature) {
|
|
425
517
|
container.removeChild(armature);
|
|
426
518
|
}
|
|
519
|
+
|
|
427
520
|
if (!component.armature) return [3, 2];
|
|
428
521
|
component.armature.destroy({
|
|
429
522
|
children: true
|
|
430
523
|
});
|
|
431
524
|
return [4, resource.getResource(component.lastResource)];
|
|
525
|
+
|
|
432
526
|
case 1:
|
|
433
527
|
res = _e.sent();
|
|
434
528
|
releaseSpineData(res.name, (_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src);
|
|
435
529
|
_e.label = 2;
|
|
530
|
+
|
|
436
531
|
case 2:
|
|
437
532
|
component.armature = null;
|
|
438
533
|
delete this.armatures[changed.gameObject.id];
|
|
@@ -442,12 +537,14 @@ var SpineSystem = function (_super) {
|
|
|
442
537
|
});
|
|
443
538
|
});
|
|
444
539
|
};
|
|
540
|
+
|
|
445
541
|
SpineSystem.systemName = 'SpineSystem';
|
|
446
542
|
SpineSystem = __decorate([decorators.componentObserver({
|
|
447
543
|
Spine: ['resource']
|
|
448
544
|
})], SpineSystem);
|
|
449
545
|
return SpineSystem;
|
|
450
546
|
}(Renderer);
|
|
547
|
+
|
|
451
548
|
var SpineSystem$1 = SpineSystem;
|
|
452
549
|
resource.registerResourceType('SPINE');
|
|
453
550
|
export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),a=function(e,t){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function o(e,t){function r(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t,r,n){var a,o=arguments.length,i=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i}function s(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){e.done?a(e.value):new r((function(t){t(e.value)})).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}var c=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t.waitExecuteInfos=[],t}return o(t,e),Object.defineProperty(t.prototype,"armature",{get:function(){return this._armature},set:function(e){var t,r;if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);try{for(var n=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(this.waitExecuteInfos),a=n.next();!a.done;a=n.next()){var o=a.value;if(o.playType){var i=o.name,s=o.loop,u=o.track;this.play(i,s,u)}else this.stop(o.track)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}this.waitExecuteInfos=[]}},enumerable:!1,configurable:!0}),t.prototype.init=function(e){e&&Object.assign(this,e)},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,r){try{e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,t)):this.waitExecuteInfos.push({playType:!0,name:e,loop:null!=t?t:this.autoPlay,track:r})}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})},t.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([r.type("string")],t.prototype,"resource",void 0),i([r.type("string")],t.prototype,"animationName",void 0),i([r.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),p={};function l(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var m={};function f(e,t,r,n){var a=null,o=function(e,t){var r=p[e];return r||(r=l(t),p[e]=r),r.tex}(t.image.src,t);new n.core.TextureAtlas(t.atlas,(function(e,t){t(o.baseTexture)}),(function(e){if(e){var o=new n.core.AtlasAttachmentLoader(e),i=new n.core.SkeletonJson(o);r&&(i.scale=r),a=i.readSkeletonData(t.ske)}}));var i={spineData:a,ref:0,imageSrc:t.image.src};return m[e]=i,i}function d(e,t){return s(this,void 0,void 0,(function(){var r;return u(this,(function(n){if(!(r=m[e.name]))if(e.complete)r=f(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=p[e];r||(r=l(t),p[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function h(e,t){var r=m[e];r&&(r.ref--,r.ref<=0&&(!function(e){e&&setTimeout((function(){var t=p[e];t&&(t.count--,t.count<=0&&(t.tex&&(t.tex.destroy(!0),t.tex=null),delete p[e]))}),100)}(t),delete m[e]))}var y=function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e.armatures={},e}return o(n,r),n.prototype.init=function(r){var n=this,a=r.pixiSpine;this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=a,this.game.canvas.addEventListener("webglcontextrestored",(function(){var t=n.game.gameObjects,r=[];for(var a in n.armatures)for(var o=+a,i=0;i<t.length;++i){var s=t[i];if(s.id===o){var u=s.getComponent(c);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:c.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:c.componentName}));break}}setTimeout((function(){r.forEach((function(e){n.add(e)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime),this.armatures[t].updateTransform();r.prototype.update.call(this)},n.prototype.componentChanged=function(t){return s(this,void 0,void 0,(function(){return u(this,(function(r){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]}))}))},n.prototype.add=function(t,r){var n,a;return s(this,void 0,void 0,(function(){var o,i,s,c,p,l,m,f,h=this;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),i=t.gameObject.id,s=this.increaseAsyncId(i),[4,e.resource.getResource(o.resource)];case 1:return c=u.sent(),this.validateAsyncId(i,s)?[4,d(c,this.pixiSpine)]:[2];case 2:return p=u.sent(),this.validateAsyncId(i,s)?p?(this.remove(t),(l=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(t.gameObject.id))?(o.lastResource=o.resource,m=new this.pixiSpine.Spine(p),this.armatures[t.gameObject.id]=m,t.gameObject&&t.gameObject.transform&&(f=t.gameObject.transform,m.x=f.size.width*f.origin.x,m.y=f.size.height*f.origin.y),l.addChildAt(m,0),m.update(),m.updateTransform(),o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:function(e,t){o.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){o.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){o.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){o.emit("end",{track:e,name:e.animation.name})},event:function(e,t){o.emit("event",e,t)}}),[2]):[2]):(o.addHandler=setTimeout((function(){o.destroied||(void 0===r&&(r=20),--r>0?h.add(t,r):console.log("retry exceed max times",o.resource))}),1e3),[2]):[2]}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n,a,o;return s(this,void 0,void 0,(function(){var i,s,c,p;return u(this,(function(u){switch(u.label){case 0:return this.increaseAsyncId(t.gameObject.id),i=t.component,clearTimeout(i.addHandler),s=this.armatures[t.gameObject.id],(c=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id))&&s&&c.removeChild(s),i.armature?(i.armature.destroy({children:!0}),[4,e.resource.getResource(i.lastResource)]):[3,2];case 1:h((p=u.sent()).name,null===(o=null===(a=p.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src),u.label=2;case 2:return i.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=i([e.decorators.componentObserver({Spine:["resource"]})],n)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=c,exports.SpineSystem=y;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "1.2.7-fix.
|
|
3
|
+
"version": "1.2.7-fix.6",
|
|
4
4
|
"description": "@eva/spine-base",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/spine-base.esm.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "1.2.7-fix.
|
|
22
|
-
"@eva/plugin-renderer": "1.2.7-fix.
|
|
21
|
+
"@eva/eva.js": "1.2.7-fix.6",
|
|
22
|
+
"@eva/plugin-renderer": "1.2.7-fix.6",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^4.8.9"
|
|
25
25
|
}
|