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