@eva/plugin-renderer-sprite-animation 2.1.0-beta.2 → 2.1.0-beta.4

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.
@@ -41,6 +41,10 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
41
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
42
  });
43
43
  }
44
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
45
+ var e = new Error(message);
46
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
47
+ };
44
48
  function __rest(s, e) {
45
49
  var t = {};
46
50
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,i,o){"use strict";function r(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function a(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(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(s,a)}c((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const p="IDE_PROPERTY_METADATA";function m(t,e,n,i){let o=Reflect.getMetadata("design:type",t,e),r=o===Array;const s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),i){const t=i();Array.isArray(t)?(r=!0,o=t[0]):o=t}const a=Reflect.getMetadata(p,t.constructor)||{},c=_extends(_extends(_extends({},a[e]||{}),{type:o,isArray:r}),n);a[e]=c,Reflect.defineMetadata(p,a,t.constructor);!function(t,e,n){const i=t.constructor,o=i.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),n),i.IDEProps=o}(t,e,function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(c,["isArray"]))}function d(t){return l({type:t})}function l(t,e){return(n,i)=>{if("symbol"==typeof i)throw new c;const{options:o,returnTypeFunc:r}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);m(n,i,o,r)}}var h;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(h||(h={}));class u extends e.Component{constructor(t){super(t),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.animations={},this.waitPlay=!1,this.waitLoop=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.complete=!0,this.emit("complete"))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;null===(t=this.onFrameChange)||void 0===t||t.call(this,this.currentFrame)}))}play(t=1/0,e=!1){let n,i="number"==typeof t?t:e?1/0:1;if("string"==typeof t){this.currentAnimation=t;const e=this.animations[t];e&&(n=e.start,void 0!==e.speed&&(this.speed=e.speed))}0!==i&&(this.times=i,this.animate?(this.complete&&this.gotoAndStop(0),void 0!==n?this.animate.gotoAndPlay(n):this.animate.play(),this.count=0,this.complete=!1):(this.waitPlay=!0,this.waitAnimation="string"==typeof t?t:void 0,this.waitLoop=e))}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(t){if(this._animate=t,this.waitPlay){this.waitPlay=!1;const t=this.waitAnimation;this.waitAnimation=void 0,this.play(null!=t?t:this.times,this.waitLoop)}this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(t){this.animate.gotoAndPlay(t)}gotoAndStop(t){this.animate.gotoAndStop(t)}get currentFrame(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame}get totalFrames(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames}}u.componentName="SpriteAnimation",r([d("string"),s("design:type",String)],u.prototype,"resource",void 0),r([d("boolean"),s("design:type",Boolean)],u.prototype,"autoPlay",void 0),r([d("number"),function(t){return l({step:t})}(10),s("design:type",Number)],u.prototype,"speed",void 0),r([d("boolean"),s("design:type",Boolean)],u.prototype,"forwards",void 0);const f="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(n=>{var i;const r=e.json.data,s=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let a=r.frames||{};if(Array.isArray(a)){const t={};for(const e of a){const n=null!==(i=e.filename)&&void 0!==i?i:e.name;n&&(t[n]=e)}a=t}const c=r.animations||{},p={},m={};for(const e in a){m[t+f+e]=a[e]}for(const e in c){const n=[];if(c[e]&&c[e].length>=0)for(const i of c[e]){const e=t+f+i;n.push(e)}p[e]=n}const d=new o.Spritesheet(s,_extends(_extends({},r),{frames:m,animations:p}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const n in t)e.push(t[n]);n(e)})})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let y=class extends n.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:n}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=n)}componentChanged(t){return a(this,void 0,void 0,function*(){const n=t.gameObject.id;if("SpriteAnimation"===t.componentName){const i=t.component;if(this.autoPlay[t.gameObject.id]=i.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:r,id:t.gameObject.id,component:i})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/i.speed;else{const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:r,id:t.gameObject.id,component:i})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:n}){const o=new i.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{n.emit("complete")},o.animatedSprite.onFrameChange=()=>{n.emit("frameChange")},o.animatedSprite.onLoop=()=>{n.emit("loop")},n.animate=this.animates[e],this.animates[e].speed=1e3/60/n.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:n}){this.remove(e,!0),this.add({frames:t,id:e,component:n})}remove(t,e){const n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=r([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],y);var g=y;return t.SpriteAnimation=u,t.SpriteAnimationSystem=g,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.spriteAnimation=globalThis.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_spriteAnimation=function(t,e,n,i,o){"use strict";function r(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}function s(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function a(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(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(s,a)}c((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const p="IDE_PROPERTY_METADATA";function d(t,e,n,i){let o=Reflect.getMetadata("design:type",t,e),r=o===Array;const s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),i){const t=i();Array.isArray(t)?(r=!0,o=t[0]):o=t}const a=Reflect.getMetadata(p,t.constructor)||{},c=_extends(_extends(_extends({},a[e]||{}),{type:o,isArray:r}),n);a[e]=c,Reflect.defineMetadata(p,a,t.constructor);!function(t,e,n){const i=t.constructor,o=i.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),n),i.IDEProps=o}(t,e,function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(t);o<i.length;o++)e.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(t,i[o])&&(n[i[o]]=t[i[o]])}return n}(c,["isArray"]))}function m(t){return l({type:t})}function l(t,e){return(n,i)=>{if("symbol"==typeof i)throw new c;const{options:o,returnTypeFunc:r}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);d(n,i,o,r)}}var h;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(h||(h={}));class u extends e.Component{constructor(t){super(t),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.animations={},this.waitPlay=!1,this.waitLoop=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.complete=!0,this.emit("complete"))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;null===(t=this.onFrameChange)||void 0===t||t.call(this,this.currentFrame)}))}play(t=1/0,e=!1){let n,i="number"==typeof t?t:e?1/0:1;if("string"==typeof t){this.currentAnimation=t;const e=this.animations[t];e&&(n=e.start,void 0!==e.speed&&(this.speed=e.speed))}0!==i&&(this.times=i,this.animate?(this.complete&&this.gotoAndStop(0),void 0!==n?this.animate.gotoAndPlay(n):this.animate.play(),this.count=0,this.complete=!1):(this.waitPlay=!0,this.waitAnimation="string"==typeof t?t:void 0,this.waitLoop=e))}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(t){if(this._animate=t,this.waitPlay){this.waitPlay=!1;const t=this.waitAnimation;this.waitAnimation=void 0,this.play(null!=t?t:this.times,this.waitLoop)}this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(t){this.animate.gotoAndPlay(t)}gotoAndStop(t){this.animate.gotoAndStop(t)}get currentFrame(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.currentFrame}get totalFrames(){var t,e;return null===(e=null===(t=this.animate)||void 0===t?void 0:t.animatedSprite)||void 0===e?void 0:e.totalFrames}}u.componentName="SpriteAnimation",r([m("string"),s("design:type",String)],u.prototype,"resource",void 0),r([m("boolean"),s("design:type",Boolean)],u.prototype,"autoPlay",void 0),r([m("number"),function(t){return l({step:t})}(10),s("design:type",Number)],u.prototype,"speed",void 0),r([m("boolean"),s("design:type",Boolean)],u.prototype,"forwards",void 0);const f="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(n=>{var i;const r=e.json.data,s=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let a=r.frames||{};if(Array.isArray(a)){const t={};for(const e of a){const n=null!==(i=e.filename)&&void 0!==i?i:e.name;n&&(t[n]=e)}a=t}const c=r.animations||{},p={},d={};for(const e in a){d[t+f+e]=a[e]}for(const e in c){const n=[];if(c[e]&&c[e].length>=0)for(const i of c[e]){const e=t+f+i;n.push(e)}p[e]=n}const m=new o.Spritesheet(s,_extends(_extends({},r),{frames:d,animations:p}));m.parse().then(()=>{const{textures:t}=m,e=[];for(const n in t)e.push(t[n]);n(e)})})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let y=class extends n.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:n}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=n)}componentChanged(t){return a(this,void 0,void 0,function*(){const n=t.gameObject.id;if("SpriteAnimation"===t.componentName){const i=t.component;if(this.autoPlay[t.gameObject.id]=i.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:r,id:t.gameObject.id,component:i})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/i.speed;else{const o=this.increaseAsyncId(n),{instance:r}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;r||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:r,id:t.gameObject.id,component:i})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(n),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:n}){const o=new i.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{n.emit("complete")},o.animatedSprite.onFrameChange=()=>{n.emit("frameChange")},o.animatedSprite.onLoop=()=>{n.emit("loop")},n.animate=this.animates[e],this.animates[e].speed=1e3/60/n.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:n}){this.remove(e,!0),this.add({frames:t,id:e,component:n})}remove(t,e){const n=this.animates[t];n&&(this.autoPlay[t]=n.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(n.animatedSprite),n.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=r([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],y);var g=y;return t.SpriteAnimation=u,t.SpriteAnimationSystem=g,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.spriteAnimation=globalThis.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": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.4",
4
4
  "description": "@eva/plugin-renderer-sprite-animation",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite-animation.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^2.0.0-beta.0",
22
- "@eva/plugin-renderer": "2.1.0-beta.2",
23
- "@eva/renderer-adapter": "2.1.0-beta.2",
24
- "@eva/eva.js": "2.1.0-beta.2",
22
+ "@eva/plugin-renderer": "2.1.0-beta.4",
23
+ "@eva/renderer-adapter": "2.1.0-beta.4",
24
+ "@eva/eva.js": "2.1.0-beta.4",
25
25
  "pixi.js": "^8.17.0"
26
26
  }
27
27
  }