@eva/plugin-renderer-sprite-animation 2.0.1-beta.39 → 2.0.1-beta.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite-animation",
3
- "version": "2.0.1-beta.39",
3
+ "version": "2.0.1-beta.40",
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": "^0.0.5",
22
- "@eva/plugin-renderer": "2.0.1-beta.39",
23
- "@eva/renderer-adapter": "2.0.1-beta.39",
24
- "@eva/eva.js": "2.0.1-beta.39",
22
+ "@eva/plugin-renderer": "2.0.1-beta.40",
23
+ "@eva/renderer-adapter": "2.0.1-beta.40",
24
+ "@eva/eva.js": "2.0.1-beta.40",
25
25
  "pixi.js": "^8.17.0"
26
26
  }
27
27
  }
@@ -1 +0,0 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)({}).hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},_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(e,t,i,n,o){"use strict";function r(e,t,i,n){var o,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,i,s):o(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s}function s(e,t,i,n){return new(i||(i=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function a(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function c(e){return function(t,i){var n=a(t,i);n.key=i,n.type=e}}class m extends t.Component{constructor(){super(...arguments),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.waitPlay=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1}init(e){e&&_extends(this,e),this.on("loop",(()=>{++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):this.animate.stop(),this.complete=!0,this.emit("complete"))}))}play(e=1/0){0!==e&&(this.times=e,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(e){this.animate.gotoAndPlay(e)}gotoAndStop(e){this.animate.gotoAndStop(e)}get currentFrame(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame}get totalFrames(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames}}m.componentName="SpriteAnimation",r([c("string")],m.prototype,"resource",void 0),r([c("boolean")],m.prototype,"autoPlay",void 0),r([c("number"),function(e){return function(t,i){a(t,i).step=e}}(10)],m.prototype,"speed",void 0),r([c("boolean")],m.prototype,"forwards",void 0);const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE_ANIMATION,(({name:e,data:t})=>new Promise((i=>{const n=t.json.data,r=t.image instanceof o.Texture?t.image:o.Texture.from(t.image),s=n.frames||{},a=n.animations||{},c={},m={};for(const t in s){m[e+p+t]=s[t]}for(const t in a){const i=[];if(a[t]&&a[t].length>=0)for(const n of a[t]){const t=e+p+n;i.push(t)}c[t]=i}const d=new o.Spritesheet(r,_extends(_extends({},n),{frames:m,animations:c}));d.parse().then((()=>{const{textures:e}=d,t=[];for(const i in e)t.push(e[i]);i(t)}))})))),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE_ANIMATION,(({instance:e})=>{if(e)for(const t of e)t.destroy(!0)}));let d=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimation",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=t,this.animates[e.id].animatedSprite.height=i)}componentChanged(e){return s(this,void 0,void 0,(function*(){const i=e.gameObject.id;if("SpriteAnimation"===e.componentName){const n=e.component;if(this.autoPlay[e.gameObject.id]=n.autoPlay,e.type===t.OBSERVER_TYPE.ADD){const o=this.increaseAsyncId(i),{instance:r}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;r||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.add({frames:r,id:e.gameObject.id,component:n})}else if(e.type===t.OBSERVER_TYPE.CHANGE)if(e.prop&&"speed"===e.prop.prop[0])this.animates[e.gameObject.id].speed=1e3/60/n.speed;else{const o=this.increaseAsyncId(i),{instance:r}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(i,o))return;r||console.error(`GameObject:${e.gameObject.name}'s Img resource load error`),this.change({frames:r,id:e.gameObject.id,component:n})}else e.type===t.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(e.gameObject.id))}}))}add({frames:e,id:t,component:i}){const o=new n.SpriteAnimation({frames:e});this.animates[t]=o,this.containerManager.getContainer(t).addChildAt(o.animatedSprite,0),o.animatedSprite.onComplete=()=>{i.emit("complete")},o.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},o.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[t],this.animates[t].speed=1e3/60/i.speed,this.autoPlay[t]&&o.animatedSprite.play()}change({frames:e,id:t,component:i}){this.remove(t,!0),this.add({frames:e,id:t,component:i})}remove(e,t){const i=this.animates[e];i&&(this.autoPlay[e]=i.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[e],t||delete this.autoPlay[e])}};d.systemName="SpriteAnimation",d=r([t.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],d);var h=d;return e.SpriteAnimation=m,e.SpriteAnimationSystem=h,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter,PIXI);globalThis.EVA.plugin.renderer.spriteAnimation=globalThis.EVA.plugin.renderer.spriteAnimation||_EVA_IIFE_spriteAnimation;
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),a=require("@eva/renderer-adapter"),s=require("pixi.js");
2
- /*! *****************************************************************************
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
- this file except in compliance with the License. You may obtain a copy of the
6
- License at http://www.apache.org/licenses/LICENSE-2.0
7
-
8
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11
- MERCHANTABLITY OR NON-INFRINGEMENT.
12
-
13
- See the Apache Version 2.0 License for specific language governing permissions
14
- and limitations under the License.
15
- ***************************************************************************** */
16
- function n(e,t,i,a){var s,n=arguments.length,o=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,i):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,a);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(n<3?s(o):n>3?s(t,i,o):s(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o}class o extends e.Component{constructor(){super(...arguments),this.resource="",this.autoPlay=!0,this.speed=100,this.forwards=!1,this.waitPlay=!1,this.waitStop=!1,this.times=1/0,this.count=0,this.complete=!1}init(e){e&&Object.assign(this,e),this.on("loop",(()=>{++this.count>=this.times&&(this.forwards?this.gotoAndStop(this.totalFrames-1):this.animate.stop(),this.complete=!0,this.emit("complete"))}))}play(e=1/0){0!==e&&(this.times=e,this.animate?(this.complete&&this.gotoAndStop(0),this.animate.play(),this.count=0,this.complete=!1):this.waitPlay=!0)}stop(){this.animate?this.animate.stop():this.waitStop=!0}set animate(e){this._animate=e,this.waitPlay&&(this.waitPlay=!1,this.play(this.times)),this.waitStop&&(this.waitStop=!1,this.stop())}get animate(){return this._animate}gotoAndPlay(e){this.animate.gotoAndPlay(e)}gotoAndStop(e){this.animate.gotoAndStop(e)}get currentFrame(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.currentFrame}get totalFrames(){var e,t;return null===(t=null===(e=this.animate)||void 0===e?void 0:e.animatedSprite)||void 0===t?void 0:t.totalFrames}}o.componentName="SpriteAnimation",n([t.type("string")],o.prototype,"resource",void 0),n([t.type("boolean")],o.prototype,"autoPlay",void 0),n([t.type("number"),t.step(10)],o.prototype,"speed",void 0),n([t.type("boolean")],o.prototype,"forwards",void 0);const r="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE_ANIMATION,(({name:e,data:t})=>new Promise((i=>{const a=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=a.frames||{},m=a.animations||{},c={},p={};for(const t in o){p[e+r+t]=o[t]}for(const t in m){const i=[];if(m[t]&&m[t].length>=0)for(const a of m[t]){const t=e+r+a;i.push(t)}c[t]=i}const d=new s.Spritesheet(n,Object.assign(Object.assign({},a),{frames:p,animations:c}));d.parse().then((()=>{const{textures:e}=d,t=[];for(const i in e)t.push(e[i]);i(t)}))})))),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE_ANIMATION,(({instance:e})=>{if(e)for(const t of e)t.destroy(!0)}));let m=class extends i.Renderer{constructor(){super(...arguments),this.name="SpriteAnimation",this.animates={},this.autoPlay={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.animates[e.id]&&(this.animates[e.id].animatedSprite.width=t,this.animates[e.id].animatedSprite.height=i)}componentChanged(t){return i=this,a=void 0,n=function*(){const i=t.gameObject.id;if("SpriteAnimation"===t.componentName){const a=t.component;if(this.autoPlay[t.gameObject.id]=a.autoPlay,t.type===e.OBSERVER_TYPE.ADD){const s=this.increaseAsyncId(i),{instance:n}=yield e.resource.getResource(a.resource);if(!this.validateAsyncId(i,s))return;n||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.add({frames:n,id:t.gameObject.id,component:a})}else if(t.type===e.OBSERVER_TYPE.CHANGE)if(t.prop&&"speed"===t.prop.prop[0])this.animates[t.gameObject.id].speed=1e3/60/a.speed;else{const s=this.increaseAsyncId(i),{instance:n}=yield e.resource.getResource(a.resource);if(!this.validateAsyncId(i,s))return;n||console.error(`GameObject:${t.gameObject.name}'s Img resource load error`),this.change({frames:n,id:t.gameObject.id,component:a})}else t.type===e.OBSERVER_TYPE.REMOVE&&(this.increaseAsyncId(i),this.remove(t.gameObject.id))}},new((s=void 0)||(s=Promise))((function(e,t){function o(e){try{m(n.next(e))}catch(e){t(e)}}function r(e){try{m(n.throw(e))}catch(e){t(e)}}function m(t){t.done?e(t.value):new s((function(e){e(t.value)})).then(o,r)}m((n=n.apply(i,a||[])).next())}));var i,a,s,n}add({frames:e,id:t,component:i}){const s=new a.SpriteAnimation({frames:e});this.animates[t]=s,this.containerManager.getContainer(t).addChildAt(s.animatedSprite,0),s.animatedSprite.onComplete=()=>{i.emit("complete")},s.animatedSprite.onFrameChange=()=>{i.emit("frameChange")},s.animatedSprite.onLoop=()=>{i.emit("loop")},i.animate=this.animates[t],this.animates[t].speed=1e3/60/i.speed,this.autoPlay[t]&&s.animatedSprite.play()}change({frames:e,id:t,component:i}){this.remove(t,!0),this.add({frames:e,id:t,component:i})}remove(e,t){const i=this.animates[e];i&&(this.autoPlay[e]=i.animatedSprite.playing,this.containerManager.getContainer(e).removeChild(i.animatedSprite),i.animatedSprite.destroy(),delete this.animates[e],t||delete this.autoPlay[e])}};m.systemName="SpriteAnimation",m=n([e.decorators.componentObserver({SpriteAnimation:["speed","resource"]})],m);var c=m;exports.SpriteAnimation=o,exports.SpriteAnimationSystem=c;
@@ -1,126 +0,0 @@
1
- import { Component } from '@eva/eva.js';
2
- import { ComponentChanged } from '@eva/eva.js';
3
- import { ContainerManager } from '@eva/plugin-renderer';
4
- import { GameObject } from '@eva/eva.js';
5
- import { Renderer } from '@eva/plugin-renderer';
6
- import { RendererManager } from '@eva/plugin-renderer';
7
- import { RendererSystem } from '@eva/plugin-renderer';
8
- import { SpriteAnimation as SpriteAnimation_2 } from '@eva/renderer-adapter';
9
-
10
- /**
11
- * 精灵动画组件
12
- *
13
- * SpriteAnimation 组件用于播放帧动画(序列帧动画)。
14
- * 通过快速切换精灵图集中的不同帧,实现动画效果,
15
- * 适用于角色动作、特效、UI 动画等场景。
16
- *
17
- * 主要功能:
18
- * - 支持自动播放和手动控制
19
- * - 可配置播放速度和循环次数
20
- * - 支持跳转到指定帧
21
- * - 提供播放完成事件
22
- * - 支持 forwards 模式(停在最后一帧)
23
- *
24
- * @example
25
- * ```typescript
26
- * // 基础用法 - 自动播放
27
- * const character = new GameObject('character');
28
- * character.addComponent(new SpriteAnimation({
29
- * resource: 'walkAnimation', // 帧动画资源
30
- * autoPlay: true,
31
- * speed: 100 // 播放速度(毫秒/帧)
32
- * }));
33
- *
34
- * // 控制播放
35
- * const anim = character.getComponent('SpriteAnimation');
36
- * anim.play(3); // 播放 3 次
37
- * anim.play(Infinity); // 无限循环
38
- * anim.stop(); // 停止播放
39
- * anim.gotoAndPlay(10); // 跳到第 10 帧并播放
40
- * anim.gotoAndStop(0); // 跳到第 0 帧并停止
41
- *
42
- * // 监听播放完成
43
- * anim.on('complete', () => {
44
- * console.log('动画播放完成');
45
- * });
46
- * ```
47
- */
48
- export declare class SpriteAnimation extends Component<SpriteAnimationParams> {
49
- /** 组件名称 */
50
- static componentName: string;
51
- /** 帧动画资源名称 */
52
- resource: string;
53
- /** 是否自动播放 */
54
- autoPlay: boolean;
55
- /** 播放速度(毫秒/帧) */
56
- speed: number;
57
- /** 是否在最后一帧停止(forwards 模式) */
58
- forwards: boolean;
59
- /** 动画引擎实例 */
60
- _animate: SpriteAnimation_2;
61
- /** 等待播放标志(资源加载前调用 play) */
62
- private waitPlay;
63
- /** 等待停止标志 */
64
- private waitStop;
65
- /** 播放次数 */
66
- private times;
67
- /** 当前已播放次数 */
68
- private count;
69
- /** 是否播放完成 */
70
- private complete;
71
- /**
72
- * 初始化组件
73
- * @param obj - 初始化参数
74
- * @param obj.resource - 帧动画资源名称
75
- * @param obj.autoPlay - 是否自动播放
76
- * @param obj.speed - 播放速度
77
- * @param obj.forwards - 是否停在最后一帧
78
- */
79
- init(obj?: SpriteAnimationParams): void;
80
- play(times?: number): void;
81
- stop(): void;
82
- set animate(val: SpriteAnimation_2);
83
- get animate(): SpriteAnimation_2;
84
- gotoAndPlay(frameNumber: any): void;
85
- gotoAndStop(frameNumber: any): void;
86
- get currentFrame(): number;
87
- get totalFrames(): number;
88
- }
89
-
90
- export declare interface SpriteAnimationParams {
91
- resource: string;
92
- autoPlay?: boolean;
93
- speed?: number;
94
- /** Stop at last frame */
95
- forwards?: boolean;
96
- }
97
-
98
- export declare class SpriteAnimationSystem extends Renderer {
99
- static systemName: string;
100
- name: string;
101
- animates: {
102
- [propName: number]: SpriteAnimation_2;
103
- };
104
- autoPlay: {
105
- [propName: number]: boolean;
106
- };
107
- renderSystem: RendererSystem;
108
- rendererManager: RendererManager;
109
- containerManager: ContainerManager;
110
- init(): void;
111
- rendererUpdate(gameObject: GameObject): void;
112
- componentChanged(changed: ComponentChanged): Promise<void>;
113
- add({ frames, id, component }: {
114
- frames: any;
115
- id: any;
116
- component: any;
117
- }): void;
118
- change({ frames, id, component }: {
119
- frames: any;
120
- id: any;
121
- component: any;
122
- }): void;
123
- remove(id: any, isChange?: boolean): void;
124
- }
125
-
126
- export { }