@eva/plugin-renderer-nine-patch 2.0.0-beta.1 → 2.0.0-beta.2
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.
- package/dist/EVA.plugin.renderer.ninePatch.js +86 -200
- package/dist/EVA.plugin.renderer.ninePatch.min.js +1 -1
- package/dist/plugin-renderer-nine-patch.cjs.js +99 -159
- package/dist/plugin-renderer-nine-patch.cjs.prod.js +16 -1
- package/dist/plugin-renderer-nine-patch.esm.js +102 -162
- package/package.json +4 -4
|
@@ -3,23 +3,6 @@ window.EVA.plugin = window.EVA.plugin || {};
|
|
|
3
3
|
window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
|
|
4
4
|
var _EVA_IIFE_ninePatch = function (exports, eva_js, pluginRenderer, rendererAdapter) {
|
|
5
5
|
'use strict';
|
|
6
|
-
var extendStatics = function (d, b) {
|
|
7
|
-
extendStatics = Object.setPrototypeOf || {
|
|
8
|
-
__proto__: []
|
|
9
|
-
} instanceof Array && function (d, b) {
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
} || function (d, b) {
|
|
12
|
-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
13
|
-
};
|
|
14
|
-
return extendStatics(d, b);
|
|
15
|
-
};
|
|
16
|
-
function __extends(d, b) {
|
|
17
|
-
extendStatics(d, b);
|
|
18
|
-
function __() {
|
|
19
|
-
this.constructor = d;
|
|
20
|
-
}
|
|
21
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
22
|
-
}
|
|
23
6
|
function __decorate(decorators, target, key, desc) {
|
|
24
7
|
var c = arguments.length,
|
|
25
8
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -54,94 +37,6 @@ var _EVA_IIFE_ninePatch = function (exports, eva_js, pluginRenderer, rendererAda
|
|
|
54
37
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
38
|
});
|
|
56
39
|
}
|
|
57
|
-
function __generator(thisArg, body) {
|
|
58
|
-
var _ = {
|
|
59
|
-
label: 0,
|
|
60
|
-
sent: function () {
|
|
61
|
-
if (t[0] & 1) throw t[1];
|
|
62
|
-
return t[1];
|
|
63
|
-
},
|
|
64
|
-
trys: [],
|
|
65
|
-
ops: []
|
|
66
|
-
},
|
|
67
|
-
f,
|
|
68
|
-
y,
|
|
69
|
-
t,
|
|
70
|
-
g;
|
|
71
|
-
return g = {
|
|
72
|
-
next: verb(0),
|
|
73
|
-
"throw": verb(1),
|
|
74
|
-
"return": verb(2)
|
|
75
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
76
|
-
return this;
|
|
77
|
-
}), g;
|
|
78
|
-
function verb(n) {
|
|
79
|
-
return function (v) {
|
|
80
|
-
return step([n, v]);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function step(op) {
|
|
84
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
85
|
-
while (_) try {
|
|
86
|
-
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;
|
|
87
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
88
|
-
switch (op[0]) {
|
|
89
|
-
case 0:
|
|
90
|
-
case 1:
|
|
91
|
-
t = op;
|
|
92
|
-
break;
|
|
93
|
-
case 4:
|
|
94
|
-
_.label++;
|
|
95
|
-
return {
|
|
96
|
-
value: op[1],
|
|
97
|
-
done: false
|
|
98
|
-
};
|
|
99
|
-
case 5:
|
|
100
|
-
_.label++;
|
|
101
|
-
y = op[1];
|
|
102
|
-
op = [0];
|
|
103
|
-
continue;
|
|
104
|
-
case 7:
|
|
105
|
-
op = _.ops.pop();
|
|
106
|
-
_.trys.pop();
|
|
107
|
-
continue;
|
|
108
|
-
default:
|
|
109
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
110
|
-
_ = 0;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
114
|
-
_.label = op[1];
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
118
|
-
_.label = t[1];
|
|
119
|
-
t = op;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (t && _.label < t[2]) {
|
|
123
|
-
_.label = t[2];
|
|
124
|
-
_.ops.push(op);
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (t[2]) _.ops.pop();
|
|
128
|
-
_.trys.pop();
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
op = body.call(thisArg, _);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
op = [6, e];
|
|
134
|
-
y = 0;
|
|
135
|
-
} finally {
|
|
136
|
-
f = t = 0;
|
|
137
|
-
}
|
|
138
|
-
if (op[0] & 5) throw op[1];
|
|
139
|
-
return {
|
|
140
|
-
value: op[0] ? op[1] : void 0,
|
|
141
|
-
done: true
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
40
|
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
146
41
|
if (!target.constructor.IDEProps) {
|
|
147
42
|
target.constructor.IDEProps = {};
|
|
@@ -165,111 +60,103 @@ var _EVA_IIFE_ninePatch = function (exports, eva_js, pluginRenderer, rendererAda
|
|
|
165
60
|
prop.step = step;
|
|
166
61
|
};
|
|
167
62
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
_this.bottomHeight = 0;
|
|
178
|
-
return _this;
|
|
63
|
+
class NinePatch$2 extends eva_js.Component {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments);
|
|
66
|
+
this.resource = '';
|
|
67
|
+
this.spriteName = '';
|
|
68
|
+
this.leftWidth = 0;
|
|
69
|
+
this.topHeight = 0;
|
|
70
|
+
this.rightWidth = 0;
|
|
71
|
+
this.bottomHeight = 0;
|
|
179
72
|
}
|
|
180
|
-
|
|
73
|
+
init(obj) {
|
|
181
74
|
this.resource = obj.resource;
|
|
182
75
|
this.spriteName = obj.spriteName;
|
|
183
76
|
this.leftWidth = obj.leftWidth;
|
|
184
77
|
this.topHeight = obj.topHeight;
|
|
185
78
|
this.rightWidth = obj.rightWidth;
|
|
186
79
|
this.bottomHeight = obj.bottomHeight;
|
|
187
|
-
};
|
|
188
|
-
NinePatch.componentName = 'NinePatch';
|
|
189
|
-
__decorate([type('string')], NinePatch.prototype, "resource", void 0);
|
|
190
|
-
__decorate([type('string')], NinePatch.prototype, "spriteName", void 0);
|
|
191
|
-
__decorate([type('number'), step(1)], NinePatch.prototype, "leftWidth", void 0);
|
|
192
|
-
__decorate([type('number'), step(1)], NinePatch.prototype, "topHeight", void 0);
|
|
193
|
-
__decorate([type('number'), step(1)], NinePatch.prototype, "rightWidth", void 0);
|
|
194
|
-
__decorate([type('number'), step(1)], NinePatch.prototype, "bottomHeight", void 0);
|
|
195
|
-
return NinePatch;
|
|
196
|
-
}(eva_js.Component);
|
|
197
|
-
var NinePatch$3 = NinePatch$2;
|
|
198
|
-
var resourceKeySplit = '_s|r|c_';
|
|
199
|
-
var NinePatch = function (_super) {
|
|
200
|
-
__extends(NinePatch, _super);
|
|
201
|
-
function NinePatch() {
|
|
202
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
203
|
-
_this.name = 'NinePatch';
|
|
204
|
-
_this.ninePatch = {};
|
|
205
|
-
return _this;
|
|
206
80
|
}
|
|
207
|
-
|
|
81
|
+
}
|
|
82
|
+
NinePatch$2.componentName = 'NinePatch';
|
|
83
|
+
__decorate([type('string')], NinePatch$2.prototype, "resource", void 0);
|
|
84
|
+
__decorate([type('string')], NinePatch$2.prototype, "spriteName", void 0);
|
|
85
|
+
__decorate([type('number'), step(1)], NinePatch$2.prototype, "leftWidth", void 0);
|
|
86
|
+
__decorate([type('number'), step(1)], NinePatch$2.prototype, "topHeight", void 0);
|
|
87
|
+
__decorate([type('number'), step(1)], NinePatch$2.prototype, "rightWidth", void 0);
|
|
88
|
+
__decorate([type('number'), step(1)], NinePatch$2.prototype, "bottomHeight", void 0);
|
|
89
|
+
const resourceKeySplit = '_s|r|c_';
|
|
90
|
+
let NinePatch = class NinePatch extends pluginRenderer.Renderer {
|
|
91
|
+
constructor() {
|
|
92
|
+
super(...arguments);
|
|
93
|
+
this.name = 'NinePatch';
|
|
94
|
+
this.ninePatch = {};
|
|
95
|
+
}
|
|
96
|
+
init() {
|
|
208
97
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
209
98
|
this.renderSystem.rendererManager.register(this);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
width
|
|
214
|
-
height
|
|
99
|
+
}
|
|
100
|
+
rendererUpdate(gameObject) {
|
|
101
|
+
const {
|
|
102
|
+
width,
|
|
103
|
+
height
|
|
104
|
+
} = gameObject.transform.size;
|
|
215
105
|
if (this.ninePatch[gameObject.id]) {
|
|
216
106
|
this.ninePatch[gameObject.id].width = width;
|
|
217
107
|
this.ninePatch[gameObject.id].height = height;
|
|
218
108
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
-
|
|
223
|
-
if (changed.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this.add(changed);
|
|
231
|
-
}
|
|
109
|
+
}
|
|
110
|
+
componentChanged(changed) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
if (changed.componentName === 'NinePatch') {
|
|
113
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
114
|
+
this.add(changed);
|
|
115
|
+
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
116
|
+
this.remove(changed);
|
|
117
|
+
} else {
|
|
118
|
+
this.remove(changed);
|
|
119
|
+
this.add(changed);
|
|
232
120
|
}
|
|
233
|
-
|
|
234
|
-
});
|
|
121
|
+
}
|
|
235
122
|
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
123
|
+
}
|
|
124
|
+
add(changed) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const component = changed.component;
|
|
127
|
+
const gameObjectId = changed.gameObject.id;
|
|
128
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
129
|
+
const {
|
|
130
|
+
type,
|
|
131
|
+
data
|
|
132
|
+
} = yield eva_js.resource.getResource(component.resource);
|
|
133
|
+
if (!this.validateAsyncId(gameObjectId, asyncId)) return;
|
|
134
|
+
if (!data) {
|
|
135
|
+
console.error(`GameObject:${changed.gameObject.name}'s NinePatch resource load error`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let img;
|
|
139
|
+
if (type === eva_js.RESOURCE_TYPE.SPRITE) {
|
|
140
|
+
img = component.resource + resourceKeySplit + component.spriteName;
|
|
141
|
+
} else {
|
|
142
|
+
img = data.image;
|
|
143
|
+
}
|
|
144
|
+
const {
|
|
145
|
+
leftWidth,
|
|
146
|
+
topHeight,
|
|
147
|
+
rightWidth,
|
|
148
|
+
bottomHeight
|
|
149
|
+
} = component;
|
|
150
|
+
const np = new rendererAdapter.NinePatch(img, leftWidth, topHeight, rightWidth, bottomHeight);
|
|
151
|
+
this.ninePatch[changed.gameObject.id] = np;
|
|
152
|
+
component.ninePatch = np;
|
|
153
|
+
this.containerManager.getContainer(changed.gameObject.id).addChildAt(np, 0);
|
|
267
154
|
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
155
|
+
}
|
|
156
|
+
remove(changed) {
|
|
157
|
+
const gameObjectId = changed.gameObject.id;
|
|
271
158
|
this.increaseAsyncId(gameObjectId);
|
|
272
|
-
|
|
159
|
+
const sprite = this.ninePatch[gameObjectId];
|
|
273
160
|
if (sprite) {
|
|
274
161
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite);
|
|
275
162
|
delete this.ninePatch[changed.gameObject.id];
|
|
@@ -277,15 +164,14 @@ var _EVA_IIFE_ninePatch = function (exports, eva_js, pluginRenderer, rendererAda
|
|
|
277
164
|
children: true
|
|
278
165
|
});
|
|
279
166
|
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}(pluginRenderer.Renderer);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
NinePatch.systemName = 'NinePatch';
|
|
170
|
+
NinePatch = __decorate([eva_js.decorators.componentObserver({
|
|
171
|
+
NinePatch: ['resource', 'spriteName', 'leftWidth', 'topHeight', 'rightWidth', 'bottomHeight']
|
|
172
|
+
})], NinePatch);
|
|
287
173
|
var NinePatch$1 = NinePatch;
|
|
288
|
-
exports.NinePatch = NinePatch$
|
|
174
|
+
exports.NinePatch = NinePatch$2;
|
|
289
175
|
exports.NinePatchSystem = NinePatch$1;
|
|
290
176
|
Object.defineProperty(exports, '__esModule', {
|
|
291
177
|
value: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_ninePatch=function(t,
|
|
1
|
+
window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_ninePatch=function(e,t,i,n){"use strict";function r(e,t,i,n){var r,o=arguments.length,c=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(c=(o<3?r(c):o>3?r(t,i,c):r(t,i))||c);return o>3&&c&&Object.defineProperty(t,i,c),c}function o(e,t,i,n){return new(i||(i=Promise))((function(r,o){function c(e){try{h(n.next(e))}catch(e){o(e)}}function s(e){try{h(n.throw(e))}catch(e){o(e)}}function h(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(c,s)}h((n=n.apply(e,t||[])).next())}))}function c(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}function s(e){return function(t,i){var n=c(t,i);n.key=i,n.type=e}}function h(e){return function(t,i){c(t,i).step=e}}class d extends t.Component{constructor(){super(...arguments),this.resource="",this.spriteName="",this.leftWidth=0,this.topHeight=0,this.rightWidth=0,this.bottomHeight=0}init(e){this.resource=e.resource,this.spriteName=e.spriteName,this.leftWidth=e.leftWidth,this.topHeight=e.topHeight,this.rightWidth=e.rightWidth,this.bottomHeight=e.bottomHeight}}d.componentName="NinePatch",r([s("string")],d.prototype,"resource",void 0),r([s("string")],d.prototype,"spriteName",void 0),r([s("number"),h(1)],d.prototype,"leftWidth",void 0),r([s("number"),h(1)],d.prototype,"topHeight",void 0),r([s("number"),h(1)],d.prototype,"rightWidth",void 0),r([s("number"),h(1)],d.prototype,"bottomHeight",void 0);let a=class extends i.Renderer{constructor(){super(...arguments),this.name="NinePatch",this.ninePatch={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.ninePatch[e.id]&&(this.ninePatch[e.id].width=t,this.ninePatch[e.id].height=i)}componentChanged(e){return o(this,void 0,void 0,(function*(){"NinePatch"===e.componentName&&(e.type===t.OBSERVER_TYPE.ADD?this.add(e):e.type===t.OBSERVER_TYPE.REMOVE?this.remove(e):(this.remove(e),this.add(e)))}))}add(e){return o(this,void 0,void 0,(function*(){const i=e.component,r=e.gameObject.id,o=this.increaseAsyncId(r),{type:c,data:s}=yield t.resource.getResource(i.resource);if(!this.validateAsyncId(r,o))return;if(!s)return void console.error(`GameObject:${e.gameObject.name}'s NinePatch resource load error`);let h;h=c===t.RESOURCE_TYPE.SPRITE?i.resource+"_s|r|c_"+i.spriteName:s.image;const{leftWidth:d,topHeight:a,rightWidth:u,bottomHeight:p}=i,g=new n.NinePatch(h,d,a,u,p);this.ninePatch[e.gameObject.id]=g,i.ninePatch=g,this.containerManager.getContainer(e.gameObject.id).addChildAt(g,0)}))}remove(e){const t=e.gameObject.id;this.increaseAsyncId(t);const i=this.ninePatch[t];i&&(this.containerManager.getContainer(e.gameObject.id).removeChild(i),delete this.ninePatch[e.gameObject.id],i.destroy({children:!0}))}};a.systemName="NinePatch",a=r([t.decorators.componentObserver({NinePatch:["resource","spriteName","leftWidth","topHeight","rightWidth","bottomHeight"]})],a);var u=a;return e.NinePatch=d,e.NinePatchSystem=u,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);window.EVA.plugin.renderer.ninePatch=window.EVA.plugin.renderer.ninePatch||_EVA_IIFE_ninePatch;
|
|
@@ -21,20 +21,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
21
21
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
22
22
|
and limitations under the License.
|
|
23
23
|
***************************************************************************** */
|
|
24
|
-
/* global Reflect, Promise */
|
|
25
|
-
|
|
26
|
-
var extendStatics = function(d, b) {
|
|
27
|
-
extendStatics = Object.setPrototypeOf ||
|
|
28
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
29
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
30
|
-
return extendStatics(d, b);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function __extends(d, b) {
|
|
34
|
-
extendStatics(d, b);
|
|
35
|
-
function __() { this.constructor = d; }
|
|
36
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
|
-
}
|
|
38
24
|
|
|
39
25
|
function __decorate(decorators, target, key, desc) {
|
|
40
26
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -50,177 +36,131 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
50
36
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
51
37
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
52
38
|
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function __generator(thisArg, body) {
|
|
56
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
57
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
-
function step(op) {
|
|
60
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
-
while (_) try {
|
|
62
|
-
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;
|
|
63
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
-
switch (op[0]) {
|
|
65
|
-
case 0: case 1: t = op; break;
|
|
66
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
-
default:
|
|
70
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
-
if (t[2]) _.ops.pop();
|
|
75
|
-
_.trys.pop(); continue;
|
|
76
|
-
}
|
|
77
|
-
op = body.call(thisArg, _);
|
|
78
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
-
}
|
|
81
39
|
}
|
|
82
40
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
_this.bottomHeight = 0;
|
|
93
|
-
return _this;
|
|
41
|
+
class NinePatch$2 extends eva_js.Component {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.resource = '';
|
|
45
|
+
this.spriteName = '';
|
|
46
|
+
this.leftWidth = 0;
|
|
47
|
+
this.topHeight = 0;
|
|
48
|
+
this.rightWidth = 0;
|
|
49
|
+
this.bottomHeight = 0;
|
|
94
50
|
}
|
|
95
|
-
|
|
51
|
+
init(obj) {
|
|
96
52
|
this.resource = obj.resource;
|
|
97
53
|
this.spriteName = obj.spriteName;
|
|
98
54
|
this.leftWidth = obj.leftWidth;
|
|
99
55
|
this.topHeight = obj.topHeight;
|
|
100
56
|
this.rightWidth = obj.rightWidth;
|
|
101
57
|
this.bottomHeight = obj.bottomHeight;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}(eva_js.Component));
|
|
128
|
-
var NinePatch$3 = NinePatch$2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
NinePatch$2.componentName = 'NinePatch';
|
|
61
|
+
__decorate([
|
|
62
|
+
inspectorDecorator.type('string')
|
|
63
|
+
], NinePatch$2.prototype, "resource", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
inspectorDecorator.type('string')
|
|
66
|
+
], NinePatch$2.prototype, "spriteName", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
inspectorDecorator.type('number'),
|
|
69
|
+
inspectorDecorator.step(1)
|
|
70
|
+
], NinePatch$2.prototype, "leftWidth", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
inspectorDecorator.type('number'),
|
|
73
|
+
inspectorDecorator.step(1)
|
|
74
|
+
], NinePatch$2.prototype, "topHeight", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
inspectorDecorator.type('number'),
|
|
77
|
+
inspectorDecorator.step(1)
|
|
78
|
+
], NinePatch$2.prototype, "rightWidth", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
inspectorDecorator.type('number'),
|
|
81
|
+
inspectorDecorator.step(1)
|
|
82
|
+
], NinePatch$2.prototype, "bottomHeight", void 0);
|
|
129
83
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
_this.ninePatch = {};
|
|
137
|
-
return _this;
|
|
84
|
+
const resourceKeySplit = '_s|r|c_';
|
|
85
|
+
let NinePatch = class NinePatch extends pluginRenderer.Renderer {
|
|
86
|
+
constructor() {
|
|
87
|
+
super(...arguments);
|
|
88
|
+
this.name = 'NinePatch';
|
|
89
|
+
this.ninePatch = {};
|
|
138
90
|
}
|
|
139
|
-
|
|
91
|
+
init() {
|
|
140
92
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
141
93
|
this.renderSystem.rendererManager.register(this);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
94
|
+
}
|
|
95
|
+
rendererUpdate(gameObject) {
|
|
96
|
+
const { width, height } = gameObject.transform.size;
|
|
145
97
|
if (this.ninePatch[gameObject.id]) {
|
|
146
98
|
this.ninePatch[gameObject.id].width = width;
|
|
147
99
|
this.ninePatch[gameObject.id].height = height;
|
|
148
100
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
|
|
153
|
-
if (changed.
|
|
154
|
-
|
|
155
|
-
this.add(changed);
|
|
156
|
-
}
|
|
157
|
-
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
158
|
-
this.remove(changed);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
this.remove(changed);
|
|
162
|
-
this.add(changed);
|
|
163
|
-
}
|
|
101
|
+
}
|
|
102
|
+
componentChanged(changed) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (changed.componentName === 'NinePatch') {
|
|
105
|
+
if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
|
|
106
|
+
this.add(changed);
|
|
164
107
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var component, gameObjectId, asyncId, _a, type, data, img, leftWidth, topHeight, rightWidth, bottomHeight, np;
|
|
172
|
-
return __generator(this, function (_b) {
|
|
173
|
-
switch (_b.label) {
|
|
174
|
-
case 0:
|
|
175
|
-
component = changed.component;
|
|
176
|
-
gameObjectId = changed.gameObject.id;
|
|
177
|
-
asyncId = this.increaseAsyncId(gameObjectId);
|
|
178
|
-
return [4, eva_js.resource.getResource(component.resource)];
|
|
179
|
-
case 1:
|
|
180
|
-
_a = _b.sent(), type = _a.type, data = _a.data;
|
|
181
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
182
|
-
return [2];
|
|
183
|
-
if (!data) {
|
|
184
|
-
console.error("GameObject:" + changed.gameObject.name + "'s NinePatch resource load error");
|
|
185
|
-
return [2];
|
|
186
|
-
}
|
|
187
|
-
if (type === eva_js.RESOURCE_TYPE.SPRITE) {
|
|
188
|
-
img = component.resource + resourceKeySplit + component.spriteName;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
img = data.image;
|
|
192
|
-
}
|
|
193
|
-
leftWidth = component.leftWidth, topHeight = component.topHeight, rightWidth = component.rightWidth, bottomHeight = component.bottomHeight;
|
|
194
|
-
np = new rendererAdapter.NinePatch(img, leftWidth, topHeight, rightWidth, bottomHeight);
|
|
195
|
-
this.ninePatch[changed.gameObject.id] = np;
|
|
196
|
-
component.ninePatch = np;
|
|
197
|
-
this.containerManager
|
|
198
|
-
.getContainer(changed.gameObject.id)
|
|
199
|
-
.addChildAt(np, 0);
|
|
200
|
-
return [2];
|
|
108
|
+
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
109
|
+
this.remove(changed);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.remove(changed);
|
|
113
|
+
this.add(changed);
|
|
201
114
|
}
|
|
202
|
-
}
|
|
115
|
+
}
|
|
203
116
|
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
117
|
+
}
|
|
118
|
+
add(changed) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const component = changed.component;
|
|
121
|
+
const gameObjectId = changed.gameObject.id;
|
|
122
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
123
|
+
const { type, data } = yield eva_js.resource.getResource(component.resource);
|
|
124
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
125
|
+
return;
|
|
126
|
+
if (!data) {
|
|
127
|
+
console.error(`GameObject:${changed.gameObject.name}'s NinePatch resource load error`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let img;
|
|
131
|
+
if (type === eva_js.RESOURCE_TYPE.SPRITE) {
|
|
132
|
+
img = component.resource + resourceKeySplit + component.spriteName;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
img = data.image;
|
|
136
|
+
}
|
|
137
|
+
const { leftWidth, topHeight, rightWidth, bottomHeight } = component;
|
|
138
|
+
const np = new rendererAdapter.NinePatch(img, leftWidth, topHeight, rightWidth, bottomHeight);
|
|
139
|
+
this.ninePatch[changed.gameObject.id] = np;
|
|
140
|
+
component.ninePatch = np;
|
|
141
|
+
this.containerManager
|
|
142
|
+
.getContainer(changed.gameObject.id)
|
|
143
|
+
.addChildAt(np, 0);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
remove(changed) {
|
|
147
|
+
const gameObjectId = changed.gameObject.id;
|
|
207
148
|
this.increaseAsyncId(gameObjectId);
|
|
208
|
-
|
|
149
|
+
const sprite = this.ninePatch[gameObjectId];
|
|
209
150
|
if (sprite) {
|
|
210
151
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite);
|
|
211
152
|
delete this.ninePatch[changed.gameObject.id];
|
|
212
153
|
sprite.destroy({ children: true });
|
|
213
154
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}(pluginRenderer.Renderer));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
NinePatch.systemName = 'NinePatch';
|
|
158
|
+
NinePatch = __decorate([
|
|
159
|
+
eva_js.decorators.componentObserver({
|
|
160
|
+
NinePatch: ['resource', 'spriteName', 'leftWidth', 'topHeight', 'rightWidth', 'bottomHeight'],
|
|
161
|
+
})
|
|
162
|
+
], NinePatch);
|
|
223
163
|
var NinePatch$1 = NinePatch;
|
|
224
164
|
|
|
225
|
-
exports.NinePatch = NinePatch$
|
|
165
|
+
exports.NinePatch = NinePatch$2;
|
|
226
166
|
exports.NinePatchSystem = NinePatch$1;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter");
|
|
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 n(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var h=e.length-1;h>=0;h--)(n=e[h])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s}function o(e,t,i,r){return new(i||(i=Promise))((function(n,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function h(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){e.done?n(e.value):new i((function(t){t(e.value)})).then(s,h)}c((r=r.apply(e,t||[])).next())}))}class s extends e.Component{constructor(){super(...arguments),this.resource="",this.spriteName="",this.leftWidth=0,this.topHeight=0,this.rightWidth=0,this.bottomHeight=0}init(e){this.resource=e.resource,this.spriteName=e.spriteName,this.leftWidth=e.leftWidth,this.topHeight=e.topHeight,this.rightWidth=e.rightWidth,this.bottomHeight=e.bottomHeight}}s.componentName="NinePatch",n([t.type("string")],s.prototype,"resource",void 0),n([t.type("string")],s.prototype,"spriteName",void 0),n([t.type("number"),t.step(1)],s.prototype,"leftWidth",void 0),n([t.type("number"),t.step(1)],s.prototype,"topHeight",void 0),n([t.type("number"),t.step(1)],s.prototype,"rightWidth",void 0),n([t.type("number"),t.step(1)],s.prototype,"bottomHeight",void 0);let h=class extends i.Renderer{constructor(){super(...arguments),this.name="NinePatch",this.ninePatch={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(e){const{width:t,height:i}=e.transform.size;this.ninePatch[e.id]&&(this.ninePatch[e.id].width=t,this.ninePatch[e.id].height=i)}componentChanged(t){return o(this,void 0,void 0,(function*(){"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)))}))}add(t){return o(this,void 0,void 0,(function*(){const i=t.component,n=t.gameObject.id,o=this.increaseAsyncId(n),{type:s,data:h}=yield e.resource.getResource(i.resource);if(!this.validateAsyncId(n,o))return;if(!h)return void console.error(`GameObject:${t.gameObject.name}'s NinePatch resource load error`);let c;c=s===e.RESOURCE_TYPE.SPRITE?i.resource+"_s|r|c_"+i.spriteName:h.image;const{leftWidth:a,topHeight:d,rightWidth:p,bottomHeight:m}=i,u=new r.NinePatch(c,a,d,p,m);this.ninePatch[t.gameObject.id]=u,i.ninePatch=u,this.containerManager.getContainer(t.gameObject.id).addChildAt(u,0)}))}remove(e){const t=e.gameObject.id;this.increaseAsyncId(t);const i=this.ninePatch[t];i&&(this.containerManager.getContainer(e.gameObject.id).removeChild(i),delete this.ninePatch[e.gameObject.id],i.destroy({children:!0}))}};h.systemName="NinePatch",h=n([e.decorators.componentObserver({NinePatch:["resource","spriteName","leftWidth","topHeight","rightWidth","bottomHeight"]})],h);var c=h;exports.NinePatch=s,exports.NinePatchSystem=c;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Component, decorators, OBSERVER_TYPE,
|
|
1
|
+
import { Component, decorators, OBSERVER_TYPE, resource, RESOURCE_TYPE } from '@eva/eva.js';
|
|
2
2
|
import { type, step } from '@eva/inspector-decorator';
|
|
3
|
-
import {
|
|
4
|
-
import { NinePatch as NinePatch$
|
|
3
|
+
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
|
+
import { NinePatch as NinePatch$3 } from '@eva/renderer-adapter';
|
|
5
5
|
|
|
6
6
|
/*! *****************************************************************************
|
|
7
7
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -17,20 +17,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
17
17
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
18
18
|
and limitations under the License.
|
|
19
19
|
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
21
|
-
|
|
22
|
-
var extendStatics = function(d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
26
|
-
return extendStatics(d, b);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function __extends(d, b) {
|
|
30
|
-
extendStatics(d, b);
|
|
31
|
-
function __() { this.constructor = d; }
|
|
32
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
33
|
-
}
|
|
34
20
|
|
|
35
21
|
function __decorate(decorators, target, key, desc) {
|
|
36
22
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -46,176 +32,130 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
46
32
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
47
33
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
34
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function __generator(thisArg, body) {
|
|
52
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
53
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
54
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
55
|
-
function step(op) {
|
|
56
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while (_) try {
|
|
58
|
-
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;
|
|
59
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
60
|
-
switch (op[0]) {
|
|
61
|
-
case 0: case 1: t = op; break;
|
|
62
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
63
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
64
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
65
|
-
default:
|
|
66
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
67
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
68
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
69
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
70
|
-
if (t[2]) _.ops.pop();
|
|
71
|
-
_.trys.pop(); continue;
|
|
72
|
-
}
|
|
73
|
-
op = body.call(thisArg, _);
|
|
74
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
75
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
76
|
-
}
|
|
77
35
|
}
|
|
78
36
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
_this.bottomHeight = 0;
|
|
89
|
-
return _this;
|
|
37
|
+
class NinePatch$2 extends Component {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(...arguments);
|
|
40
|
+
this.resource = '';
|
|
41
|
+
this.spriteName = '';
|
|
42
|
+
this.leftWidth = 0;
|
|
43
|
+
this.topHeight = 0;
|
|
44
|
+
this.rightWidth = 0;
|
|
45
|
+
this.bottomHeight = 0;
|
|
90
46
|
}
|
|
91
|
-
|
|
47
|
+
init(obj) {
|
|
92
48
|
this.resource = obj.resource;
|
|
93
49
|
this.spriteName = obj.spriteName;
|
|
94
50
|
this.leftWidth = obj.leftWidth;
|
|
95
51
|
this.topHeight = obj.topHeight;
|
|
96
52
|
this.rightWidth = obj.rightWidth;
|
|
97
53
|
this.bottomHeight = obj.bottomHeight;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}(Component));
|
|
124
|
-
var NinePatch$3 = NinePatch$2;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
NinePatch$2.componentName = 'NinePatch';
|
|
57
|
+
__decorate([
|
|
58
|
+
type('string')
|
|
59
|
+
], NinePatch$2.prototype, "resource", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
type('string')
|
|
62
|
+
], NinePatch$2.prototype, "spriteName", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
type('number'),
|
|
65
|
+
step(1)
|
|
66
|
+
], NinePatch$2.prototype, "leftWidth", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
type('number'),
|
|
69
|
+
step(1)
|
|
70
|
+
], NinePatch$2.prototype, "topHeight", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
type('number'),
|
|
73
|
+
step(1)
|
|
74
|
+
], NinePatch$2.prototype, "rightWidth", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
type('number'),
|
|
77
|
+
step(1)
|
|
78
|
+
], NinePatch$2.prototype, "bottomHeight", void 0);
|
|
125
79
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
_this.ninePatch = {};
|
|
133
|
-
return _this;
|
|
80
|
+
const resourceKeySplit = '_s|r|c_';
|
|
81
|
+
let NinePatch = class NinePatch extends Renderer {
|
|
82
|
+
constructor() {
|
|
83
|
+
super(...arguments);
|
|
84
|
+
this.name = 'NinePatch';
|
|
85
|
+
this.ninePatch = {};
|
|
134
86
|
}
|
|
135
|
-
|
|
87
|
+
init() {
|
|
136
88
|
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
137
89
|
this.renderSystem.rendererManager.register(this);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
90
|
+
}
|
|
91
|
+
rendererUpdate(gameObject) {
|
|
92
|
+
const { width, height } = gameObject.transform.size;
|
|
141
93
|
if (this.ninePatch[gameObject.id]) {
|
|
142
94
|
this.ninePatch[gameObject.id].width = width;
|
|
143
95
|
this.ninePatch[gameObject.id].height = height;
|
|
144
96
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
|
|
149
|
-
if (changed.
|
|
150
|
-
|
|
151
|
-
this.add(changed);
|
|
152
|
-
}
|
|
153
|
-
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
154
|
-
this.remove(changed);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
this.remove(changed);
|
|
158
|
-
this.add(changed);
|
|
159
|
-
}
|
|
97
|
+
}
|
|
98
|
+
componentChanged(changed) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (changed.componentName === 'NinePatch') {
|
|
101
|
+
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
102
|
+
this.add(changed);
|
|
160
103
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
var component, gameObjectId, asyncId, _a, type, data, img, leftWidth, topHeight, rightWidth, bottomHeight, np;
|
|
168
|
-
return __generator(this, function (_b) {
|
|
169
|
-
switch (_b.label) {
|
|
170
|
-
case 0:
|
|
171
|
-
component = changed.component;
|
|
172
|
-
gameObjectId = changed.gameObject.id;
|
|
173
|
-
asyncId = this.increaseAsyncId(gameObjectId);
|
|
174
|
-
return [4, resource.getResource(component.resource)];
|
|
175
|
-
case 1:
|
|
176
|
-
_a = _b.sent(), type = _a.type, data = _a.data;
|
|
177
|
-
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
178
|
-
return [2];
|
|
179
|
-
if (!data) {
|
|
180
|
-
console.error("GameObject:" + changed.gameObject.name + "'s NinePatch resource load error");
|
|
181
|
-
return [2];
|
|
182
|
-
}
|
|
183
|
-
if (type === RESOURCE_TYPE.SPRITE) {
|
|
184
|
-
img = component.resource + resourceKeySplit + component.spriteName;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
img = data.image;
|
|
188
|
-
}
|
|
189
|
-
leftWidth = component.leftWidth, topHeight = component.topHeight, rightWidth = component.rightWidth, bottomHeight = component.bottomHeight;
|
|
190
|
-
np = new NinePatch$4(img, leftWidth, topHeight, rightWidth, bottomHeight);
|
|
191
|
-
this.ninePatch[changed.gameObject.id] = np;
|
|
192
|
-
component.ninePatch = np;
|
|
193
|
-
this.containerManager
|
|
194
|
-
.getContainer(changed.gameObject.id)
|
|
195
|
-
.addChildAt(np, 0);
|
|
196
|
-
return [2];
|
|
104
|
+
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
105
|
+
this.remove(changed);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.remove(changed);
|
|
109
|
+
this.add(changed);
|
|
197
110
|
}
|
|
198
|
-
}
|
|
111
|
+
}
|
|
199
112
|
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
113
|
+
}
|
|
114
|
+
add(changed) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const component = changed.component;
|
|
117
|
+
const gameObjectId = changed.gameObject.id;
|
|
118
|
+
const asyncId = this.increaseAsyncId(gameObjectId);
|
|
119
|
+
const { type, data } = yield resource.getResource(component.resource);
|
|
120
|
+
if (!this.validateAsyncId(gameObjectId, asyncId))
|
|
121
|
+
return;
|
|
122
|
+
if (!data) {
|
|
123
|
+
console.error(`GameObject:${changed.gameObject.name}'s NinePatch resource load error`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
let img;
|
|
127
|
+
if (type === RESOURCE_TYPE.SPRITE) {
|
|
128
|
+
img = component.resource + resourceKeySplit + component.spriteName;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
img = data.image;
|
|
132
|
+
}
|
|
133
|
+
const { leftWidth, topHeight, rightWidth, bottomHeight } = component;
|
|
134
|
+
const np = new NinePatch$3(img, leftWidth, topHeight, rightWidth, bottomHeight);
|
|
135
|
+
this.ninePatch[changed.gameObject.id] = np;
|
|
136
|
+
component.ninePatch = np;
|
|
137
|
+
this.containerManager
|
|
138
|
+
.getContainer(changed.gameObject.id)
|
|
139
|
+
.addChildAt(np, 0);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
remove(changed) {
|
|
143
|
+
const gameObjectId = changed.gameObject.id;
|
|
203
144
|
this.increaseAsyncId(gameObjectId);
|
|
204
|
-
|
|
145
|
+
const sprite = this.ninePatch[gameObjectId];
|
|
205
146
|
if (sprite) {
|
|
206
147
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(sprite);
|
|
207
148
|
delete this.ninePatch[changed.gameObject.id];
|
|
208
149
|
sprite.destroy({ children: true });
|
|
209
150
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}(Renderer));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
NinePatch.systemName = 'NinePatch';
|
|
154
|
+
NinePatch = __decorate([
|
|
155
|
+
decorators.componentObserver({
|
|
156
|
+
NinePatch: ['resource', 'spriteName', 'leftWidth', 'topHeight', 'rightWidth', 'bottomHeight'],
|
|
157
|
+
})
|
|
158
|
+
], NinePatch);
|
|
219
159
|
var NinePatch$1 = NinePatch;
|
|
220
160
|
|
|
221
|
-
export { NinePatch$
|
|
161
|
+
export { NinePatch$2 as NinePatch, NinePatch$1 as NinePatchSystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-nine-patch",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "@eva/plugin-renderer-nine-patch",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-nine-patch.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.0-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.0-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.0-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.0-beta.2",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.0-beta.2",
|
|
24
|
+
"@eva/eva.js": "2.0.0-beta.2"
|
|
25
25
|
}
|
|
26
26
|
}
|