@eva/plugin-renderer-nine-patch 1.2.0 → 1.3.0-alpha.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.
@@ -0,0 +1,363 @@
1
+ this.EVA = this.EVA || {};
2
+ this.EVA.plugin = this.EVA.plugin || {};
3
+ this.EVA.plugin.renderer = this.EVA.plugin.renderer || {};
4
+
5
+ this.EVA.plugin.renderer.ninePatch = function (exports, eva_js, pluginRenderer, rendererAdapter) {
6
+ 'use strict';
7
+
8
+ var _extendStatics = function extendStatics(d, b) {
9
+ _extendStatics = Object.setPrototypeOf || {
10
+ __proto__: []
11
+ } instanceof Array && function (d, b) {
12
+ d.__proto__ = b;
13
+ } || function (d, b) {
14
+ for (var p in b) {
15
+ if (b.hasOwnProperty(p)) d[p] = b[p];
16
+ }
17
+ };
18
+
19
+ return _extendStatics(d, b);
20
+ };
21
+
22
+ function __extends(d, b) {
23
+ _extendStatics(d, b);
24
+
25
+ function __() {
26
+ this.constructor = d;
27
+ }
28
+
29
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
+ }
31
+
32
+ function __decorate(decorators, target, key, desc) {
33
+ var c = arguments.length,
34
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
35
+ d;
36
+ 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--) {
37
+ if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
38
+ }
39
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
40
+ }
41
+
42
+ function __awaiter(thisArg, _arguments, P, generator) {
43
+ function adopt(value) {
44
+ return value instanceof P ? value : new P(function (resolve) {
45
+ resolve(value);
46
+ });
47
+ }
48
+
49
+ return new (P || (P = Promise))(function (resolve, reject) {
50
+ function fulfilled(value) {
51
+ try {
52
+ step(generator.next(value));
53
+ } catch (e) {
54
+ reject(e);
55
+ }
56
+ }
57
+
58
+ function rejected(value) {
59
+ try {
60
+ step(generator["throw"](value));
61
+ } catch (e) {
62
+ reject(e);
63
+ }
64
+ }
65
+
66
+ function step(result) {
67
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
68
+ }
69
+
70
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
71
+ });
72
+ }
73
+
74
+ function __generator(thisArg, body) {
75
+ var _ = {
76
+ label: 0,
77
+ sent: function sent() {
78
+ if (t[0] & 1) throw t[1];
79
+ return t[1];
80
+ },
81
+ trys: [],
82
+ ops: []
83
+ },
84
+ f,
85
+ y,
86
+ t,
87
+ g;
88
+ return g = {
89
+ next: verb(0),
90
+ "throw": verb(1),
91
+ "return": verb(2)
92
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
93
+ return this;
94
+ }), g;
95
+
96
+ function verb(n) {
97
+ return function (v) {
98
+ return step([n, v]);
99
+ };
100
+ }
101
+
102
+ function step(op) {
103
+ if (f) throw new TypeError("Generator is already executing.");
104
+
105
+ while (_) {
106
+ try {
107
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
108
+ if (y = 0, t) op = [op[0] & 2, t.value];
109
+
110
+ switch (op[0]) {
111
+ case 0:
112
+ case 1:
113
+ t = op;
114
+ break;
115
+
116
+ case 4:
117
+ _.label++;
118
+ return {
119
+ value: op[1],
120
+ done: false
121
+ };
122
+
123
+ case 5:
124
+ _.label++;
125
+ y = op[1];
126
+ op = [0];
127
+ continue;
128
+
129
+ case 7:
130
+ op = _.ops.pop();
131
+
132
+ _.trys.pop();
133
+
134
+ continue;
135
+
136
+ default:
137
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
138
+ _ = 0;
139
+ continue;
140
+ }
141
+
142
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
+ _.label = op[1];
144
+ break;
145
+ }
146
+
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+
153
+ if (t && _.label < t[2]) {
154
+ _.label = t[2];
155
+
156
+ _.ops.push(op);
157
+
158
+ break;
159
+ }
160
+
161
+ if (t[2]) _.ops.pop();
162
+
163
+ _.trys.pop();
164
+
165
+ continue;
166
+ }
167
+
168
+ op = body.call(thisArg, _);
169
+ } catch (e) {
170
+ op = [6, e];
171
+ y = 0;
172
+ } finally {
173
+ f = t = 0;
174
+ }
175
+ }
176
+
177
+ if (op[0] & 5) throw op[1];
178
+ return {
179
+ value: op[0] ? op[1] : void 0,
180
+ done: true
181
+ };
182
+ }
183
+ }
184
+
185
+ function getIDEPropsPropertyObj(target, propertyKey) {
186
+ if (!target.constructor.IDEProps) {
187
+ target.constructor.IDEProps = {};
188
+ }
189
+
190
+ if (!target.constructor.IDEProps[propertyKey]) {
191
+ target.constructor.IDEProps[propertyKey] = {};
192
+ }
193
+
194
+ var propertyObj = target.constructor.IDEProps[propertyKey];
195
+ return propertyObj;
196
+ }
197
+
198
+ function type(type) {
199
+ return function (target, propertyKey) {
200
+ var prop = getIDEPropsPropertyObj(target, propertyKey);
201
+ prop.key = propertyKey;
202
+ prop.type = type;
203
+ };
204
+ }
205
+
206
+ function step(step) {
207
+ return function (target, propertyKey) {
208
+ var prop = getIDEPropsPropertyObj(target, propertyKey);
209
+ prop.step = step;
210
+ };
211
+ }
212
+
213
+ var NinePatch$2 = function (_super) {
214
+ __extends(NinePatch, _super);
215
+
216
+ function NinePatch() {
217
+ var _this = _super !== null && _super.apply(this, arguments) || this;
218
+
219
+ _this.resource = '';
220
+ _this.spriteName = '';
221
+ _this.leftWidth = 0;
222
+ _this.topHeight = 0;
223
+ _this.rightWidth = 0;
224
+ _this.bottomHeight = 0;
225
+ return _this;
226
+ }
227
+
228
+ NinePatch.prototype.init = function (obj) {
229
+ this.resource = obj.resource;
230
+ this.spriteName = obj.spriteName;
231
+ this.leftWidth = obj.leftWidth;
232
+ this.topHeight = obj.topHeight;
233
+ this.rightWidth = obj.rightWidth;
234
+ this.bottomHeight = obj.bottomHeight;
235
+ };
236
+
237
+ NinePatch.componentName = 'NinePatch';
238
+
239
+ __decorate([type('string')], NinePatch.prototype, "resource", void 0);
240
+
241
+ __decorate([type('string')], NinePatch.prototype, "spriteName", void 0);
242
+
243
+ __decorate([type('number'), step(1)], NinePatch.prototype, "leftWidth", void 0);
244
+
245
+ __decorate([type('number'), step(1)], NinePatch.prototype, "topHeight", void 0);
246
+
247
+ __decorate([type('number'), step(1)], NinePatch.prototype, "rightWidth", void 0);
248
+
249
+ __decorate([type('number'), step(1)], NinePatch.prototype, "bottomHeight", void 0);
250
+
251
+ return NinePatch;
252
+ }(eva_js.Component);
253
+
254
+ var NinePatch$3 = NinePatch$2;
255
+ var resourceKeySplit = '_s|r|c_';
256
+
257
+ var NinePatch = function (_super) {
258
+ __extends(NinePatch, _super);
259
+
260
+ function NinePatch() {
261
+ var _this = _super !== null && _super.apply(this, arguments) || this;
262
+
263
+ _this.name = 'NinePatch';
264
+ _this.ninePatch = {};
265
+ return _this;
266
+ }
267
+
268
+ NinePatch.prototype.init = function () {
269
+ this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
270
+ this.renderSystem.rendererManager.register(this);
271
+ };
272
+
273
+ NinePatch.prototype.rendererUpdate = function (gameObject) {
274
+ var _a = gameObject.transform.size,
275
+ width = _a.width,
276
+ height = _a.height;
277
+
278
+ if (this.ninePatch[gameObject.id]) {
279
+ this.ninePatch[gameObject.id].width = width;
280
+ this.ninePatch[gameObject.id].height = height;
281
+ }
282
+ };
283
+
284
+ NinePatch.prototype.componentChanged = function (changed) {
285
+ return __awaiter(this, void 0, void 0, function () {
286
+ return __generator(this, function (_a) {
287
+ if (changed.componentName === 'NinePatch') {
288
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
289
+ this.add(changed);
290
+ } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
291
+ this.remove(changed);
292
+ } else {
293
+ this.remove(changed);
294
+ this.add(changed);
295
+ }
296
+ }
297
+
298
+ return [2];
299
+ });
300
+ });
301
+ };
302
+
303
+ NinePatch.prototype.add = function (changed) {
304
+ return __awaiter(this, void 0, void 0, function () {
305
+ var component, _a, type, data, img, leftWidth, topHeight, rightWidth, bottomHeight, np;
306
+
307
+ return __generator(this, function (_b) {
308
+ switch (_b.label) {
309
+ case 0:
310
+ component = changed.component;
311
+ return [4, eva_js.resource.getResource(component.resource)];
312
+
313
+ case 1:
314
+ _a = _b.sent(), type = _a.type, data = _a.data;
315
+
316
+ if (!data) {
317
+ throw new Error("GameObject:" + changed.gameObject.name + "'s NinePatch resource load error");
318
+ }
319
+
320
+ if (type === eva_js.RESOURCE_TYPE.SPRITE) {
321
+ img = component.resource + resourceKeySplit + component.spriteName;
322
+ } else {
323
+ img = data.image;
324
+ }
325
+
326
+ leftWidth = component.leftWidth, topHeight = component.topHeight, rightWidth = component.rightWidth, bottomHeight = component.bottomHeight;
327
+ np = new rendererAdapter.NinePatch(img, leftWidth, topHeight, rightWidth, bottomHeight);
328
+ this.ninePatch[changed.gameObject.id] = np;
329
+ component.ninePatch = np;
330
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(np, 0);
331
+ return [2];
332
+ }
333
+ });
334
+ });
335
+ };
336
+
337
+ NinePatch.prototype.remove = function (changed) {
338
+ var sprite = this.ninePatch[changed.gameObject.id];
339
+
340
+ if (sprite) {
341
+ this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite);
342
+ delete this.ninePatch[changed.gameObject.id];
343
+ sprite.destroy({
344
+ children: true
345
+ });
346
+ }
347
+ };
348
+
349
+ NinePatch.systemName = 'NinePatch';
350
+ NinePatch = __decorate([eva_js.decorators.componentObserver({
351
+ NinePatch: ['resource', 'spriteName', 'leftWidth', 'topHeight', 'rightWidth', 'bottomHeight']
352
+ })], NinePatch);
353
+ return NinePatch;
354
+ }(pluginRenderer.Renderer);
355
+
356
+ var NinePatch$1 = NinePatch;
357
+ exports.NinePatch = NinePatch$3;
358
+ exports.NinePatchSystem = NinePatch$1;
359
+ Object.defineProperty(exports, '__esModule', {
360
+ value: true
361
+ });
362
+ return exports;
363
+ }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter);
@@ -0,0 +1 @@
1
+ this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.renderer=this.EVA.plugin.renderer||{},this.EVA.plugin.renderer.ninePatch=function(t,e,r,n){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function o(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function c(t,e,r,n){var i,o=arguments.length,c=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(c=(o<3?i(c):o>3?i(e,r,c):i(e,r))||c);return o>3&&c&&Object.defineProperty(e,r,c),c}function a(t,e,r,n){return new(r||(r=Promise))((function(i,o){function c(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(c,a)}h((n=n.apply(t,e||[])).next())}))}function h(t,e){var r,n,i,o,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,n=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(i=c.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(6===o[0]&&c.label<i[1]){c.label=i[1],i=o;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(o);break}i[2]&&c.ops.pop(),c.trys.pop();continue}o=e.call(t,c)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function s(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}function u(t){return function(e,r){var n=s(e,r);n.key=r,n.type=t}}function p(t){return function(e,r){s(e,r).step=t}}var d=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.resource="",e.spriteName="",e.leftWidth=0,e.topHeight=0,e.rightWidth=0,e.bottomHeight=0,e}return o(e,t),e.prototype.init=function(t){this.resource=t.resource,this.spriteName=t.spriteName,this.leftWidth=t.leftWidth,this.topHeight=t.topHeight,this.rightWidth=t.rightWidth,this.bottomHeight=t.bottomHeight},e.componentName="NinePatch",c([u("string")],e.prototype,"resource",void 0),c([u("string")],e.prototype,"spriteName",void 0),c([u("number"),p(1)],e.prototype,"leftWidth",void 0),c([u("number"),p(1)],e.prototype,"topHeight",void 0),c([u("number"),p(1)],e.prototype,"rightWidth",void 0),c([u("number"),p(1)],e.prototype,"bottomHeight",void 0),e}(e.Component),f=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="NinePatch",e.ninePatch={},e}return o(i,t),i.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},i.prototype.rendererUpdate=function(t){var e=t.transform.size,r=e.width,n=e.height;this.ninePatch[t.id]&&(this.ninePatch[t.id].width=r,this.ninePatch[t.id].height=n)},i.prototype.componentChanged=function(t){return a(this,void 0,void 0,(function(){return h(this,(function(r){return"NinePatch"===t.componentName&&(t.type===e.OBSERVER_TYPE.ADD?this.add(t):t.type===e.OBSERVER_TYPE.REMOVE?this.remove(t):(this.remove(t),this.add(t))),[2]}))}))},i.prototype.add=function(t){return a(this,void 0,void 0,(function(){var r,i,o,c,a,s,u,p,d,f;return h(this,(function(h){switch(h.label){case 0:return r=t.component,[4,e.resource.getResource(r.resource)];case 1:if(i=h.sent(),o=i.type,!(c=i.data))throw new Error("GameObject:"+t.gameObject.name+"'s NinePatch resource load error");return a=o===e.RESOURCE_TYPE.SPRITE?r.resource+"_s|r|c_"+r.spriteName:c.image,s=r.leftWidth,u=r.topHeight,p=r.rightWidth,d=r.bottomHeight,f=new n.NinePatch(a,s,u,p,d),this.ninePatch[t.gameObject.id]=f,r.ninePatch=f,this.containerManager.getContainer(t.gameObject.id).addChildAt(f,0),[2]}}))}))},i.prototype.remove=function(t){var e=this.ninePatch[t.gameObject.id];e&&(this.containerManager.getContainer(t.gameObject.id).removeChild(e),delete this.ninePatch[t.gameObject.id],e.destroy({children:!0}))},i.systemName="NinePatch",i=c([e.decorators.componentObserver({NinePatch:["resource","spriteName","leftWidth","topHeight","rightWidth","bottomHeight"]})],i)}(r.Renderer);return t.NinePatch=d,t.NinePatchSystem=f,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-nine-patch",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-alpha.1",
4
4
  "description": "@eva/plugin-renderer-nine-patch",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-nine-patch.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.2.0",
23
- "@eva/renderer-adapter": "1.2.0",
24
- "@eva/eva.js": "1.2.0",
22
+ "@eva/plugin-renderer": "1.3.0-alpha.1",
23
+ "@eva/renderer-adapter": "1.3.0-alpha.1",
24
+ "@eva/eva.js": "1.3.0-alpha.1",
25
25
  "@types/pixi.js": "^4.8.9"
26
26
  }
27
27
  }