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