@eva/plugin-renderer-mask 2.0.2 → 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.
- package/dist/EVA.plugin.renderer.mask.js +210 -45
- package/dist/EVA.plugin.renderer.mask.min.js +1 -1
- package/dist/plugin-renderer-mask.cjs.js +146 -39
- package/dist/plugin-renderer-mask.cjs.prod.js +1 -1
- package/dist/plugin-renderer-mask.d.ts +23 -7
- package/dist/plugin-renderer-mask.esm.js +142 -35
- package/package.json +5 -5
|
@@ -4,6 +4,14 @@ globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
|
4
4
|
globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
|
|
5
5
|
var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter) {
|
|
6
6
|
'use strict';
|
|
7
|
+
function __rest$1(s, e) {
|
|
8
|
+
var t = {};
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
10
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
7
15
|
function __decorate(decorators, target, key, desc) {
|
|
8
16
|
var c = arguments.length,
|
|
9
17
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -11,6 +19,9 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
11
19
|
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
20
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
21
|
}
|
|
22
|
+
function __metadata(metadataKey, metadataValue) {
|
|
23
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
24
|
+
}
|
|
14
25
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
15
26
|
function adopt(value) {
|
|
16
27
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -38,23 +49,106 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
38
49
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
50
|
});
|
|
40
51
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
function __rest(s, e) {
|
|
53
|
+
var t = {};
|
|
54
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
55
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
}
|
|
60
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
61
|
+
var e = new Error(message);
|
|
62
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
63
|
+
};
|
|
64
|
+
class SymbolKeysNotSupportedError extends Error {
|
|
65
|
+
constructor() {
|
|
66
|
+
super('Symbol keys are not supported yet!');
|
|
67
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
|
|
71
|
+
function transformBasicType(type) {
|
|
72
|
+
if (type === String) {
|
|
73
|
+
return 'string';
|
|
74
|
+
}
|
|
75
|
+
if (type === Number) {
|
|
76
|
+
return 'number';
|
|
77
|
+
}
|
|
78
|
+
if (type === Boolean) {
|
|
79
|
+
return 'boolean';
|
|
80
|
+
}
|
|
81
|
+
return 'unknown';
|
|
82
|
+
}
|
|
83
|
+
function defineLegacyIDEProp(target, propertyKey, patch) {
|
|
84
|
+
const constructor = target.constructor;
|
|
85
|
+
const current = constructor.IDEProps || {};
|
|
86
|
+
current[propertyKey] = _extends(_extends({
|
|
87
|
+
key: propertyKey
|
|
88
|
+
}, current[propertyKey]), patch);
|
|
89
|
+
constructor.IDEProps = current;
|
|
90
|
+
}
|
|
91
|
+
function defineTypes(target, key, options, returnTypeFunction) {
|
|
92
|
+
let type = Reflect.getMetadata('design:type', target, key);
|
|
93
|
+
let isArray = type === Array;
|
|
94
|
+
const str = transformBasicType(type);
|
|
95
|
+
if (str !== 'unknown') {
|
|
96
|
+
type = str;
|
|
44
97
|
}
|
|
45
|
-
if (
|
|
46
|
-
|
|
98
|
+
if (returnTypeFunction) {
|
|
99
|
+
const returnType = returnTypeFunction();
|
|
100
|
+
if (Array.isArray(returnType)) {
|
|
101
|
+
isArray = true;
|
|
102
|
+
type = returnType[0];
|
|
103
|
+
} else {
|
|
104
|
+
type = returnType;
|
|
105
|
+
}
|
|
47
106
|
}
|
|
48
|
-
|
|
49
|
-
|
|
107
|
+
const properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
|
|
108
|
+
const current = properties[key] || {};
|
|
109
|
+
const property = _extends(_extends(_extends({}, current), {
|
|
110
|
+
type,
|
|
111
|
+
isArray: isArray
|
|
112
|
+
}), options);
|
|
113
|
+
properties[key] = property;
|
|
114
|
+
Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
|
|
115
|
+
const legacyProperty = __rest(property, ["isArray"]);
|
|
116
|
+
defineLegacyIDEProp(target, key, legacyProperty);
|
|
50
117
|
}
|
|
51
118
|
function type(type) {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
119
|
+
return Field({
|
|
120
|
+
type
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
|
|
124
|
+
if (typeof returnTypeFuncOrOptions === 'function') {
|
|
125
|
+
return {
|
|
126
|
+
returnTypeFunc: returnTypeFuncOrOptions,
|
|
127
|
+
options: maybeOptions || {}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
options: returnTypeFuncOrOptions || {}
|
|
56
132
|
};
|
|
57
133
|
}
|
|
134
|
+
function Field(returnTypeFunction, maybeOptions) {
|
|
135
|
+
return (target, propertyKey) => {
|
|
136
|
+
if (typeof propertyKey === 'symbol') {
|
|
137
|
+
throw new SymbolKeysNotSupportedError();
|
|
138
|
+
}
|
|
139
|
+
const {
|
|
140
|
+
options,
|
|
141
|
+
returnTypeFunc
|
|
142
|
+
} = getTypeDecoratorParams(returnTypeFunction, maybeOptions);
|
|
143
|
+
defineTypes(target, propertyKey, options, returnTypeFunc);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
var ExecuteMode;
|
|
147
|
+
(function (ExecuteMode) {
|
|
148
|
+
ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
|
|
149
|
+
ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
|
|
150
|
+
ExecuteMode[ExecuteMode["All"] = 6] = "All";
|
|
151
|
+
})(ExecuteMode || (ExecuteMode = {}));
|
|
58
152
|
exports.MASK_TYPE = void 0;
|
|
59
153
|
(function (MASK_TYPE) {
|
|
60
154
|
MASK_TYPE["Circle"] = "Circle";
|
|
@@ -66,19 +160,53 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
66
160
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
67
161
|
})(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
|
|
68
162
|
class Mask$2 extends eva_js.Component {
|
|
69
|
-
constructor() {
|
|
70
|
-
super(
|
|
163
|
+
constructor(params) {
|
|
164
|
+
super(params);
|
|
165
|
+
this.type = exports.MASK_TYPE.Rect;
|
|
71
166
|
this.style = {};
|
|
167
|
+
this.x = 0;
|
|
168
|
+
this.y = 0;
|
|
72
169
|
this.resource = '';
|
|
73
170
|
this.spriteName = '';
|
|
171
|
+
this.enabled = true;
|
|
172
|
+
this.init(params);
|
|
74
173
|
}
|
|
75
174
|
init(obj) {
|
|
76
|
-
|
|
175
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
176
|
+
if (!obj) return;
|
|
177
|
+
const {
|
|
178
|
+
style
|
|
179
|
+
} = obj,
|
|
180
|
+
rest = __rest$1(obj, ["style"]);
|
|
181
|
+
_extends(this, rest);
|
|
182
|
+
this.style = _extends(_extends(_extends({}, this.style), style), {
|
|
183
|
+
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,
|
|
184
|
+
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,
|
|
185
|
+
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,
|
|
186
|
+
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,
|
|
187
|
+
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,
|
|
188
|
+
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
|
|
189
|
+
});
|
|
190
|
+
this.x = (_w = this.style.x) !== null && _w !== void 0 ? _w : 0;
|
|
191
|
+
this.y = (_x = this.style.y) !== null && _x !== void 0 ? _x : 0;
|
|
192
|
+
this.radius = this.style.radius;
|
|
193
|
+
this.width = this.style.width;
|
|
194
|
+
this.height = this.style.height;
|
|
195
|
+
this.paths = this.style.paths;
|
|
196
|
+
}
|
|
197
|
+
destroy() {
|
|
198
|
+
return this;
|
|
77
199
|
}
|
|
78
200
|
}
|
|
79
201
|
Mask$2.componentName = 'Mask';
|
|
80
|
-
__decorate([type('
|
|
81
|
-
__decorate([type('
|
|
202
|
+
__decorate([type('number'), __metadata("design:type", Number)], Mask$2.prototype, "x", void 0);
|
|
203
|
+
__decorate([type('number'), __metadata("design:type", Number)], Mask$2.prototype, "y", void 0);
|
|
204
|
+
__decorate([type('number'), __metadata("design:type", Number)], Mask$2.prototype, "radius", void 0);
|
|
205
|
+
__decorate([type('number'), __metadata("design:type", Number)], Mask$2.prototype, "width", void 0);
|
|
206
|
+
__decorate([type('number'), __metadata("design:type", Number)], Mask$2.prototype, "height", void 0);
|
|
207
|
+
__decorate([type('string'), __metadata("design:type", String)], Mask$2.prototype, "resource", void 0);
|
|
208
|
+
__decorate([type('string'), __metadata("design:type", String)], Mask$2.prototype, "spriteName", void 0);
|
|
209
|
+
__decorate([type('boolean'), __metadata("design:type", Boolean)], Mask$2.prototype, "enabled", void 0);
|
|
82
210
|
const resourceKeySplit = '_s|r|c_';
|
|
83
211
|
const propertyForGraphics = {
|
|
84
212
|
Circle: ['x', 'y', 'radius'],
|
|
@@ -94,20 +222,26 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
94
222
|
RoundedRect: 'roundRect',
|
|
95
223
|
Polygon: 'poly'
|
|
96
224
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
MASK_TYPE
|
|
100
|
-
MASK_TYPE
|
|
101
|
-
MASK_TYPE
|
|
102
|
-
MASK_TYPE
|
|
103
|
-
MASK_TYPE
|
|
104
|
-
MASK_TYPE
|
|
105
|
-
MASK_TYPE
|
|
106
|
-
|
|
225
|
+
const maskTypeAliases = {
|
|
226
|
+
circle: exports.MASK_TYPE.Circle,
|
|
227
|
+
ellipse: exports.MASK_TYPE.Ellipse,
|
|
228
|
+
rect: exports.MASK_TYPE.Rect,
|
|
229
|
+
roundedrect: exports.MASK_TYPE.RoundedRect,
|
|
230
|
+
roundedRect: exports.MASK_TYPE.RoundedRect,
|
|
231
|
+
polygon: exports.MASK_TYPE.Polygon,
|
|
232
|
+
img: exports.MASK_TYPE.Img,
|
|
233
|
+
image: exports.MASK_TYPE.Img,
|
|
234
|
+
sprite: exports.MASK_TYPE.Sprite
|
|
235
|
+
};
|
|
236
|
+
function normalizeMaskType(type) {
|
|
237
|
+
if (!type) return undefined;
|
|
238
|
+
if (Object.values(exports.MASK_TYPE).includes(type)) return type;
|
|
239
|
+
return maskTypeAliases[String(type)] || maskTypeAliases[String(type).toLowerCase()];
|
|
240
|
+
}
|
|
107
241
|
let Mask = class Mask extends pluginRenderer.Renderer {
|
|
108
242
|
constructor() {
|
|
109
243
|
super(...arguments);
|
|
110
|
-
this.name = '
|
|
244
|
+
this.name = 'MaskSystem';
|
|
111
245
|
this.changedCache = {};
|
|
112
246
|
this.maskSpriteCache = {};
|
|
113
247
|
}
|
|
@@ -134,33 +268,35 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
134
268
|
}
|
|
135
269
|
add(changed) {
|
|
136
270
|
const component = changed.component;
|
|
137
|
-
if (
|
|
271
|
+
if (component.enabled === false) return;
|
|
272
|
+
const maskType = normalizeMaskType(component.type);
|
|
273
|
+
if (!maskType) {
|
|
138
274
|
throw new Error('no have Mask type: ' + component.type);
|
|
139
275
|
}
|
|
140
276
|
if (!component.style) {
|
|
141
277
|
throw new Error('no have Mask style: ' + component.type);
|
|
142
278
|
}
|
|
143
279
|
let mask;
|
|
144
|
-
switch (
|
|
145
|
-
case MASK_TYPE.Circle:
|
|
280
|
+
switch (maskType) {
|
|
281
|
+
case exports.MASK_TYPE.Circle:
|
|
146
282
|
mask = this.createGraphics(component);
|
|
147
283
|
break;
|
|
148
|
-
case MASK_TYPE.Ellipse:
|
|
284
|
+
case exports.MASK_TYPE.Ellipse:
|
|
149
285
|
mask = this.createGraphics(component);
|
|
150
286
|
break;
|
|
151
|
-
case MASK_TYPE.Rect:
|
|
287
|
+
case exports.MASK_TYPE.Rect:
|
|
152
288
|
mask = this.createGraphics(component);
|
|
153
289
|
break;
|
|
154
|
-
case MASK_TYPE.RoundedRect:
|
|
290
|
+
case exports.MASK_TYPE.RoundedRect:
|
|
155
291
|
mask = this.createGraphics(component);
|
|
156
292
|
break;
|
|
157
|
-
case MASK_TYPE.Polygon:
|
|
293
|
+
case exports.MASK_TYPE.Polygon:
|
|
158
294
|
mask = this.createGraphics(component);
|
|
159
295
|
break;
|
|
160
|
-
case MASK_TYPE.Img:
|
|
296
|
+
case exports.MASK_TYPE.Img:
|
|
161
297
|
mask = this.createSprite(component);
|
|
162
298
|
break;
|
|
163
|
-
case MASK_TYPE.Sprite:
|
|
299
|
+
case exports.MASK_TYPE.Sprite:
|
|
164
300
|
mask = this.createSprite(component);
|
|
165
301
|
break;
|
|
166
302
|
}
|
|
@@ -173,6 +309,7 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
173
309
|
}
|
|
174
310
|
remove(changed) {
|
|
175
311
|
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
312
|
+
if (!(container === null || container === void 0 ? void 0 : container.mask)) return;
|
|
176
313
|
container.removeChild(container.mask);
|
|
177
314
|
container.mask.destroy({
|
|
178
315
|
children: true
|
|
@@ -183,17 +320,30 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
183
320
|
change(changed) {
|
|
184
321
|
if (this.changedCache[changed.gameObject.id]) return;
|
|
185
322
|
const component = changed.component;
|
|
323
|
+
if (changed.prop.prop[0] === 'enabled') {
|
|
324
|
+
this.changedCache[changed.gameObject.id] = true;
|
|
325
|
+
if (component.enabled === false) {
|
|
326
|
+
this.remove(changed);
|
|
327
|
+
} else {
|
|
328
|
+
this.add(changed);
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
186
332
|
if (changed.prop.prop[0] === 'type') {
|
|
187
333
|
this.changedCache[changed.gameObject.id] = true;
|
|
188
|
-
|
|
334
|
+
const maskType = normalizeMaskType(component.type);
|
|
335
|
+
const lastType = normalizeMaskType(component._lastType);
|
|
336
|
+
if ([exports.MASK_TYPE.Sprite, exports.MASK_TYPE.Img].indexOf(maskType) > -1 || lastType !== maskType) {
|
|
189
337
|
this.remove(changed);
|
|
190
338
|
this.add(changed);
|
|
191
339
|
component._lastType = component.type;
|
|
192
340
|
} else {
|
|
193
341
|
this.redrawGraphics(changed);
|
|
194
342
|
}
|
|
195
|
-
} else if (changed.prop.prop[0]
|
|
196
|
-
|
|
343
|
+
} else if (['style', 'x', 'y', 'radius', 'width', 'height', 'paths'].indexOf(changed.prop.prop[0]) > -1) {
|
|
344
|
+
this.syncComponentStyle(component);
|
|
345
|
+
const maskType = normalizeMaskType(component.type);
|
|
346
|
+
if ([exports.MASK_TYPE.Sprite, exports.MASK_TYPE.Img].indexOf(maskType) > -1) {
|
|
197
347
|
this.changeSpriteStyle(component);
|
|
198
348
|
} else {
|
|
199
349
|
this.redrawGraphics(changed);
|
|
@@ -218,11 +368,13 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
218
368
|
this.draw(graphics, changed.component);
|
|
219
369
|
}
|
|
220
370
|
draw(graphics, component) {
|
|
371
|
+
const maskType = normalizeMaskType(component.type);
|
|
372
|
+
const style = this.syncComponentStyle(component);
|
|
221
373
|
const params = [];
|
|
222
|
-
for (const key of propertyForGraphics[
|
|
223
|
-
params.push(
|
|
374
|
+
for (const key of propertyForGraphics[maskType]) {
|
|
375
|
+
params.push(style[key]);
|
|
224
376
|
}
|
|
225
|
-
graphics[functionForGraphics[
|
|
377
|
+
graphics[functionForGraphics[maskType]](...params);
|
|
226
378
|
graphics.fill(0x000000);
|
|
227
379
|
}
|
|
228
380
|
createSprite(component) {
|
|
@@ -245,6 +397,7 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
245
397
|
setSprite(component, sprite) {
|
|
246
398
|
var _a, _b;
|
|
247
399
|
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
const maskType = normalizeMaskType(component.type);
|
|
248
401
|
let res;
|
|
249
402
|
try {
|
|
250
403
|
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
@@ -253,7 +406,7 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
253
406
|
} catch (e) {
|
|
254
407
|
throw new Error('mask resource load error');
|
|
255
408
|
}
|
|
256
|
-
if (
|
|
409
|
+
if (maskType === exports.MASK_TYPE.Sprite) {
|
|
257
410
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
258
411
|
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
259
412
|
if (texture) {
|
|
@@ -270,13 +423,25 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
270
423
|
sprite.sprite.position.y = component.style.y;
|
|
271
424
|
});
|
|
272
425
|
}
|
|
426
|
+
syncComponentStyle(component) {
|
|
427
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
428
|
+
component.style = _extends(_extends({}, component.style), {
|
|
429
|
+
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,
|
|
430
|
+
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,
|
|
431
|
+
radius: (_g = component.radius) !== null && _g !== void 0 ? _g : (_h = component.style) === null || _h === void 0 ? void 0 : _h.radius,
|
|
432
|
+
width: (_j = component.width) !== null && _j !== void 0 ? _j : (_k = component.style) === null || _k === void 0 ? void 0 : _k.width,
|
|
433
|
+
height: (_l = component.height) !== null && _l !== void 0 ? _l : (_m = component.style) === null || _m === void 0 ? void 0 : _m.height,
|
|
434
|
+
paths: (_o = component.paths) !== null && _o !== void 0 ? _o : (_p = component.style) === null || _p === void 0 ? void 0 : _p.paths
|
|
435
|
+
});
|
|
436
|
+
return component.style;
|
|
437
|
+
}
|
|
273
438
|
};
|
|
274
|
-
Mask.systemName = '
|
|
439
|
+
Mask.systemName = 'MaskSystem';
|
|
275
440
|
Mask = __decorate([eva_js.decorators.componentObserver({
|
|
276
441
|
Mask: ['type', {
|
|
277
442
|
prop: ['style'],
|
|
278
443
|
deep: true
|
|
279
|
-
}, 'resource', 'spriteName']
|
|
444
|
+
}, 'x', 'y', 'radius', 'width', 'height', 'paths', 'resource', 'spriteName', 'enabled']
|
|
280
445
|
})], Mask);
|
|
281
446
|
var Mask$1 = Mask;
|
|
282
447
|
exports.Mask = Mask$2;
|
|
@@ -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 i in r)({}).hasOwnProperty.call(r,i)&&(e[i]=r[i])}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_mask=function(e,t,r,i){"use strict";function s(e,t,r,i){var s,n=arguments.length,o=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(o=(n<3?s(o):n>3?s(t,r,o):s(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function n(e,t,r,i){return new(r||(r=Promise))(function(s,n){function o(e){try{c(i.next(e))}catch(e){n(e)}}function a(e){try{c(i.throw(e))}catch(e){n(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((i=i.apply(e,t||[])).next())})}function o(e){return function(t,r){var i=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);i.key=r,i.type=e}}e.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(e.MASK_TYPE||(e.MASK_TYPE={}));class a extends t.Component{constructor(){super(...arguments),this.style={},this.resource="",this.spriteName=""}init(e){_extends(this,e)}}a.componentName="Mask",s([o("string")],a.prototype,"resource",void 0),s([o("string")],a.prototype,"spriteName",void 0);const c={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},p={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"};var h;!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(h||(h={}));let l=class extends r.Renderer{constructor(){super(...arguments),this.name="Mask",this.changedCache={},this.maskSpriteCache={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(){this.changedCache={}}componentChanged(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=e.component;if(!(t.type in h))throw new Error("no have Mask type: "+t.type);if(!t.style)throw new Error("no have Mask style: "+t.type);let r;switch(t.type){case h.Circle:case h.Ellipse:case h.Rect:case h.RoundedRect:case h.Polygon:r=this.createGraphics(t);break;case h.Img:case h.Sprite:r=this.createSprite(t)}if(!r)throw new Error("no have mask instance, check your mask params: "+t.type);const i=this.containerManager.getContainer(e.gameObject.id);i.mask=r,i.addChild(r)}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]}change(e){if(this.changedCache[e.gameObject.id])return;const t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[h.Sprite,h.Img].indexOf(t.type)>-1||t._lastType!==t.type?(this.remove(e),this.add(e),t._lastType=t.type):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[h.Sprite,h.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}createGraphics(e){const t=new i.Graphics;return this.draw(t,e),t}redrawGraphics(e){const t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)}draw(e,t){const r=[];for(const e of c[t.type])r.push(t.style[e]);e[p[t.type]](...r),e.fill(0)}createSprite(e){const t=new i.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite}changeSpriteStyle(e){const t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y}changeSprite(e){const t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)}setSprite(e,r){var i,s;return n(this,void 0,void 0,function*(){let n;try{const r=this.increaseAsyncId(e.gameObject.id);if(n=yield t.resource.getResource(e.resource),!this.validateAsyncId(e.gameObject.id,r))return}catch(e){throw new Error("mask resource load error")}if(e.type===h.Sprite){const t=e.resource+"_s|r|c_"+e.spriteName,s=null===(i=null==n?void 0:n.instance)||void 0===i?void 0:i[t];s&&(r.image=s)}else(null===(s=null==n?void 0:n.data)||void 0===s?void 0:s.image)&&(r.image=n.data.image);r.sprite.width=e.style.width,r.sprite.height=e.style.height,r.sprite.position.x=e.style.x,r.sprite.position.y=e.style.y})}};l.systemName="Mask",l=s([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],l);var d=l;return e.Mask=a,e.MaskSystem=d,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.mask=globalThis.EVA.plugin.renderer.mask||_EVA_IIFE_mask;
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)({}).hasOwnProperty.call(i,r)&&(e[r]=i[r])}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_mask=function(e,t,i,r){"use strict";function n(e,t,i,r){var n,s=arguments.length,o=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,r);else for(var l=e.length-1;l>=0;l--)(n=e[l])&&(o=(s<3?n(o):s>3?n(t,i,o):n(t,i))||o);return s>3&&o&&Object.defineProperty(t,i,o),o}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function o(e,t,i,r){return new(i||(i=Promise))(function(n,s){function o(e){try{a(r.next(e))}catch(e){s(e)}}function l(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,l)}a((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class l extends Error{constructor(){super("Symbol keys are not supported yet!"),Object.setPrototypeOf(this,new.target.prototype)}}const a="IDE_PROPERTY_METADATA";function d(e,t,i,r){let n=Reflect.getMetadata("design:type",e,t),s=n===Array;const o=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(n);if("unknown"!==o&&(n=o),r){const e=r();Array.isArray(e)?(s=!0,n=e[0]):n=e}const l=Reflect.getMetadata(a,e.constructor)||{},d=_extends(_extends(_extends({},l[t]||{}),{type:n,isArray:s}),i);l[t]=d,Reflect.defineMetadata(a,l,e.constructor);!function(e,t,i){const r=e.constructor,n=r.IDEProps||{};n[t]=_extends(_extends({key:t},n[t]),i),r.IDEProps=n}(e,t,function(e,t){var i={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(i[r[n]]=e[r[n]])}return i}(d,["isArray"]))}function c(e){return t={type:e},(e,r)=>{if("symbol"==typeof r)throw new l;const{options:n,returnTypeFunc:s}=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(t,i);d(e,r,n,s)};var t,i}var p,h;!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(p||(p={})),e.MASK_TYPE=void 0,(h=e.MASK_TYPE||(e.MASK_TYPE={})).Circle="Circle",h.Ellipse="Ellipse",h.Rect="Rect",h.RoundedRect="RoundedRect",h.Polygon="Polygon",h.Img="Img",h.Sprite="Sprite";class u extends t.Component{constructor(t){super(t),this.type=e.MASK_TYPE.Rect,this.style={},this.x=0,this.y=0,this.resource="",this.spriteName="",this.enabled=!0,this.init(t)}init(e){var t,i,r,n,s,o,l,a,d,c,p,h,u,y,g,v,m,f,E,S,b,_;if(!e)return;const{style:w}=e;_extends(this,function(e,t){var i={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(i[r[n]]=e[r[n]])}return i}(e,["style"])),this.style=_extends(_extends(_extends({},this.style),w),{x:null!==(n=null!==(i=null!==(t=e.x)&&void 0!==t?t:null==w?void 0:w.x)&&void 0!==i?i:null===(r=this.style)||void 0===r?void 0:r.x)&&void 0!==n?n:this.x,y:null!==(a=null!==(o=null!==(s=e.y)&&void 0!==s?s:null==w?void 0:w.y)&&void 0!==o?o:null===(l=this.style)||void 0===l?void 0:l.y)&&void 0!==a?a:this.y,radius:null!==(c=null!==(d=e.radius)&&void 0!==d?d:null==w?void 0:w.radius)&&void 0!==c?c:null===(p=this.style)||void 0===p?void 0:p.radius,width:null!==(u=null!==(h=e.width)&&void 0!==h?h:null==w?void 0:w.width)&&void 0!==u?u:null===(y=this.style)||void 0===y?void 0:y.width,height:null!==(v=null!==(g=e.height)&&void 0!==g?g:null==w?void 0:w.height)&&void 0!==v?v:null===(m=this.style)||void 0===m?void 0:m.height,paths:null!==(E=null!==(f=e.paths)&&void 0!==f?f:null==w?void 0:w.paths)&&void 0!==E?E:null===(S=this.style)||void 0===S?void 0:S.paths}),this.x=null!==(b=this.style.x)&&void 0!==b?b:0,this.y=null!==(_=this.style.y)&&void 0!==_?_:0,this.radius=this.style.radius,this.width=this.style.width,this.height=this.style.height,this.paths=this.style.paths}destroy(){return this}}u.componentName="Mask",n([c("number"),s("design:type",Number)],u.prototype,"x",void 0),n([c("number"),s("design:type",Number)],u.prototype,"y",void 0),n([c("number"),s("design:type",Number)],u.prototype,"radius",void 0),n([c("number"),s("design:type",Number)],u.prototype,"width",void 0),n([c("number"),s("design:type",Number)],u.prototype,"height",void 0),n([c("string"),s("design:type",String)],u.prototype,"resource",void 0),n([c("string"),s("design:type",String)],u.prototype,"spriteName",void 0),n([c("boolean"),s("design:type",Boolean)],u.prototype,"enabled",void 0);const y={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},g={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"},v={circle:e.MASK_TYPE.Circle,ellipse:e.MASK_TYPE.Ellipse,rect:e.MASK_TYPE.Rect,roundedrect:e.MASK_TYPE.RoundedRect,roundedRect:e.MASK_TYPE.RoundedRect,polygon:e.MASK_TYPE.Polygon,img:e.MASK_TYPE.Img,image:e.MASK_TYPE.Img,sprite:e.MASK_TYPE.Sprite};function m(t){if(t)return Object.values(e.MASK_TYPE).includes(t)?t:v[String(t)]||v[String(t).toLowerCase()]}let f=class extends i.Renderer{constructor(){super(...arguments),this.name="MaskSystem",this.changedCache={},this.maskSpriteCache={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(){this.changedCache={}}componentChanged(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(t){const i=t.component;if(!1===i.enabled)return;const r=m(i.type);if(!r)throw new Error("no have Mask type: "+i.type);if(!i.style)throw new Error("no have Mask style: "+i.type);let n;switch(r){case e.MASK_TYPE.Circle:case e.MASK_TYPE.Ellipse:case e.MASK_TYPE.Rect:case e.MASK_TYPE.RoundedRect:case e.MASK_TYPE.Polygon:n=this.createGraphics(i);break;case e.MASK_TYPE.Img:case e.MASK_TYPE.Sprite:n=this.createSprite(i)}if(!n)throw new Error("no have mask instance, check your mask params: "+i.type);const s=this.containerManager.getContainer(t.gameObject.id);s.mask=n,s.addChild(n)}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);(null==t?void 0:t.mask)&&(t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id])}change(t){if(this.changedCache[t.gameObject.id])return;const i=t.component;if("enabled"===t.prop.prop[0])return this.changedCache[t.gameObject.id]=!0,void(!1===i.enabled?this.remove(t):this.add(t));if("type"===t.prop.prop[0]){this.changedCache[t.gameObject.id]=!0;const r=m(i.type),n=m(i._lastType);[e.MASK_TYPE.Sprite,e.MASK_TYPE.Img].indexOf(r)>-1||n!==r?(this.remove(t),this.add(t),i._lastType=i.type):this.redrawGraphics(t)}else if(["style","x","y","radius","width","height","paths"].indexOf(t.prop.prop[0])>-1){this.syncComponentStyle(i);const r=m(i.type);[e.MASK_TYPE.Sprite,e.MASK_TYPE.Img].indexOf(r)>-1?this.changeSpriteStyle(i):this.redrawGraphics(t)}else("resource"===t.prop.prop[0]||"spriteName"===t.prop.prop[0])&&(this.changedCache[t.gameObject.id]=!0,this.changeSprite(i))}createGraphics(e){const t=new r.Graphics;return this.draw(t,e),t}redrawGraphics(e){const t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)}draw(e,t){const i=m(t.type),r=this.syncComponentStyle(t),n=[];for(const e of y[i])n.push(r[e]);e[g[i]](...n),e.fill(0)}createSprite(e){const t=new r.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite}changeSpriteStyle(e){const t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y}changeSprite(e){const t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)}setSprite(i,r){var n,s;return o(this,void 0,void 0,function*(){const o=m(i.type);let l;try{const e=this.increaseAsyncId(i.gameObject.id);if(l=yield t.resource.getResource(i.resource),!this.validateAsyncId(i.gameObject.id,e))return}catch(e){throw new Error("mask resource load error")}if(o===e.MASK_TYPE.Sprite){const e=i.resource+"_s|r|c_"+i.spriteName,t=null===(n=null==l?void 0:l.instance)||void 0===n?void 0:n[e];t&&(r.image=t)}else(null===(s=null==l?void 0:l.data)||void 0===s?void 0:s.image)&&(r.image=l.data.image);r.sprite.width=i.style.width,r.sprite.height=i.style.height,r.sprite.position.x=i.style.x,r.sprite.position.y=i.style.y})}syncComponentStyle(e){var t,i,r,n,s,o,l,a,d,c,p,h,u,y;return e.style=_extends(_extends({},e.style),{x:null!==(r=null!==(t=e.x)&&void 0!==t?t:null===(i=e.style)||void 0===i?void 0:i.x)&&void 0!==r?r:0,y:null!==(o=null!==(n=e.y)&&void 0!==n?n:null===(s=e.style)||void 0===s?void 0:s.y)&&void 0!==o?o:0,radius:null!==(l=e.radius)&&void 0!==l?l:null===(a=e.style)||void 0===a?void 0:a.radius,width:null!==(d=e.width)&&void 0!==d?d:null===(c=e.style)||void 0===c?void 0:c.width,height:null!==(p=e.height)&&void 0!==p?p:null===(h=e.style)||void 0===h?void 0:h.height,paths:null!==(u=e.paths)&&void 0!==u?u:null===(y=e.style)||void 0===y?void 0:y.paths}),e.style}};f.systemName="MaskSystem",f=n([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"x","y","radius","width","height","paths","resource","spriteName","enabled"]})],f);var E=f;return e.Mask=u,e.MaskSystem=E,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.mask=globalThis.EVA.plugin.renderer.mask||_EVA_IIFE_mask;
|
|
@@ -22,6 +22,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
22
22
|
PERFORMANCE OF THIS SOFTWARE.
|
|
23
23
|
***************************************************************************** */
|
|
24
24
|
|
|
25
|
+
function __rest(s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
function __decorate(decorators, target, key, desc) {
|
|
26
38
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
27
39
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -29,6 +41,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
29
41
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
42
|
}
|
|
31
43
|
|
|
44
|
+
function __metadata(metadataKey, metadataValue) {
|
|
45
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
46
|
+
}
|
|
47
|
+
|
|
32
48
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
49
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
50
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -102,36 +118,80 @@ exports.MASK_TYPE = void 0;
|
|
|
102
118
|
* ```
|
|
103
119
|
*/
|
|
104
120
|
class Mask$2 extends eva_js.Component {
|
|
105
|
-
constructor() {
|
|
106
|
-
super(
|
|
121
|
+
constructor(params) {
|
|
122
|
+
super(params);
|
|
123
|
+
/** 遮罩类型 */
|
|
124
|
+
// @decorators.IDEProp 复杂编辑后续添加
|
|
125
|
+
this.type = exports.MASK_TYPE.Rect;
|
|
107
126
|
/** 遮罩样式配置 */
|
|
108
127
|
// @decorators.IDEProp 复杂编辑后续添加
|
|
109
128
|
this.style = {};
|
|
129
|
+
this.x = 0;
|
|
130
|
+
this.y = 0;
|
|
110
131
|
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
111
132
|
this.resource = '';
|
|
112
133
|
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
113
134
|
this.spriteName = '';
|
|
135
|
+
/** 是否启用遮罩 */
|
|
136
|
+
this.enabled = true;
|
|
137
|
+
this.init(params);
|
|
114
138
|
}
|
|
115
139
|
/**
|
|
116
140
|
* 初始化组件
|
|
117
141
|
* @param obj - 初始化参数
|
|
118
|
-
* @param obj.type - 遮罩类型
|
|
119
|
-
* @param obj.style - 遮罩样式
|
|
120
|
-
* @param obj.resource - 遮罩资源(可选)
|
|
121
|
-
* @param obj.spriteName - 精灵名称(可选)
|
|
122
142
|
*/
|
|
123
143
|
init(obj) {
|
|
124
|
-
|
|
144
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
145
|
+
if (!obj)
|
|
146
|
+
return;
|
|
147
|
+
const { style } = obj, rest = __rest(obj, ["style"]);
|
|
148
|
+
Object.assign(this, rest);
|
|
149
|
+
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 });
|
|
150
|
+
this.x = (_w = this.style.x) !== null && _w !== void 0 ? _w : 0;
|
|
151
|
+
this.y = (_x = this.style.y) !== null && _x !== void 0 ? _x : 0;
|
|
152
|
+
this.radius = this.style.radius;
|
|
153
|
+
this.width = this.style.width;
|
|
154
|
+
this.height = this.style.height;
|
|
155
|
+
this.paths = this.style.paths;
|
|
156
|
+
}
|
|
157
|
+
destroy() {
|
|
158
|
+
return this;
|
|
125
159
|
}
|
|
126
160
|
}
|
|
127
161
|
/** 组件名称 */
|
|
128
162
|
Mask$2.componentName = 'Mask';
|
|
129
163
|
__decorate([
|
|
130
|
-
inspectorDecorator.type('
|
|
164
|
+
inspectorDecorator.type('number'),
|
|
165
|
+
__metadata("design:type", Number)
|
|
166
|
+
], Mask$2.prototype, "x", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
inspectorDecorator.type('number'),
|
|
169
|
+
__metadata("design:type", Number)
|
|
170
|
+
], Mask$2.prototype, "y", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
inspectorDecorator.type('number'),
|
|
173
|
+
__metadata("design:type", Number)
|
|
174
|
+
], Mask$2.prototype, "radius", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
inspectorDecorator.type('number'),
|
|
177
|
+
__metadata("design:type", Number)
|
|
178
|
+
], Mask$2.prototype, "width", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
inspectorDecorator.type('number'),
|
|
181
|
+
__metadata("design:type", Number)
|
|
182
|
+
], Mask$2.prototype, "height", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
inspectorDecorator.type('string'),
|
|
185
|
+
__metadata("design:type", String)
|
|
131
186
|
], Mask$2.prototype, "resource", void 0);
|
|
132
187
|
__decorate([
|
|
133
|
-
inspectorDecorator.type('string')
|
|
134
|
-
|
|
188
|
+
inspectorDecorator.type('string'),
|
|
189
|
+
__metadata("design:type", String)
|
|
190
|
+
], Mask$2.prototype, "spriteName", void 0);
|
|
191
|
+
__decorate([
|
|
192
|
+
inspectorDecorator.type('boolean'),
|
|
193
|
+
__metadata("design:type", Boolean)
|
|
194
|
+
], Mask$2.prototype, "enabled", void 0);
|
|
135
195
|
|
|
136
196
|
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
137
197
|
const propertyForGraphics = {
|
|
@@ -148,20 +208,28 @@ const functionForGraphics = {
|
|
|
148
208
|
RoundedRect: 'roundRect',
|
|
149
209
|
Polygon: 'poly',
|
|
150
210
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
MASK_TYPE
|
|
154
|
-
MASK_TYPE
|
|
155
|
-
MASK_TYPE
|
|
156
|
-
MASK_TYPE
|
|
157
|
-
MASK_TYPE
|
|
158
|
-
MASK_TYPE
|
|
159
|
-
MASK_TYPE
|
|
160
|
-
|
|
211
|
+
const maskTypeAliases = {
|
|
212
|
+
circle: exports.MASK_TYPE.Circle,
|
|
213
|
+
ellipse: exports.MASK_TYPE.Ellipse,
|
|
214
|
+
rect: exports.MASK_TYPE.Rect,
|
|
215
|
+
roundedrect: exports.MASK_TYPE.RoundedRect,
|
|
216
|
+
roundedRect: exports.MASK_TYPE.RoundedRect,
|
|
217
|
+
polygon: exports.MASK_TYPE.Polygon,
|
|
218
|
+
img: exports.MASK_TYPE.Img,
|
|
219
|
+
image: exports.MASK_TYPE.Img,
|
|
220
|
+
sprite: exports.MASK_TYPE.Sprite,
|
|
221
|
+
};
|
|
222
|
+
function normalizeMaskType(type) {
|
|
223
|
+
if (!type)
|
|
224
|
+
return undefined;
|
|
225
|
+
if (Object.values(exports.MASK_TYPE).includes(type))
|
|
226
|
+
return type;
|
|
227
|
+
return maskTypeAliases[String(type)] || maskTypeAliases[String(type).toLowerCase()];
|
|
228
|
+
}
|
|
161
229
|
let Mask = class Mask extends pluginRenderer.Renderer {
|
|
162
230
|
constructor() {
|
|
163
231
|
super(...arguments);
|
|
164
|
-
this.name = '
|
|
232
|
+
this.name = 'MaskSystem';
|
|
165
233
|
this.changedCache = {};
|
|
166
234
|
this.maskSpriteCache = {};
|
|
167
235
|
}
|
|
@@ -189,33 +257,36 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
189
257
|
}
|
|
190
258
|
add(changed) {
|
|
191
259
|
const component = changed.component;
|
|
192
|
-
if (
|
|
260
|
+
if (component.enabled === false)
|
|
261
|
+
return;
|
|
262
|
+
const maskType = normalizeMaskType(component.type);
|
|
263
|
+
if (!maskType) {
|
|
193
264
|
throw new Error('no have Mask type: ' + component.type);
|
|
194
265
|
}
|
|
195
266
|
if (!component.style) {
|
|
196
267
|
throw new Error('no have Mask style: ' + component.type);
|
|
197
268
|
}
|
|
198
269
|
let mask;
|
|
199
|
-
switch (
|
|
200
|
-
case MASK_TYPE.Circle:
|
|
270
|
+
switch (maskType) {
|
|
271
|
+
case exports.MASK_TYPE.Circle:
|
|
201
272
|
mask = this.createGraphics(component);
|
|
202
273
|
break;
|
|
203
|
-
case MASK_TYPE.Ellipse:
|
|
274
|
+
case exports.MASK_TYPE.Ellipse:
|
|
204
275
|
mask = this.createGraphics(component);
|
|
205
276
|
break;
|
|
206
|
-
case MASK_TYPE.Rect:
|
|
277
|
+
case exports.MASK_TYPE.Rect:
|
|
207
278
|
mask = this.createGraphics(component);
|
|
208
279
|
break;
|
|
209
|
-
case MASK_TYPE.RoundedRect:
|
|
280
|
+
case exports.MASK_TYPE.RoundedRect:
|
|
210
281
|
mask = this.createGraphics(component);
|
|
211
282
|
break;
|
|
212
|
-
case MASK_TYPE.Polygon:
|
|
283
|
+
case exports.MASK_TYPE.Polygon:
|
|
213
284
|
mask = this.createGraphics(component);
|
|
214
285
|
break;
|
|
215
|
-
case MASK_TYPE.Img:
|
|
286
|
+
case exports.MASK_TYPE.Img:
|
|
216
287
|
mask = this.createSprite(component);
|
|
217
288
|
break;
|
|
218
|
-
case MASK_TYPE.Sprite:
|
|
289
|
+
case exports.MASK_TYPE.Sprite:
|
|
219
290
|
mask = this.createSprite(component);
|
|
220
291
|
break;
|
|
221
292
|
}
|
|
@@ -228,6 +299,8 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
228
299
|
}
|
|
229
300
|
remove(changed) {
|
|
230
301
|
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
302
|
+
if (!(container === null || container === void 0 ? void 0 : container.mask))
|
|
303
|
+
return;
|
|
231
304
|
container.removeChild(container.mask);
|
|
232
305
|
container.mask.destroy({ children: true });
|
|
233
306
|
container.mask = null;
|
|
@@ -237,9 +310,21 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
237
310
|
if (this.changedCache[changed.gameObject.id])
|
|
238
311
|
return;
|
|
239
312
|
const component = changed.component;
|
|
313
|
+
if (changed.prop.prop[0] === 'enabled') {
|
|
314
|
+
this.changedCache[changed.gameObject.id] = true;
|
|
315
|
+
if (component.enabled === false) {
|
|
316
|
+
this.remove(changed);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
this.add(changed);
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
240
323
|
if (changed.prop.prop[0] === 'type') {
|
|
241
324
|
this.changedCache[changed.gameObject.id] = true;
|
|
242
|
-
|
|
325
|
+
const maskType = normalizeMaskType(component.type);
|
|
326
|
+
const lastType = normalizeMaskType(component._lastType);
|
|
327
|
+
if ([exports.MASK_TYPE.Sprite, exports.MASK_TYPE.Img].indexOf(maskType) > -1 || lastType !== maskType) {
|
|
243
328
|
this.remove(changed);
|
|
244
329
|
this.add(changed);
|
|
245
330
|
component._lastType = component.type;
|
|
@@ -248,8 +333,10 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
248
333
|
this.redrawGraphics(changed);
|
|
249
334
|
}
|
|
250
335
|
}
|
|
251
|
-
else if (changed.prop.prop[0]
|
|
252
|
-
|
|
336
|
+
else if (['style', 'x', 'y', 'radius', 'width', 'height', 'paths'].indexOf(changed.prop.prop[0]) > -1) {
|
|
337
|
+
this.syncComponentStyle(component);
|
|
338
|
+
const maskType = normalizeMaskType(component.type);
|
|
339
|
+
if ([exports.MASK_TYPE.Sprite, exports.MASK_TYPE.Img].indexOf(maskType) > -1) {
|
|
253
340
|
this.changeSpriteStyle(component);
|
|
254
341
|
}
|
|
255
342
|
else {
|
|
@@ -277,12 +364,14 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
277
364
|
this.draw(graphics, changed.component);
|
|
278
365
|
}
|
|
279
366
|
draw(graphics, component) {
|
|
367
|
+
const maskType = normalizeMaskType(component.type);
|
|
368
|
+
const style = this.syncComponentStyle(component);
|
|
280
369
|
const params = [];
|
|
281
|
-
for (const key of propertyForGraphics[
|
|
282
|
-
params.push(
|
|
370
|
+
for (const key of propertyForGraphics[maskType]) {
|
|
371
|
+
params.push(style[key]);
|
|
283
372
|
}
|
|
284
373
|
// @ts-ignore
|
|
285
|
-
graphics[functionForGraphics[
|
|
374
|
+
graphics[functionForGraphics[maskType]](...params);
|
|
286
375
|
graphics.fill(0x000000);
|
|
287
376
|
}
|
|
288
377
|
createSprite(component) {
|
|
@@ -305,6 +394,7 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
305
394
|
setSprite(component, sprite) {
|
|
306
395
|
var _a, _b;
|
|
307
396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
+
const maskType = normalizeMaskType(component.type);
|
|
308
398
|
let res;
|
|
309
399
|
try {
|
|
310
400
|
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
@@ -315,7 +405,7 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
315
405
|
catch (e) {
|
|
316
406
|
throw new Error('mask resource load error');
|
|
317
407
|
}
|
|
318
|
-
if (
|
|
408
|
+
if (maskType === exports.MASK_TYPE.Sprite) {
|
|
319
409
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
320
410
|
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
321
411
|
if (texture) {
|
|
@@ -333,11 +423,28 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
333
423
|
sprite.sprite.position.y = component.style.y;
|
|
334
424
|
});
|
|
335
425
|
}
|
|
426
|
+
syncComponentStyle(component) {
|
|
427
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
428
|
+
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 });
|
|
429
|
+
return component.style;
|
|
430
|
+
}
|
|
336
431
|
};
|
|
337
|
-
Mask.systemName = '
|
|
432
|
+
Mask.systemName = 'MaskSystem';
|
|
338
433
|
Mask = __decorate([
|
|
339
434
|
eva_js.decorators.componentObserver({
|
|
340
|
-
Mask: [
|
|
435
|
+
Mask: [
|
|
436
|
+
'type',
|
|
437
|
+
{ prop: ['style'], deep: true },
|
|
438
|
+
'x',
|
|
439
|
+
'y',
|
|
440
|
+
'radius',
|
|
441
|
+
'width',
|
|
442
|
+
'height',
|
|
443
|
+
'paths',
|
|
444
|
+
'resource',
|
|
445
|
+
'spriteName',
|
|
446
|
+
'enabled',
|
|
447
|
+
],
|
|
341
448
|
})
|
|
342
449
|
], Mask);
|
|
343
450
|
var Mask$1 = Mask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@eva/eva.js"),i=require("@eva/inspector-decorator"),s=require("@eva/plugin-renderer"),r=require("@eva/renderer-adapter");function o(e,t,i,s){var r,o=arguments.length,n=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(n=(o<3?r(n):o>3?r(t,i,n):r(t,i))||n);return o>3&&n&&Object.defineProperty(t,i,n),n}function n(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t,i,s){return new(i||(i=Promise))(function(r,o){function n(e){try{a(s.next(e))}catch(e){o(e)}}function l(e){try{a(s.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(n,l)}a((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,exports.MASK_TYPE=void 0,(e=exports.MASK_TYPE||(exports.MASK_TYPE={})).Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite";class a extends t.Component{constructor(e){super(e),this.type=exports.MASK_TYPE.Rect,this.style={},this.x=0,this.y=0,this.resource="",this.spriteName="",this.enabled=!0,this.init(e)}init(e){var t,i,s,r,o,n,l,a,d,p,c,h,y,u,g,v,m,S,x,f,b,E;if(!e)return;const{style:w}=e,P=function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(i[s[r]]=e[s[r]])}return i}(e,["style"]);Object.assign(this,P),this.style=Object.assign(Object.assign(Object.assign({},this.style),w),{x:null!==(r=null!==(i=null!==(t=e.x)&&void 0!==t?t:null==w?void 0:w.x)&&void 0!==i?i:null===(s=this.style)||void 0===s?void 0:s.x)&&void 0!==r?r:this.x,y:null!==(a=null!==(n=null!==(o=e.y)&&void 0!==o?o:null==w?void 0:w.y)&&void 0!==n?n:null===(l=this.style)||void 0===l?void 0:l.y)&&void 0!==a?a:this.y,radius:null!==(p=null!==(d=e.radius)&&void 0!==d?d:null==w?void 0:w.radius)&&void 0!==p?p:null===(c=this.style)||void 0===c?void 0:c.radius,width:null!==(y=null!==(h=e.width)&&void 0!==h?h:null==w?void 0:w.width)&&void 0!==y?y:null===(u=this.style)||void 0===u?void 0:u.width,height:null!==(v=null!==(g=e.height)&&void 0!==g?g:null==w?void 0:w.height)&&void 0!==v?v:null===(m=this.style)||void 0===m?void 0:m.height,paths:null!==(x=null!==(S=e.paths)&&void 0!==S?S:null==w?void 0:w.paths)&&void 0!==x?x:null===(f=this.style)||void 0===f?void 0:f.paths}),this.x=null!==(b=this.style.x)&&void 0!==b?b:0,this.y=null!==(E=this.style.y)&&void 0!==E?E:0,this.radius=this.style.radius,this.width=this.style.width,this.height=this.style.height,this.paths=this.style.paths}destroy(){return this}}a.componentName="Mask",o([i.type("number"),n("design:type",Number)],a.prototype,"x",void 0),o([i.type("number"),n("design:type",Number)],a.prototype,"y",void 0),o([i.type("number"),n("design:type",Number)],a.prototype,"radius",void 0),o([i.type("number"),n("design:type",Number)],a.prototype,"width",void 0),o([i.type("number"),n("design:type",Number)],a.prototype,"height",void 0),o([i.type("string"),n("design:type",String)],a.prototype,"resource",void 0),o([i.type("string"),n("design:type",String)],a.prototype,"spriteName",void 0),o([i.type("boolean"),n("design:type",Boolean)],a.prototype,"enabled",void 0);const d={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},p={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"},c={circle:exports.MASK_TYPE.Circle,ellipse:exports.MASK_TYPE.Ellipse,rect:exports.MASK_TYPE.Rect,roundedrect:exports.MASK_TYPE.RoundedRect,roundedRect:exports.MASK_TYPE.RoundedRect,polygon:exports.MASK_TYPE.Polygon,img:exports.MASK_TYPE.Img,image:exports.MASK_TYPE.Img,sprite:exports.MASK_TYPE.Sprite};function h(e){if(e)return Object.values(exports.MASK_TYPE).includes(e)?e:c[String(e)]||c[String(e).toLowerCase()]}let y=class extends s.Renderer{constructor(){super(...arguments),this.name="MaskSystem",this.changedCache={},this.maskSpriteCache={}}init(){this.renderSystem=this.game.getSystem(s.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(){this.changedCache={}}componentChanged(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=e.component;if(!1===t.enabled)return;const i=h(t.type);if(!i)throw new Error("no have Mask type: "+t.type);if(!t.style)throw new Error("no have Mask style: "+t.type);let s;switch(i){case exports.MASK_TYPE.Circle:case exports.MASK_TYPE.Ellipse:case exports.MASK_TYPE.Rect:case exports.MASK_TYPE.RoundedRect:case exports.MASK_TYPE.Polygon:s=this.createGraphics(t);break;case exports.MASK_TYPE.Img:case exports.MASK_TYPE.Sprite:s=this.createSprite(t)}if(!s)throw new Error("no have mask instance, check your mask params: "+t.type);const r=this.containerManager.getContainer(e.gameObject.id);r.mask=s,r.addChild(s)}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);(null==t?void 0:t.mask)&&(t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id])}change(e){if(this.changedCache[e.gameObject.id])return;const t=e.component;if("enabled"===e.prop.prop[0])return this.changedCache[e.gameObject.id]=!0,void(!1===t.enabled?this.remove(e):this.add(e));if("type"===e.prop.prop[0]){this.changedCache[e.gameObject.id]=!0;const i=h(t.type),s=h(t._lastType);[exports.MASK_TYPE.Sprite,exports.MASK_TYPE.Img].indexOf(i)>-1||s!==i?(this.remove(e),this.add(e),t._lastType=t.type):this.redrawGraphics(e)}else if(["style","x","y","radius","width","height","paths"].indexOf(e.prop.prop[0])>-1){this.syncComponentStyle(t);const i=h(t.type);[exports.MASK_TYPE.Sprite,exports.MASK_TYPE.Img].indexOf(i)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e)}else("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}createGraphics(e){const t=new r.Graphics;return this.draw(t,e),t}redrawGraphics(e){const t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)}draw(e,t){const i=h(t.type),s=this.syncComponentStyle(t),r=[];for(const e of d[i])r.push(s[e]);e[p[i]](...r),e.fill(0)}createSprite(e){const t=new r.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite}changeSpriteStyle(e){const t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y}changeSprite(e){const t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)}setSprite(e,i){var s,r;return l(this,void 0,void 0,function*(){const o=h(e.type);let n;try{const i=this.increaseAsyncId(e.gameObject.id);if(n=yield t.resource.getResource(e.resource),!this.validateAsyncId(e.gameObject.id,i))return}catch(e){throw new Error("mask resource load error")}if(o===exports.MASK_TYPE.Sprite){const t=e.resource+"_s|r|c_"+e.spriteName,r=null===(s=null==n?void 0:n.instance)||void 0===s?void 0:s[t];r&&(i.image=r)}else(null===(r=null==n?void 0:n.data)||void 0===r?void 0:r.image)&&(i.image=n.data.image);i.sprite.width=e.style.width,i.sprite.height=e.style.height,i.sprite.position.x=e.style.x,i.sprite.position.y=e.style.y})}syncComponentStyle(e){var t,i,s,r,o,n,l,a,d,p,c,h,y,u;return e.style=Object.assign(Object.assign({},e.style),{x:null!==(s=null!==(t=e.x)&&void 0!==t?t:null===(i=e.style)||void 0===i?void 0:i.x)&&void 0!==s?s:0,y:null!==(n=null!==(r=e.y)&&void 0!==r?r:null===(o=e.style)||void 0===o?void 0:o.y)&&void 0!==n?n:0,radius:null!==(l=e.radius)&&void 0!==l?l:null===(a=e.style)||void 0===a?void 0:a.radius,width:null!==(d=e.width)&&void 0!==d?d:null===(p=e.style)||void 0===p?void 0:p.width,height:null!==(c=e.height)&&void 0!==c?c:null===(h=e.style)||void 0===h?void 0:h.height,paths:null!==(y=e.paths)&&void 0!==y?y:null===(u=e.style)||void 0===u?void 0:u.paths}),e.style}};y.systemName="MaskSystem",y=o([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"x","y","radius","width","height","paths","resource","spriteName","enabled"]})],y);var u=y;exports.Mask=a,exports.MaskSystem=u;
|
|
@@ -59,24 +59,30 @@ export declare class Mask extends Component<MaskParams> {
|
|
|
59
59
|
/** 组件名称 */
|
|
60
60
|
static componentName: string;
|
|
61
61
|
/** 上一次的遮罩类型 */
|
|
62
|
-
_lastType:
|
|
62
|
+
_lastType: MaskTypeValue;
|
|
63
63
|
/** 遮罩类型 */
|
|
64
|
-
type:
|
|
64
|
+
type: MaskTypeValue;
|
|
65
65
|
/** 遮罩样式配置 */
|
|
66
66
|
style?: MaskParams['style'];
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
radius?: number;
|
|
70
|
+
width?: number;
|
|
71
|
+
height?: number;
|
|
72
|
+
paths?: number[];
|
|
67
73
|
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
68
74
|
resource?: string;
|
|
69
75
|
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
70
76
|
spriteName?: string;
|
|
77
|
+
/** 是否启用遮罩 */
|
|
78
|
+
enabled: boolean;
|
|
79
|
+
constructor(params?: MaskParams);
|
|
71
80
|
/**
|
|
72
81
|
* 初始化组件
|
|
73
82
|
* @param obj - 初始化参数
|
|
74
|
-
* @param obj.type - 遮罩类型
|
|
75
|
-
* @param obj.style - 遮罩样式
|
|
76
|
-
* @param obj.resource - 遮罩资源(可选)
|
|
77
|
-
* @param obj.spriteName - 精灵名称(可选)
|
|
78
83
|
*/
|
|
79
84
|
init(obj?: MaskParams): void;
|
|
85
|
+
destroy(): this;
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
export declare enum MASK_TYPE {
|
|
@@ -90,7 +96,7 @@ export declare enum MASK_TYPE {
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
export declare interface MaskParams {
|
|
93
|
-
type:
|
|
99
|
+
type: MaskTypeValue;
|
|
94
100
|
style?: {
|
|
95
101
|
x?: number;
|
|
96
102
|
y?: number;
|
|
@@ -99,8 +105,15 @@ export declare interface MaskParams {
|
|
|
99
105
|
height?: number;
|
|
100
106
|
paths?: number[];
|
|
101
107
|
};
|
|
108
|
+
x?: number;
|
|
109
|
+
y?: number;
|
|
110
|
+
radius?: number;
|
|
111
|
+
width?: number;
|
|
112
|
+
height?: number;
|
|
113
|
+
paths?: number[];
|
|
102
114
|
resource?: string;
|
|
103
115
|
spriteName?: string;
|
|
116
|
+
enabled?: boolean;
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
export declare class MaskSystem extends Renderer {
|
|
@@ -128,6 +141,9 @@ export declare class MaskSystem extends Renderer {
|
|
|
128
141
|
changeSpriteStyle(component: Mask): void;
|
|
129
142
|
changeSprite(component: Mask): void;
|
|
130
143
|
setSprite(component: Mask, sprite: any): Promise<void>;
|
|
144
|
+
private syncComponentStyle;
|
|
131
145
|
}
|
|
132
146
|
|
|
147
|
+
declare type MaskTypeValue = MASK_TYPE | 'circle' | 'ellipse' | 'rect' | 'roundedRect' | 'polygon' | 'img' | 'sprite';
|
|
148
|
+
|
|
133
149
|
export { }
|
|
@@ -18,6 +18,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
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
|
+
|
|
21
33
|
function __decorate(decorators, target, key, desc) {
|
|
22
34
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
35
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -25,6 +37,10 @@ function __decorate(decorators, target, key, desc) {
|
|
|
25
37
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
38
|
}
|
|
27
39
|
|
|
40
|
+
function __metadata(metadataKey, metadataValue) {
|
|
41
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
29
45
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
46
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -40,7 +56,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
40
56
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
41
57
|
};
|
|
42
58
|
|
|
43
|
-
var MASK_TYPE
|
|
59
|
+
var MASK_TYPE;
|
|
44
60
|
(function (MASK_TYPE) {
|
|
45
61
|
MASK_TYPE["Circle"] = "Circle";
|
|
46
62
|
MASK_TYPE["Ellipse"] = "Ellipse";
|
|
@@ -49,7 +65,7 @@ var MASK_TYPE$1;
|
|
|
49
65
|
MASK_TYPE["Polygon"] = "Polygon";
|
|
50
66
|
MASK_TYPE["Img"] = "Img";
|
|
51
67
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
52
|
-
})(MASK_TYPE
|
|
68
|
+
})(MASK_TYPE || (MASK_TYPE = {}));
|
|
53
69
|
/**
|
|
54
70
|
* 遮罩组件
|
|
55
71
|
*
|
|
@@ -98,36 +114,80 @@ var MASK_TYPE$1;
|
|
|
98
114
|
* ```
|
|
99
115
|
*/
|
|
100
116
|
class Mask$2 extends Component {
|
|
101
|
-
constructor() {
|
|
102
|
-
super(
|
|
117
|
+
constructor(params) {
|
|
118
|
+
super(params);
|
|
119
|
+
/** 遮罩类型 */
|
|
120
|
+
// @decorators.IDEProp 复杂编辑后续添加
|
|
121
|
+
this.type = MASK_TYPE.Rect;
|
|
103
122
|
/** 遮罩样式配置 */
|
|
104
123
|
// @decorators.IDEProp 复杂编辑后续添加
|
|
105
124
|
this.style = {};
|
|
125
|
+
this.x = 0;
|
|
126
|
+
this.y = 0;
|
|
106
127
|
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
107
128
|
this.resource = '';
|
|
108
129
|
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
109
130
|
this.spriteName = '';
|
|
131
|
+
/** 是否启用遮罩 */
|
|
132
|
+
this.enabled = true;
|
|
133
|
+
this.init(params);
|
|
110
134
|
}
|
|
111
135
|
/**
|
|
112
136
|
* 初始化组件
|
|
113
137
|
* @param obj - 初始化参数
|
|
114
|
-
* @param obj.type - 遮罩类型
|
|
115
|
-
* @param obj.style - 遮罩样式
|
|
116
|
-
* @param obj.resource - 遮罩资源(可选)
|
|
117
|
-
* @param obj.spriteName - 精灵名称(可选)
|
|
118
138
|
*/
|
|
119
139
|
init(obj) {
|
|
120
|
-
|
|
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;
|
|
121
155
|
}
|
|
122
156
|
}
|
|
123
157
|
/** 组件名称 */
|
|
124
158
|
Mask$2.componentName = 'Mask';
|
|
125
159
|
__decorate([
|
|
126
|
-
type('
|
|
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)
|
|
127
182
|
], Mask$2.prototype, "resource", void 0);
|
|
128
183
|
__decorate([
|
|
129
|
-
type('string')
|
|
130
|
-
|
|
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);
|
|
131
191
|
|
|
132
192
|
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
133
193
|
const propertyForGraphics = {
|
|
@@ -144,20 +204,28 @@ const functionForGraphics = {
|
|
|
144
204
|
RoundedRect: 'roundRect',
|
|
145
205
|
Polygon: 'poly',
|
|
146
206
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
MASK_TYPE
|
|
150
|
-
MASK_TYPE
|
|
151
|
-
MASK_TYPE
|
|
152
|
-
MASK_TYPE
|
|
153
|
-
MASK_TYPE
|
|
154
|
-
MASK_TYPE
|
|
155
|
-
MASK_TYPE
|
|
156
|
-
|
|
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
|
+
}
|
|
157
225
|
let Mask = class Mask extends Renderer {
|
|
158
226
|
constructor() {
|
|
159
227
|
super(...arguments);
|
|
160
|
-
this.name = '
|
|
228
|
+
this.name = 'MaskSystem';
|
|
161
229
|
this.changedCache = {};
|
|
162
230
|
this.maskSpriteCache = {};
|
|
163
231
|
}
|
|
@@ -185,14 +253,17 @@ let Mask = class Mask extends Renderer {
|
|
|
185
253
|
}
|
|
186
254
|
add(changed) {
|
|
187
255
|
const component = changed.component;
|
|
188
|
-
if (
|
|
256
|
+
if (component.enabled === false)
|
|
257
|
+
return;
|
|
258
|
+
const maskType = normalizeMaskType(component.type);
|
|
259
|
+
if (!maskType) {
|
|
189
260
|
throw new Error('no have Mask type: ' + component.type);
|
|
190
261
|
}
|
|
191
262
|
if (!component.style) {
|
|
192
263
|
throw new Error('no have Mask style: ' + component.type);
|
|
193
264
|
}
|
|
194
265
|
let mask;
|
|
195
|
-
switch (
|
|
266
|
+
switch (maskType) {
|
|
196
267
|
case MASK_TYPE.Circle:
|
|
197
268
|
mask = this.createGraphics(component);
|
|
198
269
|
break;
|
|
@@ -224,6 +295,8 @@ let Mask = class Mask extends Renderer {
|
|
|
224
295
|
}
|
|
225
296
|
remove(changed) {
|
|
226
297
|
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
298
|
+
if (!(container === null || container === void 0 ? void 0 : container.mask))
|
|
299
|
+
return;
|
|
227
300
|
container.removeChild(container.mask);
|
|
228
301
|
container.mask.destroy({ children: true });
|
|
229
302
|
container.mask = null;
|
|
@@ -233,9 +306,21 @@ let Mask = class Mask extends Renderer {
|
|
|
233
306
|
if (this.changedCache[changed.gameObject.id])
|
|
234
307
|
return;
|
|
235
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
|
+
}
|
|
236
319
|
if (changed.prop.prop[0] === 'type') {
|
|
237
320
|
this.changedCache[changed.gameObject.id] = true;
|
|
238
|
-
|
|
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) {
|
|
239
324
|
this.remove(changed);
|
|
240
325
|
this.add(changed);
|
|
241
326
|
component._lastType = component.type;
|
|
@@ -244,8 +329,10 @@ let Mask = class Mask extends Renderer {
|
|
|
244
329
|
this.redrawGraphics(changed);
|
|
245
330
|
}
|
|
246
331
|
}
|
|
247
|
-
else if (changed.prop.prop[0]
|
|
248
|
-
|
|
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) {
|
|
249
336
|
this.changeSpriteStyle(component);
|
|
250
337
|
}
|
|
251
338
|
else {
|
|
@@ -273,12 +360,14 @@ let Mask = class Mask extends Renderer {
|
|
|
273
360
|
this.draw(graphics, changed.component);
|
|
274
361
|
}
|
|
275
362
|
draw(graphics, component) {
|
|
363
|
+
const maskType = normalizeMaskType(component.type);
|
|
364
|
+
const style = this.syncComponentStyle(component);
|
|
276
365
|
const params = [];
|
|
277
|
-
for (const key of propertyForGraphics[
|
|
278
|
-
params.push(
|
|
366
|
+
for (const key of propertyForGraphics[maskType]) {
|
|
367
|
+
params.push(style[key]);
|
|
279
368
|
}
|
|
280
369
|
// @ts-ignore
|
|
281
|
-
graphics[functionForGraphics[
|
|
370
|
+
graphics[functionForGraphics[maskType]](...params);
|
|
282
371
|
graphics.fill(0x000000);
|
|
283
372
|
}
|
|
284
373
|
createSprite(component) {
|
|
@@ -301,6 +390,7 @@ let Mask = class Mask extends Renderer {
|
|
|
301
390
|
setSprite(component, sprite) {
|
|
302
391
|
var _a, _b;
|
|
303
392
|
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
+
const maskType = normalizeMaskType(component.type);
|
|
304
394
|
let res;
|
|
305
395
|
try {
|
|
306
396
|
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
@@ -311,7 +401,7 @@ let Mask = class Mask extends Renderer {
|
|
|
311
401
|
catch (e) {
|
|
312
402
|
throw new Error('mask resource load error');
|
|
313
403
|
}
|
|
314
|
-
if (
|
|
404
|
+
if (maskType === MASK_TYPE.Sprite) {
|
|
315
405
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
316
406
|
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
317
407
|
if (texture) {
|
|
@@ -329,13 +419,30 @@ let Mask = class Mask extends Renderer {
|
|
|
329
419
|
sprite.sprite.position.y = component.style.y;
|
|
330
420
|
});
|
|
331
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
|
+
}
|
|
332
427
|
};
|
|
333
|
-
Mask.systemName = '
|
|
428
|
+
Mask.systemName = 'MaskSystem';
|
|
334
429
|
Mask = __decorate([
|
|
335
430
|
decorators.componentObserver({
|
|
336
|
-
Mask: [
|
|
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
|
+
],
|
|
337
444
|
})
|
|
338
445
|
], Mask);
|
|
339
446
|
var Mask$1 = Mask;
|
|
340
447
|
|
|
341
|
-
export { MASK_TYPE
|
|
448
|
+
export { MASK_TYPE, Mask$2 as Mask, Mask$1 as MaskSystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-mask",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.1",
|
|
4
4
|
"description": "@eva/plugin-renderer-mask",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-mask.esm.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/inspector-decorator": "^0.0.
|
|
22
|
-
"@eva/plugin-renderer": "2.0.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
21
|
+
"@eva/inspector-decorator": "^2.0.0-beta.0",
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.1",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.1",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.1",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|