@eva/spine-base 2.0.2 → 2.1.0-beta.2
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 +216 -42
- package/dist/EVA.plugin.spineBase.min.js +1 -1
- package/dist/spine-base.cjs.js +149 -31
- package/dist/spine-base.cjs.prod.js +1 -1
- package/dist/spine-base.d.ts +24 -0
- package/dist/spine-base.esm.js +149 -31
- package/package.json +4 -4
|
@@ -10,6 +10,9 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
10
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
11
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
12
|
}
|
|
13
|
+
function __metadata(metadataKey, metadataValue) {
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
15
|
+
}
|
|
13
16
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
14
17
|
function adopt(value) {
|
|
15
18
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -37,38 +40,128 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
37
40
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
function __rest(s, e) {
|
|
44
|
+
var t = {};
|
|
45
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
46
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
47
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
}
|
|
51
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
52
|
+
var e = new Error(message);
|
|
53
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
54
|
+
};
|
|
55
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
56
|
+
constructor() {
|
|
57
|
+
super('Symbol keys are not supported yet!');
|
|
58
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
62
|
+
function transformBasicType(type) {
|
|
63
|
+
if (type === String) {
|
|
64
|
+
return 'string';
|
|
65
|
+
}
|
|
66
|
+
if (type === Number) {
|
|
67
|
+
return 'number';
|
|
68
|
+
}
|
|
69
|
+
if (type === Boolean) {
|
|
70
|
+
return 'boolean';
|
|
71
|
+
}
|
|
72
|
+
return 'unknown';
|
|
73
|
+
}
|
|
74
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
75
|
+
const constructor = target.constructor;
|
|
76
|
+
const current = constructor.IDEProps || {};
|
|
77
|
+
current[propertyKey] = _extends(_extends({
|
|
78
|
+
key: propertyKey
|
|
79
|
+
}, current[propertyKey]), patch);
|
|
80
|
+
constructor.IDEProps = current;
|
|
81
|
+
}
|
|
82
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
83
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
84
|
+
let isArray = type === Array;
|
|
85
|
+
const str = transformBasicType(type);
|
|
86
|
+
if (str !== 'unknown') {
|
|
87
|
+
type = str;
|
|
43
88
|
}
|
|
44
|
-
if (
|
|
45
|
-
|
|
89
|
+
if (returnTypeFunction) {
|
|
90
|
+
const returnType = returnTypeFunction();
|
|
91
|
+
if (Array.isArray(returnType)) {
|
|
92
|
+
isArray = true;
|
|
93
|
+
type = returnType[0];
|
|
94
|
+
} else {
|
|
95
|
+
type = returnType;
|
|
96
|
+
}
|
|
46
97
|
}
|
|
47
|
-
|
|
48
|
-
|
|
98
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
99
|
+
const current = properties[key] || {};
|
|
100
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
101
|
+
type,
|
|
102
|
+
isArray: isArray
|
|
103
|
+
}), options);
|
|
104
|
+
properties[key] = property;
|
|
105
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
106
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
107
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
49
108
|
}
|
|
50
109
|
function type(type) {
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
110
|
+
return Field({
|
|
111
|
+
type
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
115
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
116
|
+
return {
|
|
117
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
118
|
+
options: maybeOptions || {}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
options: returnTypeFuncOrOptions || {}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
126
|
+
return (target, propertyKey) => {
|
|
127
|
+
if (typeof propertyKey === 'symbol') {
|
|
128
|
+
throw new SymbolKeysNotSupportedError();
|
|
129
|
+
}
|
|
130
|
+
const {
|
|
131
|
+
options,
|
|
132
|
+
returnTypeFunc
|
|
133
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
134
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
55
135
|
};
|
|
56
136
|
}
|
|
137
|
+
var ExecuteMode;
|
|
138
|
+
(function (ExecuteMode) {
|
|
139
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
140
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
141
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
142
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
57
143
|
class Spine extends eva_js.Component {
|
|
58
|
-
constructor() {
|
|
59
|
-
super(
|
|
144
|
+
constructor(params) {
|
|
145
|
+
super(params);
|
|
60
146
|
this.resource = '';
|
|
61
147
|
this.scale = 1;
|
|
62
148
|
this.animationName = '';
|
|
63
149
|
this.autoPlay = true;
|
|
64
150
|
this.keepResource = false;
|
|
151
|
+
this.timeScale = 1;
|
|
152
|
+
this.skin = '';
|
|
65
153
|
this._slotGameObjects = new Map();
|
|
66
154
|
this._pendingSlotObjects = [];
|
|
67
155
|
this.waitExecuteInfos = [];
|
|
156
|
+
this.listenerBound = false;
|
|
157
|
+
this.paused = false;
|
|
158
|
+
this.init(params);
|
|
68
159
|
}
|
|
69
160
|
set armature(val) {
|
|
70
161
|
this._armature = val;
|
|
71
162
|
if (!val) return;
|
|
163
|
+
this.applyTimeScale();
|
|
164
|
+
if (this.skin) this.setSkin(this.skin);
|
|
72
165
|
if (this.autoPlay) {
|
|
73
166
|
this.play(this.animationName);
|
|
74
167
|
}
|
|
@@ -90,12 +183,59 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
90
183
|
return this._armature;
|
|
91
184
|
}
|
|
92
185
|
init(obj) {
|
|
93
|
-
if (
|
|
94
|
-
|
|
186
|
+
if (obj) _extends(this, obj);
|
|
187
|
+
if (!this.listenerBound) {
|
|
188
|
+
this.listenerBound = true;
|
|
189
|
+
this.on('start', event => {
|
|
190
|
+
var _a;
|
|
191
|
+
(_a = this.onStart) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
192
|
+
});
|
|
193
|
+
this.on('complete', event => {
|
|
194
|
+
var _a;
|
|
195
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
196
|
+
});
|
|
197
|
+
this.on('event', (track, event) => {
|
|
198
|
+
var _a;
|
|
199
|
+
(_a = this.onEvent) === null || _a === void 0 ? void 0 : _a.call(this, track, event);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
95
202
|
}
|
|
96
203
|
onDestroy() {
|
|
97
204
|
this.destroied = true;
|
|
98
205
|
}
|
|
206
|
+
load() {
|
|
207
|
+
return this.armature;
|
|
208
|
+
}
|
|
209
|
+
destroy() {
|
|
210
|
+
this.onDestroy();
|
|
211
|
+
if (this.armature && !this.armature.destroyed) {
|
|
212
|
+
this._destroySlotGameObjects();
|
|
213
|
+
this.armature.destroy({
|
|
214
|
+
children: true
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
this.armature = null;
|
|
218
|
+
}
|
|
219
|
+
pause() {
|
|
220
|
+
this.paused = true;
|
|
221
|
+
this.applyTimeScale();
|
|
222
|
+
}
|
|
223
|
+
resume() {
|
|
224
|
+
this.paused = false;
|
|
225
|
+
this.applyTimeScale();
|
|
226
|
+
}
|
|
227
|
+
setSkin(name) {
|
|
228
|
+
var _a, _b, _c, _d, _e;
|
|
229
|
+
this.skin = name;
|
|
230
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.skeleton)) return;
|
|
231
|
+
if (this.armature.skeleton.setSkinByName) {
|
|
232
|
+
this.armature.skeleton.setSkinByName(name);
|
|
233
|
+
} else if (this.armature.skeleton.setSkin) {
|
|
234
|
+
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;
|
|
235
|
+
this.armature.skeleton.setSkin(skin);
|
|
236
|
+
}
|
|
237
|
+
(_e = (_d = this.armature.skeleton).setSlotsToSetupPose) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
238
|
+
}
|
|
99
239
|
play(name, loopAnimation, track) {
|
|
100
240
|
try {
|
|
101
241
|
const loop = loopAnimation !== null && loopAnimation !== void 0 ? loopAnimation : this.autoPlay;
|
|
@@ -111,6 +251,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
111
251
|
if (track === undefined) {
|
|
112
252
|
track = 0;
|
|
113
253
|
}
|
|
254
|
+
this.applyTimeScale();
|
|
114
255
|
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
115
256
|
}
|
|
116
257
|
} catch (e) {
|
|
@@ -130,6 +271,11 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
130
271
|
}
|
|
131
272
|
this.armature.state.setEmptyAnimation(track, 0);
|
|
132
273
|
}
|
|
274
|
+
applyTimeScale() {
|
|
275
|
+
var _a;
|
|
276
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.state)) return;
|
|
277
|
+
this.armature.state.timeScale = this.paused ? 0 : this.timeScale;
|
|
278
|
+
}
|
|
133
279
|
addAnimation(name, delay, loop, track) {
|
|
134
280
|
try {
|
|
135
281
|
if (!this.armature) {} else {
|
|
@@ -260,12 +406,20 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
260
406
|
}
|
|
261
407
|
}
|
|
262
408
|
Spine.componentName = 'Spine';
|
|
263
|
-
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
264
|
-
__decorate([type('number')], Spine.prototype, "scale", void 0);
|
|
265
|
-
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
266
|
-
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
267
|
-
__decorate([type('boolean')], Spine.prototype, "keepResource", void 0);
|
|
409
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "resource", void 0);
|
|
410
|
+
__decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "scale", void 0);
|
|
411
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "animationName", void 0);
|
|
412
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "autoPlay", void 0);
|
|
413
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], Spine.prototype, "keepResource", void 0);
|
|
414
|
+
__decorate([type('number'), __metadata("design:type", Number)], Spine.prototype, "timeScale", void 0);
|
|
415
|
+
__decorate([type('string'), __metadata("design:type", String)], Spine.prototype, "skin", void 0);
|
|
268
416
|
let dataMap = {};
|
|
417
|
+
function resolveImageSrc(image) {
|
|
418
|
+
var _a, _b, _c, _d, _e;
|
|
419
|
+
if (!image) return '';
|
|
420
|
+
if (typeof image === 'string') return image;
|
|
421
|
+
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) || '';
|
|
422
|
+
}
|
|
269
423
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
270
424
|
const skeletonAsset = data.ske;
|
|
271
425
|
const atlasAsset = data.atlas;
|
|
@@ -276,7 +430,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
276
430
|
const obj = {
|
|
277
431
|
spineData: skeletonData,
|
|
278
432
|
ref: 0,
|
|
279
|
-
imageSrc: data.image
|
|
433
|
+
imageSrc: resolveImageSrc(data.image)
|
|
280
434
|
};
|
|
281
435
|
dataMap[name] = obj;
|
|
282
436
|
return obj;
|
|
@@ -357,13 +511,25 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
357
511
|
}, false);
|
|
358
512
|
}
|
|
359
513
|
update(e) {
|
|
514
|
+
super.update();
|
|
360
515
|
for (let key in this.armatures) {
|
|
361
|
-
this.armatures[key]
|
|
516
|
+
const armature = this.armatures[key];
|
|
517
|
+
const component = this._spineComponents[key];
|
|
518
|
+
if (!armature || armature.destroyed || (component === null || component === void 0 ? void 0 : component.destroied)) {
|
|
519
|
+
delete this.armatures[key];
|
|
520
|
+
delete this._spineComponents[key];
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
armature.update(e.deltaTime * 0.001);
|
|
362
524
|
}
|
|
363
525
|
for (let key in this._spineComponents) {
|
|
364
|
-
this._spineComponents[key]
|
|
526
|
+
const component = this._spineComponents[key];
|
|
527
|
+
if (!component || component.destroied) {
|
|
528
|
+
delete this._spineComponents[key];
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
component._flushPendingSlotObjects();
|
|
365
532
|
}
|
|
366
|
-
super.update();
|
|
367
533
|
}
|
|
368
534
|
componentChanged(changed) {
|
|
369
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -390,12 +556,12 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
390
556
|
const gameObjectId = changed.gameObject.id;
|
|
391
557
|
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
392
558
|
const res = yield eva_js.resource.getResource(component.resource);
|
|
393
|
-
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
559
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed) return;
|
|
394
560
|
const spineData = yield getSpineData(res, component.scale, this.pixiSpine);
|
|
395
|
-
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
561
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed) return;
|
|
396
562
|
if (!spineData) {
|
|
397
563
|
component.addHandler = setTimeout(() => {
|
|
398
|
-
if (!component.destroied) {
|
|
564
|
+
if (!component.destroied && !changed.gameObject.destroyed) {
|
|
399
565
|
if (count === undefined) {
|
|
400
566
|
count = MaxRetryCount;
|
|
401
567
|
}
|
|
@@ -411,7 +577,7 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
411
577
|
}
|
|
412
578
|
this.remove(changed);
|
|
413
579
|
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);
|
|
414
|
-
if (!container) {
|
|
580
|
+
if (!container || component.destroied || changed.gameObject.destroyed) {
|
|
415
581
|
return;
|
|
416
582
|
}
|
|
417
583
|
component.lastResource = component.resource;
|
|
@@ -471,28 +637,36 @@ var _EVA_IIFE_spineBase = function (exports, eva_js, pluginRenderer, pixi_js) {
|
|
|
471
637
|
remove(changed) {
|
|
472
638
|
var _a, _b, _c, _d, _e, _f;
|
|
473
639
|
return __awaiter(this, void 0, void 0, function* () {
|
|
474
|
-
|
|
640
|
+
const gameObjectId = changed.gameObject.id;
|
|
641
|
+
this.increaseAsyncId(gameObjectId);
|
|
475
642
|
const component = changed.component;
|
|
476
643
|
clearTimeout(component.addHandler);
|
|
477
|
-
const armature = this.armatures[
|
|
478
|
-
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(
|
|
644
|
+
const armature = this.armatures[gameObjectId];
|
|
645
|
+
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(gameObjectId);
|
|
479
646
|
if (container && armature) {
|
|
480
647
|
container.removeChild(armature);
|
|
481
648
|
}
|
|
482
|
-
|
|
649
|
+
const componentArmature = component.armature;
|
|
650
|
+
component.armature = null;
|
|
651
|
+
delete this.armatures[gameObjectId];
|
|
652
|
+
delete this._spineComponents[gameObjectId];
|
|
653
|
+
if (componentArmature) {
|
|
483
654
|
component._destroySlotGameObjects();
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
655
|
+
if (!componentArmature.destroyed) {
|
|
656
|
+
componentArmature.destroy({
|
|
657
|
+
children: true
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
if (!component.keepResource && component.lastResource) {
|
|
661
|
+
try {
|
|
662
|
+
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
663
|
+
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);
|
|
664
|
+
releaseSpineData(res, imageSrc);
|
|
665
|
+
} catch (error) {
|
|
666
|
+
console.warn('Failed to release Spine resource', component.lastResource, error);
|
|
667
|
+
}
|
|
491
668
|
}
|
|
492
669
|
}
|
|
493
|
-
component.armature = null;
|
|
494
|
-
delete this.armatures[changed.gameObject.id];
|
|
495
|
-
delete this._spineComponents[changed.gameObject.id];
|
|
496
670
|
if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
|
|
497
671
|
});
|
|
498
672
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,r){"use strict";function a(e,t,n,r){var a,i=arguments.length,o=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(o=(i<3?a(o):i>3?a(t,n,o):a(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}function i(e,t,n,r){return new(n||(n=Promise))(function(a,i){function o(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}c((r=r.apply(e,t||[])).next())})}function o(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}}class s extends t.Component{constructor(){super(...arguments),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[]}set armature(e){if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:r}=e;this.play(t,n,r)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e)}onDestroy(){this.destroied=!0}play(e,t,n){try{const r=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.armature.state.setAnimation(n,this.animationName,r)):this.waitExecuteInfos.push({playType:!0,name:e,loop:r,track:n})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}addAnimation(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)}}setMix(e,t,n){this.armature&&this.armature.state.data.setMix(e,t,n)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,n){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const r=this._containerManager.getContainer(t.id);r?this._doAddSlotObject(e,t,r,n):this._pendingSlotObjects.push({slot:e,gameObject:t,options:n})}_doAddSlotObject(e,t,n,a){const i=new r.Container;i.addChild(n),this.armature.addSlotObject(e,i,a),this._slotGameObjects.set(t,{slot:e,wrapper:i}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const n=this._containerManager.getContainer(t.gameObject.id);n?this._doAddSlotObject(t.slot,t.gameObject,n,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}s.componentName="Spine",a([o("string")],s.prototype,"resource",void 0),a([o("number")],s.prototype,"scale",void 0),a([o("string")],s.prototype,"animationName",void 0),a([o("boolean")],s.prototype,"autoPlay",void 0),a([o("boolean")],s.prototype,"keepResource",void 0);let c={};function d(e,t,n){return i(this,void 0,void 0,function*(){let r=c[e.name];if(!r)if(e.complete)r=function(e,t,n,r){const a=t.ske,i=t.atlas,o=new r.AtlasAttachmentLoader(i),s=a instanceof Uint8Array?new r.SkeletonBinary(o):new r.SkeletonJson(o);s.scale=n||1;const d={spineData:s.readSkeletonData(a),ref:0,imageSrc:t.image.label};return c[e]=d,d}(e.name,e.data,t,n);else if(!r)return;return r.ref++,r.spineData})}let m=class extends n.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:e}){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=e,this.game.canvas.addEventListener("webglcontextrestored",()=>{const e=this.game.gameObjects;let n=[];for(let r in this.armatures){const a=+r;for(let r=0;r<e.length;++r){let i=e[r];if(i.id===a){let e=i.getComponent(s);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:i,component:e,componentName:s.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:i,component:e,componentName:s.componentName}));break}}}setTimeout(()=>{n.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){for(let t in this.armatures)this.armatures[t].update(.001*e.deltaTime);for(let e in this._spineComponents)this._spineComponents[e]._flushPendingSlotObjects();super.update()}componentChanged(e){return i(this,void 0,void 0,function*(){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE){if("resource"===e.prop.prop[0])this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e)})}add(e,n){var r,a,o;return i(this,void 0,void 0,function*(){const i=e.component;clearTimeout(i.addHandler);const s=e.gameObject.id,c=this.increaseAsyncId(s),m=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(s,c))return;const l=yield d(m,i.scale,this.pixiSpine);if(!this.validateAsyncId(s,c))return;if(!l)return void(i.addHandler=setTimeout(()=>{i.destroied||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",i.resource))},1e3));this.remove(e);const u=null===(a=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===a?void 0:a.getContainer(e.gameObject.id);if(!u)return;i.lastResource=i.resource;const h=new this.pixiSpine.Spine({skeletonData:l,autoUpdate:!1});if(this.armatures[e.gameObject.id]=h,this._spineComponents[e.gameObject.id]=i,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;h.x=t.size.width*t.origin.x,h.y=t.size.height*t.origin.y}u.addChildAt(h,0),h.update(),i._containerManager=null===(o=this.renderSystem)||void 0===o?void 0:o.containerManager,i.armature=h,i.emit("loaded",{resource:i.resource}),h.state.addListener({start:(e,t)=>{i.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{i.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{i.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{i.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{i.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(e){var n,r,a,o,s,d;return i(this,void 0,void 0,function*(){this.increaseAsyncId(e.gameObject.id);const m=e.component;clearTimeout(m.addHandler);const l=this.armatures[e.gameObject.id],u=null===(r=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===r?void 0:r.getContainer(e.gameObject.id);if(u&&l&&u.removeChild(l),m.armature&&(m._destroySlotGameObjects(),m.armature.destroy({children:!0}),!m.keepResource)){const e=yield t.resource.getResource(m.lastResource);(null===(o=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src)||null===(d=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===d||d.label,function(e){const n=e.name,r=c[n];r&&(r.ref--,setTimeout(()=>i(this,void 0,void 0,function*(){r.ref<=0&&(t.resource.destroy(n),delete c[n])}),100))}(e)}m.armature=null,delete this.armatures[e.gameObject.id],delete this._spineComponents[e.gameObject.id],e.type,t.OBSERVER_TYPE.CHANGE})}};m.systemName="SpineSystem",m=a([t.decorators.componentObserver({Spine:["resource"]})],m);var l=m;return t.resource.registerResourceType("SPINE"),e.Spine=s,e.SpineSystem=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.spineBase=globalThis.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_spineBase=function(e,t,n,i){"use strict";function s(e,t,n,i){var s,r=arguments.length,o=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(o=(r<3?s(o):r>3?s(t,n,o):s(t,n))||o);return r>3&&o&&Object.defineProperty(t,n,o),o}function r(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(e,t,n,i){return new(n||(n=Promise))(function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,a)}c((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="IDE_PROPERTY_METADATA";function l(e,t,n,i){let s=Reflect.getMetadata("design:type",e,t),r=s===Array;const o=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(s);if("unknown"!==o&&(s=o),i){const e=i();Array.isArray(e)?(r=!0,s=e[0]):s=e}const a=Reflect.getMetadata(c,e.constructor)||{},l=_extends(_extends(_extends({},a[t]||{}),{type:s,isArray:r}),n);a[t]=l,Reflect.defineMetadata(c,a,e.constructor);!function(e,t,n){const i=e.constructor,s=i.IDEProps||{};s[t]=_extends(_extends({key:t},s[t]),n),i.IDEProps=s}(e,t,function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(i=Object.getOwnPropertySymbols(e);s<i.length;s++)t.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(e,i[s])&&(n[i[s]]=e[i[s]])}return n}(l,["isArray"]))}function d(e){return t={type:e},(e,i)=>{if("symbol"==typeof i)throw new a;const{options:s,returnTypeFunc:r}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,n);l(e,i,s,r)};var t,n}var u;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(u||(u={}));class m extends t.Component{constructor(e){super(e),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this.timeScale=1,this.skin="",this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[],this.listenerBound=!1,this.paused=!1,this.init(e)}set armature(e){if(this._armature=e,e){this.applyTimeScale(),this.skin&&this.setSkin(this.skin),this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:n,track:i}=e;this.play(t,n,i)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&_extends(this,e),this.listenerBound||(this.listenerBound=!0,this.on("start",e=>{var t;null===(t=this.onStart)||void 0===t||t.call(this,e)}),this.on("complete",e=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this,e)}),this.on("event",(e,t)=>{var n;null===(n=this.onEvent)||void 0===n||n.call(this,e,t)}))}onDestroy(){this.destroied=!0}load(){return this.armature}destroy(){this.onDestroy(),this.armature&&!this.armature.destroyed&&(this._destroySlotGameObjects(),this.armature.destroy({children:!0})),this.armature=null}pause(){this.paused=!0,this.applyTimeScale()}resume(){this.paused=!1,this.applyTimeScale()}setSkin(e){var t,n,i,s,r;if(this.skin=e,null===(t=this.armature)||void 0===t?void 0:t.skeleton){if(this.armature.skeleton.setSkinByName)this.armature.skeleton.setSkinByName(e);else if(this.armature.skeleton.setSkin){const t=(null===(i=null===(n=this.armature.skeleton.data)||void 0===n?void 0:n.findSkin)||void 0===i?void 0:i.call(n,e))||e;this.armature.skeleton.setSkin(t)}null===(r=(s=this.armature.skeleton).setSlotsToSetupPose)||void 0===r||r.call(s)}}play(e,t,n){try{const i=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===n&&(n=0),this.applyTimeScale(),this.armature.state.setAnimation(n,this.animationName,i)):this.waitExecuteInfos.push({playType:!0,name:e,loop:i,track:n})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}applyTimeScale(){var e;(null===(e=this.armature)||void 0===e?void 0:e.state)&&(this.armature.state.timeScale=this.paused?0:this.timeScale)}addAnimation(e,t,n,i){try{this.armature&&(void 0===i&&(i=0),this.armature.state.addAnimation(i,e,n,t))}catch(e){console.log(e)}}setMix(e,t,n){this.armature&&this.armature.state.data.setMix(e,t,n)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,n){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const i=this._containerManager.getContainer(t.id);i?this._doAddSlotObject(e,t,i,n):this._pendingSlotObjects.push({slot:e,gameObject:t,options:n})}_doAddSlotObject(e,t,n,s){const r=new i.Container;r.addChild(n),this.armature.addSlotObject(e,r,s),this._slotGameObjects.set(t,{slot:e,wrapper:r}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const n=this._containerManager.getContainer(t.gameObject.id);n?this._doAddSlotObject(t.slot,t.gameObject,n,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}m.componentName="Spine",s([d("string"),r("design:type",String)],m.prototype,"resource",void 0),s([d("number"),r("design:type",Number)],m.prototype,"scale",void 0),s([d("string"),r("design:type",String)],m.prototype,"animationName",void 0),s([d("boolean"),r("design:type",Boolean)],m.prototype,"autoPlay",void 0),s([d("boolean"),r("design:type",Boolean)],m.prototype,"keepResource",void 0),s([d("number"),r("design:type",Number)],m.prototype,"timeScale",void 0),s([d("string"),r("design:type",String)],m.prototype,"skin",void 0);let p={};function h(e,t,n){return o(this,void 0,void 0,function*(){let i=p[e.name];if(!i)if(e.complete)i=function(e,t,n,i){const s=t.ske,r=t.atlas,o=new i.AtlasAttachmentLoader(r),a=s instanceof Uint8Array?new i.SkeletonBinary(o):new i.SkeletonJson(o);a.scale=n||1;const c={spineData:a.readSkeletonData(s),ref:0,imageSrc:(l=t.image,l?"string"==typeof l?l:l.label||(null===(d=l.source)||void 0===d?void 0:d.label)||(null===(m=null===(u=l.source)||void 0===u?void 0:u.resource)||void 0===m?void 0:m.src)||(null===(h=l.source)||void 0===h?void 0:h._sourceOrigin)||l.src||(null===(y=l.baseTexture)||void 0===y?void 0:y.cacheId)||"":"")};var l,d,u,m,h,y;return p[e]=c,c}(e.name,e.data,t,n);else if(!i)return;return i.ref++,i.spineData})}let y=class extends n.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:e}){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=e,this.game.canvas.addEventListener("webglcontextrestored",()=>{const e=this.game.gameObjects;let n=[];for(let i in this.armatures){const s=+i;for(let i=0;i<e.length;++i){let r=e[i];if(r.id===s){let e=r.getComponent(m);e&&(this.remove({type:t.OBSERVER_TYPE.REMOVE,gameObject:r,component:e,componentName:m.componentName}),n.push({type:t.OBSERVER_TYPE.ADD,gameObject:r,component:e,componentName:m.componentName}));break}}}setTimeout(()=>{n.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){super.update();for(let t in this.armatures){const n=this.armatures[t],i=this._spineComponents[t];!n||n.destroyed||(null==i?void 0:i.destroied)?(delete this.armatures[t],delete this._spineComponents[t]):n.update(.001*e.deltaTime)}for(let e in this._spineComponents){const t=this._spineComponents[e];t&&!t.destroied?t._flushPendingSlotObjects():delete this._spineComponents[e]}}componentChanged(e){return o(this,void 0,void 0,function*(){if("Spine"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD)this.add(e);else if(e.type===t.OBSERVER_TYPE.CHANGE){if("resource"===e.prop.prop[0])this.change(e)}else e.type===t.OBSERVER_TYPE.REMOVE&&this.remove(e)})}add(e,n){var i,s,r;return o(this,void 0,void 0,function*(){const o=e.component;clearTimeout(o.addHandler);const a=e.gameObject.id,c=this.increaseAsyncId(a),l=yield t.resource.getResource(o.resource);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;const d=yield h(l,o.scale,this.pixiSpine);if(!this.validateAsyncId(a,c)||o.destroied||e.gameObject.destroyed)return;if(!d)return void(o.addHandler=setTimeout(()=>{o.destroied||e.gameObject.destroyed||(void 0===n&&(n=20),--n>0?this.add(e,n):console.log("retry exceed max times",o.resource))},1e3));this.remove(e);const u=null===(s=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager)||void 0===s?void 0:s.getContainer(e.gameObject.id);if(!u||o.destroied||e.gameObject.destroyed)return;o.lastResource=o.resource;const m=new this.pixiSpine.Spine({skeletonData:d,autoUpdate:!1});if(this.armatures[e.gameObject.id]=m,this._spineComponents[e.gameObject.id]=o,e.gameObject&&e.gameObject.transform){const t=e.gameObject.transform;m.x=t.size.width*t.origin.x,m.y=t.size.height*t.origin.y}u.addChildAt(m,0),m.update(),o._containerManager=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager,o.armature=m,o.emit("loaded",{resource:o.resource}),m.state.addListener({start:(e,t)=>{o.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{o.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{o.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{o.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{o.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(e){var n,i,s,r,a,c;return o(this,void 0,void 0,function*(){const l=e.gameObject.id;this.increaseAsyncId(l);const d=e.component;clearTimeout(d.addHandler);const u=this.armatures[l],m=null===(i=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===i?void 0:i.getContainer(l);m&&u&&m.removeChild(u);const h=d.armature;if(d.armature=null,delete this.armatures[l],delete this._spineComponents[l],h&&(d._destroySlotGameObjects(),h.destroyed||h.destroy({children:!0}),!d.keepResource&&d.lastResource))try{const e=yield t.resource.getResource(d.lastResource);(null===(r=null===(s=e.data)||void 0===s?void 0:s.image)||void 0===r?void 0:r.src)||(null===(c=null===(a=e.data)||void 0===a?void 0:a.image)||void 0===c||c.label);!function(e){const n=e.name,i=p[n];i&&(i.ref--,setTimeout(()=>o(this,void 0,void 0,function*(){i.ref<=0&&(t.resource.destroy(n),delete p[n])}),100))}(e)}catch(e){console.warn("Failed to release Spine resource",d.lastResource,e)}e.type,t.OBSERVER_TYPE.CHANGE})}};y.systemName="SpineSystem",y=s([t.decorators.componentObserver({Spine:["resource"]})],y);var f=y;return t.resource.registerResourceType("SPINE"),e.Spine=m,e.SpineSystem=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.spineBase=globalThis.EVA.plugin.spineBase||_EVA_IIFE_spineBase;
|
package/dist/spine-base.cjs.js
CHANGED
|
@@ -29,6 +29,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
29
29
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function __metadata(metadataKey, metadataValue) {
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
37
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
38
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -99,8 +103,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
99
103
|
* ```
|
|
100
104
|
*/
|
|
101
105
|
class Spine extends eva_js.Component {
|
|
102
|
-
constructor() {
|
|
103
|
-
super(
|
|
106
|
+
constructor(params) {
|
|
107
|
+
super(params);
|
|
104
108
|
/** Spine 资源名称 */
|
|
105
109
|
this.resource = '';
|
|
106
110
|
/** 动画缩放比例 */
|
|
@@ -111,12 +115,19 @@ class Spine extends eva_js.Component {
|
|
|
111
115
|
this.autoPlay = true;
|
|
112
116
|
/** 是否保留资源(销毁时不释放) */
|
|
113
117
|
this.keepResource = false;
|
|
118
|
+
/** 动画播放时间缩放 */
|
|
119
|
+
this.timeScale = 1;
|
|
120
|
+
/** 当前皮肤名称 */
|
|
121
|
+
this.skin = '';
|
|
114
122
|
/** 挂载到插槽的 GameObject 映射(GameObject -> { slot, wrapper }) */
|
|
115
123
|
this._slotGameObjects = new Map();
|
|
116
124
|
/** 等待容器就绪的 slot 挂载请求 */
|
|
117
125
|
this._pendingSlotObjects = [];
|
|
118
126
|
/** 等待执行的动画操作队列 */
|
|
119
127
|
this.waitExecuteInfos = [];
|
|
128
|
+
this.listenerBound = false;
|
|
129
|
+
this.paused = false;
|
|
130
|
+
this.init(params);
|
|
120
131
|
}
|
|
121
132
|
/**
|
|
122
133
|
* 设置骨架实例
|
|
@@ -126,6 +137,9 @@ class Spine extends eva_js.Component {
|
|
|
126
137
|
this._armature = val;
|
|
127
138
|
if (!val)
|
|
128
139
|
return;
|
|
140
|
+
this.applyTimeScale();
|
|
141
|
+
if (this.skin)
|
|
142
|
+
this.setSkin(this.skin);
|
|
129
143
|
if (this.autoPlay) {
|
|
130
144
|
this.play(this.animationName);
|
|
131
145
|
}
|
|
@@ -153,14 +167,61 @@ class Spine extends eva_js.Component {
|
|
|
153
167
|
* @param obj.autoPlay - 是否自动播放
|
|
154
168
|
*/
|
|
155
169
|
init(obj) {
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
if (obj)
|
|
171
|
+
Object.assign(this, obj);
|
|
172
|
+
if (!this.listenerBound) {
|
|
173
|
+
this.listenerBound = true;
|
|
174
|
+
this.on('start', event => {
|
|
175
|
+
var _a;
|
|
176
|
+
(_a = this.onStart) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
177
|
+
});
|
|
178
|
+
this.on('complete', event => {
|
|
179
|
+
var _a;
|
|
180
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
181
|
+
});
|
|
182
|
+
this.on('event', (track, event) => {
|
|
183
|
+
var _a;
|
|
184
|
+
(_a = this.onEvent) === null || _a === void 0 ? void 0 : _a.call(this, track, event);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
159
187
|
}
|
|
160
188
|
/** 组件销毁时调用 */
|
|
161
189
|
onDestroy() {
|
|
162
190
|
this.destroied = true;
|
|
163
191
|
}
|
|
192
|
+
load() {
|
|
193
|
+
return this.armature;
|
|
194
|
+
}
|
|
195
|
+
destroy() {
|
|
196
|
+
this.onDestroy();
|
|
197
|
+
if (this.armature && !this.armature.destroyed) {
|
|
198
|
+
this._destroySlotGameObjects();
|
|
199
|
+
this.armature.destroy({ children: true });
|
|
200
|
+
}
|
|
201
|
+
this.armature = null;
|
|
202
|
+
}
|
|
203
|
+
pause() {
|
|
204
|
+
this.paused = true;
|
|
205
|
+
this.applyTimeScale();
|
|
206
|
+
}
|
|
207
|
+
resume() {
|
|
208
|
+
this.paused = false;
|
|
209
|
+
this.applyTimeScale();
|
|
210
|
+
}
|
|
211
|
+
setSkin(name) {
|
|
212
|
+
var _a, _b, _c, _d, _e;
|
|
213
|
+
this.skin = name;
|
|
214
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.skeleton))
|
|
215
|
+
return;
|
|
216
|
+
if (this.armature.skeleton.setSkinByName) {
|
|
217
|
+
this.armature.skeleton.setSkinByName(name);
|
|
218
|
+
}
|
|
219
|
+
else if (this.armature.skeleton.setSkin) {
|
|
220
|
+
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;
|
|
221
|
+
this.armature.skeleton.setSkin(skin);
|
|
222
|
+
}
|
|
223
|
+
(_e = (_d = this.armature.skeleton).setSlotsToSetupPose) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
224
|
+
}
|
|
164
225
|
/**
|
|
165
226
|
* 播放指定动画
|
|
166
227
|
*
|
|
@@ -193,6 +254,7 @@ class Spine extends eva_js.Component {
|
|
|
193
254
|
if (track === undefined) {
|
|
194
255
|
track = 0;
|
|
195
256
|
}
|
|
257
|
+
this.applyTimeScale();
|
|
196
258
|
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
197
259
|
}
|
|
198
260
|
}
|
|
@@ -220,6 +282,12 @@ class Spine extends eva_js.Component {
|
|
|
220
282
|
}
|
|
221
283
|
this.armature.state.setEmptyAnimation(track, 0);
|
|
222
284
|
}
|
|
285
|
+
applyTimeScale() {
|
|
286
|
+
var _a;
|
|
287
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.state))
|
|
288
|
+
return;
|
|
289
|
+
this.armature.state.timeScale = this.paused ? 0 : this.timeScale;
|
|
290
|
+
}
|
|
223
291
|
/**
|
|
224
292
|
* 在当前动画之后添加新动画到队列
|
|
225
293
|
*
|
|
@@ -433,22 +501,51 @@ class Spine extends eva_js.Component {
|
|
|
433
501
|
/** 组件名称 */
|
|
434
502
|
Spine.componentName = 'Spine';
|
|
435
503
|
__decorate([
|
|
436
|
-
inspectorDecorator.type('string')
|
|
504
|
+
inspectorDecorator.type('string'),
|
|
505
|
+
__metadata("design:type", String)
|
|
437
506
|
], Spine.prototype, "resource", void 0);
|
|
438
507
|
__decorate([
|
|
439
|
-
inspectorDecorator.type('number')
|
|
508
|
+
inspectorDecorator.type('number'),
|
|
509
|
+
__metadata("design:type", Number)
|
|
440
510
|
], Spine.prototype, "scale", void 0);
|
|
441
511
|
__decorate([
|
|
442
|
-
inspectorDecorator.type('string')
|
|
512
|
+
inspectorDecorator.type('string'),
|
|
513
|
+
__metadata("design:type", String)
|
|
443
514
|
], Spine.prototype, "animationName", void 0);
|
|
444
515
|
__decorate([
|
|
445
|
-
inspectorDecorator.type('boolean')
|
|
516
|
+
inspectorDecorator.type('boolean'),
|
|
517
|
+
__metadata("design:type", Boolean)
|
|
446
518
|
], Spine.prototype, "autoPlay", void 0);
|
|
447
519
|
__decorate([
|
|
448
|
-
inspectorDecorator.type('boolean')
|
|
449
|
-
|
|
520
|
+
inspectorDecorator.type('boolean'),
|
|
521
|
+
__metadata("design:type", Boolean)
|
|
522
|
+
], Spine.prototype, "keepResource", void 0);
|
|
523
|
+
__decorate([
|
|
524
|
+
inspectorDecorator.type('number'),
|
|
525
|
+
__metadata("design:type", Number)
|
|
526
|
+
], Spine.prototype, "timeScale", void 0);
|
|
527
|
+
__decorate([
|
|
528
|
+
inspectorDecorator.type('string'),
|
|
529
|
+
__metadata("design:type", String)
|
|
530
|
+
], Spine.prototype, "skin", void 0);
|
|
450
531
|
|
|
451
532
|
let dataMap = {};
|
|
533
|
+
function resolveImageSrc(image) {
|
|
534
|
+
var _a, _b, _c, _d, _e;
|
|
535
|
+
if (!image)
|
|
536
|
+
return '';
|
|
537
|
+
if (typeof image === 'string')
|
|
538
|
+
return image;
|
|
539
|
+
// PixiJS v8 Texture / TextureSource shapes vary depending on loader; try every
|
|
540
|
+
// common label/url accessor before bailing out.
|
|
541
|
+
return (image.label ||
|
|
542
|
+
((_a = image.source) === null || _a === void 0 ? void 0 : _a.label) ||
|
|
543
|
+
((_c = (_b = image.source) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.src) ||
|
|
544
|
+
((_d = image.source) === null || _d === void 0 ? void 0 : _d._sourceOrigin) ||
|
|
545
|
+
image.src ||
|
|
546
|
+
((_e = image.baseTexture) === null || _e === void 0 ? void 0 : _e.cacheId) ||
|
|
547
|
+
'');
|
|
548
|
+
}
|
|
452
549
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
453
550
|
const skeletonAsset = data.ske;
|
|
454
551
|
const atlasAsset = data.atlas;
|
|
@@ -458,7 +555,7 @@ function createSpineData(name, data, scale, pixiSpine) {
|
|
|
458
555
|
: new pixiSpine.SkeletonJson(attachmentLoader);
|
|
459
556
|
parser.scale = scale || 1;
|
|
460
557
|
const skeletonData = parser.readSkeletonData(skeletonAsset);
|
|
461
|
-
const obj = { spineData: skeletonData, ref: 0, imageSrc: data.image
|
|
558
|
+
const obj = { spineData: skeletonData, ref: 0, imageSrc: resolveImageSrc(data.image) };
|
|
462
559
|
dataMap[name] = obj;
|
|
463
560
|
return obj;
|
|
464
561
|
}
|
|
@@ -565,16 +662,28 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
565
662
|
* @param e - 更新参数,包含帧间隔时间
|
|
566
663
|
*/
|
|
567
664
|
update(e) {
|
|
665
|
+
super.update();
|
|
568
666
|
for (let key in this.armatures) {
|
|
667
|
+
const armature = this.armatures[key];
|
|
668
|
+
const component = this._spineComponents[key];
|
|
669
|
+
if (!armature || armature.destroyed || (component === null || component === void 0 ? void 0 : component.destroied)) {
|
|
670
|
+
delete this.armatures[key];
|
|
671
|
+
delete this._spineComponents[key];
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
569
674
|
// TODO: 类型
|
|
570
675
|
// @ts-ignore
|
|
571
|
-
|
|
676
|
+
armature.update(e.deltaTime * 0.001);
|
|
572
677
|
}
|
|
573
678
|
// 处理等待容器就绪的 slot 挂载请求
|
|
574
679
|
for (let key in this._spineComponents) {
|
|
575
|
-
this._spineComponents[key]
|
|
680
|
+
const component = this._spineComponents[key];
|
|
681
|
+
if (!component || component.destroied) {
|
|
682
|
+
delete this._spineComponents[key];
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
component._flushPendingSlotObjects();
|
|
576
686
|
}
|
|
577
|
-
super.update();
|
|
578
687
|
}
|
|
579
688
|
componentChanged(changed) {
|
|
580
689
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -603,14 +712,14 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
603
712
|
const gameObjectId = changed.gameObject.id;
|
|
604
713
|
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
605
714
|
const res = yield eva_js.resource.getResource(component.resource);
|
|
606
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
715
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed)
|
|
607
716
|
return;
|
|
608
717
|
const spineData = yield getSpineData(res, component.scale, this.pixiSpine);
|
|
609
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
718
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed)
|
|
610
719
|
return;
|
|
611
720
|
if (!spineData) {
|
|
612
721
|
component.addHandler = setTimeout(() => {
|
|
613
|
-
if (!component.destroied) {
|
|
722
|
+
if (!component.destroied && !changed.gameObject.destroyed) {
|
|
614
723
|
if (count === undefined) {
|
|
615
724
|
// 最大重试次数
|
|
616
725
|
count = MaxRetryCount;
|
|
@@ -628,7 +737,7 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
628
737
|
}
|
|
629
738
|
this.remove(changed);
|
|
630
739
|
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);
|
|
631
|
-
if (!container) {
|
|
740
|
+
if (!container || component.destroied || changed.gameObject.destroyed) {
|
|
632
741
|
// console.warn('添加spine的container不存在');
|
|
633
742
|
return;
|
|
634
743
|
}
|
|
@@ -683,27 +792,36 @@ let SpineSystem = class SpineSystem extends pluginRenderer.Renderer {
|
|
|
683
792
|
remove(changed) {
|
|
684
793
|
var _a, _b, _c, _d, _e, _f;
|
|
685
794
|
return __awaiter(this, void 0, void 0, function* () {
|
|
686
|
-
|
|
795
|
+
const gameObjectId = changed.gameObject.id;
|
|
796
|
+
this.increaseAsyncId(gameObjectId);
|
|
687
797
|
const component = changed.component;
|
|
688
798
|
clearTimeout(component.addHandler);
|
|
689
|
-
const armature = this.armatures[
|
|
690
|
-
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(
|
|
799
|
+
const armature = this.armatures[gameObjectId];
|
|
800
|
+
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(gameObjectId);
|
|
691
801
|
if (container && armature) {
|
|
692
802
|
container.removeChild(armature);
|
|
693
803
|
}
|
|
694
|
-
|
|
804
|
+
const componentArmature = component.armature;
|
|
805
|
+
component.armature = null;
|
|
806
|
+
delete this.armatures[gameObjectId];
|
|
807
|
+
delete this._spineComponents[gameObjectId];
|
|
808
|
+
if (componentArmature) {
|
|
695
809
|
// 销毁所有挂载到插槽的 GameObject
|
|
696
810
|
component._destroySlotGameObjects();
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
811
|
+
if (!componentArmature.destroyed) {
|
|
812
|
+
componentArmature.destroy({ children: true });
|
|
813
|
+
}
|
|
814
|
+
if (!component.keepResource && component.lastResource) {
|
|
815
|
+
try {
|
|
816
|
+
const res = yield eva_js.resource.getResource(component.lastResource);
|
|
817
|
+
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);
|
|
818
|
+
releaseSpineData(res, imageSrc);
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
console.warn('Failed to release Spine resource', component.lastResource, error);
|
|
822
|
+
}
|
|
702
823
|
}
|
|
703
824
|
}
|
|
704
|
-
component.armature = null;
|
|
705
|
-
delete this.armatures[changed.gameObject.id];
|
|
706
|
-
delete this._spineComponents[changed.gameObject.id];
|
|
707
825
|
if (changed.type === eva_js.OBSERVER_TYPE.CHANGE) ;
|
|
708
826
|
});
|
|
709
827
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("pixi.js"),n=require("@eva/inspector-decorator");function a(e,t,r,n){var a,i=arguments.length,o=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(o=(i<3?a(o):i>3?a(t,r,o):a(t,r))||o);return i>3&&o&&Object.defineProperty(t,r,o),o}function i(e,t,r,n){return new(r||(r=Promise))(function(a,i){function o(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,s)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class o extends e.Component{constructor(){super(...arguments),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[]}set armature(e){if(this._armature=e,e){this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:r,track:n}=e;this.play(t,r,n)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&Object.assign(this,e)}onDestroy(){this.destroied=!0}play(e,t,r){try{const n=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,n)):this.waitExecuteInfos.push({playType:!0,name:e,loop:n,track:r})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}addAnimation(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)}}setMix(e,t,r){this.armature&&this.armature.state.data.setMix(e,t,r)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,r){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const n=this._containerManager.getContainer(t.id);n?this._doAddSlotObject(e,t,n,r):this._pendingSlotObjects.push({slot:e,gameObject:t,options:r})}_doAddSlotObject(e,t,n,a){const i=new r.Container;i.addChild(n),this.armature.addSlotObject(e,i,a),this._slotGameObjects.set(t,{slot:e,wrapper:i}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const r=this._containerManager.getContainer(t.gameObject.id);r?this._doAddSlotObject(t.slot,t.gameObject,r,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}o.componentName="Spine",a([n.type("string")],o.prototype,"resource",void 0),a([n.type("number")],o.prototype,"scale",void 0),a([n.type("string")],o.prototype,"animationName",void 0),a([n.type("boolean")],o.prototype,"autoPlay",void 0),a([n.type("boolean")],o.prototype,"keepResource",void 0);let s={};function c(e,t,r){return i(this,void 0,void 0,function*(){let n=s[e.name];if(!n)if(e.complete)n=function(e,t,r,n){const a=t.ske,i=t.atlas,o=new n.AtlasAttachmentLoader(i),c=a instanceof Uint8Array?new n.SkeletonBinary(o):new n.SkeletonJson(o);c.scale=r||1;const d={spineData:c.readSkeletonData(a),ref:0,imageSrc:t.image.label};return s[e]=d,d}(e.name,e.data,t,r);else if(!n)return;return n.ref++,n.spineData})}let d=class extends t.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:r}){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=r,this.game.canvas.addEventListener("webglcontextrestored",()=>{const t=this.game.gameObjects;let r=[];for(let n in this.armatures){const a=+n;for(let n=0;n<t.length;++n){let i=t[n];if(i.id===a){let t=i.getComponent(o);t&&(this.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:i,component:t,componentName:o.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:i,component:t,componentName:o.componentName}));break}}}setTimeout(()=>{r.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){for(let t in this.armatures)this.armatures[t].update(.001*e.deltaTime);for(let e in this._spineComponents)this._spineComponents[e]._flushPendingSlotObjects();super.update()}componentChanged(t){return i(this,void 0,void 0,function*(){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE){if("resource"===t.prop.prop[0])this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t)})}add(t,r){var n,a,o;return i(this,void 0,void 0,function*(){const i=t.component;clearTimeout(i.addHandler);const s=t.gameObject.id,d=this.increaseAsyncId(s),m=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(s,d))return;const l=yield c(m,i.scale,this.pixiSpine);if(!this.validateAsyncId(s,d))return;if(!l)return void(i.addHandler=setTimeout(()=>{i.destroied||(void 0===r&&(r=20),--r>0?this.add(t,r):console.log("retry exceed max times",i.resource))},1e3));this.remove(t);const u=null===(a=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager)||void 0===a?void 0:a.getContainer(t.gameObject.id);if(!u)return;i.lastResource=i.resource;const h=new this.pixiSpine.Spine({skeletonData:l,autoUpdate:!1});if(this.armatures[t.gameObject.id]=h,this._spineComponents[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform){const e=t.gameObject.transform;h.x=e.size.width*e.origin.x,h.y=e.size.height*e.origin.y}u.addChildAt(h,0),h.update(),i._containerManager=null===(o=this.renderSystem)||void 0===o?void 0:o.containerManager,i.armature=h,i.emit("loaded",{resource:i.resource}),h.state.addListener({start:(e,t)=>{i.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{i.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{i.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{i.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{i.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(t){var r,n,a,o,c,d;return i(this,void 0,void 0,function*(){this.increaseAsyncId(t.gameObject.id);const m=t.component;clearTimeout(m.addHandler);const l=this.armatures[t.gameObject.id],u=null===(n=null===(r=this.renderSystem)||void 0===r?void 0:r.containerManager)||void 0===n?void 0:n.getContainer(t.gameObject.id);if(u&&l&&u.removeChild(l),m.armature&&(m._destroySlotGameObjects(),m.armature.destroy({children:!0}),!m.keepResource)){const t=yield e.resource.getResource(m.lastResource);(null===(o=null===(a=t.data)||void 0===a?void 0:a.image)||void 0===o?void 0:o.src)||null===(d=null===(c=t.data)||void 0===c?void 0:c.image)||void 0===d||d.label,function(t){const r=t.name,n=s[r];n&&(n.ref--,setTimeout(()=>i(this,void 0,void 0,function*(){n.ref<=0&&(e.resource.destroy(r),delete s[r])}),100))}(t)}m.armature=null,delete this.armatures[t.gameObject.id],delete this._spineComponents[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE})}};d.systemName="SpineSystem",d=a([e.decorators.componentObserver({Spine:["resource"]})],d);var m=d;e.resource.registerResourceType("SPINE"),exports.Spine=o,exports.SpineSystem=m;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),i=require("pixi.js"),s=require("@eva/inspector-decorator");function r(e,t,i,s){var r,n=arguments.length,a=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,s);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(n<3?r(a):n>3?r(t,i,a):r(t,i))||a);return n>3&&a&&Object.defineProperty(t,i,a),a}function n(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function a(e,t,i,s){return new(i||(i=Promise))(function(r,n){function a(e){try{c(s.next(e))}catch(e){n(e)}}function o(e){try{c(s.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,o)}c((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class o extends e.Component{constructor(e){super(e),this.resource="",this.scale=1,this.animationName="",this.autoPlay=!0,this.keepResource=!1,this.timeScale=1,this.skin="",this._slotGameObjects=new Map,this._pendingSlotObjects=[],this.waitExecuteInfos=[],this.listenerBound=!1,this.paused=!1,this.init(e)}set armature(e){if(this._armature=e,e){this.applyTimeScale(),this.skin&&this.setSkin(this.skin),this.autoPlay&&this.play(this.animationName);for(const e of this.waitExecuteInfos)if(e.playType){const{name:t,loop:i,track:s}=e;this.play(t,i,s)}else this.stop(e.track);this.waitExecuteInfos=[]}}get armature(){return this._armature}init(e){e&&Object.assign(this,e),this.listenerBound||(this.listenerBound=!0,this.on("start",e=>{var t;null===(t=this.onStart)||void 0===t||t.call(this,e)}),this.on("complete",e=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this,e)}),this.on("event",(e,t)=>{var i;null===(i=this.onEvent)||void 0===i||i.call(this,e,t)}))}onDestroy(){this.destroied=!0}load(){return this.armature}destroy(){this.onDestroy(),this.armature&&!this.armature.destroyed&&(this._destroySlotGameObjects(),this.armature.destroy({children:!0})),this.armature=null}pause(){this.paused=!0,this.applyTimeScale()}resume(){this.paused=!1,this.applyTimeScale()}setSkin(e){var t,i,s,r,n;if(this.skin=e,null===(t=this.armature)||void 0===t?void 0:t.skeleton){if(this.armature.skeleton.setSkinByName)this.armature.skeleton.setSkinByName(e);else if(this.armature.skeleton.setSkin){const t=(null===(s=null===(i=this.armature.skeleton.data)||void 0===i?void 0:i.findSkin)||void 0===s?void 0:s.call(i,e))||e;this.armature.skeleton.setSkin(t)}null===(n=(r=this.armature.skeleton).setSlotsToSetupPose)||void 0===n||n.call(r)}}play(e,t,i){try{const s=null!=t?t:this.autoPlay;e&&(this.animationName=e),this.armature?(void 0===i&&(i=0),this.applyTimeScale(),this.armature.state.setAnimation(i,this.animationName,s)):this.waitExecuteInfos.push({playType:!0,name:e,loop:s,track:i})}catch(e){console.log(e)}}stop(e){this.armature?(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0)):this.waitExecuteInfos.push({playType:!1,track:e})}applyTimeScale(){var e;(null===(e=this.armature)||void 0===e?void 0:e.state)&&(this.armature.state.timeScale=this.paused?0:this.timeScale)}addAnimation(e,t,i,s){try{this.armature&&(void 0===s&&(s=0),this.armature.state.addAnimation(s,e,i,t))}catch(e){console.log(e)}}setMix(e,t,i){this.armature&&this.armature.state.data.setMix(e,t,i)}getAnim(e=0){try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}}setDefaultMix(e){this.armature&&(this.armature.state.data.defaultMix=e)}setAttachment(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)}getBone(e){if(this.armature)return this.armature.skeleton.findBone(e)}addSlotObject(e,t,i){if(!this.armature)return void console.warn("Spine armature is not ready, cannot addSlotObject");if(!this._containerManager)return void console.warn("ContainerManager is not available");const s=this._containerManager.getContainer(t.id);s?this._doAddSlotObject(e,t,s,i):this._pendingSlotObjects.push({slot:e,gameObject:t,options:i})}_doAddSlotObject(e,t,s,r){const n=new i.Container;n.addChild(s),this.armature.addSlotObject(e,n,r),this._slotGameObjects.set(t,{slot:e,wrapper:n}),this._syncTransformTree(t)}_syncTransformTree(e){var t;if(this._containerManager&&(this._containerManager.updateTransform({name:e.id,transform:e.transform}),null===(t=e.transform)||void 0===t?void 0:t.children))for(const t of e.transform.children)t.gameObject&&this._syncTransformTree(t.gameObject)}_flushPendingSlotObjects(){if(0===this._pendingSlotObjects.length)return;if(!this.armature||!this._containerManager)return;const e=[];for(const t of this._pendingSlotObjects){const i=this._containerManager.getContainer(t.gameObject.id);i?this._doAddSlotObject(t.slot,t.gameObject,i,t.options):e.push(t)}this._pendingSlotObjects=e}removeSlotObject(e){this._pendingSlotObjects=this._pendingSlotObjects.filter(t=>t.gameObject!==e);const t=this._slotGameObjects.get(e);t&&this.armature&&(this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1})),this._slotGameObjects.delete(e)}_destroySlotGameObjects(){for(const[e,t]of this._slotGameObjects)e.destroyed||(this.armature&&this.armature.removeSlotObject(t.wrapper),t.wrapper.destroy({children:!1}),e.destroy());this._slotGameObjects.clear(),this._pendingSlotObjects=[]}}o.componentName="Spine",r([s.type("string"),n("design:type",String)],o.prototype,"resource",void 0),r([s.type("number"),n("design:type",Number)],o.prototype,"scale",void 0),r([s.type("string"),n("design:type",String)],o.prototype,"animationName",void 0),r([s.type("boolean"),n("design:type",Boolean)],o.prototype,"autoPlay",void 0),r([s.type("boolean"),n("design:type",Boolean)],o.prototype,"keepResource",void 0),r([s.type("number"),n("design:type",Number)],o.prototype,"timeScale",void 0),r([s.type("string"),n("design:type",String)],o.prototype,"skin",void 0);let c={};function d(e,t,i){return a(this,void 0,void 0,function*(){let s=c[e.name];if(!s)if(e.complete)s=function(e,t,i,s){const r=t.ske,n=t.atlas,a=new s.AtlasAttachmentLoader(n),o=r instanceof Uint8Array?new s.SkeletonBinary(a):new s.SkeletonJson(a);o.scale=i||1;const d={spineData:o.readSkeletonData(r),ref:0,imageSrc:(l=t.image,l?"string"==typeof l?l:l.label||(null===(m=l.source)||void 0===m?void 0:m.label)||(null===(h=null===(u=l.source)||void 0===u?void 0:u.resource)||void 0===h?void 0:h.src)||(null===(p=l.source)||void 0===p?void 0:p._sourceOrigin)||l.src||(null===(y=l.baseTexture)||void 0===y?void 0:y.cacheId)||"":"")};var l,m,u,h,p,y;return c[e]=d,d}(e.name,e.data,t,i);else if(!s)return;return s.ref++,s.spineData})}let l=class extends t.Renderer{constructor(){super(...arguments),this.armatures={},this._spineComponents={}}init({pixiSpine:i}){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this),this.pixiSpine=i,this.game.canvas.addEventListener("webglcontextrestored",()=>{const t=this.game.gameObjects;let i=[];for(let s in this.armatures){const r=+s;for(let s=0;s<t.length;++s){let n=t[s];if(n.id===r){let t=n.getComponent(o);t&&(this.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:n,component:t,componentName:o.componentName}),i.push({type:e.OBSERVER_TYPE.ADD,gameObject:n,component:t,componentName:o.componentName}));break}}}setTimeout(()=>{i.forEach(e=>{this.add(e)})},1e3)},!1)}update(e){super.update();for(let t in this.armatures){const i=this.armatures[t],s=this._spineComponents[t];!i||i.destroyed||(null==s?void 0:s.destroied)?(delete this.armatures[t],delete this._spineComponents[t]):i.update(.001*e.deltaTime)}for(let e in this._spineComponents){const t=this._spineComponents[e];t&&!t.destroied?t._flushPendingSlotObjects():delete this._spineComponents[e]}}componentChanged(t){return a(this,void 0,void 0,function*(){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE){if("resource"===t.prop.prop[0])this.change(t)}else t.type===e.OBSERVER_TYPE.REMOVE&&this.remove(t)})}add(t,i){var s,r,n;return a(this,void 0,void 0,function*(){const a=t.component;clearTimeout(a.addHandler);const o=t.gameObject.id,c=this.increaseAsyncId(o),l=yield e.resource.getResource(a.resource);if(!this.validateAsyncId(o,c)||a.destroied||t.gameObject.destroyed)return;const m=yield d(l,a.scale,this.pixiSpine);if(!this.validateAsyncId(o,c)||a.destroied||t.gameObject.destroyed)return;if(!m)return void(a.addHandler=setTimeout(()=>{a.destroied||t.gameObject.destroyed||(void 0===i&&(i=20),--i>0?this.add(t,i):console.log("retry exceed max times",a.resource))},1e3));this.remove(t);const u=null===(r=null===(s=this.renderSystem)||void 0===s?void 0:s.containerManager)||void 0===r?void 0:r.getContainer(t.gameObject.id);if(!u||a.destroied||t.gameObject.destroyed)return;a.lastResource=a.resource;const h=new this.pixiSpine.Spine({skeletonData:m,autoUpdate:!1});if(this.armatures[t.gameObject.id]=h,this._spineComponents[t.gameObject.id]=a,t.gameObject&&t.gameObject.transform){const e=t.gameObject.transform;h.x=e.size.width*e.origin.x,h.y=e.size.height*e.origin.y}u.addChildAt(h,0),h.update(),a._containerManager=null===(n=this.renderSystem)||void 0===n?void 0:n.containerManager,a.armature=h,a.emit("loaded",{resource:a.resource}),h.state.addListener({start:(e,t)=>{a.emit("start",{track:e,name:e.animation.name})},complete:(e,t)=>{a.emit("complete",{track:e,name:e.animation.name})},interrupt:(e,t)=>{a.emit("interrupt",{track:e,name:e.animation.name})},end:(e,t)=>{a.emit("end",{track:e,name:e.animation.name})},event:(e,t)=>{a.emit("event",e,t)}})})}change(e){this.remove(e),this.add(e)}remove(t){var i,s,r,n,o,d;return a(this,void 0,void 0,function*(){const l=t.gameObject.id;this.increaseAsyncId(l);const m=t.component;clearTimeout(m.addHandler);const u=this.armatures[l],h=null===(s=null===(i=this.renderSystem)||void 0===i?void 0:i.containerManager)||void 0===s?void 0:s.getContainer(l);h&&u&&h.removeChild(u);const p=m.armature;if(m.armature=null,delete this.armatures[l],delete this._spineComponents[l],p&&(m._destroySlotGameObjects(),p.destroyed||p.destroy({children:!0}),!m.keepResource&&m.lastResource))try{const t=yield e.resource.getResource(m.lastResource);(null===(n=null===(r=t.data)||void 0===r?void 0:r.image)||void 0===n?void 0:n.src)||(null===(d=null===(o=t.data)||void 0===o?void 0:o.image)||void 0===d||d.label);!function(t){const i=t.name,s=c[i];s&&(s.ref--,setTimeout(()=>a(this,void 0,void 0,function*(){s.ref<=0&&(e.resource.destroy(i),delete c[i])}),100))}(t)}catch(e){console.warn("Failed to release Spine resource",m.lastResource,e)}t.type,e.OBSERVER_TYPE.CHANGE})}};l.systemName="SpineSystem",l=r([e.decorators.componentObserver({Spine:["resource"]})],l);var m=l;e.resource.registerResourceType("SPINE"),exports.Spine=o,exports.SpineSystem=m;
|
package/dist/spine-base.d.ts
CHANGED
|
@@ -76,6 +76,16 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
76
76
|
autoPlay: boolean;
|
|
77
77
|
/** 是否保留资源(销毁时不释放) */
|
|
78
78
|
keepResource: boolean;
|
|
79
|
+
/** 动画播放时间缩放 */
|
|
80
|
+
timeScale: number;
|
|
81
|
+
/** 当前皮肤名称 */
|
|
82
|
+
skin: string;
|
|
83
|
+
/** 动画开始事件回调 */
|
|
84
|
+
onStart?: (event?: unknown) => void;
|
|
85
|
+
/** 动画完成事件回调 */
|
|
86
|
+
onComplete?: (event?: unknown) => void;
|
|
87
|
+
/** Spine 自定义事件回调 */
|
|
88
|
+
onEvent?: (track?: unknown, event?: unknown) => void;
|
|
79
89
|
/** Spine 骨架实例(内部使用) */
|
|
80
90
|
private _armature;
|
|
81
91
|
/** 容器管理器引用(由 SpineSystem 设置) */
|
|
@@ -92,6 +102,9 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
92
102
|
}[];
|
|
93
103
|
/** 等待执行的动画操作队列 */
|
|
94
104
|
private waitExecuteInfos;
|
|
105
|
+
private listenerBound;
|
|
106
|
+
private paused;
|
|
107
|
+
constructor(params?: SpineParams);
|
|
95
108
|
/**
|
|
96
109
|
* 设置骨架实例
|
|
97
110
|
* 当骨架加载完成后自动执行等待队列中的动画操作
|
|
@@ -116,6 +129,11 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
116
129
|
init(obj?: SpineParams): void;
|
|
117
130
|
/** 组件销毁时调用 */
|
|
118
131
|
onDestroy(): void;
|
|
132
|
+
load(): any;
|
|
133
|
+
destroy(): void;
|
|
134
|
+
pause(): void;
|
|
135
|
+
resume(): void;
|
|
136
|
+
setSkin(name: string): void;
|
|
119
137
|
/**
|
|
120
138
|
* 播放指定动画
|
|
121
139
|
*
|
|
@@ -134,6 +152,7 @@ export declare class Spine extends Component<SpineParams> {
|
|
|
134
152
|
* @param track - 动画轨道编号,默认为 0
|
|
135
153
|
*/
|
|
136
154
|
stop(track?: number): void;
|
|
155
|
+
private applyTimeScale;
|
|
137
156
|
/**
|
|
138
157
|
* 在当前动画之后添加新动画到队列
|
|
139
158
|
*
|
|
@@ -228,6 +247,11 @@ export declare interface SpineParams {
|
|
|
228
247
|
animationName?: string;
|
|
229
248
|
scale?: number;
|
|
230
249
|
autoPlay?: boolean;
|
|
250
|
+
timeScale?: number;
|
|
251
|
+
skin?: string;
|
|
252
|
+
onStart?: (event?: unknown) => void;
|
|
253
|
+
onComplete?: (event?: unknown) => void;
|
|
254
|
+
onEvent?: (track?: unknown, event?: unknown) => void;
|
|
231
255
|
}
|
|
232
256
|
|
|
233
257
|
/**
|
package/dist/spine-base.esm.js
CHANGED
|
@@ -25,6 +25,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
25
25
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function __metadata(metadataKey, metadataValue) {
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
29
33
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
34
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -95,8 +99,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
95
99
|
* ```
|
|
96
100
|
*/
|
|
97
101
|
class Spine extends Component {
|
|
98
|
-
constructor() {
|
|
99
|
-
super(
|
|
102
|
+
constructor(params) {
|
|
103
|
+
super(params);
|
|
100
104
|
/** Spine 资源名称 */
|
|
101
105
|
this.resource = '';
|
|
102
106
|
/** 动画缩放比例 */
|
|
@@ -107,12 +111,19 @@ class Spine extends Component {
|
|
|
107
111
|
this.autoPlay = true;
|
|
108
112
|
/** 是否保留资源(销毁时不释放) */
|
|
109
113
|
this.keepResource = false;
|
|
114
|
+
/** 动画播放时间缩放 */
|
|
115
|
+
this.timeScale = 1;
|
|
116
|
+
/** 当前皮肤名称 */
|
|
117
|
+
this.skin = '';
|
|
110
118
|
/** 挂载到插槽的 GameObject 映射(GameObject -> { slot, wrapper }) */
|
|
111
119
|
this._slotGameObjects = new Map();
|
|
112
120
|
/** 等待容器就绪的 slot 挂载请求 */
|
|
113
121
|
this._pendingSlotObjects = [];
|
|
114
122
|
/** 等待执行的动画操作队列 */
|
|
115
123
|
this.waitExecuteInfos = [];
|
|
124
|
+
this.listenerBound = false;
|
|
125
|
+
this.paused = false;
|
|
126
|
+
this.init(params);
|
|
116
127
|
}
|
|
117
128
|
/**
|
|
118
129
|
* 设置骨架实例
|
|
@@ -122,6 +133,9 @@ class Spine extends Component {
|
|
|
122
133
|
this._armature = val;
|
|
123
134
|
if (!val)
|
|
124
135
|
return;
|
|
136
|
+
this.applyTimeScale();
|
|
137
|
+
if (this.skin)
|
|
138
|
+
this.setSkin(this.skin);
|
|
125
139
|
if (this.autoPlay) {
|
|
126
140
|
this.play(this.animationName);
|
|
127
141
|
}
|
|
@@ -149,14 +163,61 @@ class Spine extends Component {
|
|
|
149
163
|
* @param obj.autoPlay - 是否自动播放
|
|
150
164
|
*/
|
|
151
165
|
init(obj) {
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
if (obj)
|
|
167
|
+
Object.assign(this, obj);
|
|
168
|
+
if (!this.listenerBound) {
|
|
169
|
+
this.listenerBound = true;
|
|
170
|
+
this.on('start', event => {
|
|
171
|
+
var _a;
|
|
172
|
+
(_a = this.onStart) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
173
|
+
});
|
|
174
|
+
this.on('complete', event => {
|
|
175
|
+
var _a;
|
|
176
|
+
(_a = this.onComplete) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
177
|
+
});
|
|
178
|
+
this.on('event', (track, event) => {
|
|
179
|
+
var _a;
|
|
180
|
+
(_a = this.onEvent) === null || _a === void 0 ? void 0 : _a.call(this, track, event);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
155
183
|
}
|
|
156
184
|
/** 组件销毁时调用 */
|
|
157
185
|
onDestroy() {
|
|
158
186
|
this.destroied = true;
|
|
159
187
|
}
|
|
188
|
+
load() {
|
|
189
|
+
return this.armature;
|
|
190
|
+
}
|
|
191
|
+
destroy() {
|
|
192
|
+
this.onDestroy();
|
|
193
|
+
if (this.armature && !this.armature.destroyed) {
|
|
194
|
+
this._destroySlotGameObjects();
|
|
195
|
+
this.armature.destroy({ children: true });
|
|
196
|
+
}
|
|
197
|
+
this.armature = null;
|
|
198
|
+
}
|
|
199
|
+
pause() {
|
|
200
|
+
this.paused = true;
|
|
201
|
+
this.applyTimeScale();
|
|
202
|
+
}
|
|
203
|
+
resume() {
|
|
204
|
+
this.paused = false;
|
|
205
|
+
this.applyTimeScale();
|
|
206
|
+
}
|
|
207
|
+
setSkin(name) {
|
|
208
|
+
var _a, _b, _c, _d, _e;
|
|
209
|
+
this.skin = name;
|
|
210
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.skeleton))
|
|
211
|
+
return;
|
|
212
|
+
if (this.armature.skeleton.setSkinByName) {
|
|
213
|
+
this.armature.skeleton.setSkinByName(name);
|
|
214
|
+
}
|
|
215
|
+
else if (this.armature.skeleton.setSkin) {
|
|
216
|
+
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;
|
|
217
|
+
this.armature.skeleton.setSkin(skin);
|
|
218
|
+
}
|
|
219
|
+
(_e = (_d = this.armature.skeleton).setSlotsToSetupPose) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
220
|
+
}
|
|
160
221
|
/**
|
|
161
222
|
* 播放指定动画
|
|
162
223
|
*
|
|
@@ -189,6 +250,7 @@ class Spine extends Component {
|
|
|
189
250
|
if (track === undefined) {
|
|
190
251
|
track = 0;
|
|
191
252
|
}
|
|
253
|
+
this.applyTimeScale();
|
|
192
254
|
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
193
255
|
}
|
|
194
256
|
}
|
|
@@ -216,6 +278,12 @@ class Spine extends Component {
|
|
|
216
278
|
}
|
|
217
279
|
this.armature.state.setEmptyAnimation(track, 0);
|
|
218
280
|
}
|
|
281
|
+
applyTimeScale() {
|
|
282
|
+
var _a;
|
|
283
|
+
if (!((_a = this.armature) === null || _a === void 0 ? void 0 : _a.state))
|
|
284
|
+
return;
|
|
285
|
+
this.armature.state.timeScale = this.paused ? 0 : this.timeScale;
|
|
286
|
+
}
|
|
219
287
|
/**
|
|
220
288
|
* 在当前动画之后添加新动画到队列
|
|
221
289
|
*
|
|
@@ -429,22 +497,51 @@ class Spine extends Component {
|
|
|
429
497
|
/** 组件名称 */
|
|
430
498
|
Spine.componentName = 'Spine';
|
|
431
499
|
__decorate([
|
|
432
|
-
type('string')
|
|
500
|
+
type('string'),
|
|
501
|
+
__metadata("design:type", String)
|
|
433
502
|
], Spine.prototype, "resource", void 0);
|
|
434
503
|
__decorate([
|
|
435
|
-
type('number')
|
|
504
|
+
type('number'),
|
|
505
|
+
__metadata("design:type", Number)
|
|
436
506
|
], Spine.prototype, "scale", void 0);
|
|
437
507
|
__decorate([
|
|
438
|
-
type('string')
|
|
508
|
+
type('string'),
|
|
509
|
+
__metadata("design:type", String)
|
|
439
510
|
], Spine.prototype, "animationName", void 0);
|
|
440
511
|
__decorate([
|
|
441
|
-
type('boolean')
|
|
512
|
+
type('boolean'),
|
|
513
|
+
__metadata("design:type", Boolean)
|
|
442
514
|
], Spine.prototype, "autoPlay", void 0);
|
|
443
515
|
__decorate([
|
|
444
|
-
type('boolean')
|
|
445
|
-
|
|
516
|
+
type('boolean'),
|
|
517
|
+
__metadata("design:type", Boolean)
|
|
518
|
+
], Spine.prototype, "keepResource", void 0);
|
|
519
|
+
__decorate([
|
|
520
|
+
type('number'),
|
|
521
|
+
__metadata("design:type", Number)
|
|
522
|
+
], Spine.prototype, "timeScale", void 0);
|
|
523
|
+
__decorate([
|
|
524
|
+
type('string'),
|
|
525
|
+
__metadata("design:type", String)
|
|
526
|
+
], Spine.prototype, "skin", void 0);
|
|
446
527
|
|
|
447
528
|
let dataMap = {};
|
|
529
|
+
function resolveImageSrc(image) {
|
|
530
|
+
var _a, _b, _c, _d, _e;
|
|
531
|
+
if (!image)
|
|
532
|
+
return '';
|
|
533
|
+
if (typeof image === 'string')
|
|
534
|
+
return image;
|
|
535
|
+
// PixiJS v8 Texture / TextureSource shapes vary depending on loader; try every
|
|
536
|
+
// common label/url accessor before bailing out.
|
|
537
|
+
return (image.label ||
|
|
538
|
+
((_a = image.source) === null || _a === void 0 ? void 0 : _a.label) ||
|
|
539
|
+
((_c = (_b = image.source) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.src) ||
|
|
540
|
+
((_d = image.source) === null || _d === void 0 ? void 0 : _d._sourceOrigin) ||
|
|
541
|
+
image.src ||
|
|
542
|
+
((_e = image.baseTexture) === null || _e === void 0 ? void 0 : _e.cacheId) ||
|
|
543
|
+
'');
|
|
544
|
+
}
|
|
448
545
|
function createSpineData(name, data, scale, pixiSpine) {
|
|
449
546
|
const skeletonAsset = data.ske;
|
|
450
547
|
const atlasAsset = data.atlas;
|
|
@@ -454,7 +551,7 @@ function createSpineData(name, data, scale, pixiSpine) {
|
|
|
454
551
|
: new pixiSpine.SkeletonJson(attachmentLoader);
|
|
455
552
|
parser.scale = scale || 1;
|
|
456
553
|
const skeletonData = parser.readSkeletonData(skeletonAsset);
|
|
457
|
-
const obj = { spineData: skeletonData, ref: 0, imageSrc: data.image
|
|
554
|
+
const obj = { spineData: skeletonData, ref: 0, imageSrc: resolveImageSrc(data.image) };
|
|
458
555
|
dataMap[name] = obj;
|
|
459
556
|
return obj;
|
|
460
557
|
}
|
|
@@ -561,16 +658,28 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
561
658
|
* @param e - 更新参数,包含帧间隔时间
|
|
562
659
|
*/
|
|
563
660
|
update(e) {
|
|
661
|
+
super.update();
|
|
564
662
|
for (let key in this.armatures) {
|
|
663
|
+
const armature = this.armatures[key];
|
|
664
|
+
const component = this._spineComponents[key];
|
|
665
|
+
if (!armature || armature.destroyed || (component === null || component === void 0 ? void 0 : component.destroied)) {
|
|
666
|
+
delete this.armatures[key];
|
|
667
|
+
delete this._spineComponents[key];
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
565
670
|
// TODO: 类型
|
|
566
671
|
// @ts-ignore
|
|
567
|
-
|
|
672
|
+
armature.update(e.deltaTime * 0.001);
|
|
568
673
|
}
|
|
569
674
|
// 处理等待容器就绪的 slot 挂载请求
|
|
570
675
|
for (let key in this._spineComponents) {
|
|
571
|
-
this._spineComponents[key]
|
|
676
|
+
const component = this._spineComponents[key];
|
|
677
|
+
if (!component || component.destroied) {
|
|
678
|
+
delete this._spineComponents[key];
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
component._flushPendingSlotObjects();
|
|
572
682
|
}
|
|
573
|
-
super.update();
|
|
574
683
|
}
|
|
575
684
|
componentChanged(changed) {
|
|
576
685
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -599,14 +708,14 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
599
708
|
const gameObjectId = changed.gameObject.id;
|
|
600
709
|
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
601
710
|
const res = yield resource.getResource(component.resource);
|
|
602
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
711
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed)
|
|
603
712
|
return;
|
|
604
713
|
const spineData = yield getSpineData(res, component.scale, this.pixiSpine);
|
|
605
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
714
|
+
if (!this.validateAsyncId(gameObjectId, asyncId) || component.destroied || changed.gameObject.destroyed)
|
|
606
715
|
return;
|
|
607
716
|
if (!spineData) {
|
|
608
717
|
component.addHandler = setTimeout(() => {
|
|
609
|
-
if (!component.destroied) {
|
|
718
|
+
if (!component.destroied && !changed.gameObject.destroyed) {
|
|
610
719
|
if (count === undefined) {
|
|
611
720
|
// 最大重试次数
|
|
612
721
|
count = MaxRetryCount;
|
|
@@ -624,7 +733,7 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
624
733
|
}
|
|
625
734
|
this.remove(changed);
|
|
626
735
|
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);
|
|
627
|
-
if (!container) {
|
|
736
|
+
if (!container || component.destroied || changed.gameObject.destroyed) {
|
|
628
737
|
// console.warn('添加spine的container不存在');
|
|
629
738
|
return;
|
|
630
739
|
}
|
|
@@ -679,27 +788,36 @@ let SpineSystem = class SpineSystem extends Renderer {
|
|
|
679
788
|
remove(changed) {
|
|
680
789
|
var _a, _b, _c, _d, _e, _f;
|
|
681
790
|
return __awaiter(this, void 0, void 0, function* () {
|
|
682
|
-
|
|
791
|
+
const gameObjectId = changed.gameObject.id;
|
|
792
|
+
this.increaseAsyncId(gameObjectId);
|
|
683
793
|
const component = changed.component;
|
|
684
794
|
clearTimeout(component.addHandler);
|
|
685
|
-
const armature = this.armatures[
|
|
686
|
-
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(
|
|
795
|
+
const armature = this.armatures[gameObjectId];
|
|
796
|
+
const container = (_b = (_a = this.renderSystem) === null || _a === void 0 ? void 0 : _a.containerManager) === null || _b === void 0 ? void 0 : _b.getContainer(gameObjectId);
|
|
687
797
|
if (container && armature) {
|
|
688
798
|
container.removeChild(armature);
|
|
689
799
|
}
|
|
690
|
-
|
|
800
|
+
const componentArmature = component.armature;
|
|
801
|
+
component.armature = null;
|
|
802
|
+
delete this.armatures[gameObjectId];
|
|
803
|
+
delete this._spineComponents[gameObjectId];
|
|
804
|
+
if (componentArmature) {
|
|
691
805
|
// 销毁所有挂载到插槽的 GameObject
|
|
692
806
|
component._destroySlotGameObjects();
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
807
|
+
if (!componentArmature.destroyed) {
|
|
808
|
+
componentArmature.destroy({ children: true });
|
|
809
|
+
}
|
|
810
|
+
if (!component.keepResource && component.lastResource) {
|
|
811
|
+
try {
|
|
812
|
+
const res = yield resource.getResource(component.lastResource);
|
|
813
|
+
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);
|
|
814
|
+
releaseSpineData(res, imageSrc);
|
|
815
|
+
}
|
|
816
|
+
catch (error) {
|
|
817
|
+
console.warn('Failed to release Spine resource', component.lastResource, error);
|
|
818
|
+
}
|
|
698
819
|
}
|
|
699
820
|
}
|
|
700
|
-
component.armature = null;
|
|
701
|
-
delete this.armatures[changed.gameObject.id];
|
|
702
|
-
delete this._spineComponents[changed.gameObject.id];
|
|
703
821
|
if (changed.type === OBSERVER_TYPE.CHANGE) ;
|
|
704
822
|
});
|
|
705
823
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "2.0.2",
|
|
3
|
+
"version": "2.1.0-beta.2",
|
|
4
4
|
"description": "@eva/spine-base",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/spine-base.esm.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "2.0.2",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.2",
|
|
23
|
-
"@eva/inspector-decorator": "^0.0.
|
|
21
|
+
"@eva/eva.js": "2.1.0-beta.2",
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.2",
|
|
23
|
+
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
24
24
|
"pixi.js": "^8.17.0"
|
|
25
25
|
}
|
|
26
26
|
}
|