@eva/spine-base 2.1.0-beta.3 → 2.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.spineBase.js +691 -0
- package/dist/EVA.plugin.spineBase.min.js +1 -0
- package/dist/global.d.ts +6 -0
- package/dist/spine-base.cjs.js +841 -0
- package/dist/spine-base.cjs.prod.js +1 -0
- package/dist/spine-base.d.ts +305 -0
- package/dist/spine-base.esm.js +836 -0
- package/package.json +3 -3
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
globalThis.EVA = globalThis.EVA || {};
|
|
3
|
+
globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
4
|
+
var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
5
|
+
'use strict';
|
|
6
|
+
function __decorate(decorators, target, key, desc) {
|
|
7
|
+
var c = arguments.length,
|
|
8
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
9
|
+
d;
|
|
10
|
+
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--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
|
+
}
|
|
13
|
+
function __metadata(metadataKey, metadataValue) {
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
15
|
+
}
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) {
|
|
18
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
19
|
+
resolve(value);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function rejected(value) {
|
|
31
|
+
try {
|
|
32
|
+
step(generator["throw"](value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function step(result) {
|
|
38
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
39
|
+
}
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
};
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
50
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
51
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
}
|
|
55
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
56
|
+
var e = new Error(message);
|
|
57
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
58
|
+
};
|
|
59
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
60
|
+
constructor() {
|
|
61
|
+
super('Symbol keys are not supported yet!');
|
|
62
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
66
|
+
function transformBasicType(type) {
|
|
67
|
+
if (type === String) {
|
|
68
|
+
return 'string';
|
|
69
|
+
}
|
|
70
|
+
if (type === Number) {
|
|
71
|
+
return 'number';
|
|
72
|
+
}
|
|
73
|
+
if (type === Boolean) {
|
|
74
|
+
return 'boolean';
|
|
75
|
+
}
|
|
76
|
+
return 'unknown';
|
|
77
|
+
}
|
|
78
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
79
|
+
const constructor = target.constructor;
|
|
80
|
+
const current = constructor.IDEProps || {};
|
|
81
|
+
current[propertyKey] = _extends(_extends({
|
|
82
|
+
key: propertyKey
|
|
83
|
+
}, current[propertyKey]), patch);
|
|
84
|
+
constructor.IDEProps = current;
|
|
85
|
+
}
|
|
86
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
87
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
88
|
+
let isArray = type === Array;
|
|
89
|
+
const str = transformBasicType(type);
|
|
90
|
+
if (str !== 'unknown') {
|
|
91
|
+
type = str;
|
|
92
|
+
}
|
|
93
|
+
if (returnTypeFunction) {
|
|
94
|
+
const returnType = returnTypeFunction();
|
|
95
|
+
if (Array.isArray(returnType)) {
|
|
96
|
+
isArray = true;
|
|
97
|
+
type = returnType[0];
|
|
98
|
+
} else {
|
|
99
|
+
type = returnType;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
103
|
+
const current = properties[key] || {};
|
|
104
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
105
|
+
type,
|
|
106
|
+
isArray: isArray
|
|
107
|
+
}), options);
|
|
108
|
+
properties[key] = property;
|
|
109
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
110
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
111
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
112
|
+
}
|
|
113
|
+
function type(type) {
|
|
114
|
+
return Field({
|
|
115
|
+
type
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
119
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
120
|
+
return {
|
|
121
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
122
|
+
options: maybeOptions || {}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
options: returnTypeFuncOrOptions || {}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
130
|
+
return (target, propertyKey) => {
|
|
131
|
+
if (typeof propertyKey === 'symbol') {
|
|
132
|
+
throw new SymbolKeysNotSupportedError();
|
|
133
|
+
}
|
|
134
|
+
const {
|
|
135
|
+
options,
|
|
136
|
+
returnTypeFunc
|
|
137
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
138
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var ExecuteMode;
|
|
142
|
+
(function (ExecuteMode) {
|
|
143
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
144
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
145
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
146
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
147
|
+
class Spine extends eva_js.Component {
|
|
148
|
+
constructor(params) {
|
|
149
|
+
super(params);
|
|
150
|
+
this.resource = '';
|
|
151
|
+
this.scale = 1;
|
|
152
|
+
this.animationName = '';
|
|
153
|
+
this.autoPlay = true;
|
|
154
|
+
this.keepResource = false;
|
|
155
|
+
this.timeScale = 1;
|
|
156
|
+
this.skin = '';
|
|
157
|
+
this._slotGameObjects = new Map();
|
|
158
|
+
this._pendingSlotObjects = [];
|
|
159
|
+
this.waitExecuteInfos = [];
|
|
160
|
+
this.listenerBound = false;
|
|
161
|
+
this.paused = false;
|
|
162
|
+
this.init(params);
|
|
163
|
+
}
|
|
164
|
+
set armature(val) {
|
|
165
|
+
this._armature = val;
|
|
166
|
+
if (!val) return;
|
|
167
|
+
this.applyTimeScale();
|
|
168
|
+
if (this.skin) this.setSkin(this.skin);
|
|
169
|
+
if (this.autoPlay) {
|
|
170
|
+
this.play(this.animationName);
|
|
171
|
+
}
|
|
172
|
+
for (const info of this.waitExecuteInfos) {
|
|
173
|
+
if (info.playType) {
|
|
174
|
+
const {
|
|
175
|
+
name,
|
|
176
|
+
loop,
|
|
177
|
+
track
|
|
178
|
+
} = info;
|
|
179
|
+
this.play(name, loop, track);
|
|
180
|
+
} else {
|
|
181
|
+
this.stop(info.track);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
this.waitExecuteInfos = [];
|
|
185
|
+
}
|
|
186
|
+
get armature() {
|
|
187
|
+
return this._armature;
|
|
188
|
+
}
|
|
189
|
+
init(obj) {
|
|
190
|
+
if (obj) _extends(this, obj);
|
|
191
|
+
if (!this.listenerBound) {
|
|
192
|
+
this.listenerBound = true;
|
|
193
|
+
this.on('start', event => {
|
|
194
|
+
var _a;
|
|
195
|
+
(_a = this.onStart) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
196
|
+
});
|
|
197
|
+
this.on('complete', event => {
|
|
198
|
+
var _a;
|
|
199
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
200
|
+
});
|
|
201
|
+
this.on('event', (track, event) => {
|
|
202
|
+
var _a;
|
|
203
|
+
(_a = this.onEvent) === null || _a === void 0 ? void 0 : _a.call(this, track, event);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
onDestroy() {
|
|
208
|
+
this.destroied = true;
|
|
209
|
+
}
|
|
210
|
+
load() {
|
|
211
|
+
return this.armature;
|
|
212
|
+
}
|
|
213
|
+
destroy() {
|
|
214
|
+
this.onDestroy();
|
|
215
|
+
if (this.armature && !this.armature.destroyed) {
|
|
216
|
+
this._destroySlotGameObjects();
|
|
217
|
+
this.armature.destroy({
|
|
218
|
+
children: true
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
this.armature = null;
|
|
222
|
+
}
|
|
223
|
+
pause() {
|
|
224
|
+
this.paused = true;
|
|
225
|
+
this.applyTimeScale();
|
|
226
|
+
}
|
|
227
|
+
resume() {
|
|
228
|
+
this.paused = false;
|
|
229
|
+
this.applyTimeScale();
|
|
230
|
+
}
|
|
231
|
+
setSkin(name) {
|
|
232
|
+
var _a, _b, _c, _d, _e;
|
|
233
|
+
this.skin = name;
|
|
234
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.skeleton)) return;
|
|
235
|
+
if (this.armature.skeleton.setSkinByName) {
|
|
236
|
+
this.armature.skeleton.setSkinByName(name);
|
|
237
|
+
} else if (this.armature.skeleton.setSkin) {
|
|
238
|
+
const skin = ((_c = (_b = this.armature.skeleton.data) === null || _b === void 0 ? void 0 : _b.findSkin) === null || _c === void 0 ? void 0 : _c.call(_b, name)) || name;
|
|
239
|
+
this.armature.skeleton.setSkin(skin);
|
|
240
|
+
}
|
|
241
|
+
(_e = (_d = this.armature.skeleton).setSlotsToSetupPose) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
242
|
+
}
|
|
243
|
+
play(name, loopAnimation, track) {
|
|
244
|
+
try {
|
|
245
|
+
const loop = loopAnimation !== null && loopAnimation !== void 0 ? loopAnimation : this.autoPlay;
|
|
246
|
+
if (name) this.animationName = name;
|
|
247
|
+
if (!this.armature) {
|
|
248
|
+
this.waitExecuteInfos.push({
|
|
249
|
+
playType: true,
|
|
250
|
+
name,
|
|
251
|
+
loop,
|
|
252
|
+
track
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
if (track === undefined) {
|
|
256
|
+
track = 0;
|
|
257
|
+
}
|
|
258
|
+
this.applyTimeScale();
|
|
259
|
+
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
260
|
+
}
|
|
261
|
+
} catch (e) {
|
|
262
|
+
console.log(e);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
stop(track) {
|
|
266
|
+
if (!this.armature) {
|
|
267
|
+
this.waitExecuteInfos.push({
|
|
268
|
+
playType: false,
|
|
269
|
+
track
|
|
270
|
+
});
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (track === undefined) {
|
|
274
|
+
track = 0;
|
|
275
|
+
}
|
|
276
|
+
this.armature.state.setEmptyAnimation(track, 0);
|
|
277
|
+
}
|
|
278
|
+
applyTimeScale() {
|
|
279
|
+
var _a;
|
|
280
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.state)) return;
|
|
281
|
+
this.armature.state.timeScale = this.paused ? 0 : this.timeScale;
|
|
282
|
+
}
|
|
283
|
+
addAnimation(name, delay, loop, track) {
|
|
284
|
+
try {
|
|
285
|
+
if (!this.armature) {} else {
|
|
286
|
+
if (track === undefined) {
|
|
287
|
+
track = 0;
|
|
288
|
+
}
|
|
289
|
+
this.armature.state.addAnimation(track, name, loop, delay);
|
|
290
|
+
}
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.log(e);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
setMix(from, to, duration) {
|
|
296
|
+
if (!this.armature) ;else {
|
|
297
|
+
this.armature.state.data.setMix(from, to, duration);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
getAnim(track = 0) {
|
|
301
|
+
try {
|
|
302
|
+
if (!this.armature) {} else {
|
|
303
|
+
return this.armature.state.tracks[track].animation.name;
|
|
304
|
+
}
|
|
305
|
+
} catch (e) {
|
|
306
|
+
console.log(e);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
setDefaultMix(duration) {
|
|
310
|
+
if (!this.armature) ;else {
|
|
311
|
+
this.armature.state.data.defaultMix = duration;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
setAttachment(slotName, attachmentName) {
|
|
315
|
+
if (!this.armature) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
319
|
+
}
|
|
320
|
+
getBone(boneName) {
|
|
321
|
+
if (!this.armature) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
return this.armature.skeleton.findBone(boneName);
|
|
325
|
+
}
|
|
326
|
+
addSlotObject(slot, gameObject, options) {
|
|
327
|
+
if (!this.armature) {
|
|
328
|
+
console.warn('Spine armature is not ready, cannot addSlotObject');
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (!this._containerManager) {
|
|
332
|
+
console.warn('ContainerManager is not available');
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const container = this._containerManager.getContainer(gameObject.id);
|
|
336
|
+
if (!container) {
|
|
337
|
+
this._pendingSlotObjects.push({
|
|
338
|
+
slot,
|
|
339
|
+
gameObject,
|
|
340
|
+
options
|
|
341
|
+
});
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
this._doAddSlotObject(slot, gameObject, container, options);
|
|
345
|
+
}
|
|
346
|
+
_doAddSlotObject(slot, gameObject, container, options) {
|
|
347
|
+
const wrapper = new pixi_js.Container();
|
|
348
|
+
wrapper.addChild(container);
|
|
349
|
+
this.armature.addSlotObject(slot, wrapper, options);
|
|
350
|
+
this._slotGameObjects.set(gameObject, {
|
|
351
|
+
slot,
|
|
352
|
+
wrapper
|
|
353
|
+
});
|
|
354
|
+
this._syncTransformTree(gameObject);
|
|
355
|
+
}
|
|
356
|
+
_syncTransformTree(gameObject) {
|
|
357
|
+
var _a;
|
|
358
|
+
if (!this._containerManager) return;
|
|
359
|
+
this._containerManager.updateTransform({
|
|
360
|
+
name: gameObject.id,
|
|
361
|
+
transform: gameObject.transform
|
|
362
|
+
});
|
|
363
|
+
if ((_a = gameObject.transform) === null || _a === void 0 ? void 0 : _a.children) {
|
|
364
|
+
for (const childTransform of gameObject.transform.children) {
|
|
365
|
+
if (childTransform.gameObject) {
|
|
366
|
+
this._syncTransformTree(childTransform.gameObject);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
_flushPendingSlotObjects() {
|
|
372
|
+
if (this._pendingSlotObjects.length === 0) return;
|
|
373
|
+
if (!this.armature || !this._containerManager) return;
|
|
374
|
+
const still = [];
|
|
375
|
+
for (const pending of this._pendingSlotObjects) {
|
|
376
|
+
const container = this._containerManager.getContainer(pending.gameObject.id);
|
|
377
|
+
if (container) {
|
|
378
|
+
this._doAddSlotObject(pending.slot, pending.gameObject, container, pending.options);
|
|
379
|
+
} else {
|
|
380
|
+
still.push(pending);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
this._pendingSlotObjects = still;
|
|
384
|
+
}
|
|
385
|
+
removeSlotObject(gameObject) {
|
|
386
|
+
this._pendingSlotObjects = this._pendingSlotObjects.filter(p => p.gameObject !== gameObject);
|
|
387
|
+
const entry = this._slotGameObjects.get(gameObject);
|
|
388
|
+
if (entry && this.armature) {
|
|
389
|
+
this.armature.removeSlotObject(entry.wrapper);
|
|
390
|
+
entry.wrapper.destroy({
|
|
391
|
+
children: false
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
this._slotGameObjects.delete(gameObject);
|
|
395
|
+
}
|
|
396
|
+
_destroySlotGameObjects() {
|
|
397
|
+
for (const [gameObject, entry] of this._slotGameObjects) {
|
|
398
|
+
if (!gameObject.destroyed) {
|
|
399
|
+
if (this.armature) {
|
|
400
|
+
this.armature.removeSlotObject(entry.wrapper);
|
|
401
|
+
}
|
|
402
|
+
entry.wrapper.destroy({
|
|
403
|
+
children: false
|
|
404
|
+
});
|
|
405
|
+
gameObject.destroy();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
this._slotGameObjects.clear();
|
|
409
|
+
this._pendingSlotObjects = [];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
Spine.componentName = 'Spine';
|
|
413
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "resource", void 0);
|
|
414
|
+
__decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "scale", void 0);
|
|
415
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "animationName", void 0);
|
|
416
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
|
|
417
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "keepResource", void 0);
|
|
418
|
+
__decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "timeScale", void 0);
|
|
419
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "skin", void 0);
|
|
420
|
+
let dataMap = {};
|
|
421
|
+
function resolveImageSrc(image) {
|
|
422
|
+
var _a, _b, _c, _d, _e;
|
|
423
|
+
if (!image) return '';
|
|
424
|
+
if (typeof image === 'string') return image;
|
|
425
|
+
return image.label || ((_a = image.source) === null || _a === void 0 ? void 0 : _a.label) || ((_c = (_b = image.source) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.src) || ((_d = image.source) === null || _d === void 0 ? void 0 : _d._sourceOrigin) || image.src || ((_e = image.baseTexture) === null || _e === void 0 ? void 0 : _e.cacheId) || '';
|
|
426
|
+
}
|
|
427
|
+
function createSpineData(name, data, scale, pixiSpine) {
|
|
428
|
+
const skeletonAsset = data.ske;
|
|
429
|
+
const atlasAsset = data.atlas;
|
|
430
|
+
const attachmentLoader = new pixiSpine.AtlasAttachmentLoader(atlasAsset);
|
|
431
|
+
const parser = skeletonAsset instanceof Uint8Array ? new pixiSpine.SkeletonBinary(attachmentLoader) : new pixiSpine.SkeletonJson(attachmentLoader);
|
|
432
|
+
parser.scale = scale || 1;
|
|
433
|
+
const skeletonData = parser.readSkeletonData(skeletonAsset);
|
|
434
|
+
const obj = {
|
|
435
|
+
spineData: skeletonData,
|
|
436
|
+
ref: 0,
|
|
437
|
+
imageSrc: resolveImageSrc(data.image)
|
|
438
|
+
};
|
|
439
|
+
dataMap[name] = obj;
|
|
440
|
+
return obj;
|
|
441
|
+
}
|
|
442
|
+
function getSpineData(res, scale, pixiSpine) {
|
|
443
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
+
let data = dataMap[res.name];
|
|
445
|
+
if (!data) {
|
|
446
|
+
if (res.complete) {
|
|
447
|
+
data = createSpineData(res.name, res.data, scale, pixiSpine);
|
|
448
|
+
} else if (!data) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
data.ref++;
|
|
453
|
+
return data.spineData;
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function releaseSpineData(res, _imageSrc) {
|
|
457
|
+
const resourceName = res.name;
|
|
458
|
+
const data = dataMap[resourceName];
|
|
459
|
+
if (!data) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
data.ref--;
|
|
463
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
if (data.ref <= 0) {
|
|
465
|
+
eva_js.resource.destroy(resourceName);
|
|
466
|
+
delete dataMap[resourceName];
|
|
467
|
+
}
|
|
468
|
+
}), 100);
|
|
469
|
+
}
|
|
470
|
+
const MaxRetryCount = 20;
|
|
471
|
+
let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
472
|
+
constructor() {
|
|
473
|
+
super(...arguments);
|
|
474
|
+
this.armatures = {};
|
|
475
|
+
this._spineComponents = {};
|
|
476
|
+
}
|
|
477
|
+
init({
|
|
478
|
+
pixiSpine
|
|
479
|
+
}) {
|
|
480
|
+
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
481
|
+
this.renderSystem.rendererManager.register(this);
|
|
482
|
+
this.pixiSpine = pixiSpine;
|
|
483
|
+
this.game.canvas.addEventListener('webglcontextrestored', () => {
|
|
484
|
+
const objs = this.game.gameObjects;
|
|
485
|
+
let toAdd = [];
|
|
486
|
+
for (let k in this.armatures) {
|
|
487
|
+
const id = +k;
|
|
488
|
+
for (let i = 0; i < objs.length; ++i) {
|
|
489
|
+
let obj = objs[i];
|
|
490
|
+
if (obj.id === id) {
|
|
491
|
+
let sp = obj.getComponent(Spine);
|
|
492
|
+
if (sp) {
|
|
493
|
+
this.remove({
|
|
494
|
+
type: eva_js.OBSERVER_TYPE.REMOVE,
|
|
495
|
+
gameObject: obj,
|
|
496
|
+
component: sp,
|
|
497
|
+
componentName: Spine.componentName
|
|
498
|
+
});
|
|
499
|
+
toAdd.push({
|
|
500
|
+
type: eva_js.OBSERVER_TYPE.ADD,
|
|
501
|
+
gameObject: obj,
|
|
502
|
+
component: sp,
|
|
503
|
+
componentName: Spine.componentName
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
setTimeout(() => {
|
|
511
|
+
toAdd.forEach(obj => {
|
|
512
|
+
this.add(obj);
|
|
513
|
+
});
|
|
514
|
+
}, 1000);
|
|
515
|
+
}, false);
|
|
516
|
+
}
|
|
517
|
+
update(e) {
|
|
518
|
+
super.update();
|
|
519
|
+
for (let key in this.armatures) {
|
|
520
|
+
const armature = this.armatures[key];
|
|
521
|
+
const component = this._spineComponents[key];
|
|
522
|
+
if (!armature || armature.destroyed || (component === null || component === void 0 ? void 0 : component.destroied)) {
|
|
523
|
+
delete this.armatures[key];
|
|
524
|
+
delete this._spineComponents[key];
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
armature.update(e.deltaTime * 0.001);
|
|
528
|
+
}
|
|
529
|
+
for (let key in this._spineComponents) {
|
|
530
|
+
const component = this._spineComponents[key];
|
|
531
|
+
if (!component || component.destroied) {
|
|
532
|
+
delete this._spineComponents[key];
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
component._flushPendingSlotObjects();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
componentChanged(changed) {
|
|
539
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
540
|
+
if (changed.componentName === 'Spine') {
|
|
541
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
542
|
+
this.add(changed);
|
|
543
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) {
|
|
544
|
+
switch (changed.prop.prop[0]) {
|
|
545
|
+
case 'resource':
|
|
546
|
+
this.change(changed);
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
550
|
+
this.remove(changed);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
add(changed, count) {
|
|
556
|
+
var _a, _b, _c;
|
|
557
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
558
|
+
const component = changed.component;
|
|
559
|
+
clearTimeout(component.addHandler);
|
|
560
|
+
const gameObjectId = changed.gameObject.id;
|
|
561
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
562
|
+
const res = yield eva_js.resource.getResource(component.resource);
|
|
563
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed) return;
|
|
564
|
+
const spineData = yield getSpineData(res, component.scale, this.pixiSpine);
|
|
565
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed) return;
|
|
566
|
+
if (!spineData) {
|
|
567
|
+
component.addHandler = setTimeout(() => {
|
|
568
|
+
if (!component.destroied && !changed.gameObject.destroyed) {
|
|
569
|
+
if (count === undefined) {
|
|
570
|
+
count = MaxRetryCount;
|
|
571
|
+
}
|
|
572
|
+
count--;
|
|
573
|
+
if (count > 0) {
|
|
574
|
+
this.add(changed, count);
|
|
575
|
+
} else {
|
|
576
|
+
console.log('retry exceed max times', component.resource);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}, 1000);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this.remove(changed);
|
|
583
|
+
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);
|
|
584
|
+
if (!container || component.destroied || changed.gameObject.destroyed) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
component.lastResource = component.resource;
|
|
588
|
+
const armature = new this.pixiSpine.Spine({
|
|
589
|
+
skeletonData: spineData,
|
|
590
|
+
autoUpdate: false
|
|
591
|
+
});
|
|
592
|
+
this.armatures[changed.gameObject.id] = armature;
|
|
593
|
+
this._spineComponents[changed.gameObject.id] = component;
|
|
594
|
+
if (changed.gameObject && changed.gameObject.transform) {
|
|
595
|
+
const tran = changed.gameObject.transform;
|
|
596
|
+
armature.x = tran.size.width * tran.origin.x;
|
|
597
|
+
armature.y = tran.size.height * tran.origin.y;
|
|
598
|
+
}
|
|
599
|
+
container.addChildAt(armature, 0);
|
|
600
|
+
armature.update();
|
|
601
|
+
component._containerManager = (_c = this.renderSystem) === null || _c === void 0 ? void 0 : _c.containerManager;
|
|
602
|
+
component.armature = armature;
|
|
603
|
+
component.emit('loaded', {
|
|
604
|
+
resource: component.resource
|
|
605
|
+
});
|
|
606
|
+
armature.state.addListener({
|
|
607
|
+
start: (track, event) => {
|
|
608
|
+
component.emit('start', {
|
|
609
|
+
track,
|
|
610
|
+
name: track.animation.name
|
|
611
|
+
});
|
|
612
|
+
},
|
|
613
|
+
complete: (track, event) => {
|
|
614
|
+
component.emit('complete', {
|
|
615
|
+
track,
|
|
616
|
+
name: track.animation.name
|
|
617
|
+
});
|
|
618
|
+
},
|
|
619
|
+
interrupt: (track, event) => {
|
|
620
|
+
component.emit('interrupt', {
|
|
621
|
+
track,
|
|
622
|
+
name: track.animation.name
|
|
623
|
+
});
|
|
624
|
+
},
|
|
625
|
+
end: (track, event) => {
|
|
626
|
+
component.emit('end', {
|
|
627
|
+
track,
|
|
628
|
+
name: track.animation.name
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
event: (track, event) => {
|
|
632
|
+
component.emit('event', track, event);
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
change(changed) {
|
|
638
|
+
this.remove(changed);
|
|
639
|
+
this.add(changed);
|
|
640
|
+
}
|
|
641
|
+
remove(changed) {
|
|
642
|
+
var _a, _b, _c, _d, _e, _f;
|
|
643
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
644
|
+
const gameObjectId = changed.gameObject.id;
|
|
645
|
+
this.increaseAsyncId(gameObjectId);
|
|
646
|
+
const component = changed.component;
|
|
647
|
+
clearTimeout(component.addHandler);
|
|
648
|
+
const armature = this.armatures[gameObjectId];
|
|
649
|
+
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(gameObjectId);
|
|
650
|
+
if (container && armature) {
|
|
651
|
+
container.removeChild(armature);
|
|
652
|
+
}
|
|
653
|
+
const componentArmature = component.armature;
|
|
654
|
+
component.armature = null;
|
|
655
|
+
delete this.armatures[gameObjectId];
|
|
656
|
+
delete this._spineComponents[gameObjectId];
|
|
657
|
+
if (componentArmature) {
|
|
658
|
+
component._destroySlotGameObjects();
|
|
659
|
+
if (!componentArmature.destroyed) {
|
|
660
|
+
componentArmature.destroy({
|
|
661
|
+
children: true
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
if (!component.keepResource && component.lastResource) {
|
|
665
|
+
try {
|
|
666
|
+
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
667
|
+
const imageSrc = ((_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.image) === null || _d === void 0 ? void 0 : _d.src) || ((_f = (_e = res.data) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.label);
|
|
668
|
+
releaseSpineData(res, imageSrc);
|
|
669
|
+
} catch (error) {
|
|
670
|
+
console.warn('Failed to release Spine resource', component.lastResource, error);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
SpineSystem.systemName = 'SpineSystem';
|
|
679
|
+
SpineSystem = __decorate([eva_js.decorators.componentObserver({
|
|
680
|
+
Spine: ['resource']
|
|
681
|
+
})], SpineSystem);
|
|
682
|
+
var SpineSystem$1 = SpineSystem;
|
|
683
|
+
eva_js.resource.registerResourceType('SPINE');
|
|
684
|
+
exports.Spine = Spine;
|
|
685
|
+
exports.SpineSystem = SpineSystem$1;
|
|
686
|
+
Object.defineProperty(exports, '__esModule', {
|
|
687
|
+
value: true
|
|
688
|
+
});
|
|
689
|
+
return exports;
|
|
690
|
+
}({}, EVA, EVA.plugin.renderer, PIXI);
|
|
691
|
+
globalThis.EVA.plugin.spineBase = globalThis.EVA.plugin.spineBase || _EVA_IIFE_spineBase;
|