@eva/plugin-renderer-sprite 2.0.1-beta.3 → 2.0.1-beta.31

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,3 +1,4 @@
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); }
1
2
  globalThis.EVA = globalThis.EVA || {};
2
3
  globalThis.EVA.plugin = globalThis.EVA.plugin || {};
3
4
  globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
@@ -110,6 +111,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
110
111
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
111
112
  const frames = textureObj.frames || {};
112
113
  const animations = textureObj.animations || {};
114
+ const newAnimations = {};
113
115
  const newFrames = {};
114
116
  for (const key in frames) {
115
117
  const newKey = name + resourceKeySplit + key;
@@ -123,10 +125,12 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
123
125
  spriteList.push(newSpriteName);
124
126
  }
125
127
  }
126
- animations[key] = spriteList;
128
+ newAnimations[key] = spriteList;
127
129
  }
128
- textureObj.frames = newFrames;
129
- const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
130
+ const spriteSheet = new pixi_js.Spritesheet(texture, _extends(_extends({}, textureObj), {
131
+ frames: newFrames,
132
+ animations: newAnimations
133
+ }));
130
134
  spriteSheet.parse().then(() => {
131
135
  r(spriteSheet.textures);
132
136
  });
@@ -1 +1 @@
1
- globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_sprite=function(e,t,r,s){"use strict";function i(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function n(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{a(s.next(e))}catch(e){n(e)}}function c(e){try{a(s.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}a((s=s.apply(e,t||[])).next())}))}function o(e){return function(t,r){var s=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);s.key=r,s.type=e}}class c extends t.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}c.componentName="Sprite",i([o("string")],c.prototype,"resource",void 0),i([o("string")],c.prototype,"spriteName",void 0);class a{constructor(e){this._image=null,this._image=e,e?"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?this.sprite=s.Sprite.from(e):e instanceof s.Texture&&(this.sprite=new s.Sprite(e)):this.sprite=new s.Sprite}set image(e){this._image!==e&&("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=s.Texture.from(e)):e instanceof s.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const i=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=i.frames||{},c=i.animations||{},a={};for(const t in o){a[e+p+t]=o[t]}for(const t in c){const r=[];if(c[t]&&c[t].length>=0)for(const s of c[t]){const t=e+p+s;r.push(t)}c[t]=r}i.frames=a;const u=new s.Spritesheet(n,i);u.parse().then((()=>{r(u.textures)}))})))),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let u=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(e){return n(this,void 0,void 0,(function*(){if("Sprite"===e.componentName){const r=e.gameObject.id,s=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const i=new a(null);this.sprites[e.gameObject.id]=i,this.containerManager.getContainer(e.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:o}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!o)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);i.image=o[s.resource+p+s.spriteName]}else if(e.type===t.OBSERVER_TYPE.CHANGE){const i=this.increaseAsyncId(r),{instance:n}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(r,i))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);this.sprites[e.gameObject.id].image=n[s.resource+p+s.spriteName]}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const t=this.sprites[e.gameObject.id];this.containerManager.getContainer(e.gameObject.id).removeChild(t.sprite),t.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]}}}))}};u.systemName="Sprite",u=i([t.decorators.componentObserver({Sprite:["spriteName"]})],u);var m=u;return e.Sprite=c,e.SpriteSystem=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.sprite=globalThis.EVA.plugin.renderer.sprite||_EVA_IIFE_sprite;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)({}).hasOwnProperty.call(r,s)&&(e[s]=r[s])}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_sprite=function(e,t,r,s){"use strict";function i(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function n(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{a(s.next(e))}catch(e){n(e)}}function c(e){try{a(s.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}a((s=s.apply(e,t||[])).next())}))}function o(e){return function(t,r){var s=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);s.key=r,s.type=e}}class c extends t.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}c.componentName="Sprite",i([o("string")],c.prototype,"resource",void 0),i([o("string")],c.prototype,"spriteName",void 0);class a{constructor(e){this._image=null,this._image=e,e?"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?this.sprite=s.Sprite.from(e):e instanceof s.Texture&&(this.sprite=new s.Sprite(e)):this.sprite=new s.Sprite}set image(e){this._image!==e&&("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=s.Texture.from(e)):e instanceof s.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const p="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const i=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=i.frames||{},c=i.animations||{},a={},u={};for(const t in o){u[e+p+t]=o[t]}for(const t in c){const r=[];if(c[t]&&c[t].length>=0)for(const s of c[t]){const t=e+p+s;r.push(t)}a[t]=r}const d=new s.Spritesheet(n,_extends(_extends({},i),{frames:u,animations:a}));d.parse().then((()=>{r(d.textures)}))})))),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let u=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(e){return n(this,void 0,void 0,(function*(){if("Sprite"===e.componentName){const r=e.gameObject.id,s=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const i=new a(null);this.sprites[e.gameObject.id]=i,this.containerManager.getContainer(e.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:o}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!o)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);i.image=o[s.resource+p+s.spriteName]}else if(e.type===t.OBSERVER_TYPE.CHANGE){const i=this.increaseAsyncId(r),{instance:n}=yield t.resource.getResource(s.resource);if(!this.validateAsyncId(r,i))return;if(!n)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);this.sprites[e.gameObject.id].image=n[s.resource+p+s.spriteName]}else if(e.type===t.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const t=this.sprites[e.gameObject.id];this.containerManager.getContainer(e.gameObject.id).removeChild(t.sprite),t.sprite.destroy({children:!0}),delete this.sprites[e.gameObject.id]}}}))}};u.systemName="Sprite",u=i([t.decorators.componentObserver({Sprite:["spriteName"]})],u);var d=u;return e.Sprite=c,e.SpriteSystem=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,PIXI);globalThis.EVA.plugin.renderer.sprite=globalThis.EVA.plugin.renderer.sprite||_EVA_IIFE_sprite;
@@ -38,12 +38,37 @@ function __awaiter(thisArg, _arguments, P, generator) {
38
38
  });
39
39
  }
40
40
 
41
+ /**
42
+ * 精灵图组件
43
+ *
44
+ * Sprite 组件用于渲染精灵图集(Sprite Sheet)中的单个精灵。
45
+ * 它从一个包含多个小图的大图资源中提取指定的子图进行渲染,
46
+ * 这种方式可以减少纹理切换,提高渲染性能。
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // 渲染精灵图集中的某个精灵
51
+ * const player = new GameObject('player');
52
+ * player.addComponent(new Sprite({
53
+ * resource: 'playerAtlas', // 资源名称
54
+ * spriteName: 'player_idle_01.png' // 精灵图集中的子图名称
55
+ * }));
56
+ * ```
57
+ */
41
58
  class Sprite$3 extends eva_js.Component {
42
59
  constructor() {
43
60
  super(...arguments);
61
+ /** 精灵图集资源名称 */
44
62
  this.resource = '';
63
+ /** 精灵图集中的子图名称 */
45
64
  this.spriteName = '';
46
65
  }
66
+ /**
67
+ * 初始化组件
68
+ * @param obj - 初始化参数
69
+ * @param obj.resource - 资源名称
70
+ * @param obj.spriteName - 精灵名称
71
+ */
47
72
  init(obj) {
48
73
  if (obj && obj.resource) {
49
74
  this.resource = obj.resource;
@@ -51,6 +76,7 @@ class Sprite$3 extends eva_js.Component {
51
76
  }
52
77
  }
53
78
  }
79
+ /** 组件名称 */
54
80
  Sprite$3.componentName = 'Sprite';
55
81
  __decorate([
56
82
  inspectorDecorator.type('string')
@@ -93,13 +119,14 @@ class Sprite$2 {
93
119
  }
94
120
  }
95
121
 
96
- const resourceKeySplit = '_s|r|c_';
122
+ const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
97
123
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) => {
98
124
  return new Promise(r => {
99
125
  const textureObj = data.json.data;
100
126
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
101
127
  const frames = textureObj.frames || {};
102
128
  const animations = textureObj.animations || {};
129
+ const newAnimations = {};
103
130
  const newFrames = {};
104
131
  for (const key in frames) {
105
132
  const newKey = name + resourceKeySplit + key;
@@ -113,10 +140,9 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) =
113
140
  spriteList.push(newSpriteName);
114
141
  }
115
142
  }
116
- animations[key] = spriteList;
143
+ newAnimations[key] = spriteList;
117
144
  }
118
- textureObj.frames = newFrames;
119
- const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
145
+ const spriteSheet = new pixi_js.Spritesheet(texture, Object.assign(Object.assign({}, textureObj), { frames: newFrames, animations: newAnimations }));
120
146
  spriteSheet.parse().then(() => {
121
147
  r(spriteSheet.textures);
122
148
  });
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
15
  ***************************************************************************** */
16
- function i(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}class n extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}n.componentName="Sprite",i([t.type("string")],n.prototype,"resource",void 0),i([t.type("string")],n.prototype,"spriteName",void 0);class o{constructor(e){this._image=null,this._image=e,e?"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?this.sprite=s.Sprite.from(e):e instanceof s.Texture&&(this.sprite=new s.Sprite(e)):this.sprite=new s.Sprite}set image(e){this._image!==e&&("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=s.Texture.from(e)):e instanceof s.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const c="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const i=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=i.frames||{},a=i.animations||{},p={};for(const t in o){p[e+c+t]=o[t]}for(const t in a){const r=[];if(a[t]&&a[t].length>=0)for(const s of a[t]){const t=e+c+s;r.push(t)}a[t]=r}i.frames=p;const m=new s.Spritesheet(n,i);m.parse().then((()=>{r(m.textures)}))})))),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let a=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(t){return r=this,s=void 0,n=function*(){if("Sprite"===t.componentName){const r=t.gameObject.id,s=t.component;if(t.type===e.OBSERVER_TYPE.ADD){const i=new o(null);this.sprites[t.gameObject.id]=i,this.containerManager.getContainer(t.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:a}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!a)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);i.image=a[s.resource+c+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.CHANGE){const i=this.increaseAsyncId(r),{instance:n}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,i))return;if(!n)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);this.sprites[t.gameObject.id].image=n[s.resource+c+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const e=this.sprites[t.gameObject.id];this.containerManager.getContainer(t.gameObject.id).removeChild(e.sprite),e.sprite.destroy({children:!0}),delete this.sprites[t.gameObject.id]}}},new((i=void 0)||(i=Promise))((function(e,t){function o(e){try{a(n.next(e))}catch(e){t(e)}}function c(e){try{a(n.throw(e))}catch(e){t(e)}}function a(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(o,c)}a((n=n.apply(r,s||[])).next())}));var r,s,i,n}};a.systemName="Sprite",a=i([e.decorators.componentObserver({Sprite:["spriteName"]})],a);var p=a;exports.Sprite=n,exports.SpriteSystem=p;
16
+ function i(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}class n extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}n.componentName="Sprite",i([t.type("string")],n.prototype,"resource",void 0),i([t.type("string")],n.prototype,"spriteName",void 0);class o{constructor(e){this._image=null,this._image=e,e?"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?this.sprite=s.Sprite.from(e):e instanceof s.Texture&&(this.sprite=new s.Sprite(e)):this.sprite=new s.Sprite}set image(e){this._image!==e&&("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=s.Texture.from(e)):e instanceof s.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const a="_s|r|c_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,(({name:e,data:t})=>new Promise((r=>{const i=t.json.data,n=t.image instanceof s.Texture?t.image:s.Texture.from(t.image),o=i.frames||{},c=i.animations||{},p={},m={};for(const t in o){m[e+a+t]=o[t]}for(const t in c){const r=[];if(c[t]&&c[t].length>=0)for(const s of c[t]){const t=e+a+s;r.push(t)}p[t]=r}const d=new s.Spritesheet(n,Object.assign(Object.assign({},i),{frames:m,animations:p}));d.parse().then((()=>{r(d.textures)}))})))),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,(({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)}));let c=class extends r.Renderer{constructor(){super(...arguments),this.name="Sprite",this.sprites={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:r}=e.transform.size;this.sprites[e.id]&&(this.sprites[e.id].sprite.width=t,this.sprites[e.id].sprite.height=r)}componentChanged(t){return r=this,s=void 0,n=function*(){if("Sprite"===t.componentName){const r=t.gameObject.id,s=t.component;if(t.type===e.OBSERVER_TYPE.ADD){const i=new o(null);this.sprites[t.gameObject.id]=i,this.containerManager.getContainer(t.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:c}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!c)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);i.image=c[s.resource+a+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.CHANGE){const i=this.increaseAsyncId(r),{instance:n}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,i))return;if(!n)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);this.sprites[t.gameObject.id].image=n[s.resource+a+s.spriteName]}else if(t.type===e.OBSERVER_TYPE.REMOVE){this.increaseAsyncId(r);const e=this.sprites[t.gameObject.id];this.containerManager.getContainer(t.gameObject.id).removeChild(e.sprite),e.sprite.destroy({children:!0}),delete this.sprites[t.gameObject.id]}}},new((i=void 0)||(i=Promise))((function(e,t){function o(e){try{c(n.next(e))}catch(e){t(e)}}function a(e){try{c(n.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(o,a)}c((n=n.apply(r,s||[])).next())}));var r,s,i,n}};c.systemName="Sprite",c=i([e.decorators.componentObserver({Sprite:["spriteName"]})],c);var p=c;exports.Sprite=n,exports.SpriteSystem=p;
@@ -7,10 +7,36 @@ import { RendererManager } from '@eva/plugin-renderer';
7
7
  import { RendererSystem } from '@eva/plugin-renderer';
8
8
  import { Sprite as Sprite_2 } from '@eva/renderer-adapter';
9
9
 
10
+ /**
11
+ * 精灵图组件
12
+ *
13
+ * Sprite 组件用于渲染精灵图集(Sprite Sheet)中的单个精灵。
14
+ * 它从一个包含多个小图的大图资源中提取指定的子图进行渲染,
15
+ * 这种方式可以减少纹理切换,提高渲染性能。
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // 渲染精灵图集中的某个精灵
20
+ * const player = new GameObject('player');
21
+ * player.addComponent(new Sprite({
22
+ * resource: 'playerAtlas', // 资源名称
23
+ * spriteName: 'player_idle_01.png' // 精灵图集中的子图名称
24
+ * }));
25
+ * ```
26
+ */
10
27
  export declare class Sprite extends Component<SpriteParams> {
28
+ /** 组件名称 */
11
29
  static componentName: string;
30
+ /** 精灵图集资源名称 */
12
31
  resource: string;
32
+ /** 精灵图集中的子图名称 */
13
33
  spriteName: string;
34
+ /**
35
+ * 初始化组件
36
+ * @param obj - 初始化参数
37
+ * @param obj.resource - 资源名称
38
+ * @param obj.spriteName - 精灵名称
39
+ */
14
40
  init(obj?: SpriteParams): void;
15
41
  }
16
42
 
@@ -34,12 +34,37 @@ function __awaiter(thisArg, _arguments, P, generator) {
34
34
  });
35
35
  }
36
36
 
37
+ /**
38
+ * 精灵图组件
39
+ *
40
+ * Sprite 组件用于渲染精灵图集(Sprite Sheet)中的单个精灵。
41
+ * 它从一个包含多个小图的大图资源中提取指定的子图进行渲染,
42
+ * 这种方式可以减少纹理切换,提高渲染性能。
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // 渲染精灵图集中的某个精灵
47
+ * const player = new GameObject('player');
48
+ * player.addComponent(new Sprite({
49
+ * resource: 'playerAtlas', // 资源名称
50
+ * spriteName: 'player_idle_01.png' // 精灵图集中的子图名称
51
+ * }));
52
+ * ```
53
+ */
37
54
  class Sprite$3 extends Component {
38
55
  constructor() {
39
56
  super(...arguments);
57
+ /** 精灵图集资源名称 */
40
58
  this.resource = '';
59
+ /** 精灵图集中的子图名称 */
41
60
  this.spriteName = '';
42
61
  }
62
+ /**
63
+ * 初始化组件
64
+ * @param obj - 初始化参数
65
+ * @param obj.resource - 资源名称
66
+ * @param obj.spriteName - 精灵名称
67
+ */
43
68
  init(obj) {
44
69
  if (obj && obj.resource) {
45
70
  this.resource = obj.resource;
@@ -47,6 +72,7 @@ class Sprite$3 extends Component {
47
72
  }
48
73
  }
49
74
  }
75
+ /** 组件名称 */
50
76
  Sprite$3.componentName = 'Sprite';
51
77
  __decorate([
52
78
  type('string')
@@ -89,13 +115,14 @@ class Sprite$2 {
89
115
  }
90
116
  }
91
117
 
92
- const resourceKeySplit = '_s|r|c_';
118
+ const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
93
119
  resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
94
120
  return new Promise(r => {
95
121
  const textureObj = data.json.data;
96
122
  const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
97
123
  const frames = textureObj.frames || {};
98
124
  const animations = textureObj.animations || {};
125
+ const newAnimations = {};
99
126
  const newFrames = {};
100
127
  for (const key in frames) {
101
128
  const newKey = name + resourceKeySplit + key;
@@ -109,10 +136,9 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
109
136
  spriteList.push(newSpriteName);
110
137
  }
111
138
  }
112
- animations[key] = spriteList;
139
+ newAnimations[key] = spriteList;
113
140
  }
114
- textureObj.frames = newFrames;
115
- const spriteSheet = new Spritesheet(texture, textureObj);
141
+ const spriteSheet = new Spritesheet(texture, Object.assign(Object.assign({}, textureObj), { frames: newFrames, animations: newAnimations }));
116
142
  spriteSheet.parse().then(() => {
117
143
  r(spriteSheet.textures);
118
144
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite",
3
- "version": "2.0.1-beta.3",
3
+ "version": "2.0.1-beta.31",
4
4
  "description": "@eva/plugin-renderer-sprite",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite.esm.js",
@@ -19,8 +19,8 @@
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.3",
23
- "@eva/eva.js": "2.0.1-beta.3",
22
+ "@eva/plugin-renderer": "2.0.1-beta.31",
23
+ "@eva/eva.js": "2.0.1-beta.31",
24
24
  "pixi.js": "^8.8.1"
25
25
  }
26
26
  }