@eva/plugin-renderer-mask 2.1.0-beta.2 → 2.1.0-beta.3
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/package.json +4 -4
- package/dist/EVA.plugin.renderer.mask.js +0 -454
- package/dist/EVA.plugin.renderer.mask.min.js +0 -1
- package/dist/plugin-renderer-mask.cjs.js +0 -453
- package/dist/plugin-renderer-mask.cjs.prod.js +0 -1
- package/dist/plugin-renderer-mask.d.ts +0 -149
- package/dist/plugin-renderer-mask.esm.js +0 -448
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
import { Component, OBSERVER_TYPE, decorators, resource } from '@eva/eva.js';
|
|
2
|
-
import { type } from '@eva/inspector-decorator';
|
|
3
|
-
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
|
-
import { Graphics, Sprite } from '@eva/renderer-adapter';
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
|
|
21
|
-
function __rest(s, e) {
|
|
22
|
-
var t = {};
|
|
23
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
-
t[p] = s[p];
|
|
25
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
-
t[p[i]] = s[p[i]];
|
|
29
|
-
}
|
|
30
|
-
return t;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function __decorate(decorators, target, key, desc) {
|
|
34
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
35
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
36
|
-
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;
|
|
37
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function __metadata(metadataKey, metadataValue) {
|
|
41
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
55
|
-
var e = new Error(message);
|
|
56
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
var MASK_TYPE;
|
|
60
|
-
(function (MASK_TYPE) {
|
|
61
|
-
MASK_TYPE["Circle"] = "Circle";
|
|
62
|
-
MASK_TYPE["Ellipse"] = "Ellipse";
|
|
63
|
-
MASK_TYPE["Rect"] = "Rect";
|
|
64
|
-
MASK_TYPE["RoundedRect"] = "RoundedRect";
|
|
65
|
-
MASK_TYPE["Polygon"] = "Polygon";
|
|
66
|
-
MASK_TYPE["Img"] = "Img";
|
|
67
|
-
MASK_TYPE["Sprite"] = "Sprite";
|
|
68
|
-
})(MASK_TYPE || (MASK_TYPE = {}));
|
|
69
|
-
/**
|
|
70
|
-
* 遮罩组件
|
|
71
|
-
*
|
|
72
|
-
* Mask 组件用于裁剪游戏对象的显示区域,只显示遮罩形状内的内容。
|
|
73
|
-
* 支持多种遮罩形状(矩形、圆形、多边形、图片、精灵等),
|
|
74
|
-
* 适用于头像裁剪、窗口遮罩、特殊形状显示等场景。
|
|
75
|
-
*
|
|
76
|
-
* 遮罩类型:
|
|
77
|
-
* - Circle - 圆形遮罩
|
|
78
|
-
* - Ellipse - 椭圆形遮罩
|
|
79
|
-
* - Rect - 矩形遮罩
|
|
80
|
-
* - RoundedRect - 圆角矩形遮罩
|
|
81
|
-
* - Polygon - 多边形遮罩
|
|
82
|
-
* - Img - 图片遮罩(基于图片 alpha 通道)
|
|
83
|
-
* - Sprite - 精灵遮罩
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* // 圆形头像遮罩
|
|
88
|
-
* const avatar = new GameObject('avatar');
|
|
89
|
-
* avatar.addComponent(new Img({ resource: 'userAvatar' }));
|
|
90
|
-
* avatar.addComponent(new Mask({
|
|
91
|
-
* type: MASK_TYPE.Circle,
|
|
92
|
-
* style: {
|
|
93
|
-
* x: 50, // 圆心 x
|
|
94
|
-
* y: 50, // 圆心 y
|
|
95
|
-
* radius: 50 // 半径
|
|
96
|
-
* }
|
|
97
|
-
* }));
|
|
98
|
-
*
|
|
99
|
-
* // 矩形遮罩
|
|
100
|
-
* avatar.addComponent(new Mask({
|
|
101
|
-
* type: MASK_TYPE.Rect,
|
|
102
|
-
* style: {
|
|
103
|
-
* x: 0, y: 0,
|
|
104
|
-
* width: 100,
|
|
105
|
-
* height: 100
|
|
106
|
-
* }
|
|
107
|
-
* }));
|
|
108
|
-
*
|
|
109
|
-
* // 使用图片作为遮罩
|
|
110
|
-
* avatar.addComponent(new Mask({
|
|
111
|
-
* type: MASK_TYPE.Img,
|
|
112
|
-
* resource: 'maskImage' // alpha 通道作为遮罩
|
|
113
|
-
* }));
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
class Mask$2 extends Component {
|
|
117
|
-
constructor(params) {
|
|
118
|
-
super(params);
|
|
119
|
-
/** 遮罩类型 */
|
|
120
|
-
// @decorators.IDEProp 复杂编辑后续添加
|
|
121
|
-
this.type = MASK_TYPE.Rect;
|
|
122
|
-
/** 遮罩样式配置 */
|
|
123
|
-
// @decorators.IDEProp 复杂编辑后续添加
|
|
124
|
-
this.style = {};
|
|
125
|
-
this.x = 0;
|
|
126
|
-
this.y = 0;
|
|
127
|
-
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
128
|
-
this.resource = '';
|
|
129
|
-
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
130
|
-
this.spriteName = '';
|
|
131
|
-
/** 是否启用遮罩 */
|
|
132
|
-
this.enabled = true;
|
|
133
|
-
this.init(params);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 初始化组件
|
|
137
|
-
* @param obj - 初始化参数
|
|
138
|
-
*/
|
|
139
|
-
init(obj) {
|
|
140
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
141
|
-
if (!obj)
|
|
142
|
-
return;
|
|
143
|
-
const { style } = obj, rest = __rest(obj, ["style"]);
|
|
144
|
-
Object.assign(this, rest);
|
|
145
|
-
this.style = Object.assign(Object.assign(Object.assign({}, this.style), style), { x: (_d = (_b = (_a = obj.x) !== null && _a !== void 0 ? _a : style === null || style === void 0 ? void 0 : style.x) !== null && _b !== void 0 ? _b : (_c = this.style) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : this.x, y: (_h = (_f = (_e = obj.y) !== null && _e !== void 0 ? _e : style === null || style === void 0 ? void 0 : style.y) !== null && _f !== void 0 ? _f : (_g = this.style) === null || _g === void 0 ? void 0 : _g.y) !== null && _h !== void 0 ? _h : this.y, radius: (_k = (_j = obj.radius) !== null && _j !== void 0 ? _j : style === null || style === void 0 ? void 0 : style.radius) !== null && _k !== void 0 ? _k : (_l = this.style) === null || _l === void 0 ? void 0 : _l.radius, width: (_o = (_m = obj.width) !== null && _m !== void 0 ? _m : style === null || style === void 0 ? void 0 : style.width) !== null && _o !== void 0 ? _o : (_p = this.style) === null || _p === void 0 ? void 0 : _p.width, height: (_r = (_q = obj.height) !== null && _q !== void 0 ? _q : style === null || style === void 0 ? void 0 : style.height) !== null && _r !== void 0 ? _r : (_s = this.style) === null || _s === void 0 ? void 0 : _s.height, paths: (_u = (_t = obj.paths) !== null && _t !== void 0 ? _t : style === null || style === void 0 ? void 0 : style.paths) !== null && _u !== void 0 ? _u : (_v = this.style) === null || _v === void 0 ? void 0 : _v.paths });
|
|
146
|
-
this.x = (_w = this.style.x) !== null && _w !== void 0 ? _w : 0;
|
|
147
|
-
this.y = (_x = this.style.y) !== null && _x !== void 0 ? _x : 0;
|
|
148
|
-
this.radius = this.style.radius;
|
|
149
|
-
this.width = this.style.width;
|
|
150
|
-
this.height = this.style.height;
|
|
151
|
-
this.paths = this.style.paths;
|
|
152
|
-
}
|
|
153
|
-
destroy() {
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/** 组件名称 */
|
|
158
|
-
Mask$2.componentName = 'Mask';
|
|
159
|
-
__decorate([
|
|
160
|
-
type('number'),
|
|
161
|
-
__metadata("design:type", Number)
|
|
162
|
-
], Mask$2.prototype, "x", void 0);
|
|
163
|
-
__decorate([
|
|
164
|
-
type('number'),
|
|
165
|
-
__metadata("design:type", Number)
|
|
166
|
-
], Mask$2.prototype, "y", void 0);
|
|
167
|
-
__decorate([
|
|
168
|
-
type('number'),
|
|
169
|
-
__metadata("design:type", Number)
|
|
170
|
-
], Mask$2.prototype, "radius", void 0);
|
|
171
|
-
__decorate([
|
|
172
|
-
type('number'),
|
|
173
|
-
__metadata("design:type", Number)
|
|
174
|
-
], Mask$2.prototype, "width", void 0);
|
|
175
|
-
__decorate([
|
|
176
|
-
type('number'),
|
|
177
|
-
__metadata("design:type", Number)
|
|
178
|
-
], Mask$2.prototype, "height", void 0);
|
|
179
|
-
__decorate([
|
|
180
|
-
type('string'),
|
|
181
|
-
__metadata("design:type", String)
|
|
182
|
-
], Mask$2.prototype, "resource", void 0);
|
|
183
|
-
__decorate([
|
|
184
|
-
type('string'),
|
|
185
|
-
__metadata("design:type", String)
|
|
186
|
-
], Mask$2.prototype, "spriteName", void 0);
|
|
187
|
-
__decorate([
|
|
188
|
-
type('boolean'),
|
|
189
|
-
__metadata("design:type", Boolean)
|
|
190
|
-
], Mask$2.prototype, "enabled", void 0);
|
|
191
|
-
|
|
192
|
-
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
193
|
-
const propertyForGraphics = {
|
|
194
|
-
Circle: ['x', 'y', 'radius'],
|
|
195
|
-
Ellipse: ['x', 'y', 'width', 'height'],
|
|
196
|
-
Rect: ['x', 'y', 'width', 'height'],
|
|
197
|
-
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
198
|
-
Polygon: ['paths'],
|
|
199
|
-
};
|
|
200
|
-
const functionForGraphics = {
|
|
201
|
-
Circle: 'circle',
|
|
202
|
-
Ellipse: 'ellipse',
|
|
203
|
-
Rect: 'rect',
|
|
204
|
-
RoundedRect: 'roundRect',
|
|
205
|
-
Polygon: 'poly',
|
|
206
|
-
};
|
|
207
|
-
const maskTypeAliases = {
|
|
208
|
-
circle: MASK_TYPE.Circle,
|
|
209
|
-
ellipse: MASK_TYPE.Ellipse,
|
|
210
|
-
rect: MASK_TYPE.Rect,
|
|
211
|
-
roundedrect: MASK_TYPE.RoundedRect,
|
|
212
|
-
roundedRect: MASK_TYPE.RoundedRect,
|
|
213
|
-
polygon: MASK_TYPE.Polygon,
|
|
214
|
-
img: MASK_TYPE.Img,
|
|
215
|
-
image: MASK_TYPE.Img,
|
|
216
|
-
sprite: MASK_TYPE.Sprite,
|
|
217
|
-
};
|
|
218
|
-
function normalizeMaskType(type) {
|
|
219
|
-
if (!type)
|
|
220
|
-
return undefined;
|
|
221
|
-
if (Object.values(MASK_TYPE).includes(type))
|
|
222
|
-
return type;
|
|
223
|
-
return maskTypeAliases[String(type)] || maskTypeAliases[String(type).toLowerCase()];
|
|
224
|
-
}
|
|
225
|
-
let Mask = class Mask extends Renderer {
|
|
226
|
-
constructor() {
|
|
227
|
-
super(...arguments);
|
|
228
|
-
this.name = 'MaskSystem';
|
|
229
|
-
this.changedCache = {};
|
|
230
|
-
this.maskSpriteCache = {};
|
|
231
|
-
}
|
|
232
|
-
init() {
|
|
233
|
-
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
234
|
-
this.renderSystem.rendererManager.register(this);
|
|
235
|
-
}
|
|
236
|
-
rendererUpdate() {
|
|
237
|
-
this.changedCache = {};
|
|
238
|
-
}
|
|
239
|
-
componentChanged(changed) {
|
|
240
|
-
if (changed.component.name !== 'Mask')
|
|
241
|
-
return;
|
|
242
|
-
switch (changed.type) {
|
|
243
|
-
case OBSERVER_TYPE.ADD:
|
|
244
|
-
this.add(changed);
|
|
245
|
-
break;
|
|
246
|
-
case OBSERVER_TYPE.REMOVE:
|
|
247
|
-
this.remove(changed);
|
|
248
|
-
break;
|
|
249
|
-
case OBSERVER_TYPE.CHANGE:
|
|
250
|
-
this.change(changed);
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
add(changed) {
|
|
255
|
-
const component = changed.component;
|
|
256
|
-
if (component.enabled === false)
|
|
257
|
-
return;
|
|
258
|
-
const maskType = normalizeMaskType(component.type);
|
|
259
|
-
if (!maskType) {
|
|
260
|
-
throw new Error('no have Mask type: ' + component.type);
|
|
261
|
-
}
|
|
262
|
-
if (!component.style) {
|
|
263
|
-
throw new Error('no have Mask style: ' + component.type);
|
|
264
|
-
}
|
|
265
|
-
let mask;
|
|
266
|
-
switch (maskType) {
|
|
267
|
-
case MASK_TYPE.Circle:
|
|
268
|
-
mask = this.createGraphics(component);
|
|
269
|
-
break;
|
|
270
|
-
case MASK_TYPE.Ellipse:
|
|
271
|
-
mask = this.createGraphics(component);
|
|
272
|
-
break;
|
|
273
|
-
case MASK_TYPE.Rect:
|
|
274
|
-
mask = this.createGraphics(component);
|
|
275
|
-
break;
|
|
276
|
-
case MASK_TYPE.RoundedRect:
|
|
277
|
-
mask = this.createGraphics(component);
|
|
278
|
-
break;
|
|
279
|
-
case MASK_TYPE.Polygon:
|
|
280
|
-
mask = this.createGraphics(component);
|
|
281
|
-
break;
|
|
282
|
-
case MASK_TYPE.Img:
|
|
283
|
-
mask = this.createSprite(component);
|
|
284
|
-
break;
|
|
285
|
-
case MASK_TYPE.Sprite:
|
|
286
|
-
mask = this.createSprite(component);
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
if (!mask) {
|
|
290
|
-
throw new Error('no have mask instance, check your mask params: ' + component.type);
|
|
291
|
-
}
|
|
292
|
-
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
293
|
-
container.mask = mask;
|
|
294
|
-
container.addChild(mask);
|
|
295
|
-
}
|
|
296
|
-
remove(changed) {
|
|
297
|
-
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
298
|
-
if (!(container === null || container === void 0 ? void 0 : container.mask))
|
|
299
|
-
return;
|
|
300
|
-
container.removeChild(container.mask);
|
|
301
|
-
container.mask.destroy({ children: true });
|
|
302
|
-
container.mask = null;
|
|
303
|
-
delete this.maskSpriteCache[changed.gameObject.id];
|
|
304
|
-
}
|
|
305
|
-
change(changed) {
|
|
306
|
-
if (this.changedCache[changed.gameObject.id])
|
|
307
|
-
return;
|
|
308
|
-
const component = changed.component;
|
|
309
|
-
if (changed.prop.prop[0] === 'enabled') {
|
|
310
|
-
this.changedCache[changed.gameObject.id] = true;
|
|
311
|
-
if (component.enabled === false) {
|
|
312
|
-
this.remove(changed);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
this.add(changed);
|
|
316
|
-
}
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
if (changed.prop.prop[0] === 'type') {
|
|
320
|
-
this.changedCache[changed.gameObject.id] = true;
|
|
321
|
-
const maskType = normalizeMaskType(component.type);
|
|
322
|
-
const lastType = normalizeMaskType(component._lastType);
|
|
323
|
-
if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(maskType) > -1 || lastType !== maskType) {
|
|
324
|
-
this.remove(changed);
|
|
325
|
-
this.add(changed);
|
|
326
|
-
component._lastType = component.type;
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
this.redrawGraphics(changed);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
else if (['style', 'x', 'y', 'radius', 'width', 'height', 'paths'].indexOf(changed.prop.prop[0]) > -1) {
|
|
333
|
-
this.syncComponentStyle(component);
|
|
334
|
-
const maskType = normalizeMaskType(component.type);
|
|
335
|
-
if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(maskType) > -1) {
|
|
336
|
-
this.changeSpriteStyle(component);
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
this.redrawGraphics(changed);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
else if (changed.prop.prop[0] === 'resource') {
|
|
343
|
-
this.changedCache[changed.gameObject.id] = true;
|
|
344
|
-
this.changeSprite(component);
|
|
345
|
-
}
|
|
346
|
-
else if (changed.prop.prop[0] === 'spriteName') {
|
|
347
|
-
this.changedCache[changed.gameObject.id] = true;
|
|
348
|
-
this.changeSprite(component);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
createGraphics(component) {
|
|
352
|
-
const graphics = new Graphics();
|
|
353
|
-
this.draw(graphics, component);
|
|
354
|
-
return graphics;
|
|
355
|
-
}
|
|
356
|
-
redrawGraphics(changed) {
|
|
357
|
-
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
358
|
-
const graphics = container.mask;
|
|
359
|
-
graphics.clear();
|
|
360
|
-
this.draw(graphics, changed.component);
|
|
361
|
-
}
|
|
362
|
-
draw(graphics, component) {
|
|
363
|
-
const maskType = normalizeMaskType(component.type);
|
|
364
|
-
const style = this.syncComponentStyle(component);
|
|
365
|
-
const params = [];
|
|
366
|
-
for (const key of propertyForGraphics[maskType]) {
|
|
367
|
-
params.push(style[key]);
|
|
368
|
-
}
|
|
369
|
-
// @ts-ignore
|
|
370
|
-
graphics[functionForGraphics[maskType]](...params);
|
|
371
|
-
graphics.fill(0x000000);
|
|
372
|
-
}
|
|
373
|
-
createSprite(component) {
|
|
374
|
-
const sprite = new Sprite(null);
|
|
375
|
-
this.maskSpriteCache[component.gameObject.id] = sprite;
|
|
376
|
-
this.setSprite(component, sprite);
|
|
377
|
-
return sprite.sprite;
|
|
378
|
-
}
|
|
379
|
-
changeSpriteStyle(component) {
|
|
380
|
-
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
381
|
-
sprite.sprite.width = component.style.width;
|
|
382
|
-
sprite.sprite.height = component.style.height;
|
|
383
|
-
sprite.sprite.position.x = component.style.x;
|
|
384
|
-
sprite.sprite.position.y = component.style.y;
|
|
385
|
-
}
|
|
386
|
-
changeSprite(component) {
|
|
387
|
-
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
388
|
-
this.setSprite(component, sprite);
|
|
389
|
-
}
|
|
390
|
-
setSprite(component, sprite) {
|
|
391
|
-
var _a, _b;
|
|
392
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
const maskType = normalizeMaskType(component.type);
|
|
394
|
-
let res;
|
|
395
|
-
try {
|
|
396
|
-
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
397
|
-
res = yield resource.getResource(component.resource);
|
|
398
|
-
if (!this.validateAsyncId(component.gameObject.id, asyncId))
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
catch (e) {
|
|
402
|
-
throw new Error('mask resource load error');
|
|
403
|
-
}
|
|
404
|
-
if (maskType === MASK_TYPE.Sprite) {
|
|
405
|
-
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
406
|
-
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
407
|
-
if (texture) {
|
|
408
|
-
sprite.image = texture;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.image) {
|
|
413
|
-
sprite.image = res.data.image;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
sprite.sprite.width = component.style.width;
|
|
417
|
-
sprite.sprite.height = component.style.height;
|
|
418
|
-
sprite.sprite.position.x = component.style.x;
|
|
419
|
-
sprite.sprite.position.y = component.style.y;
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
syncComponentStyle(component) {
|
|
423
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
424
|
-
component.style = Object.assign(Object.assign({}, component.style), { x: (_c = (_a = component.x) !== null && _a !== void 0 ? _a : (_b = component.style) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 0, y: (_f = (_d = component.y) !== null && _d !== void 0 ? _d : (_e = component.style) === null || _e === void 0 ? void 0 : _e.y) !== null && _f !== void 0 ? _f : 0, radius: (_g = component.radius) !== null && _g !== void 0 ? _g : (_h = component.style) === null || _h === void 0 ? void 0 : _h.radius, width: (_j = component.width) !== null && _j !== void 0 ? _j : (_k = component.style) === null || _k === void 0 ? void 0 : _k.width, height: (_l = component.height) !== null && _l !== void 0 ? _l : (_m = component.style) === null || _m === void 0 ? void 0 : _m.height, paths: (_o = component.paths) !== null && _o !== void 0 ? _o : (_p = component.style) === null || _p === void 0 ? void 0 : _p.paths });
|
|
425
|
-
return component.style;
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
Mask.systemName = 'MaskSystem';
|
|
429
|
-
Mask = __decorate([
|
|
430
|
-
decorators.componentObserver({
|
|
431
|
-
Mask: [
|
|
432
|
-
'type',
|
|
433
|
-
{ prop: ['style'], deep: true },
|
|
434
|
-
'x',
|
|
435
|
-
'y',
|
|
436
|
-
'radius',
|
|
437
|
-
'width',
|
|
438
|
-
'height',
|
|
439
|
-
'paths',
|
|
440
|
-
'resource',
|
|
441
|
-
'spriteName',
|
|
442
|
-
'enabled',
|
|
443
|
-
],
|
|
444
|
-
})
|
|
445
|
-
], Mask);
|
|
446
|
-
var Mask$1 = Mask;
|
|
447
|
-
|
|
448
|
-
export { MASK_TYPE, Mask$2 as Mask, Mask$1 as MaskSystem };
|