@eva/plugin-renderer-sprite 2.0.2 → 2.1.0-beta.10

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.
@@ -11,6 +11,9 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
11
11
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12
12
  return c > 3 && r && Object.defineProperty(target, key, r), r;
13
13
  }
14
+ function __metadata(metadataKey, metadataValue) {
15
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
16
+ }
14
17
  function __awaiter(thisArg, _arguments, P, generator) {
15
18
  function adopt(value) {
16
19
  return value instanceof P ? value : new P(function (resolve) {
@@ -38,28 +41,116 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
38
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
39
42
  });
40
43
  }
41
- function getIDEPropsPropertyObj(target, propertyKey) {
42
- if (!target.constructor.IDEProps) {
43
- target.constructor.IDEProps = {};
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';
44
70
  }
45
- if (!target.constructor.IDEProps[propertyKey]) {
46
- target.constructor.IDEProps[propertyKey] = {};
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
+ }
47
102
  }
48
- var propertyObj = target.constructor.IDEProps[propertyKey];
49
- return propertyObj;
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);
50
113
  }
51
114
  function type(type) {
52
- return function (target, propertyKey) {
53
- var prop = getIDEPropsPropertyObj(target, propertyKey);
54
- prop.key = propertyKey;
55
- prop.type = type;
115
+ return Field({
116
+ type
117
+ });
118
+ }
119
+ function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
120
+ if (typeof returnTypeFuncOrOptions === 'function') {
121
+ return {
122
+ returnTypeFunc: returnTypeFuncOrOptions,
123
+ options: maybeOptions || {}
124
+ };
125
+ }
126
+ return {
127
+ options: returnTypeFuncOrOptions || {}
128
+ };
129
+ }
130
+ function Field(returnTypeFunction, maybeOptions) {
131
+ return (target, propertyKey) => {
132
+ if (typeof propertyKey === 'symbol') {
133
+ throw new SymbolKeysNotSupportedError();
134
+ }
135
+ const {
136
+ options,
137
+ returnTypeFunc
138
+ } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
139
+ defineTypes(target, propertyKey, options, returnTypeFunc);
56
140
  };
57
141
  }
142
+ var ExecuteMode;
143
+ (function (ExecuteMode) {
144
+ ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
145
+ ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
146
+ ExecuteMode[ExecuteMode["All"] = 6] = "All";
147
+ })(ExecuteMode || (ExecuteMode = {}));
58
148
  class Sprite$3 extends eva_js.Component {
59
- constructor() {
60
- super(...arguments);
149
+ constructor(params) {
150
+ super(params);
61
151
  this.resource = '';
62
152
  this.spriteName = '';
153
+ this.init(params);
63
154
  }
64
155
  init(obj) {
65
156
  if (obj && obj.resource) {
@@ -67,10 +158,14 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
67
158
  this.spriteName = obj.spriteName;
68
159
  }
69
160
  }
161
+ setSprite(spriteName) {
162
+ this.spriteName = spriteName;
163
+ return this;
164
+ }
70
165
  }
71
166
  Sprite$3.componentName = 'Sprite';
72
- __decorate([type('string')], Sprite$3.prototype, "resource", void 0);
73
- __decorate([type('string')], Sprite$3.prototype, "spriteName", void 0);
167
+ __decorate([type('string'), __metadata("design:type", String)], Sprite$3.prototype, "resource", void 0);
168
+ __decorate([type('string'), __metadata("design:type", String)], Sprite$3.prototype, "spriteName", void 0);
74
169
  class Sprite$2 {
75
170
  constructor(image) {
76
171
  this._image = null;
@@ -107,9 +202,28 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
107
202
  data
108
203
  }) => {
109
204
  return new Promise(r => {
205
+ var _a;
110
206
  const textureObj = data.json.data;
111
207
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
112
- const frames = textureObj.frames || {};
208
+ let frames = textureObj.frames || {};
209
+ if (Array.isArray(frames)) {
210
+ const hashFrames = {};
211
+ for (const f of frames) {
212
+ const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
213
+ if (key) hashFrames[key] = f;
214
+ }
215
+ frames = hashFrames;
216
+ } else {
217
+ const sample = Object.values(frames)[0];
218
+ if (sample && typeof sample.filename === 'string') {
219
+ const remapped = {};
220
+ for (const k in frames) {
221
+ const f = frames[k];
222
+ remapped[f.filename || k] = f;
223
+ }
224
+ frames = remapped;
225
+ }
226
+ }
113
227
  const animations = textureObj.animations || {};
114
228
  const newAnimations = {};
115
229
  const newFrames = {};
@@ -147,7 +261,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
147
261
  let Sprite = class Sprite extends pluginRenderer.Renderer {
148
262
  constructor() {
149
263
  super(...arguments);
150
- this.name = 'Sprite';
264
+ this.name = 'SpriteSystem';
151
265
  this.sprites = {};
152
266
  }
153
267
  init() {
@@ -207,7 +321,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
207
321
  });
208
322
  }
209
323
  };
210
- Sprite.systemName = 'Sprite';
324
+ Sprite.systemName = 'SpriteSystem';
211
325
  Sprite = __decorate([eva_js.decorators.componentObserver({
212
326
  Sprite: ['spriteName']
213
327
  })], Sprite);
@@ -1 +1 @@
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;
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 n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[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_sprite=function(e,t,r,n){"use strict";function s(e,t,r,n){var s,i=arguments.length,o=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(o=(i<3?s(o):i>3?s(t,r,o):s(t,r))||o);return i>3&&o&&Object.defineProperty(t,r,o),o}function i(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(e,t,r,n){return new(r||(r=Promise))(function(s,i){function o(e){try{a(n.next(e))}catch(e){i(e)}}function c(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,c)}a((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;class c extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const a="IDE_PROPERTY_METADATA";function p(e,t,r,n){let s=Reflect.getMetadata("design:type",e,t),i=s===Array;const o=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(s);if("unknown"!==o&&(s=o),n){const e=n();Array.isArray(e)?(i=!0,s=e[0]):s=e}const c=Reflect.getMetadata(a,e.constructor)||{},p=_extends(_extends(_extends({},c[t]||{}),{type:s,isArray:i}),r);c[t]=p,Reflect.defineMetadata(a,c,e.constructor);!function(e,t,r){const n=e.constructor,s=n.IDEProps||{};s[t]=_extends(_extends({key:t},s[t]),r),n.IDEProps=s}(e,t,function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(r[n[s]]=e[n[s]])}return r}(p,["isArray"]))}function u(e){return t={type:e},(e,n)=>{if("symbol"==typeof n)throw new c;const{options:s,returnTypeFunc:i}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,r);p(e,n,s,i)};var t,r}var l;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(l||(l={}));class f extends t.Component{constructor(e){super(e),this.resource="",this.spriteName="",this.init(e)}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}setSprite(e){return this.spriteName=e,this}}f.componentName="Sprite",s([u("string"),i("design:type",String)],f.prototype,"resource",void 0),s([u("string"),i("design:type",String)],f.prototype,"spriteName",void 0);class d{constructor(e){this._image=null,this._image=e,e?"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?this.sprite=n.Sprite.from(e):e instanceof n.Texture&&(this.sprite=new n.Sprite(e)):this.sprite=new n.Sprite}set image(e){this._image!==e&&("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(this.sprite.texture&&this.sprite.texture.destroy(!1),this.sprite.texture=n.Texture.from(e)):e instanceof n.Texture&&(this.sprite.texture=e),this._image=e)}get image(){return this._image}}const m="_s|r|c_";t.resource.registerInstance(t.RESOURCE_TYPE.SPRITE,({name:e,data:t})=>new Promise(r=>{var s;const i=t.json.data,o=t.image instanceof n.Texture?t.image:n.Texture.from(t.image);let c=i.frames||{};if(Array.isArray(c)){const e={};for(const t of c){const r=null!==(s=t.filename)&&void 0!==s?s:t.name;r&&(e[r]=t)}c=e}else{const e=Object.values(c)[0];if(e&&"string"==typeof e.filename){const e={};for(const t in c){const r=c[t];e[r.filename||t]=r}c=e}}const a=i.animations||{},p={},u={};for(const t in c){u[e+m+t]=c[t]}for(const t in a){const r=[];if(a[t]&&a[t].length>=0)for(const n of a[t]){const t=e+m+n;r.push(t)}p[t]=r}const l=new n.Spritesheet(o,_extends(_extends({},i),{frames:u,animations:p}));l.parse().then(()=>{r(l.textures)})})),t.resource.registerDestroy(t.RESOURCE_TYPE.SPRITE,({instance:e})=>{if(e)for(const t in e)e[t].destroy(!0)});let g=class extends r.Renderer{constructor(){super(...arguments),this.name="SpriteSystem",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 o(this,void 0,void 0,function*(){if("Sprite"===e.componentName){const r=e.gameObject.id,n=e.component;if(e.type===t.OBSERVER_TYPE.ADD){const s=new d(null);this.sprites[e.gameObject.id]=s,this.containerManager.getContainer(e.gameObject.id).addChildAt(s.sprite,0);const i=this.increaseAsyncId(r),{instance:o}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(r,i))return;if(!o)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);s.image=o[n.resource+m+n.spriteName]}else if(e.type===t.OBSERVER_TYPE.CHANGE){const s=this.increaseAsyncId(r),{instance:i}=yield t.resource.getResource(n.resource);if(!this.validateAsyncId(r,s))return;if(!i)return void console.error(`GameObject:${e.gameObject.name}'s Sprite resource load error`);this.sprites[e.gameObject.id].image=i[n.resource+m+n.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]}}})}};g.systemName="SpriteSystem",g=s([t.decorators.componentObserver({Sprite:["spriteName"]})],g);var h=g;return e.Sprite=f,e.SpriteSystem=h,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;
@@ -29,6 +29,10 @@ function __decorate(decorators, target, key, desc) {
29
29
  return c > 3 && r && Object.defineProperty(target, key, r), r;
30
30
  }
31
31
 
32
+ function __metadata(metadataKey, metadataValue) {
33
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
34
+ }
35
+
32
36
  function __awaiter(thisArg, _arguments, P, generator) {
33
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -62,18 +66,19 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
62
66
  * ```
63
67
  */
64
68
  class Sprite$3 extends eva_js.Component {
65
- constructor() {
66
- super(...arguments);
69
+ constructor(params) {
70
+ super(params);
67
71
  /** 精灵图集资源名称 */
68
72
  this.resource = '';
69
73
  /** 精灵图集中的子图名称 */
70
74
  this.spriteName = '';
75
+ this.init(params);
71
76
  }
72
77
  /**
73
78
  * 初始化组件
74
79
  * @param obj - 初始化参数
75
- * @param obj.resource - 资源名称
76
- * @param obj.spriteName - 精灵名称
80
+ *
81
+ * 配置项包括 resource spriteName。
77
82
  */
78
83
  init(obj) {
79
84
  if (obj && obj.resource) {
@@ -81,14 +86,27 @@ class Sprite$3 extends eva_js.Component {
81
86
  this.spriteName = obj.spriteName;
82
87
  }
83
88
  }
89
+ /**
90
+ * 切换当前精灵图集帧。
91
+ *
92
+ * SpriteSystem 会监听 spriteName 变化并刷新渲染纹理。
93
+ *
94
+ * @param spriteName - 精灵图集中的子图名称
95
+ */
96
+ setSprite(spriteName) {
97
+ this.spriteName = spriteName;
98
+ return this;
99
+ }
84
100
  }
85
101
  /** 组件名称 */
86
102
  Sprite$3.componentName = 'Sprite';
87
103
  __decorate([
88
- inspectorDecorator.type('string')
104
+ inspectorDecorator.type('string'),
105
+ __metadata("design:type", String)
89
106
  ], Sprite$3.prototype, "resource", void 0);
90
107
  __decorate([
91
- inspectorDecorator.type('string')
108
+ inspectorDecorator.type('string'),
109
+ __metadata("design:type", String)
92
110
  ], Sprite$3.prototype, "spriteName", void 0);
93
111
 
94
112
  class Sprite$2 {
@@ -128,9 +146,34 @@ class Sprite$2 {
128
146
  const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
129
147
  eva_js.resource.registerInstance(eva_js.RESOURCE_TYPE.SPRITE, ({ name, data }) => {
130
148
  return new Promise(r => {
149
+ var _a;
131
150
  const textureObj = data.json.data;
132
151
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
133
- const frames = textureObj.frames || {};
152
+ // Phaser-style atlas JSON often ships frames as an array (`frames: [{ filename, frame, ... }]`)
153
+ // while PixiJS Spritesheet expects a hash (`frames: { name: { frame, ... } }`).
154
+ // TexturePacker "Hash" exports use numeric keys but carry the real name in `filename`.
155
+ // Normalize all three so DSL spawn `texture: "atlas#name"` resolves correctly.
156
+ let frames = textureObj.frames || {};
157
+ if (Array.isArray(frames)) {
158
+ const hashFrames = {};
159
+ for (const f of frames) {
160
+ const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
161
+ if (key)
162
+ hashFrames[key] = f;
163
+ }
164
+ frames = hashFrames;
165
+ }
166
+ else {
167
+ const sample = Object.values(frames)[0];
168
+ if (sample && typeof sample.filename === 'string') {
169
+ const remapped = {};
170
+ for (const k in frames) {
171
+ const f = frames[k];
172
+ remapped[f.filename || k] = f;
173
+ }
174
+ frames = remapped;
175
+ }
176
+ }
134
177
  const animations = textureObj.animations || {};
135
178
  const newAnimations = {};
136
179
  const newFrames = {};
@@ -164,7 +207,7 @@ eva_js.resource.registerDestroy(eva_js.RESOURCE_TYPE.SPRITE, ({ instance }) => {
164
207
  let Sprite = class Sprite extends pluginRenderer.Renderer {
165
208
  constructor() {
166
209
  super(...arguments);
167
- this.name = 'Sprite';
210
+ this.name = 'SpriteSystem';
168
211
  this.sprites = {};
169
212
  }
170
213
  init() {
@@ -220,7 +263,7 @@ let Sprite = class Sprite extends pluginRenderer.Renderer {
220
263
  });
221
264
  }
222
265
  };
223
- Sprite.systemName = 'Sprite';
266
+ Sprite.systemName = 'SpriteSystem';
224
267
  Sprite = __decorate([
225
268
  eva_js.decorators.componentObserver({
226
269
  Sprite: ['spriteName'],
@@ -1 +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");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;
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){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(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 c extends e.Component{constructor(e){super(e),this.resource="",this.spriteName="",this.init(e)}init(e){e&&e.resource&&(this.resource=e.resource,this.spriteName=e.spriteName)}setSprite(e){return this.spriteName=e,this}}c.componentName="Sprite",i([t.type("string"),n("design:type",String)],c.prototype,"resource",void 0),i([t.type("string"),n("design:type",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_";e.resource.registerInstance(e.RESOURCE_TYPE.SPRITE,({name:e,data:t})=>new Promise(r=>{var i;const n=t.json.data,o=t.image instanceof s.Texture?t.image:s.Texture.from(t.image);let c=n.frames||{};if(Array.isArray(c)){const e={};for(const t of c){const r=null!==(i=t.filename)&&void 0!==i?i:t.name;r&&(e[r]=t)}c=e}else{const e=Object.values(c)[0];if(e&&"string"==typeof e.filename){const e={};for(const t in c){const r=c[t];e[r.filename||t]=r}c=e}}const a=n.animations||{},m={},u={};for(const t in c){u[e+p+t]=c[t]}for(const t in a){const r=[];if(a[t]&&a[t].length>=0)for(const s of a[t]){const t=e+p+s;r.push(t)}m[t]=r}const d=new s.Spritesheet(o,Object.assign(Object.assign({},n),{frames:u,animations:m}));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 m=class extends r.Renderer{constructor(){super(...arguments),this.name="SpriteSystem",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 o(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 a(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+p+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+p+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]}}})}};m.systemName="SpriteSystem",m=i([e.decorators.componentObserver({Sprite:["spriteName"]})],m);var u=m;exports.Sprite=c,exports.SpriteSystem=u;
@@ -31,13 +31,22 @@ export declare class Sprite extends Component<SpriteParams> {
31
31
  resource: string;
32
32
  /** 精灵图集中的子图名称 */
33
33
  spriteName: string;
34
+ constructor(params?: SpriteParams);
34
35
  /**
35
36
  * 初始化组件
36
37
  * @param obj - 初始化参数
37
- * @param obj.resource - 资源名称
38
- * @param obj.spriteName - 精灵名称
38
+ *
39
+ * 配置项包括 resource spriteName。
39
40
  */
40
41
  init(obj?: SpriteParams): void;
42
+ /**
43
+ * 切换当前精灵图集帧。
44
+ *
45
+ * SpriteSystem 会监听 spriteName 变化并刷新渲染纹理。
46
+ *
47
+ * @param spriteName - 精灵图集中的子图名称
48
+ */
49
+ setSprite(spriteName: string): this;
41
50
  }
42
51
 
43
52
  export declare interface SpriteParams {
@@ -25,6 +25,10 @@ function __decorate(decorators, target, key, desc) {
25
25
  return c > 3 && r && Object.defineProperty(target, key, r), r;
26
26
  }
27
27
 
28
+ function __metadata(metadataKey, metadataValue) {
29
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
30
+ }
31
+
28
32
  function __awaiter(thisArg, _arguments, P, generator) {
29
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -58,18 +62,19 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
58
62
  * ```
59
63
  */
60
64
  class Sprite$3 extends Component {
61
- constructor() {
62
- super(...arguments);
65
+ constructor(params) {
66
+ super(params);
63
67
  /** 精灵图集资源名称 */
64
68
  this.resource = '';
65
69
  /** 精灵图集中的子图名称 */
66
70
  this.spriteName = '';
71
+ this.init(params);
67
72
  }
68
73
  /**
69
74
  * 初始化组件
70
75
  * @param obj - 初始化参数
71
- * @param obj.resource - 资源名称
72
- * @param obj.spriteName - 精灵名称
76
+ *
77
+ * 配置项包括 resource spriteName。
73
78
  */
74
79
  init(obj) {
75
80
  if (obj && obj.resource) {
@@ -77,14 +82,27 @@ class Sprite$3 extends Component {
77
82
  this.spriteName = obj.spriteName;
78
83
  }
79
84
  }
85
+ /**
86
+ * 切换当前精灵图集帧。
87
+ *
88
+ * SpriteSystem 会监听 spriteName 变化并刷新渲染纹理。
89
+ *
90
+ * @param spriteName - 精灵图集中的子图名称
91
+ */
92
+ setSprite(spriteName) {
93
+ this.spriteName = spriteName;
94
+ return this;
95
+ }
80
96
  }
81
97
  /** 组件名称 */
82
98
  Sprite$3.componentName = 'Sprite';
83
99
  __decorate([
84
- type('string')
100
+ type('string'),
101
+ __metadata("design:type", String)
85
102
  ], Sprite$3.prototype, "resource", void 0);
86
103
  __decorate([
87
- type('string')
104
+ type('string'),
105
+ __metadata("design:type", String)
88
106
  ], Sprite$3.prototype, "spriteName", void 0);
89
107
 
90
108
  class Sprite$2 {
@@ -124,9 +142,34 @@ class Sprite$2 {
124
142
  const resourceKeySplit = '_s|r|c_'; // Notice: This key be used in ninepatch system.
125
143
  resource.registerInstance(RESOURCE_TYPE.SPRITE, ({ name, data }) => {
126
144
  return new Promise(r => {
145
+ var _a;
127
146
  const textureObj = data.json.data;
128
147
  const texture = data.image instanceof Texture ? data.image : Texture.from(data.image);
129
- const frames = textureObj.frames || {};
148
+ // Phaser-style atlas JSON often ships frames as an array (`frames: [{ filename, frame, ... }]`)
149
+ // while PixiJS Spritesheet expects a hash (`frames: { name: { frame, ... } }`).
150
+ // TexturePacker "Hash" exports use numeric keys but carry the real name in `filename`.
151
+ // Normalize all three so DSL spawn `texture: "atlas#name"` resolves correctly.
152
+ let frames = textureObj.frames || {};
153
+ if (Array.isArray(frames)) {
154
+ const hashFrames = {};
155
+ for (const f of frames) {
156
+ const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
157
+ if (key)
158
+ hashFrames[key] = f;
159
+ }
160
+ frames = hashFrames;
161
+ }
162
+ else {
163
+ const sample = Object.values(frames)[0];
164
+ if (sample && typeof sample.filename === 'string') {
165
+ const remapped = {};
166
+ for (const k in frames) {
167
+ const f = frames[k];
168
+ remapped[f.filename || k] = f;
169
+ }
170
+ frames = remapped;
171
+ }
172
+ }
130
173
  const animations = textureObj.animations || {};
131
174
  const newAnimations = {};
132
175
  const newFrames = {};
@@ -160,7 +203,7 @@ resource.registerDestroy(RESOURCE_TYPE.SPRITE, ({ instance }) => {
160
203
  let Sprite = class Sprite extends Renderer {
161
204
  constructor() {
162
205
  super(...arguments);
163
- this.name = 'Sprite';
206
+ this.name = 'SpriteSystem';
164
207
  this.sprites = {};
165
208
  }
166
209
  init() {
@@ -216,7 +259,7 @@ let Sprite = class Sprite extends Renderer {
216
259
  });
217
260
  }
218
261
  };
219
- Sprite.systemName = 'Sprite';
262
+ Sprite.systemName = 'SpriteSystem';
220
263
  Sprite = __decorate([
221
264
  decorators.componentObserver({
222
265
  Sprite: ['spriteName'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-sprite",
3
- "version": "2.0.2",
3
+ "version": "2.1.0-beta.10",
4
4
  "description": "@eva/plugin-renderer-sprite",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-sprite.esm.js",
@@ -18,9 +18,9 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "2.0.2",
23
- "@eva/eva.js": "2.0.2",
21
+ "@eva/inspector-decorator": "^2.0.0-beta.0",
22
+ "@eva/plugin-renderer": "2.1.0-beta.10",
23
+ "@eva/eva.js": "2.1.0-beta.10",
24
24
  "pixi.js": "^8.17.0"
25
25
  }
26
26
  }