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