@eva/plugin-renderer-sprite-animation 1.2.7-editor.5 → 1.2.7-editor.8

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.
@@ -326,6 +326,14 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
326
326
  };
327
327
  }
328
328
 
329
+ var ExecuteMode;
330
+
331
+ (function (ExecuteMode) {
332
+ ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
333
+ ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
334
+ ExecuteMode[ExecuteMode["All"] = 6] = "All";
335
+ })(ExecuteMode || (ExecuteMode = {}));
336
+
329
337
  var SpriteAnimation$2 = function (_super) {
330
338
  __extends(SpriteAnimation, _super);
331
339
 
@@ -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||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,r,o){"use strict";var i=function(t,e){return i=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])},i(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}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return s=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},s.apply(this,arguments)};function c(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function u(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(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(a,s)}c((r=r.apply(t,e||[])).next())}))}function l(t,e){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=e.call(t,a)}catch(t){i=[6,t],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])}}}function f(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.")}var d=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 m="IDE_PROPERTY_METADATA";function y(t,e,n,r){var o=Reflect.getMetadata("design:type",t,e),i=o===Array,a=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==a&&(o=a),r){var c=r();Array.isArray(c)?(i=!0,o=c[0]):o=c}var p=Reflect.getMetadata(m,t.constructor)||{};p[e]=s({type:o,isArray:i},n),Reflect.defineMetadata(m,p,t.constructor)}function h(t,e){return function(n,r){if("symbol"==typeof r)throw new d;var o=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);y(n,r,o.options,o.returnTypeFunc)}}var v=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.autoPlay=!0,e.speed=100,e.forwards=!1,e.waitPlay=!1,e.waitStop=!1,e.times=1/0,e.count=0,e.complete=!1,e}return a(e,t),e.prototype.init=function(t){var e=this;t&&_extends(this,t),this.on("loop",(function(){++e.count>=e.times&&(e.forwards?e.gotoAndStop(e.totalFrames-1):e.animate.stop(),e.complete=!0,e.emit("complete"))}))},e.prototype.play=function(t){void 0===t&&(t=1/0),0!==t&&(this.times=t,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},e.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(e.prototype,"animate",{get:function(){return this._animate},set:function(t){this._animate=t,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),e.prototype.gotoAndPlay=function(t){this.animate.gotoAndPlay(t)},e.prototype.gotoAndStop=function(t){this.animate.gotoAndStop(t)},Object.defineProperty(e.prototype,"currentFrame",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"totalFrames",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames},enumerable:!1,configurable:!0}),e.componentName="SpriteAnimation",c([h(),p("design:type",String)],e.prototype,"resource",void 0),c([h(),p("design:type",Boolean)],e.prototype,"autoPlay",void 0),c([h({step:10}),p("design:type",Number)],e.prototype,"speed",void 0),c([h(),p("design:type",Boolean)],e.prototype,"forwards",void 0),e}(e.Component),g=v,b="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e=t.name,n=t.data;return new Promise((function(t){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},u={};for(var l in c){u[e+b+l]=c[l]}for(var l in p){var d=[];if(p[l]&&p[l].length>=0)try{for(var m=(r=void 0,f(p[l])),y=m.next();!y.done;y=m.next()){var h=y.value,v=e+b+h;d.push(v)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}p[l]=d}a.frames=u;var g=new o.Spritesheet(s,a);g.parse((function(){var e=g.textures,n=[];for(var r in e)n.push(e[r]);t(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e,n,r=t.instance;if(r)try{for(var o=f(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}));var w=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(t){var e=t.transform.size,n=e.width,r=e.height;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=n,this.animates[t.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){var n,r,o,i,a;return l(this,(function(s){switch(s.label){case 0:return n=t.gameObject.id,"SpriteAnimation"!==t.componentName?[3,7]:(r=t.component,this.autoPlay[t.gameObject.id]=r.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(n,i)?(o||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:t.gameObject.id,component:r}),[3,7]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/r.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(n,i))return[2];a||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:t.gameObject.id,component:r}),s.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id)),s.label=7;case 7:return[2]}}))}))},o.prototype.add=function(t){var e=t.frames,n=t.id,o=t.component,i=new r.SpriteAnimation({frames:e});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(t){var e=t.frames,n=t.id,r=t.component;this.remove(n,!0),this.add({frames:e,id:n,component:r})},o.prototype.remove=function(t,e){var n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[t],e||delete this.autoPlay[t])},o.systemName="SpriteAnimation",o=c([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer),A=w;return t.SpriteAnimation=g,t.SpriteAnimationSystem=A,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);window.EVA.plugin.renderer.spriteAnimation=window.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
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||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,r,o){"use strict";var i=function(t,e){return i=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])},i(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}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return s=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},s.apply(this,arguments)};function c(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function u(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(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(a,s)}c((r=r.apply(t,e||[])).next())}))}function l(t,e){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=e.call(t,a)}catch(t){i=[6,t],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])}}}function f(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.")}var d=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 m,y="IDE_PROPERTY_METADATA";function h(t,e,n,r){var o=Reflect.getMetadata("design:type",t,e),i=o===Array,a=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==a&&(o=a),r){var c=r();Array.isArray(c)?(i=!0,o=c[0]):o=c}var p=Reflect.getMetadata(y,t.constructor)||{};p[e]=s({type:o,isArray:i},n),Reflect.defineMetadata(y,p,t.constructor)}function v(t,e){return function(n,r){if("symbol"==typeof r)throw new d;var o=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);h(n,r,o.options,o.returnTypeFunc)}}!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(m||(m={}));var g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.autoPlay=!0,e.speed=100,e.forwards=!1,e.waitPlay=!1,e.waitStop=!1,e.times=1/0,e.count=0,e.complete=!1,e}return a(e,t),e.prototype.init=function(t){var e=this;t&&_extends(this,t),this.on("loop",(function(){++e.count>=e.times&&(e.forwards?e.gotoAndStop(e.totalFrames-1):e.animate.stop(),e.complete=!0,e.emit("complete"))}))},e.prototype.play=function(t){void 0===t&&(t=1/0),0!==t&&(this.times=t,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)},e.prototype.stop=function(){this.animate?this.animate.stop():this.waitStop=!0},Object.defineProperty(e.prototype,"animate",{get:function(){return this._animate},set:function(t){this._animate=t,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())},enumerable:!1,configurable:!0}),e.prototype.gotoAndPlay=function(t){this.animate.gotoAndPlay(t)},e.prototype.gotoAndStop=function(t){this.animate.gotoAndStop(t)},Object.defineProperty(e.prototype,"currentFrame",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"totalFrames",{get:function(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames},enumerable:!1,configurable:!0}),e.componentName="SpriteAnimation",c([v(),p("design:type",String)],e.prototype,"resource",void 0),c([v(),p("design:type",Boolean)],e.prototype,"autoPlay",void 0),c([v({step:10}),p("design:type",Number)],e.prototype,"speed",void 0),c([v(),p("design:type",Boolean)],e.prototype,"forwards",void 0),e}(e.Component),b=g,w="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e=t.name,n=t.data;return new Promise((function(t){var r,i,a=n.json,s=o.BaseTexture.from(n.image),c=a.frames||{},p=a.animations||{},u={};for(var l in c){u[e+w+l]=c[l]}for(var l in p){var d=[];if(p[l]&&p[l].length>=0)try{for(var m=(r=void 0,f(p[l])),y=m.next();!y.done;y=m.next()){var h=y.value,v=e+w+h;d.push(v)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}p[l]=d}a.frames=u;var g=new o.Spritesheet(s,a);g.parse((function(){var e=g.textures,n=[];for(var r in e)n.push(e[r]);t(n)}))}))})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(function(t){var e,n,r=t.instance;if(r)try{for(var o=f(r),i=o.next();!i.done;i=o.next()){i.value.destroy(!0)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}}));var A=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="SpriteAnimation",e.animates={},e.autoPlay={},e}return a(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(t){var e=t.transform.size,n=e.width,r=e.height;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=n,this.animates[t.id].animatedSprite.height=r)},o.prototype.componentChanged=function(t){return u(this,void 0,void 0,(function(){var n,r,o,i,a;return l(this,(function(s){switch(s.label){case 0:return n=t.gameObject.id,"SpriteAnimation"!==t.componentName?[3,7]:(r=t.component,this.autoPlay[t.gameObject.id]=r.autoPlay,t.type!==e.OBSERVER_TYPE.ADD?[3,2]:(i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)]));case 1:return o=s.sent().instance,this.validateAsyncId(n,i)?(o||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.add({frames:o,id:t.gameObject.id,component:r}),[3,7]):[2];case 2:return t.type!==e.OBSERVER_TYPE.CHANGE?[3,6]:t.prop&&"speed"===t.prop.prop[0]?(this.animates[t.gameObject.id].speed=1e3/60/r.speed,[3,5]):[3,3];case 3:return i=this.increaseAsyncId(n),[4,e.resource.getResource(r.resource)];case 4:if(a=s.sent().instance,!this.validateAsyncId(n,i))return[2];a||console.error("GameObject:"+t.gameObject.name+"'s Img resource load error"),this.change({frames:a,id:t.gameObject.id,component:r}),s.label=5;case 5:return[3,7];case 6:t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id)),s.label=7;case 7:return[2]}}))}))},o.prototype.add=function(t){var e=t.frames,n=t.id,o=t.component,i=new r.SpriteAnimation({frames:e});this.animates[n]=i,this.containerManager.getContainer(n).addChildAt(i.animatedSprite,0),i.animatedSprite.onComplete=function(){o.emit("complete")},i.animatedSprite.onFrameChange=function(){o.emit("frameChange")},i.animatedSprite.onLoop=function(){o.emit("loop")},o.animate=this.animates[n],this.animates[n].speed=1e3/60/o.speed,this.autoPlay[n]&&i.animatedSprite.play()},o.prototype.change=function(t){var e=t.frames,n=t.id,r=t.component;this.remove(n,!0),this.add({frames:e,id:n,component:r})},o.prototype.remove=function(t,e){var n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy({children:!0}),delete this.animates[t],e||delete this.autoPlay[t])},o.systemName="SpriteAnimation",o=c([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],o)}(n.Renderer),S=A;return t.SpriteAnimation=b,t.SpriteAnimationSystem=S,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);window.EVA.plugin.renderer.spriteAnimation=window.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite-animation",
3
- "version": "1.2.7-editor.5",
3
+ "version": "1.2.7-editor.8",
4
4
  "description": "@eva/plugin-renderer-sprite-animation",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite-animation.esm.js",
@@ -18,10 +18,10 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/inspector-decorator": "0.1.0-alpha.1",
22
- "@eva/plugin-renderer": "1.2.7-editor.5",
23
- "@eva/renderer-adapter": "1.2.7-editor.5",
24
- "@eva/eva.js": "1.2.7-editor.5",
21
+ "@eva/inspector-decorator": "0.1.0-alpha.2",
22
+ "@eva/plugin-renderer": "1.2.7-editor.8",
23
+ "@eva/renderer-adapter": "1.2.7-editor.8",
24
+ "@eva/eva.js": "1.2.7-editor.8",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }
@@ -1,389 +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 { __extends, __decorate, __metadata, __values, __awaiter, __generator } from 'tslib';
4
- import { Component, resource, RESOURCE_TYPE, OBSERVER_TYPE, decorators } from '@eva/eva.js/dist/miniprogram';
5
- import { Field } from '@eva/inspector-decorator';
6
- import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
7
- import { SpriteAnimation as SpriteAnimation$4 } from '@eva/renderer-adapter/dist/miniprogram';
8
- import { BaseTexture, Spritesheet } from '@eva/miniprogram-pixi';
9
-
10
- var SpriteAnimation$2 = function (_super) {
11
- __extends(SpriteAnimation, _super);
12
-
13
- function SpriteAnimation() {
14
- var _this = _super !== null && _super.apply(this, arguments) || this;
15
-
16
- _this.resource = '';
17
- _this.autoPlay = true;
18
- _this.speed = 100;
19
- _this.forwards = false;
20
- _this.waitPlay = false;
21
- _this.waitStop = false;
22
- _this.times = Infinity;
23
- _this.count = 0;
24
- _this.complete = false;
25
- return _this;
26
- }
27
-
28
- SpriteAnimation.prototype.init = function (obj) {
29
- var _this = this;
30
-
31
- obj && _extends(this, obj);
32
- this.on('loop', function () {
33
- if (++_this.count >= _this.times) {
34
- if (_this.forwards) {
35
- _this.gotoAndStop(_this.totalFrames - 1);
36
- } else {
37
- _this.animate.stop();
38
- }
39
-
40
- _this.complete = true;
41
-
42
- _this.emit('complete');
43
- }
44
- });
45
- };
46
-
47
- SpriteAnimation.prototype.play = function (times) {
48
- if (times === void 0) {
49
- times = Infinity;
50
- }
51
-
52
- if (times === 0) {
53
- return;
54
- }
55
-
56
- this.times = times;
57
-
58
- if (!this.animate) {
59
- this.waitPlay = true;
60
- } else {
61
- if (this.complete) {
62
- this.gotoAndStop(0);
63
- }
64
-
65
- this.animate.play();
66
- this.count = 0;
67
- this.complete = false;
68
- }
69
- };
70
-
71
- SpriteAnimation.prototype.stop = function () {
72
- if (!this.animate) {
73
- this.waitStop = true;
74
- } else {
75
- this.animate.stop();
76
- }
77
- };
78
-
79
- Object.defineProperty(SpriteAnimation.prototype, "animate", {
80
- get: function get() {
81
- return this._animate;
82
- },
83
- set: function set(val) {
84
- this._animate = val;
85
-
86
- if (this.waitPlay) {
87
- this.waitPlay = false;
88
- this.play(this.times);
89
- }
90
-
91
- if (this.waitStop) {
92
- this.waitStop = false;
93
- this.stop();
94
- }
95
- },
96
- enumerable: false,
97
- configurable: true
98
- });
99
-
100
- SpriteAnimation.prototype.gotoAndPlay = function (frameNumber) {
101
- this.animate.gotoAndPlay(frameNumber);
102
- };
103
-
104
- SpriteAnimation.prototype.gotoAndStop = function (frameNumber) {
105
- this.animate.gotoAndStop(frameNumber);
106
- };
107
-
108
- Object.defineProperty(SpriteAnimation.prototype, "currentFrame", {
109
- get: function get() {
110
- var _a, _b;
111
-
112
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.currentFrame;
113
- },
114
- enumerable: false,
115
- configurable: true
116
- });
117
- Object.defineProperty(SpriteAnimation.prototype, "totalFrames", {
118
- get: function get() {
119
- var _a, _b;
120
-
121
- return (_b = (_a = this.animate) === null || _a === void 0 ? void 0 : _a.animatedSprite) === null || _b === void 0 ? void 0 : _b.totalFrames;
122
- },
123
- enumerable: false,
124
- configurable: true
125
- });
126
- SpriteAnimation.componentName = 'SpriteAnimation';
127
-
128
- __decorate([Field(), __metadata("design:type", String)], SpriteAnimation.prototype, "resource", void 0);
129
-
130
- __decorate([Field(), __metadata("design:type", Boolean)], SpriteAnimation.prototype, "autoPlay", void 0);
131
-
132
- __decorate([Field({
133
- step: 10
134
- }), __metadata("design:type", Number)], SpriteAnimation.prototype, "speed", void 0);
135
-
136
- __decorate([Field(), __metadata("design:type", Boolean)], SpriteAnimation.prototype, "forwards", void 0);
137
-
138
- return SpriteAnimation;
139
- }(Component);
140
-
141
- var SpriteAnimation$3 = SpriteAnimation$2;
142
- var resourceKeySplit = '_s|r|c_';
143
- resource.registerInstance(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
144
- var name = _a.name,
145
- data = _a.data;
146
- return new Promise(function (r) {
147
- var e_1, _a;
148
-
149
- var textureObj = data.json;
150
- var texture = BaseTexture.from(data.image);
151
- var frames = textureObj.frames || {};
152
- var animations = textureObj.animations || {};
153
- var newFrames = {};
154
-
155
- for (var key in frames) {
156
- var newKey = name + resourceKeySplit + key;
157
- newFrames[newKey] = frames[key];
158
- }
159
-
160
- for (var key in animations) {
161
- var spriteList = [];
162
-
163
- if (animations[key] && animations[key].length >= 0) {
164
- try {
165
- for (var _b = (e_1 = void 0, __values(animations[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
166
- var spriteName = _c.value;
167
- var newSpriteName = name + resourceKeySplit + spriteName;
168
- spriteList.push(newSpriteName);
169
- }
170
- } catch (e_1_1) {
171
- e_1 = {
172
- error: e_1_1
173
- };
174
- } finally {
175
- try {
176
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
177
- } finally {
178
- if (e_1) throw e_1.error;
179
- }
180
- }
181
- }
182
-
183
- animations[key] = spriteList;
184
- }
185
-
186
- textureObj.frames = newFrames;
187
- var spriteSheet = new Spritesheet(texture, textureObj);
188
- spriteSheet.parse(function () {
189
- var textures = spriteSheet.textures;
190
- var spriteFrames = [];
191
-
192
- for (var key in textures) {
193
- spriteFrames.push(textures[key]);
194
- }
195
-
196
- r(spriteFrames);
197
- });
198
- });
199
- });
200
- resource.registerDestroy(RESOURCE_TYPE.SPRITE_ANIMATION, function (_a) {
201
- var e_2, _b;
202
-
203
- var instance = _a.instance;
204
- if (!instance) return;
205
-
206
- try {
207
- for (var instance_1 = __values(instance), instance_1_1 = instance_1.next(); !instance_1_1.done; instance_1_1 = instance_1.next()) {
208
- var texture = instance_1_1.value;
209
- texture.destroy(true);
210
- }
211
- } catch (e_2_1) {
212
- e_2 = {
213
- error: e_2_1
214
- };
215
- } finally {
216
- try {
217
- if (instance_1_1 && !instance_1_1.done && (_b = instance_1.return)) _b.call(instance_1);
218
- } finally {
219
- if (e_2) throw e_2.error;
220
- }
221
- }
222
- });
223
-
224
- var SpriteAnimation = function (_super) {
225
- __extends(SpriteAnimation, _super);
226
-
227
- function SpriteAnimation() {
228
- var _this = _super !== null && _super.apply(this, arguments) || this;
229
-
230
- _this.name = 'SpriteAnimation';
231
- _this.animates = {};
232
- _this.autoPlay = {};
233
- return _this;
234
- }
235
-
236
- SpriteAnimation.prototype.init = function () {
237
- this.renderSystem = this.game.getSystem(RendererSystem);
238
- this.renderSystem.rendererManager.register(this);
239
- };
240
-
241
- SpriteAnimation.prototype.rendererUpdate = function (gameObject) {
242
- var _a = gameObject.transform.size,
243
- width = _a.width,
244
- height = _a.height;
245
-
246
- if (this.animates[gameObject.id]) {
247
- this.animates[gameObject.id].animatedSprite.width = width;
248
- this.animates[gameObject.id].animatedSprite.height = height;
249
- }
250
- };
251
-
252
- SpriteAnimation.prototype.componentChanged = function (changed) {
253
- return __awaiter(this, void 0, void 0, function () {
254
- var gameObjectId, component, asyncId, frames_1, asyncId, frames_2;
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0:
258
- gameObjectId = changed.gameObject.id;
259
- if (!(changed.componentName === 'SpriteAnimation')) return [3, 7];
260
- component = changed.component;
261
- this.autoPlay[changed.gameObject.id] = component.autoPlay;
262
- if (!(changed.type === OBSERVER_TYPE.ADD)) return [3, 2];
263
- asyncId = this.increaseAsyncId(gameObjectId);
264
- return [4, resource.getResource(component.resource)];
265
-
266
- case 1:
267
- frames_1 = _a.sent().instance;
268
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
269
-
270
- if (!frames_1) {
271
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
272
- }
273
-
274
- this.add({
275
- frames: frames_1,
276
- id: changed.gameObject.id,
277
- component: component
278
- });
279
- return [3, 7];
280
-
281
- case 2:
282
- if (!(changed.type === OBSERVER_TYPE.CHANGE)) return [3, 6];
283
- if (!(changed.prop && changed.prop.prop[0] === 'speed')) return [3, 3];
284
- this.animates[changed.gameObject.id].speed = 1000 / 60 / component.speed;
285
- return [3, 5];
286
-
287
- case 3:
288
- asyncId = this.increaseAsyncId(gameObjectId);
289
- return [4, resource.getResource(component.resource)];
290
-
291
- case 4:
292
- frames_2 = _a.sent().instance;
293
- if (!this.validateAsyncId(gameObjectId, asyncId)) return [2];
294
-
295
- if (!frames_2) {
296
- console.error("GameObject:" + changed.gameObject.name + "'s Img resource load error");
297
- }
298
-
299
- this.change({
300
- frames: frames_2,
301
- id: changed.gameObject.id,
302
- component: component
303
- });
304
- _a.label = 5;
305
-
306
- case 5:
307
- return [3, 7];
308
-
309
- case 6:
310
- if (changed.type === OBSERVER_TYPE.REMOVE) {
311
- this.increaseAsyncId(gameObjectId);
312
- this.remove(changed.gameObject.id);
313
- }
314
-
315
- _a.label = 7;
316
-
317
- case 7:
318
- return [2];
319
- }
320
- });
321
- });
322
- };
323
-
324
- SpriteAnimation.prototype.add = function (_a) {
325
- var frames = _a.frames,
326
- id = _a.id,
327
- component = _a.component;
328
- var animate = new SpriteAnimation$4({
329
- frames: frames
330
- });
331
- this.animates[id] = animate;
332
- this.containerManager.getContainer(id).addChildAt(animate.animatedSprite, 0);
333
-
334
- animate.animatedSprite.onComplete = function () {
335
- component.emit('complete');
336
- };
337
-
338
- animate.animatedSprite.onFrameChange = function () {
339
- component.emit('frameChange');
340
- };
341
-
342
- animate.animatedSprite.onLoop = function () {
343
- component.emit('loop');
344
- };
345
-
346
- component.animate = this.animates[id];
347
- this.animates[id].speed = 1000 / 60 / component.speed;
348
-
349
- if (this.autoPlay[id]) {
350
- animate.animatedSprite.play();
351
- }
352
- };
353
-
354
- SpriteAnimation.prototype.change = function (_a) {
355
- var frames = _a.frames,
356
- id = _a.id,
357
- component = _a.component;
358
- this.remove(id, true);
359
- this.add({
360
- frames: frames,
361
- id: id,
362
- component: component
363
- });
364
- };
365
-
366
- SpriteAnimation.prototype.remove = function (id, isChange) {
367
- var animate = this.animates[id];
368
- if (!animate) return;
369
- this.autoPlay[id] = animate.animatedSprite.playing;
370
- this.containerManager.getContainer(id).removeChild(animate.animatedSprite);
371
- animate.animatedSprite.destroy({
372
- children: true
373
- });
374
- delete this.animates[id];
375
-
376
- if (!isChange) {
377
- delete this.autoPlay[id];
378
- }
379
- };
380
-
381
- SpriteAnimation.systemName = 'SpriteAnimation';
382
- SpriteAnimation = __decorate([decorators.componentObserver({
383
- SpriteAnimation: ['speed', 'resource']
384
- })], SpriteAnimation);
385
- return SpriteAnimation;
386
- }(Renderer);
387
-
388
- var SpriteAnimation$1 = SpriteAnimation;
389
- export { SpriteAnimation$3 as SpriteAnimation, SpriteAnimation$1 as SpriteAnimationSystem };