@eva/spine-base 1.2.2-alpha.2 → 1.2.2-type.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return
|
|
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)}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)e.hasOwnProperty(n)&&(t[n]=e[n])},o(t,e)};function a(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function i(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 s(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{c(r.next(t))}catch(t){a(t)}}function s(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,s)}c((r=r.apply(t,e||[])).next())}))}function c(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])}}}function u(t){return function(e,n){var r=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);r.key=n,r.type=t}}var m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.animationName="",e.autoPlay=!0,e}return a(e,t),e.prototype.init=function(t){t&&(_extends(this,t),this.autoPlay&&this.play(this.animationName))},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))}catch(t){console.log(t)}},e.prototype.stop=function(t){this.armature&&(void 0===t&&(t=0),this.armature.state.setEmptyAnimation(t,0))},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",i([u("string")],e.prototype,"resource",void 0),i([u("string")],e.prototype,"animationName",void 0),i([u("boolean")],e.prototype,"autoPlay",void 0),e}(e.Component),p=m,f={};function l(t){var e=t.image;return{tex:r.Texture.from(e),count:0}}var d={};function h(t,e,n,r){var o=null,a=function(t,e){var n=f[t];return n||(n=l(e),f[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 d[t]=i,i}function y(t,e){return s(this,void 0,void 0,(function(){var n;return c(this,(function(r){if(!(n=d[t.name]))if(t.complete)n=h(t.name,t.data,t.scale,e);else if(!n)return[2];return function(t,e){var n=f[t];n||(n=l(e),f[t]=n),n.count++,n.tex}(t.data.image.src,t.data),n.ref++,[2,n.spineData]}))}))}function v(t,e){var n=d[t];n&&(n.ref--,n.ref<=0&&(!function(t){t&&setTimeout((function(){var e=f[t];e&&(e.count--,e.count<=0&&(e.tex&&(e.tex.destroy(!0),e.tex=null),delete f[t]))}),100)}(e),delete d[t]))}var g=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 c=s.getComponent(p);c&&(r.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:c,componentName:p.componentName}),n.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:c,componentName:p.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 s(this,void 0,void 0,(function(){return c(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){return s(this,void 0,void 0,(function(){var r,o,a,i,s,u=this;return c(this,(function(c){switch(c.label){case 0:return r=t.component,clearTimeout(r.addHandler),[4,e.resource.getResource(r.resource)];case 1:return[4,y(c.sent(),this.pixiSpine)];case 2:if(!(o=c.sent()))return r.addHandler=setTimeout((function(){r.destroied||(void 0===n&&(n=20),--n>0?u.add(t,n):console.log("retry exceed max times",r.resource))}),1e3),[2];if(this.remove(t),!(a=this.renderSystem.containerManager.getContainer(t.gameObject.id)))return[2];if(r.lastResource=r.resource,i=new this.pixiSpine.Spine(o),this.armatures[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform&&(s=t.gameObject.transform,i.x=s.size.width*s.origin.x,i.y=s.size.height*s.origin.y),a.addChildAt(i,0),i.update(),i.updateTransform(),r.armature=i,r.autoPlay)try{i.state.setAnimation(0,r.animationName,!0)}catch(t){console.log(t)}return r.emit("loaded",{resource:r.resource}),i.state.addListener({start:function(t,e){r.emit("start",{track:t,name:t.animation.name})},complete:function(t,e){r.emit("complete",{track:t,name:t.animation.name})},interrupt:function(t,e){r.emit("interrupt",{track:t,name:t.animation.name})},end:function(t,e){r.emit("end",{track:t,name:t.animation.name})},event:function(t,e){r.emit("event",t,e)}}),[2]}}))}))},r.prototype.change=function(t){this.remove(t),this.add(t)},r.prototype.remove=function(t){var n,r;return s(this,void 0,void 0,(function(){var o,a,i,s;return c(this,(function(c){switch(c.label){case 0:return o=t.component,clearTimeout(o.addHandler),a=this.armatures[t.gameObject.id],(i=this.renderSystem.containerManager.getContainer(t.gameObject.id))&&a&&i.removeChild(a),o.armature?(o.armature.destroy({children:!0}),[4,e.resource.getResource(o.lastResource)]):[3,2];case 1:v((s=c.sent()).name,null===(r=null===(n=s.data)||void 0===n?void 0:n.image)||void 0===r?void 0:r.src),c.label=2;case 2:return o.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},r.systemName="SpineSystem",r=i([e.decorators.componentObserver({Spine:["resource"]})],r)}(n.Renderer),b=g;return e.resource.registerResourceType("SPINE"),t.Spine=p,t.SpineSystem=b,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,PIXI);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),o=function(e,t){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/plugin-renderer"),r=require("@eva/inspector-decorator"),n=require("pixi.js"),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)}function i(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 s(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 u(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 c=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.resource="",t.animationName="",t.autoPlay=!0,t}return a(t,e),t.prototype.init=function(e){e&&(Object.assign(this,e),this.autoPlay&&this.play(this.animationName))},t.prototype.onDestroy=function(){this.destroied=!0},t.prototype.play=function(e,t,r){try{e&&(this.animationName=e),this.armature&&(void 0===r&&(r=0),this.armature.state.setAnimation(r,this.animationName,t))}catch(e){console.log(e)}},t.prototype.stop=function(e){this.armature&&(void 0===e&&(e=0),this.armature.state.setEmptyAnimation(e,0))},t.prototype.addAnimation=function(e,t,r,n){try{this.armature&&(void 0===n&&(n=0),this.armature.state.addAnimation(n,e,r,t))}catch(e){console.log(e)}},t.prototype.setMix=function(e,t,r){this.armature&&this.armature.stateData.setMix(e,t,r)},t.prototype.getAnim=function(e){void 0===e&&(e=0);try{if(this.armature)return this.armature.state.tracks[e].animation.name}catch(e){console.log(e)}},t.prototype.setDefaultMix=function(e){this.armature&&(this.armature.stateData.defaultMix=e)},t.prototype.setAttachment=function(e,t){this.armature&&this.armature.skeleton.setAttachment(e,t)},t.prototype.getBone=function(e){if(this.armature)return this.armature.skeleton.findBone(e)},t.componentName="Spine",i([r.type("string")],t.prototype,"resource",void 0),i([r.type("string")],t.prototype,"animationName",void 0),i([r.type("boolean")],t.prototype,"autoPlay",void 0),t}(e.Component),m={};function p(e){var t=e.image;return{tex:n.Texture.from(t),count:0}}var l={};function f(e,t,r,n){var o=null,a=function(e,t){var r=m[e];return r||(r=p(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 l[e]=i,i}function d(e,t){return s(this,void 0,void 0,(function(){var r;return u(this,(function(n){if(!(r=l[e.name]))if(e.complete)r=f(e.name,e.data,e.scale,t);else if(!r)return[2];return function(e,t){var r=m[e];r||(r=p(t),m[e]=r),r.count++,r.tex}(e.data.image.src,e.data),r.ref++,[2,r.spineData]}))}))}function h(e,t){var r=l[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 l[e]))}var y=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(c);u&&(n.remove({type:e.OBSERVER_TYPE.REMOVE,gameObject:s,component:u,componentName:c.componentName}),r.push({type:e.OBSERVER_TYPE.ADD,gameObject:s,component:u,componentName:c.componentName}));break}}setTimeout((function(){r.forEach((function(e){n.add(e)}))}),1e3)}),!1)},n.prototype.update=function(e){for(var t in this.armatures)this.armatures[t].update(.001*e.deltaTime),this.armatures[t].updateTransform();r.prototype.update.call(this)},n.prototype.componentChanged=function(t){return s(this,void 0,void 0,(function(){return u(this,(function(r){if("Spine"===t.componentName)if(t.type===e.OBSERVER_TYPE.ADD)this.add(t);else if(t.type===e.OBSERVER_TYPE.CHANGE){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){return s(this,void 0,void 0,(function(){var n,o,a,i,s,c=this;return u(this,(function(u){switch(u.label){case 0:return n=t.component,clearTimeout(n.addHandler),[4,e.resource.getResource(n.resource)];case 1:return[4,d(u.sent(),this.pixiSpine)];case 2:if(!(o=u.sent()))return n.addHandler=setTimeout((function(){n.destroied||(void 0===r&&(r=20),--r>0?c.add(t,r):console.log("retry exceed max times",n.resource))}),1e3),[2];if(this.remove(t),!(a=this.renderSystem.containerManager.getContainer(t.gameObject.id)))return[2];if(n.lastResource=n.resource,i=new this.pixiSpine.Spine(o),this.armatures[t.gameObject.id]=i,t.gameObject&&t.gameObject.transform&&(s=t.gameObject.transform,i.x=s.size.width*s.origin.x,i.y=s.size.height*s.origin.y),a.addChildAt(i,0),i.update(),i.updateTransform(),n.armature=i,n.autoPlay)try{i.state.setAnimation(0,n.animationName,!0)}catch(e){console.log(e)}return n.emit("loaded",{resource:n.resource}),i.state.addListener({start:function(e,t){n.emit("start",{track:e,name:e.animation.name})},complete:function(e,t){n.emit("complete",{track:e,name:e.animation.name})},interrupt:function(e,t){n.emit("interrupt",{track:e,name:e.animation.name})},end:function(e,t){n.emit("end",{track:e,name:e.animation.name})},event:function(e,t){n.emit("event",e,t)}}),[2]}}))}))},n.prototype.change=function(e){this.remove(e),this.add(e)},n.prototype.remove=function(t){var r,n;return s(this,void 0,void 0,(function(){var o,a,i,s;return u(this,(function(u){switch(u.label){case 0:return o=t.component,clearTimeout(o.addHandler),a=this.armatures[t.gameObject.id],(i=this.renderSystem.containerManager.getContainer(t.gameObject.id))&&a&&i.removeChild(a),o.armature?(o.armature.destroy({children:!0}),[4,e.resource.getResource(o.lastResource)]):[3,2];case 1:h((s=u.sent()).name,null===(n=null===(r=s.data)||void 0===r?void 0:r.image)||void 0===n?void 0:n.src),u.label=2;case 2:return o.armature=null,delete this.armatures[t.gameObject.id],t.type,e.OBSERVER_TYPE.CHANGE,[2]}}))}))},n.systemName="SpineSystem",n=i([e.decorators.componentObserver({Spine:["resource"]})],n)}(t.Renderer);e.resource.registerResourceType("SPINE"),exports.Spine=c,exports.SpineSystem=y;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/spine-base",
|
|
3
|
-
"version": "1.2.2-
|
|
3
|
+
"version": "1.2.2-type.1",
|
|
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.2-
|
|
22
|
-
"@eva/plugin-renderer": "1.2.2-
|
|
21
|
+
"@eva/eva.js": "1.2.2-type.1",
|
|
22
|
+
"@eva/plugin-renderer": "1.2.2-type.1",
|
|
23
23
|
"@eva/inspector-decorator": "^0.0.5",
|
|
24
24
|
"pixi.js": "^4.8.9"
|
|
25
25
|
}
|
package/dist/miniprogram.js
DELETED
|
@@ -1,499 +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, __decorate, __awaiter, __generator } from 'tslib';
|
|
5
|
-
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
6
|
-
import { type } 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
|
-
return _this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
Spine.prototype.init = function (obj) {
|
|
22
|
-
if (!obj) return;
|
|
23
|
-
|
|
24
|
-
_extends(this, obj);
|
|
25
|
-
|
|
26
|
-
if (this.autoPlay) {
|
|
27
|
-
this.play(this.animationName);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
Spine.prototype.onDestroy = function () {
|
|
32
|
-
this.destroied = true;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
Spine.prototype.play = function (name, loop, track) {
|
|
36
|
-
try {
|
|
37
|
-
if (name) this.animationName = name;
|
|
38
|
-
|
|
39
|
-
if (!this.armature) {} else {
|
|
40
|
-
if (track === undefined) {
|
|
41
|
-
track = 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.armature.state.setAnimation(track, this.animationName, loop);
|
|
45
|
-
}
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.log(e);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
Spine.prototype.stop = function (track) {
|
|
52
|
-
if (!this.armature) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (track === undefined) {
|
|
57
|
-
track = 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.armature.state.setEmptyAnimation(track, 0);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
Spine.prototype.addAnimation = function (name, delay, loop, track) {
|
|
64
|
-
try {
|
|
65
|
-
if (!this.armature) {} else {
|
|
66
|
-
if (track === undefined) {
|
|
67
|
-
track = 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.armature.state.addAnimation(track, name, loop, delay);
|
|
71
|
-
}
|
|
72
|
-
} catch (e) {
|
|
73
|
-
console.log(e);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
Spine.prototype.setMix = function (from, to, duration) {
|
|
78
|
-
if (!this.armature) ;else {
|
|
79
|
-
this.armature.stateData.setMix(from, to, duration);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
Spine.prototype.getAnim = function (track) {
|
|
84
|
-
if (track === void 0) {
|
|
85
|
-
track = 0;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
if (!this.armature) {} else {
|
|
90
|
-
return this.armature.state.tracks[track].animation.name;
|
|
91
|
-
}
|
|
92
|
-
} catch (e) {
|
|
93
|
-
console.log(e);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
Spine.prototype.setDefaultMix = function (duration) {
|
|
98
|
-
if (!this.armature) ;else {
|
|
99
|
-
this.armature.stateData.defaultMix = duration;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
Spine.prototype.setAttachment = function (slotName, attachmentName) {
|
|
104
|
-
if (!this.armature) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.armature.skeleton.setAttachment(slotName, attachmentName);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
Spine.prototype.getBone = function (boneName) {
|
|
112
|
-
if (!this.armature) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return this.armature.skeleton.findBone(boneName);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
Spine.componentName = 'Spine';
|
|
120
|
-
|
|
121
|
-
__decorate([type('string')], Spine.prototype, "resource", void 0);
|
|
122
|
-
|
|
123
|
-
__decorate([type('string')], Spine.prototype, "animationName", void 0);
|
|
124
|
-
|
|
125
|
-
__decorate([type('boolean')], Spine.prototype, "autoPlay", void 0);
|
|
126
|
-
|
|
127
|
-
return Spine;
|
|
128
|
-
}(Component);
|
|
129
|
-
|
|
130
|
-
var Spine$1 = Spine;
|
|
131
|
-
var texCache = {};
|
|
132
|
-
|
|
133
|
-
function cacheImage(data) {
|
|
134
|
-
var oldImg = data.image;
|
|
135
|
-
return {
|
|
136
|
-
tex: Texture.from(oldImg),
|
|
137
|
-
count: 0
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function retainTexture(name, data) {
|
|
142
|
-
var cache = texCache[name];
|
|
143
|
-
|
|
144
|
-
if (!cache) {
|
|
145
|
-
cache = cacheImage(data);
|
|
146
|
-
texCache[name] = cache;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
cache.count++;
|
|
150
|
-
return cache.tex;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function getTexture(imageSrc, data) {
|
|
154
|
-
var cache = texCache[imageSrc];
|
|
155
|
-
|
|
156
|
-
if (!cache) {
|
|
157
|
-
cache = cacheImage(data);
|
|
158
|
-
texCache[imageSrc] = cache;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return cache.tex;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function releaseTexture(imageSrc) {
|
|
165
|
-
if (!imageSrc) return;
|
|
166
|
-
setTimeout(function () {
|
|
167
|
-
var cache = texCache[imageSrc];
|
|
168
|
-
|
|
169
|
-
if (cache) {
|
|
170
|
-
cache.count--;
|
|
171
|
-
|
|
172
|
-
if (cache.count <= 0) {
|
|
173
|
-
if (cache.tex) {
|
|
174
|
-
cache.tex.destroy(true);
|
|
175
|
-
cache.tex = null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
delete texCache[imageSrc];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}, 100);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
var dataMap = {};
|
|
185
|
-
|
|
186
|
-
function createSpineData(name, data, scale, pixiSpine) {
|
|
187
|
-
var spineData = null;
|
|
188
|
-
var img = getTexture(data.image.src, data);
|
|
189
|
-
new pixiSpine.core.TextureAtlas(data.atlas, function (line, callback) {
|
|
190
|
-
callback(img.baseTexture);
|
|
191
|
-
}, function (spineAtlas) {
|
|
192
|
-
if (spineAtlas) {
|
|
193
|
-
var attachmentLoader = new pixiSpine.core.AtlasAttachmentLoader(spineAtlas);
|
|
194
|
-
var spineJsonParser = new pixiSpine.core.SkeletonJson(attachmentLoader);
|
|
195
|
-
|
|
196
|
-
if (scale) {
|
|
197
|
-
spineJsonParser.scale = scale;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
spineData = spineJsonParser.readSkeletonData(data.ske);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
var obj = {
|
|
204
|
-
spineData: spineData,
|
|
205
|
-
ref: 0,
|
|
206
|
-
imageSrc: data.image.src
|
|
207
|
-
};
|
|
208
|
-
dataMap[name] = obj;
|
|
209
|
-
return obj;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function getSpineData(res, pixiSpine) {
|
|
213
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
-
var data;
|
|
215
|
-
return __generator(this, function (_a) {
|
|
216
|
-
data = dataMap[res.name];
|
|
217
|
-
|
|
218
|
-
if (!data) {
|
|
219
|
-
if (res.complete) {
|
|
220
|
-
data = createSpineData(res.name, res.data, res.scale, pixiSpine);
|
|
221
|
-
} else if (!data) {
|
|
222
|
-
return [2];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
retainTexture(res.data.image.src, res.data);
|
|
227
|
-
data.ref++;
|
|
228
|
-
return [2, data.spineData];
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function releaseSpineData(resourceName, imageSrc) {
|
|
234
|
-
var data = dataMap[resourceName];
|
|
235
|
-
|
|
236
|
-
if (!data) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
data.ref--;
|
|
241
|
-
|
|
242
|
-
if (data.ref <= 0) {
|
|
243
|
-
releaseTexture(imageSrc);
|
|
244
|
-
delete dataMap[resourceName];
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
var MaxRetryCount = 20;
|
|
249
|
-
|
|
250
|
-
var SpineSystem = function (_super) {
|
|
251
|
-
__extends(SpineSystem, _super);
|
|
252
|
-
|
|
253
|
-
function SpineSystem() {
|
|
254
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
255
|
-
|
|
256
|
-
_this.armatures = {};
|
|
257
|
-
return _this;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
SpineSystem.prototype.init = function (_a) {
|
|
261
|
-
var _this = this;
|
|
262
|
-
|
|
263
|
-
var pixiSpine = _a.pixiSpine;
|
|
264
|
-
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
265
|
-
this.renderSystem.rendererManager.register(this);
|
|
266
|
-
this.pixiSpine = pixiSpine;
|
|
267
|
-
this.game.canvas.addEventListener('webglcontextrestored', function () {
|
|
268
|
-
var objs = _this.game.gameObjects;
|
|
269
|
-
var toAdd = [];
|
|
270
|
-
|
|
271
|
-
for (var k in _this.armatures) {
|
|
272
|
-
var id = +k;
|
|
273
|
-
|
|
274
|
-
for (var i = 0; i < objs.length; ++i) {
|
|
275
|
-
var obj = objs[i];
|
|
276
|
-
|
|
277
|
-
if (obj.id === id) {
|
|
278
|
-
var sp = obj.getComponent(Spine$1);
|
|
279
|
-
|
|
280
|
-
if (sp) {
|
|
281
|
-
_this.remove({
|
|
282
|
-
type: OBSERVER_TYPE.REMOVE,
|
|
283
|
-
gameObject: obj,
|
|
284
|
-
component: sp,
|
|
285
|
-
componentName: Spine$1.componentName
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
toAdd.push({
|
|
289
|
-
type: OBSERVER_TYPE.ADD,
|
|
290
|
-
gameObject: obj,
|
|
291
|
-
component: sp,
|
|
292
|
-
componentName: Spine$1.componentName
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
setTimeout(function () {
|
|
302
|
-
toAdd.forEach(function (obj) {
|
|
303
|
-
_this.add(obj);
|
|
304
|
-
});
|
|
305
|
-
}, 1000);
|
|
306
|
-
}, false);
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
SpineSystem.prototype.update = function (e) {
|
|
310
|
-
for (var key in this.armatures) {
|
|
311
|
-
this.armatures[key].update(e.deltaTime * 0.001);
|
|
312
|
-
this.armatures[key].updateTransform();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
_super.prototype.update.call(this);
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
SpineSystem.prototype.componentChanged = function (changed) {
|
|
319
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
320
|
-
return __generator(this, function (_a) {
|
|
321
|
-
if (changed.componentName === 'Spine') {
|
|
322
|
-
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
323
|
-
this.add(changed);
|
|
324
|
-
} else if (changed.type === OBSERVER_TYPE.CHANGE) {
|
|
325
|
-
switch (changed.prop.prop[0]) {
|
|
326
|
-
case 'resource':
|
|
327
|
-
this.change(changed);
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
} else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
331
|
-
this.remove(changed);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return [2];
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
SpineSystem.prototype.add = function (changed, count) {
|
|
341
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
342
|
-
var component, res, spineData, container, armature, tran;
|
|
343
|
-
|
|
344
|
-
var _this = this;
|
|
345
|
-
|
|
346
|
-
return __generator(this, function (_a) {
|
|
347
|
-
switch (_a.label) {
|
|
348
|
-
case 0:
|
|
349
|
-
component = changed.component;
|
|
350
|
-
clearTimeout(component.addHandler);
|
|
351
|
-
return [4, resource.getResource(component.resource)];
|
|
352
|
-
|
|
353
|
-
case 1:
|
|
354
|
-
res = _a.sent();
|
|
355
|
-
return [4, getSpineData(res, this.pixiSpine)];
|
|
356
|
-
|
|
357
|
-
case 2:
|
|
358
|
-
spineData = _a.sent();
|
|
359
|
-
|
|
360
|
-
if (!spineData) {
|
|
361
|
-
component.addHandler = setTimeout(function () {
|
|
362
|
-
if (!component.destroied) {
|
|
363
|
-
if (count === undefined) {
|
|
364
|
-
count = MaxRetryCount;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
count--;
|
|
368
|
-
|
|
369
|
-
if (count > 0) {
|
|
370
|
-
_this.add(changed, count);
|
|
371
|
-
} else {
|
|
372
|
-
console.log('retry exceed max times', component.resource);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}, 1000);
|
|
376
|
-
return [2];
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
this.remove(changed);
|
|
380
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
381
|
-
|
|
382
|
-
if (!container) {
|
|
383
|
-
return [2];
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
component.lastResource = component.resource;
|
|
387
|
-
armature = new this.pixiSpine.Spine(spineData);
|
|
388
|
-
this.armatures[changed.gameObject.id] = armature;
|
|
389
|
-
|
|
390
|
-
if (changed.gameObject && changed.gameObject.transform) {
|
|
391
|
-
tran = changed.gameObject.transform;
|
|
392
|
-
armature.x = tran.size.width * tran.origin.x;
|
|
393
|
-
armature.y = tran.size.height * tran.origin.y;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
container.addChildAt(armature, 0);
|
|
397
|
-
armature.update();
|
|
398
|
-
armature.updateTransform();
|
|
399
|
-
component.armature = armature;
|
|
400
|
-
|
|
401
|
-
if (component.autoPlay) {
|
|
402
|
-
try {
|
|
403
|
-
armature.state.setAnimation(0, component.animationName, true);
|
|
404
|
-
} catch (e) {
|
|
405
|
-
console.log(e);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
component.emit('loaded', {
|
|
410
|
-
resource: component.resource
|
|
411
|
-
});
|
|
412
|
-
armature.state.addListener({
|
|
413
|
-
start: function start(track, event) {
|
|
414
|
-
component.emit('start', {
|
|
415
|
-
track: track,
|
|
416
|
-
name: track.animation.name
|
|
417
|
-
});
|
|
418
|
-
},
|
|
419
|
-
complete: function complete(track, event) {
|
|
420
|
-
component.emit('complete', {
|
|
421
|
-
track: track,
|
|
422
|
-
name: track.animation.name
|
|
423
|
-
});
|
|
424
|
-
},
|
|
425
|
-
interrupt: function interrupt(track, event) {
|
|
426
|
-
component.emit('interrupt', {
|
|
427
|
-
track: track,
|
|
428
|
-
name: track.animation.name
|
|
429
|
-
});
|
|
430
|
-
},
|
|
431
|
-
end: function end(track, event) {
|
|
432
|
-
component.emit('end', {
|
|
433
|
-
track: track,
|
|
434
|
-
name: track.animation.name
|
|
435
|
-
});
|
|
436
|
-
},
|
|
437
|
-
event: function event(track, _event) {
|
|
438
|
-
component.emit('event', track, _event);
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
return [2];
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
SpineSystem.prototype.change = function (changed) {
|
|
448
|
-
this.remove(changed);
|
|
449
|
-
this.add(changed);
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
SpineSystem.prototype.remove = function (changed) {
|
|
453
|
-
var _a, _b;
|
|
454
|
-
|
|
455
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
456
|
-
var component, armature, container, res;
|
|
457
|
-
return __generator(this, function (_c) {
|
|
458
|
-
switch (_c.label) {
|
|
459
|
-
case 0:
|
|
460
|
-
component = changed.component;
|
|
461
|
-
clearTimeout(component.addHandler);
|
|
462
|
-
armature = this.armatures[changed.gameObject.id];
|
|
463
|
-
container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
464
|
-
|
|
465
|
-
if (container && armature) {
|
|
466
|
-
container.removeChild(armature);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
if (!component.armature) return [3, 2];
|
|
470
|
-
component.armature.destroy({
|
|
471
|
-
children: true
|
|
472
|
-
});
|
|
473
|
-
return [4, resource.getResource(component.lastResource)];
|
|
474
|
-
|
|
475
|
-
case 1:
|
|
476
|
-
res = _c.sent();
|
|
477
|
-
releaseSpineData(res.name, (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.image) === null || _b === void 0 ? void 0 : _b.src);
|
|
478
|
-
_c.label = 2;
|
|
479
|
-
|
|
480
|
-
case 2:
|
|
481
|
-
component.armature = null;
|
|
482
|
-
delete this.armatures[changed.gameObject.id];
|
|
483
|
-
if (changed.type === OBSERVER_TYPE.CHANGE) ;
|
|
484
|
-
return [2];
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
SpineSystem.systemName = 'SpineSystem';
|
|
491
|
-
SpineSystem = __decorate([decorators.componentObserver({
|
|
492
|
-
Spine: ['resource']
|
|
493
|
-
})], SpineSystem);
|
|
494
|
-
return SpineSystem;
|
|
495
|
-
}(Renderer);
|
|
496
|
-
|
|
497
|
-
var SpineSystem$1 = SpineSystem;
|
|
498
|
-
resource.registerResourceType('SPINE');
|
|
499
|
-
export { Spine$1 as Spine, SpineSystem$1 as SpineSystem };
|