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

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,112 @@ 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
+ function __rest(s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
47
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
48
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
49
+ }
50
+ return t;
51
+ }
52
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
53
+ var e = new Error(message);
54
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
55
+ };
56
+ class SymbolKeysNotSupportedError extends Error {
57
+ constructor() {
58
+ super('Symbol keys are not supported yet!');
59
+ Object.setPrototypeOf(this, new.target.prototype);
60
+ }
61
+ }
62
+ const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
63
+ function transformBasicType(type) {
64
+ if (type === String) {
65
+ return 'string';
66
+ }
67
+ if (type === Number) {
68
+ return 'number';
44
69
  }
45
- if (!target.constructor.IDEProps[propertyKey]) {
46
- target.constructor.IDEProps[propertyKey] = {};
70
+ if (type === Boolean) {
71
+ return 'boolean';
47
72
  }
48
- var propertyObj = target.constructor.IDEProps[propertyKey];
49
- return propertyObj;
73
+ return 'unknown';
74
+ }
75
+ function defineLegacyIDEProp(target, propertyKey, patch) {
76
+ const constructor = target.constructor;
77
+ const current = constructor.IDEProps || {};
78
+ current[propertyKey] = _extends(_extends({
79
+ key: propertyKey
80
+ }, current[propertyKey]), patch);
81
+ constructor.IDEProps = current;
82
+ }
83
+ function defineTypes(target, key, options, returnTypeFunction) {
84
+ let type = Reflect.getMetadata('design:type', target, key);
85
+ let isArray = type === Array;
86
+ const str = transformBasicType(type);
87
+ if (str !== 'unknown') {
88
+ type = str;
89
+ }
90
+ if (returnTypeFunction) {
91
+ const returnType = returnTypeFunction();
92
+ if (Array.isArray(returnType)) {
93
+ isArray = true;
94
+ type = returnType[0];
95
+ } else {
96
+ type = returnType;
97
+ }
98
+ }
99
+ const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
100
+ const current = properties[key] || {};
101
+ const property = _extends(_extends(_extends({}, current), {
102
+ type,
103
+ isArray: isArray
104
+ }), options);
105
+ properties[key] = property;
106
+ Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
107
+ const legacyProperty = __rest(property, ["isArray"]);
108
+ defineLegacyIDEProp(target, key, legacyProperty);
50
109
  }
51
110
  function type(type) {
52
- return function (target, propertyKey) {
53
- var prop = getIDEPropsPropertyObj(target, propertyKey);
54
- prop.key = propertyKey;
55
- prop.type = type;
111
+ return Field({
112
+ type
113
+ });
114
+ }
115
+ function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
116
+ if (typeof returnTypeFuncOrOptions === 'function') {
117
+ return {
118
+ returnTypeFunc: returnTypeFuncOrOptions,
119
+ options: maybeOptions || {}
120
+ };
121
+ }
122
+ return {
123
+ options: returnTypeFuncOrOptions || {}
56
124
  };
57
125
  }
126
+ function Field(returnTypeFunction, maybeOptions) {
127
+ return (target, propertyKey) => {
128
+ if (typeof propertyKey === 'symbol') {
129
+ throw new SymbolKeysNotSupportedError();
130
+ }
131
+ const {
132
+ options,
133
+ returnTypeFunc
134
+ } = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
135
+ defineTypes(target, propertyKey, options, returnTypeFunc);
136
+ };
137
+ }
138
+ var ExecuteMode;
139
+ (function (ExecuteMode) {
140
+ ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
141
+ ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
142
+ ExecuteMode[ExecuteMode["All"] = 6] = "All";
143
+ })(ExecuteMode || (ExecuteMode = {}));
58
144
  class Sprite$3 extends eva_js.Component {
59
- constructor() {
60
- super(...arguments);
145
+ constructor(params) {
146
+ super(params);
61
147
  this.resource = '';
62
148
  this.spriteName = '';
149
+ this.init(params);
63
150
  }
64
151
  init(obj) {
65
152
  if (obj && obj.resource) {
@@ -67,10 +154,14 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
67
154
  this.spriteName = obj.spriteName;
68
155
  }
69
156
  }
157
+ setSprite(spriteName) {
158
+ this.spriteName = spriteName;
159
+ return this;
160
+ }
70
161
  }
71
162
  Sprite$3.componentName = 'Sprite';
72
- __decorate([type('string')], Sprite$3.prototype, "resource", void 0);
73
- __decorate([type('string')], Sprite$3.prototype, "spriteName", void 0);
163
+ __decorate([type('string'), __metadata("design:type", String)], Sprite$3.prototype, "resource", void 0);
164
+ __decorate([type('string'), __metadata("design:type", String)], Sprite$3.prototype, "spriteName", void 0);
74
165
  class Sprite$2 {
75
166
  constructor(image) {
76
167
  this._image = null;
@@ -107,9 +198,28 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
107
198
  data
108
199
  }) => {
109
200
  return new Promise(r => {
201
+ var _a;
110
202
  const textureObj = data.json.data;
111
203
  const texture = data.image instanceof pixi_js.Texture ? data.image : pixi_js.Texture.from(data.image);
112
- const frames = textureObj.frames || {};
204
+ let frames = textureObj.frames || {};
205
+ if (Array.isArray(frames)) {
206
+ const hashFrames = {};
207
+ for (const f of frames) {
208
+ const key = (_a = f.filename) !== null && _a !== void 0 ? _a : f.name;
209
+ if (key) hashFrames[key] = f;
210
+ }
211
+ frames = hashFrames;
212
+ } else {
213
+ const sample = Object.values(frames)[0];
214
+ if (sample && typeof sample.filename === 'string') {
215
+ const remapped = {};
216
+ for (const k in frames) {
217
+ const f = frames[k];
218
+ remapped[f.filename || k] = f;
219
+ }
220
+ frames = remapped;
221
+ }
222
+ }
113
223
  const animations = textureObj.animations || {};
114
224
  const newAnimations = {};
115
225
  const newFrames = {};
@@ -147,7 +257,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
147
257
  let Sprite = class Sprite extends pluginRenderer.Renderer {
148
258
  constructor() {
149
259
  super(...arguments);
150
- this.name = 'Sprite';
260
+ this.name = 'SpriteSystem';
151
261
  this.sprites = {};
152
262
  }
153
263
  init() {
@@ -207,7 +317,7 @@ var _EVA_IIFE_sprite = function (exports, eva_js, pluginRenderer, pixi_js) {
207
317
  });
208
318
  }
209
319
  };
210
- Sprite.systemName = 'Sprite';
320
+ Sprite.systemName = 'SpriteSystem';
211
321
  Sprite = __decorate([eva_js.decorators.componentObserver({
212
322
  Sprite: ['spriteName']
213
323
  })], 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 a=e.length-1;a>=0;a--)(s=e[a])&&(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{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const c="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 a=Reflect.getMetadata(c,e.constructor)||{},p=_extends(_extends(_extends({},a[t]||{}),{type:s,isArray:i}),r);a[t]=p,Reflect.defineMetadata(c,a,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 a;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 a=i.frames||{};if(Array.isArray(a)){const e={};for(const t of a){const r=null!==(s=t.filename)&&void 0!==s?s:t.name;r&&(e[r]=t)}a=e}else{const e=Object.values(a)[0];if(e&&"string"==typeof e.filename){const e={};for(const t in a){const r=a[t];e[r.filename||t]=r}a=e}}const c=i.animations||{},p={},u={};for(const t in a){u[e+m+t]=a[t]}for(const t in c){const r=[];if(c[t]&&c[t].length>=0)for(const n of c[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-beta.3",
3
+ "version": "2.1.0-beta.1",
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-beta.3",
23
- "@eva/eva.js": "2.0.2-beta.3",
21
+ "@eva/inspector-decorator": "^2.0.0-beta.0",
22
+ "@eva/plugin-renderer": "2.1.0-beta.1",
23
+ "@eva/eva.js": "2.1.0-beta.1",
24
24
  "pixi.js": "^8.17.0"
25
25
  }
26
26
  }