@eva/plugin-renderer-sprite-animation 2.1.0-beta.13 → 2.1.0-beta.15

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,8 +1,9 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ var globalThis = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : Function('return this')();
2
3
  globalThis.EVA = globalThis.EVA || {};
3
4
  globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
5
  globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
- var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rendererAdapter, pixi_js) {
6
+ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, inspectorDecorator, pluginRenderer, rendererAdapter, pixi_js) {
6
7
  'use strict';
7
8
  function __decorate(decorators, target, key, desc) {
8
9
  var c = arguments.length,
@@ -41,115 +42,6 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
41
42
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
43
  });
43
44
  }
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
- };
48
- function __rest(s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
51
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
52
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
53
- }
54
- return t;
55
- }
56
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
57
- var e = new Error(message);
58
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
- };
60
- class SymbolKeysNotSupportedError extends Error {
61
- constructor() {
62
- super('Symbol keys are not supported yet!');
63
- Object.setPrototypeOf(this, new.target.prototype);
64
- }
65
- }
66
- const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
67
- function transformBasicType(type) {
68
- if (type === String) {
69
- return 'string';
70
- }
71
- if (type === Number) {
72
- return 'number';
73
- }
74
- if (type === Boolean) {
75
- return 'boolean';
76
- }
77
- return 'unknown';
78
- }
79
- function defineLegacyIDEProp(target, propertyKey, patch) {
80
- const constructor = target.constructor;
81
- const current = constructor.IDEProps || {};
82
- current[propertyKey] = _extends(_extends({
83
- key: propertyKey
84
- }, current[propertyKey]), patch);
85
- constructor.IDEProps = current;
86
- }
87
- function defineTypes(target, key, options, returnTypeFunction) {
88
- let type = Reflect.getMetadata('design:type', target, key);
89
- let isArray = type === Array;
90
- const str = transformBasicType(type);
91
- if (str !== 'unknown') {
92
- type = str;
93
- }
94
- if (returnTypeFunction) {
95
- const returnType = returnTypeFunction();
96
- if (Array.isArray(returnType)) {
97
- isArray = true;
98
- type = returnType[0];
99
- } else {
100
- type = returnType;
101
- }
102
- }
103
- const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
104
- const current = properties[key] || {};
105
- const property = _extends(_extends(_extends({}, current), {
106
- type,
107
- isArray: isArray
108
- }), options);
109
- properties[key] = property;
110
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
111
- const legacyProperty = __rest(property, ["isArray"]);
112
- defineLegacyIDEProp(target, key, legacyProperty);
113
- }
114
- function type(type) {
115
- return Field({
116
- type
117
- });
118
- }
119
- function step(step) {
120
- return Field({
121
- step
122
- });
123
- }
124
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
125
- if (typeof returnTypeFuncOrOptions === 'function') {
126
- return {
127
- returnTypeFunc: returnTypeFuncOrOptions,
128
- options: maybeOptions || {}
129
- };
130
- }
131
- return {
132
- options: returnTypeFuncOrOptions || {}
133
- };
134
- }
135
- function Field(returnTypeFunction, maybeOptions) {
136
- return (target, propertyKey) => {
137
- if (typeof propertyKey === 'symbol') {
138
- throw new SymbolKeysNotSupportedError();
139
- }
140
- const {
141
- options,
142
- returnTypeFunc
143
- } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
144
- defineTypes(target, propertyKey, options, returnTypeFunc);
145
- };
146
- }
147
- var ExecuteMode;
148
- (function (ExecuteMode) {
149
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
150
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
151
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
152
- })(ExecuteMode || (ExecuteMode = {}));
153
45
  class SpriteAnimation$2 extends eva_js.Component {
154
46
  constructor(params) {
155
47
  super(params);
@@ -307,10 +199,10 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
307
199
  }
308
200
  }
309
201
  SpriteAnimation$2.componentName = 'SpriteAnimation';
310
- __decorate([type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
311
- __decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
312
- __decorate([type('number'), step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
313
- __decorate([type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
202
+ __decorate([inspectorDecorator.type('string'), __metadata("design:type", String)], SpriteAnimation$2.prototype, "resource", void 0);
203
+ __decorate([inspectorDecorator.type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "autoPlay", void 0);
204
+ __decorate([inspectorDecorator.type('number'), inspectorDecorator.step(10), __metadata("design:type", Number)], SpriteAnimation$2.prototype, "speed", void 0);
205
+ __decorate([inspectorDecorator.type('boolean'), __metadata("design:type", Boolean)], SpriteAnimation$2.prototype, "forwards", void 0);
314
206
  const resourceKeySplit = '_s|r|c_';
315
207
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE_ANIMATION, ({
316
208
  name,
@@ -498,5 +390,5 @@ var _EVA_IIFE_spriteAnimation = function (exports, eva_js, pluginRenderer, rende
498
390
  value: true
499
391
  });
500
392
  return exports;
501
- }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
393
+ }({}, EVA, inspectorDecorator, EVA.plugin.renderer, EVA.rendererAdapter, PIXI);
502
394
  globalThis.EVA.plugin.renderer.spriteAnimation = globalThis.EVA.plugin.renderer.spriteAnimation || _EVA_IIFE_spriteAnimation;
@@ -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,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;
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)}var globalThis="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();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";var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},r(t,e)};function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var a=function(){return a=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},a.apply(this,arguments)};function c(t,e,i,n){var o,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,i,s):o(e,i))||s);return r>3&&s&&Object.defineProperty(e,i,s),s}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function l(t,e,i,n){return new(i||(i=Promise))(function(o,r){function s(t){try{c(n.next(t))}catch(t){r(t)}}function a(t){try{c(n.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}c((n=n.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;var h=function(t){function e(){var e=this.constructor,i=t.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(i,e.prototype),i}return s(e,t),e}(Error);!function(t){function e(){var e=this.constructor,i=t.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(i,e.prototype),i}s(e,t)}(Error);var d,m="IDE_PROPERTY_METADATA";function u(t,e,i,n){var o=Reflect.getMetadata("design:type",t,e),r=o===Array,s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),n){var c=n();Array.isArray(c)?(r=!0,o=c[0]):o=c}var p=Reflect.getMetadata(m,t.constructor)||{},l=p[e]||{},h=a(a(a({},l),{type:o,isArray:r}),i);p[e]=h,Reflect.defineMetadata(m,p,t.constructor),h.isArray,function(t,e,i){var n=t.constructor,o=n.IDEProps||{};o[e]=a(a({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}(h,["isArray"]))}function f(t){return y({type:t})}function y(t,e){return function(i,n){if("symbol"==typeof n)throw new h;var o=function(t,e){return"function"==typeof t?{returnTypeFunc:t,options:e||{}}:{options:t||{}}}(t,e);u(i,n,o.options,o.returnTypeFunc)}}!function(t){t[t.Edit=2]="Edit",t[t.Game=4]="Game",t[t.All=6]="All"}(d||(d={}));class g 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}}g.componentName="SpriteAnimation",c([f("string"),p("design:type",String)],g.prototype,"resource",void 0),c([f("boolean"),p("design:type",Boolean)],g.prototype,"autoPlay",void 0),c([f("number"),function(t){return y({step:t})}(10),p("design:type",Number)],g.prototype,"speed",void 0),c([f("boolean"),p("design:type",Boolean)],g.prototype,"forwards",void 0);const v="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,({name:t,data:e})=>new Promise(i=>{var n;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 i=null!==(n=e.filename)&&void 0!==n?n:e.name;i&&(t[i]=e)}a=t}const c=r.animations||{},p={},l={};for(const e in a){l[t+v+e]=a[e]}for(const e in c){const i=[];if(c[e]&&c[e].length>=0)for(const n of c[e]){const e=t+v+n;i.push(e)}p[e]=i}const h=new o.Spritesheet(s,_extends(_extends({},r),{frames:l,animations:p}));h.parse().then(()=>{const{textures:t}=h,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 A=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 l(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:r}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;if(!r)return void console.error(`GameObject:${t.gameObject.name}'s Img resource load error`);this.add({frames:r,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:r}=yield e.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;if(!r)return void console.error(`GameObject:${t.gameObject.name}'s Img resource load error`);this.change({frames:r,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])}};A.systemName="SpriteAnimationSystem",A=c([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],A);var b=A;return t.SpriteAnimation=g,t.SpriteAnimationSystem=b,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.13",
3
+ "version": "2.1.0-beta.15",
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.13",
23
- "@eva/renderer-adapter": "2.1.0-beta.13",
24
- "@eva/eva.js": "2.1.0-beta.13",
25
- "pixi.js": "^8.17.0"
22
+ "@eva/plugin-renderer": "2.1.0-beta.15",
23
+ "@eva/renderer-adapter": "2.1.0-beta.15",
24
+ "@eva/eva.js": "2.1.0-beta.15",
25
+ "pixi.js": "8.19.0"
26
26
  }
27
27
  }