@eva/plugin-renderer-sprite 2.0.1-beta.9 → 2.0.2-beta.0

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;
@@ -7,19 +7,19 @@ var inspectorDecorator = require('@eva/inspector-decorator');
7
7
  var pluginRenderer = require('@eva/plugin-renderer');
8
8
  var pixi_js = require('pixi.js');
9
9
 
10
- /*! *****************************************************************************
11
- Copyright (c) Microsoft Corporation. All rights reserved.
12
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
13
- this file except in compliance with the License. You may obtain a copy of the
14
- License at http://www.apache.org/licenses/LICENSE-2.0
10
+ /******************************************************************************
11
+ Copyright (c) Microsoft Corporation.
15
12
 
16
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19
- MERCHANTABLITY OR NON-INFRINGEMENT.
13
+ Permission to use, copy, modify, and/or distribute this software for any
14
+ purpose with or without fee is hereby granted.
20
15
 
21
- See the Apache Version 2.0 License for specific language governing permissions
22
- and limitations under the License.
16
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
+ PERFORMANCE OF THIS SOFTWARE.
23
23
  ***************************************************************************** */
24
24
 
25
25
  function __decorate(decorators, target, key, desc) {
@@ -30,20 +30,51 @@ function __decorate(decorators, target, key, desc) {
30
30
  }
31
31
 
32
32
  function __awaiter(thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
34
  return new (P || (P = Promise))(function (resolve, reject) {
34
35
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
36
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
38
  step((generator = generator.apply(thisArg, _arguments || [])).next());
38
39
  });
39
- }
40
+ }
41
+
42
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
+ var e = new Error(message);
44
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
+ };
40
46
 
47
+ /**
48
+ * 精灵图组件
49
+ *
50
+ * Sprite 组件用于渲染精灵图集(Sprite Sheet)中的单个精灵。
51
+ * 它从一个包含多个小图的大图资源中提取指定的子图进行渲染,
52
+ * 这种方式可以减少纹理切换,提高渲染性能。
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // 渲染精灵图集中的某个精灵
57
+ * const player = new GameObject('player');
58
+ * player.addComponent(new Sprite({
59
+ * resource: 'playerAtlas', // 资源名称
60
+ * spriteName: 'player_idle_01.png' // 精灵图集中的子图名称
61
+ * }));
62
+ * ```
63
+ */
41
64
  class Sprite$3 extends eva_js.Component {
42
65
  constructor() {
43
66
  super(...arguments);
67
+ /** 精灵图集资源名称 */
44
68
  this.resource = '';
69
+ /** 精灵图集中的子图名称 */
45
70
  this.spriteName = '';
46
71
  }
72
+ /**
73
+ * 初始化组件
74
+ * @param obj - 初始化参数
75
+ * @param obj.resource - 资源名称
76
+ * @param obj.spriteName - 精灵名称
77
+ */
47
78
  init(obj) {
48
79
  if (obj && obj.resource) {
49
80
  this.resource = obj.resource;
@@ -51,6 +82,7 @@ class Sprite$3 extends eva_js.Component {
51
82
  }
52
83
  }
53
84
  }
85
+ /** 组件名称 */
54
86
  Sprite$3.componentName = 'Sprite';
55
87
  __decorate([
56
88
  inspectorDecorator.type('string')
@@ -93,13 +125,14 @@ class Sprite$2 {
93
125
  }
94
126
  }
95
127
 
96
- const resourceKeySplit = '_s|r|c_';
128
+ const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
97
129
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) => {
98
130
  return new Promise(r => {
99
131
  const textureObj = data.json.data;
100
132
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
101
133
  const frames = textureObj.frames || {};
102
134
  const animations = textureObj.animations || {};
135
+ const newAnimations = {};
103
136
  const newFrames = {};
104
137
  for (const key in frames) {
105
138
  const newKey = name + resourceKeySplit + key;
@@ -113,10 +146,9 @@ eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) =
113
146
  spriteList.push(newSpriteName);
114
147
  }
115
148
  }
116
- animations[key] = spriteList;
149
+ newAnimations[key] = spriteList;
117
150
  }
118
- textureObj.frames = newFrames;
119
- const spriteSheet = new pixi_js.Spritesheet(texture, textureObj);
151
+ const spriteSheet = new pixi_js.Spritesheet(texture, Object.assign(Object.assign({}, textureObj), { frames: newFrames, animations: newAnimations }));
120
152
  spriteSheet.parse().then(() => {
121
153
  r(spriteSheet.textures);
122
154
  });
@@ -1,16 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),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 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;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),s=require("pixi.js");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"==typeof SuppressedError&&SuppressedError;class o extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName=""}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}}o.componentName="Sprite",i([t.type("string")],o.prototype,"resource",void 0),i([t.type("string")],o.prototype,"spriteName",void 0);class c{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 u=new s.Spritesheet(n,Object.assign(Object.assign({},i),{frames:m,animations:p}));u.parse().then(()=>{r(u.textures)})})),e.resource.registerDestroy(e.RESOURCE_TYPE.SPRITE,({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)});let p=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 n(this,void 0,void 0,function*(){if("Sprite"===t.componentName){const r=t.gameObject.id,s=t.component;if(t.type===e.OBSERVER_TYPE.ADD){const i=new c(null);this.sprites[t.gameObject.id]=i,this.containerManager.getContainer(t.gameObject.id).addChildAt(i.sprite,0);const n=this.increaseAsyncId(r),{instance:o}=yield e.resource.getResource(s.resource);if(!this.validateAsyncId(r,n))return;if(!o)return void console.error(`GameObject:${t.gameObject.name}'s Sprite resource load error`);i.image=o[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]}}})}};p.systemName="Sprite",p=i([e.decorators.componentObserver({Sprite:["spriteName"]})],p);var m=p;exports.Sprite=o,exports.SpriteSystem=m;
@@ -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
 
@@ -3,19 +3,19 @@ import { type } from '@eva/inspector-decorator';
3
3
  import { Renderer, RendererSystem } from '@eva/plugin-renderer';
4
4
  import { Sprite as Sprite$4, Texture, Spritesheet } from 'pixi.js';
5
5
 
6
- /*! *****************************************************************************
7
- Copyright (c) Microsoft Corporation. All rights reserved.
8
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9
- this file except in compliance with the License. You may obtain a copy of the
10
- License at http://www.apache.org/licenses/LICENSE-2.0
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
11
8
 
12
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
14
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
15
- MERCHANTABLITY OR NON-INFRINGEMENT.
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
16
11
 
17
- See the Apache Version 2.0 License for specific language governing permissions
18
- and limitations under the License.
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
19
  ***************************************************************************** */
20
20
 
21
21
  function __decorate(decorators, target, key, desc) {
@@ -26,20 +26,51 @@ function __decorate(decorators, target, key, desc) {
26
26
  }
27
27
 
28
28
  function __awaiter(thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
30
  return new (P || (P = Promise))(function (resolve, reject) {
30
31
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
32
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
34
  step((generator = generator.apply(thisArg, _arguments || [])).next());
34
35
  });
35
- }
36
+ }
37
+
38
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
39
+ var e = new Error(message);
40
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
+ };
36
42
 
43
+ /**
44
+ * 精灵图组件
45
+ *
46
+ * Sprite 组件用于渲染精灵图集(Sprite Sheet)中的单个精灵。
47
+ * 它从一个包含多个小图的大图资源中提取指定的子图进行渲染,
48
+ * 这种方式可以减少纹理切换,提高渲染性能。
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // 渲染精灵图集中的某个精灵
53
+ * const player = new GameObject('player');
54
+ * player.addComponent(new Sprite({
55
+ * resource: 'playerAtlas', // 资源名称
56
+ * spriteName: 'player_idle_01.png' // 精灵图集中的子图名称
57
+ * }));
58
+ * ```
59
+ */
37
60
  class Sprite$3 extends Component {
38
61
  constructor() {
39
62
  super(...arguments);
63
+ /** 精灵图集资源名称 */
40
64
  this.resource = '';
65
+ /** 精灵图集中的子图名称 */
41
66
  this.spriteName = '';
42
67
  }
68
+ /**
69
+ * 初始化组件
70
+ * @param obj - 初始化参数
71
+ * @param obj.resource - 资源名称
72
+ * @param obj.spriteName - 精灵名称
73
+ */
43
74
  init(obj) {
44
75
  if (obj && obj.resource) {
45
76
  this.resource = obj.resource;
@@ -47,6 +78,7 @@ class Sprite$3 extends Component {
47
78
  }
48
79
  }
49
80
  }
81
+ /** 组件名称 */
50
82
  Sprite$3.componentName = 'Sprite';
51
83
  __decorate([
52
84
  type('string')
@@ -89,13 +121,14 @@ class Sprite$2 {
89
121
  }
90
122
  }
91
123
 
92
- const resourceKeySplit = '_s|r|c_';
124
+ const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
93
125
  resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
94
126
  return new Promise(r => {
95
127
  const textureObj = data.json.data;
96
128
  const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
97
129
  const frames = textureObj.frames || {};
98
130
  const animations = textureObj.animations || {};
131
+ const newAnimations = {};
99
132
  const newFrames = {};
100
133
  for (const key in frames) {
101
134
  const newKey = name + resourceKeySplit + key;
@@ -109,10 +142,9 @@ resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
109
142
  spriteList.push(newSpriteName);
110
143
  }
111
144
  }
112
- animations[key] = spriteList;
145
+ newAnimations[key] = spriteList;
113
146
  }
114
- textureObj.frames = newFrames;
115
- const spriteSheet = new Spritesheet(texture, textureObj);
147
+ const spriteSheet = new Spritesheet(texture, Object.assign(Object.assign({}, textureObj), { frames: newFrames, animations: newAnimations }));
116
148
  spriteSheet.parse().then(() => {
117
149
  r(spriteSheet.textures);
118
150
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite",
3
- "version": "2.0.1-beta.9",
3
+ "version": "2.0.2-beta.0",
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.9",
23
- "@eva/eva.js": "2.0.1-beta.9",
24
- "pixi.js": "^8.8.1"
22
+ "@eva/plugin-renderer": "2.0.2-beta.0",
23
+ "@eva/eva.js": "2.0.2-beta.0",
24
+ "pixi.js": "^8.17.0"
25
25
  }
26
26
  }