@eva/plugin-renderer-sprite-animation 2.1.0-beta.12 → 2.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.renderer.spriteAnimation.js +2 -0
- package/dist/EVA.plugin.renderer.spriteAnimation.min.js +1 -1
- package/dist/plugin-renderer-sprite-animation.cjs.js +2 -0
- package/dist/plugin-renderer-sprite-animation.cjs.prod.js +1 -1
- package/dist/plugin-renderer-sprite-animation.esm.js +2 -0
- package/package.json +4 -4
|
@@ -405,6 +405,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
405
405
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
406
406
|
if (!frames) {
|
|
407
407
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
408
|
+
return;
|
|
408
409
|
}
|
|
409
410
|
this.add({
|
|
410
411
|
frames: frames,
|
|
@@ -422,6 +423,7 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
|
|
|
422
423
|
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
423
424
|
if (!frames) {
|
|
424
425
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
426
|
+
return;
|
|
425
427
|
}
|
|
426
428
|
this.change({
|
|
427
429
|
frames: frames,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}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,i,n,o){"use strict";function s(t,e,i,n){var o,s=arguments.length,
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}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,i,n,o){"use strict";function s(t,e,i,n){var o,s=arguments.length,r=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s<3?o(r):s>3?o(e,i,r):o(e,i))||r);return s>3&&r&&Object.defineProperty(e,i,r),r}function r(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function a(t,e,i,n){return new(i||(i=Promise))(function(o,s){function r(t){try{p(n.next(t))}catch(t){s(t)}}function a(t){try{p(n.throw(t))}catch(t){s(t)}}function p(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(r,a)}p((n=n.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class p extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="IDE_PROPERTY_METADATA";function l(t,e,i,n){let o=Reflect.getMetadata("design:type",t,e),s=o===Array;const r=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==r&&(o=r),n){const t=n();Array.isArray(t)?(s=!0,o=t[0]):o=t}const a=Reflect.getMetadata(c,t.constructor)||{},p=_extends(_extends(_extends({},a[e]||{}),{type:o,isArray:s}),i);a[e]=p,Reflect.defineMetadata(c,a,t.constructor);!function(t,e,i){const n=t.constructor,o=n.IDEProps||{};o[e]=_extends(_extends({key:e},o[e]),i),n.IDEProps=o}(t,e,function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}return i}(p,["isArray"]))}function d(t){return h({type:t})}function h(t,e){return(i,n)=>{if("symbol"==typeof n)throw new p;const{options:o,returnTypeFunc:s}=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);l(i,n,o,s)}}var m;!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(m||(m={}));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.activeClipLoop=!1,this.listenerBound=!1,this.init(t)}init(t){t&&_extends(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;this.complete||(this.activeClip?this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.gotoAndStop(this.activeClip.end),this.finish()):++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.finish()))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;const e=this.currentFrame;null===(t=this.onFrameChange)||void 0===t||t.call(this,e),!this.complete&&this.activeClip&&e>=this.activeClip.end&&(this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.stop(),e>this.activeClip.end&&this.animate.gotoAndStop(this.activeClip.end),this.finish()))}))}finish(){this.complete||(this.complete=!0,this.emit("complete"))}_handleRendererComplete(){this.finish()}isValidClip(t){return Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.start<=t.end&&t.end<this.totalFrames}play(t=1/0,e=!1){const i="number"==typeof t?t:e?1/0:1;let n;if("string"==typeof t){this.currentAnimation=t,this.activeClip=void 0,this.activeClipLoop=!1;const i=this.animations[t];i&&(n=i.start,this.animate&&this.isValidClip(i)&&(this.activeClip=i,this.activeClipLoop=e),void 0!==i.speed&&(this.speed=i.speed))}else this.currentAnimation=void 0,this.activeClip=void 0,this.activeClipLoop=!1;0!==i&&(this.times=i,this.animate?(this.complete&&void 0===n&&this.gotoAndStop(0),this.count=0,this.complete=!1,void 0!==n?this.animate.gotoAndPlay(n):this.animate.play()):(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",s([d("string"),r("design:type",String)],u.prototype,"resource",void 0),s([d("boolean"),r("design:type",Boolean)],u.prototype,"autoPlay",void 0),s([d("number"),function(t){return h({step:t})}(10),r("design:type",Number)],u.prototype,"speed",void 0),s([d("boolean"),r("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(i=>{var n;const s=e.json.data,r=e.image instanceof o.Texture?e.image:o.Texture.from(e.image);let a=s.frames||{};if(Array.isArray(a)){const t={};for(const e of a){const i=null!==(n=e.filename)&&void 0!==n?n:e.name;i&&(t[i]=e)}a=t}const p=s.animations||{},c={},l={};for(const e in a){l[t+f+e]=a[e]}for(const e in p){const i=[];if(p[e]&&p[e].length>=0)for(const n of p[e]){const e=t+f+n;i.push(e)}c[e]=i}const d=new o.Spritesheet(r,_extends(_extends({},s),{frames:l,animations:c}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const i in t)e.push(t[i]);i(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 i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:i}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=i)}componentChanged(t){return a(this,void 0,void 0,function*(){const i=t.gameObject.id;if("SpriteAnimation"===t.componentName){const n=t.component;if(this.autoPlay[t.gameObject.id]=n.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(i),{instance:s}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;if(!s)return void console.error(`GameObject:${t.gameObject.name}'s Img resource load error`);this.add({frames:s,id:t.gameObject.id,component:n})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/n.speed;else{const o=this.increaseAsyncId(i),{instance:s}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;if(!s)return void console.error(`GameObject:${t.gameObject.name}'s Img resource load error`);this.change({frames:s,id:t.gameObject.id,component:n})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(t.gameObject.id))}})}add({frames:t,id:e,component:i}){const o=new n.SpriteAnimation({frames:t});this.animates[e]=o,this.containerManager.getContainer(e).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{i._handleRendererComplete()},o.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},o.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[e],this.animates[e].speed=1e3/60/i.speed,this.autoPlay[e]&&o.animatedSprite.play()}change({frames:t,id:e,component:i}){this.remove(e,!0),this.add({frames:t,id:e,component:i})}remove(t,e){const i=this.animates[t];i&&(this.autoPlay[t]=i.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};y.systemName="SpriteAnimationSystem",y=s([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;
|
|
@@ -381,6 +381,7 @@ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
|
381
381
|
return;
|
|
382
382
|
if (!frames) {
|
|
383
383
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
384
|
+
return;
|
|
384
385
|
}
|
|
385
386
|
this.add({
|
|
386
387
|
frames: frames,
|
|
@@ -399,6 +400,7 @@ let SpriteAnimation = class SpriteAnimation extends pluginRenderer.Renderer {
|
|
|
399
400
|
return;
|
|
400
401
|
if (!frames) {
|
|
401
402
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
403
|
+
return;
|
|
402
404
|
}
|
|
403
405
|
this.change({
|
|
404
406
|
frames: frames,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),s=require("@eva/renderer-adapter"),n=require("pixi.js");function a(t,e,i,s){var n,a=arguments.length,o=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var r=t.length-1;r>=0;r--)(n=t[r])&&(o=(a<3?n(o):a>3?n(e,i,o):n(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}function o(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function r(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{h(s.next(t))}catch(t){a(t)}}function r(t){try{h(s.throw(t))}catch(t){a(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}h((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class h extends t.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.activeClipLoop=!1,this.listenerBound=!1,this.init(t)}init(t){t&&Object.assign(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;this.complete||(this.activeClip?this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.gotoAndStop(this.activeClip.end),this.finish()):++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.finish()))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;const e=this.currentFrame;null===(t=this.onFrameChange)||void 0===t||t.call(this,e),!this.complete&&this.activeClip&&e>=this.activeClip.end&&(this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.stop(),e>this.activeClip.end&&this.animate.gotoAndStop(this.activeClip.end),this.finish()))}))}finish(){this.complete||(this.complete=!0,this.emit("complete"))}_handleRendererComplete(){this.finish()}isValidClip(t){return Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.start<=t.end&&t.end<this.totalFrames}play(t=1/0,e=!1){const i="number"==typeof t?t:e?1/0:1;let s;if("string"==typeof t){this.currentAnimation=t,this.activeClip=void 0,this.activeClipLoop=!1;const i=this.animations[t];i&&(s=i.start,this.animate&&this.isValidClip(i)&&(this.activeClip=i,this.activeClipLoop=e),void 0!==i.speed&&(this.speed=i.speed))}else this.currentAnimation=void 0,this.activeClip=void 0,this.activeClipLoop=!1;0!==i&&(this.times=i,this.animate?(this.complete&&void 0===s&&this.gotoAndStop(0),this.count=0,this.complete=!1,void 0!==s?this.animate.gotoAndPlay(s):this.animate.play()):(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}}h.componentName="SpriteAnimation",a([e.type("string"),o("design:type",String)],h.prototype,"resource",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"autoPlay",void 0),a([e.type("number"),e.step(10),o("design:type",Number)],h.prototype,"speed",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"forwards",void 0);const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(i=>{var s;const a=e.json.data,o=e.image instanceof n.Texture?e.image:n.Texture.from(e.image);let r=a.frames||{};if(Array.isArray(r)){const t={};for(const e of r){const i=null!==(s=e.filename)&&void 0!==s?s:e.name;i&&(t[i]=e)}r=t}const h=a.animations||{},c={},m={};for(const e in r){m[t+p+e]=r[e]}for(const e in h){const i=[];if(h[e]&&h[e].length>=0)for(const s of h[e]){const e=t+p+s;i.push(e)}c[e]=i}const d=new n.Spritesheet(o,Object.assign(Object.assign({},a),{frames:m,animations:c}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const i in t)e.push(t[i]);i(e)})})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let c=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:i}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=i)}componentChanged(e){return r(this,void 0,void 0,function*(){const i=e.gameObject.id;if("SpriteAnimation"===e.componentName){const s=e.component;if(this.autoPlay[e.gameObject.id]=s.autoPlay,e.type===t.OBSERVER_TYPE.ADD){const n=this.increaseAsyncId(i),{instance:a}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(i,n))return;a
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),s=require("@eva/renderer-adapter"),n=require("pixi.js");function a(t,e,i,s){var n,a=arguments.length,o=a<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var r=t.length-1;r>=0;r--)(n=t[r])&&(o=(a<3?n(o):a>3?n(e,i,o):n(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}function o(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function r(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{h(s.next(t))}catch(t){a(t)}}function r(t){try{h(s.throw(t))}catch(t){a(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}h((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class h extends t.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.activeClipLoop=!1,this.listenerBound=!1,this.init(t)}init(t){t&&Object.assign(this,t),this.listenerBound||(this.listenerBound=!0,this.on("loop",()=>{var t;this.complete||(this.activeClip?this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.gotoAndStop(this.activeClip.end),this.finish()):++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):null===(t=this.animate)||void 0===t||t.stop(),this.finish()))}),this.on("complete",()=>{var t;null===(t=this.onComplete)||void 0===t||t.call(this)}),this.on("frameChange",()=>{var t;const e=this.currentFrame;null===(t=this.onFrameChange)||void 0===t||t.call(this,e),!this.complete&&this.activeClip&&e>=this.activeClip.end&&(this.activeClipLoop?this.animate.gotoAndPlay(this.activeClip.start):(this.animate.stop(),e>this.activeClip.end&&this.animate.gotoAndStop(this.activeClip.end),this.finish()))}))}finish(){this.complete||(this.complete=!0,this.emit("complete"))}_handleRendererComplete(){this.finish()}isValidClip(t){return Number.isInteger(t.start)&&Number.isInteger(t.end)&&t.start>=0&&t.start<=t.end&&t.end<this.totalFrames}play(t=1/0,e=!1){const i="number"==typeof t?t:e?1/0:1;let s;if("string"==typeof t){this.currentAnimation=t,this.activeClip=void 0,this.activeClipLoop=!1;const i=this.animations[t];i&&(s=i.start,this.animate&&this.isValidClip(i)&&(this.activeClip=i,this.activeClipLoop=e),void 0!==i.speed&&(this.speed=i.speed))}else this.currentAnimation=void 0,this.activeClip=void 0,this.activeClipLoop=!1;0!==i&&(this.times=i,this.animate?(this.complete&&void 0===s&&this.gotoAndStop(0),this.count=0,this.complete=!1,void 0!==s?this.animate.gotoAndPlay(s):this.animate.play()):(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}}h.componentName="SpriteAnimation",a([e.type("string"),o("design:type",String)],h.prototype,"resource",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"autoPlay",void 0),a([e.type("number"),e.step(10),o("design:type",Number)],h.prototype,"speed",void 0),a([e.type("boolean"),o("design:type",Boolean)],h.prototype,"forwards",void 0);const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(i=>{var s;const a=e.json.data,o=e.image instanceof n.Texture?e.image:n.Texture.from(e.image);let r=a.frames||{};if(Array.isArray(r)){const t={};for(const e of r){const i=null!==(s=e.filename)&&void 0!==s?s:e.name;i&&(t[i]=e)}r=t}const h=a.animations||{},c={},m={};for(const e in r){m[t+p+e]=r[e]}for(const e in h){const i=[];if(h[e]&&h[e].length>=0)for(const s of h[e]){const e=t+p+s;i.push(e)}c[e]=i}const d=new n.Spritesheet(o,Object.assign(Object.assign({},a),{frames:m,animations:c}));d.parse().then(()=>{const{textures:t}=d,e=[];for(const i in t)e.push(t[i]);i(e)})})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,({instance:t})=>{if(t)for(const e of t)e.destroy(!0)});let c=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimationSystem",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(t){const{width:e,height:i}=t.transform.size;this.animates[t.id]&&(this.animates[t.id].animatedSprite.width=e,this.animates[t.id].animatedSprite.height=i)}componentChanged(e){return r(this,void 0,void 0,function*(){const i=e.gameObject.id;if("SpriteAnimation"===e.componentName){const s=e.component;if(this.autoPlay[e.gameObject.id]=s.autoPlay,e.type===t.OBSERVER_TYPE.ADD){const n=this.increaseAsyncId(i),{instance:a}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(i,n))return;if(!a)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);this.add({frames:a,id:e.gameObject.id,component:s})}else if(e.type===t.OBSERVER_TYPE.CHANGE)if(e.prop&&"speed"===e.prop.prop[0])this.animates[e.gameObject.id].speed=1e3/60/s.speed;else{const n=this.increaseAsyncId(i),{instance:a}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(i,n))return;if(!a)return void console.error(`GameObject:${e.gameObject.name}'s Img resource load error`);this.change({frames:a,id:e.gameObject.id,component:s})}else e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(e.gameObject.id))}})}add({frames:t,id:e,component:i}){const n=new s.SpriteAnimation({frames:t});this.animates[e]=n,this.containerManager.getContainer(e).addChildAt(n.animatedSprite,0),n.animatedSprite.onComplete=()=>{i._handleRendererComplete()},n.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},n.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[e],this.animates[e].speed=1e3/60/i.speed,this.autoPlay[e]&&n.animatedSprite.play()}change({frames:t,id:e,component:i}){this.remove(e,!0),this.add({frames:t,id:e,component:i})}remove(t,e){const i=this.animates[t];i&&(this.autoPlay[t]=i.animatedSprite.playing,this.containerManager.getContainer(t).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[t],e||delete this.autoPlay[t])}};c.systemName="SpriteAnimationSystem",c=a([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],c);var m=c;exports.SpriteAnimation=h,exports.SpriteAnimationSystem=m;
|
|
@@ -377,6 +377,7 @@ let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
|
377
377
|
return;
|
|
378
378
|
if (!frames) {
|
|
379
379
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
380
|
+
return;
|
|
380
381
|
}
|
|
381
382
|
this.add({
|
|
382
383
|
frames: frames,
|
|
@@ -395,6 +396,7 @@ let SpriteAnimation = class SpriteAnimation extends Renderer {
|
|
|
395
396
|
return;
|
|
396
397
|
if (!frames) {
|
|
397
398
|
console.error(`GameObject:${changed.gameObject.name}'s Img resource load error`);
|
|
399
|
+
return;
|
|
398
400
|
}
|
|
399
401
|
this.change({
|
|
400
402
|
frames: frames,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-sprite-animation",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.13",
|
|
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.
|
|
23
|
-
"@eva/renderer-adapter": "2.1.0-beta.
|
|
24
|
-
"@eva/eva.js": "2.1.0-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.13",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.13",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.13",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|