@eva/plugin-renderer-mask 2.0.1-beta.3 → 2.0.1-beta.30
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 +8 -3
- package/dist/EVA.plugin.renderer.mask.min.js +1 -1
- package/dist/plugin-renderer-mask.cjs.js +70 -4
- package/dist/plugin-renderer-mask.cjs.prod.js +1 -1
- package/dist/plugin-renderer-mask.d.ts +61 -0
- package/dist/plugin-renderer-mask.esm.js +70 -4
- package/package.json +4 -4
|
@@ -243,6 +243,7 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
243
243
|
this.setSprite(component, sprite);
|
|
244
244
|
}
|
|
245
245
|
setSprite(component, sprite) {
|
|
246
|
+
var _a, _b;
|
|
246
247
|
return __awaiter(this, void 0, void 0, function* () {
|
|
247
248
|
let res;
|
|
248
249
|
try {
|
|
@@ -254,10 +255,14 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
254
255
|
}
|
|
255
256
|
if (component.type === MASK_TYPE.Sprite) {
|
|
256
257
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
257
|
-
const texture = res.instance[img];
|
|
258
|
-
|
|
258
|
+
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
259
|
+
if (texture) {
|
|
260
|
+
sprite.image = texture;
|
|
261
|
+
}
|
|
259
262
|
} else {
|
|
260
|
-
|
|
263
|
+
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.image) {
|
|
264
|
+
sprite.image = res.data.image;
|
|
265
|
+
}
|
|
261
266
|
}
|
|
262
267
|
sprite.sprite.width = component.style.width;
|
|
263
268
|
sprite.sprite.height = component.style.height;
|
|
@@ -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
|
|
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;
|
|
@@ -48,17 +48,77 @@ exports.MASK_TYPE = void 0;
|
|
|
48
48
|
MASK_TYPE["Img"] = "Img";
|
|
49
49
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
50
50
|
})(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
|
|
51
|
+
/**
|
|
52
|
+
* 遮罩组件
|
|
53
|
+
*
|
|
54
|
+
* Mask 组件用于裁剪游戏对象的显示区域,只显示遮罩形状内的内容。
|
|
55
|
+
* 支持多种遮罩形状(矩形、圆形、多边形、图片、精灵等),
|
|
56
|
+
* 适用于头像裁剪、窗口遮罩、特殊形状显示等场景。
|
|
57
|
+
*
|
|
58
|
+
* 遮罩类型:
|
|
59
|
+
* - Circle - 圆形遮罩
|
|
60
|
+
* - Ellipse - 椭圆形遮罩
|
|
61
|
+
* - Rect - 矩形遮罩
|
|
62
|
+
* - RoundedRect - 圆角矩形遮罩
|
|
63
|
+
* - Polygon - 多边形遮罩
|
|
64
|
+
* - Img - 图片遮罩(基于图片 alpha 通道)
|
|
65
|
+
* - Sprite - 精灵遮罩
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // 圆形头像遮罩
|
|
70
|
+
* const avatar = new GameObject('avatar');
|
|
71
|
+
* avatar.addComponent(new Img({ resource: 'userAvatar' }));
|
|
72
|
+
* avatar.addComponent(new Mask({
|
|
73
|
+
* type: MASK_TYPE.Circle,
|
|
74
|
+
* style: {
|
|
75
|
+
* x: 50, // 圆心 x
|
|
76
|
+
* y: 50, // 圆心 y
|
|
77
|
+
* radius: 50 // 半径
|
|
78
|
+
* }
|
|
79
|
+
* }));
|
|
80
|
+
*
|
|
81
|
+
* // 矩形遮罩
|
|
82
|
+
* avatar.addComponent(new Mask({
|
|
83
|
+
* type: MASK_TYPE.Rect,
|
|
84
|
+
* style: {
|
|
85
|
+
* x: 0, y: 0,
|
|
86
|
+
* width: 100,
|
|
87
|
+
* height: 100
|
|
88
|
+
* }
|
|
89
|
+
* }));
|
|
90
|
+
*
|
|
91
|
+
* // 使用图片作为遮罩
|
|
92
|
+
* avatar.addComponent(new Mask({
|
|
93
|
+
* type: MASK_TYPE.Img,
|
|
94
|
+
* resource: 'maskImage' // alpha 通道作为遮罩
|
|
95
|
+
* }));
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
51
98
|
class Mask$2 extends eva_js.Component {
|
|
52
99
|
constructor() {
|
|
53
100
|
super(...arguments);
|
|
101
|
+
/** 遮罩样式配置 */
|
|
102
|
+
// @decorators.IDEProp 复杂编辑后续添加
|
|
54
103
|
this.style = {};
|
|
104
|
+
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
55
105
|
this.resource = '';
|
|
106
|
+
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
56
107
|
this.spriteName = '';
|
|
57
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 初始化组件
|
|
111
|
+
* @param obj - 初始化参数
|
|
112
|
+
* @param obj.type - 遮罩类型
|
|
113
|
+
* @param obj.style - 遮罩样式
|
|
114
|
+
* @param obj.resource - 遮罩资源(可选)
|
|
115
|
+
* @param obj.spriteName - 精灵名称(可选)
|
|
116
|
+
*/
|
|
58
117
|
init(obj) {
|
|
59
118
|
Object.assign(this, obj);
|
|
60
119
|
}
|
|
61
120
|
}
|
|
121
|
+
/** 组件名称 */
|
|
62
122
|
Mask$2.componentName = 'Mask';
|
|
63
123
|
__decorate([
|
|
64
124
|
inspectorDecorator.type('string')
|
|
@@ -67,7 +127,7 @@ __decorate([
|
|
|
67
127
|
inspectorDecorator.type('string')
|
|
68
128
|
], Mask$2.prototype, "spriteName", void 0);
|
|
69
129
|
|
|
70
|
-
const resourceKeySplit = '_s|r|c_';
|
|
130
|
+
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
71
131
|
const propertyForGraphics = {
|
|
72
132
|
Circle: ['x', 'y', 'radius'],
|
|
73
133
|
Ellipse: ['x', 'y', 'width', 'height'],
|
|
@@ -215,6 +275,7 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
215
275
|
for (const key of propertyForGraphics[component.type]) {
|
|
216
276
|
params.push(component.style[key]);
|
|
217
277
|
}
|
|
278
|
+
// @ts-ignore
|
|
218
279
|
graphics[functionForGraphics[component.type]](...params);
|
|
219
280
|
graphics.fill(0x000000);
|
|
220
281
|
}
|
|
@@ -236,6 +297,7 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
236
297
|
this.setSprite(component, sprite);
|
|
237
298
|
}
|
|
238
299
|
setSprite(component, sprite) {
|
|
300
|
+
var _a, _b;
|
|
239
301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
240
302
|
let res;
|
|
241
303
|
try {
|
|
@@ -249,11 +311,15 @@ let Mask = class Mask extends pluginRenderer.Renderer {
|
|
|
249
311
|
}
|
|
250
312
|
if (component.type === MASK_TYPE.Sprite) {
|
|
251
313
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
252
|
-
const texture = res.instance[img];
|
|
253
|
-
|
|
314
|
+
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
315
|
+
if (texture) {
|
|
316
|
+
sprite.image = texture;
|
|
317
|
+
}
|
|
254
318
|
}
|
|
255
319
|
else {
|
|
256
|
-
|
|
320
|
+
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.image) {
|
|
321
|
+
sprite.image = res.data.image;
|
|
322
|
+
}
|
|
257
323
|
}
|
|
258
324
|
sprite.sprite.width = component.style.width;
|
|
259
325
|
sprite.sprite.height = component.style.height;
|
|
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function s(e,t,r,i){var s,a=arguments.length,
|
|
16
|
+
function s(e,t,r,i){var s,a=arguments.length,n=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(n=(a<3?s(n):a>3?s(t,r,n):s(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}exports.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"}(exports.MASK_TYPE||(exports.MASK_TYPE={}));class a extends e.Component{constructor(){super(...arguments),this.style={},this.resource="",this.spriteName=""}init(e){Object.assign(this,e)}}a.componentName="Mask",s([t.type("string")],a.prototype,"resource",void 0),s([t.type("string")],a.prototype,"spriteName",void 0);const n={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},c={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"};var o;!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(o||(o={}));let p=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(t){if("Mask"===t.component.name)switch(t.type){case e.OBSERVER_TYPE.ADD:this.add(t);break;case e.OBSERVER_TYPE.REMOVE:this.remove(t);break;case e.OBSERVER_TYPE.CHANGE:this.change(t)}}add(e){const t=e.component;if(!(t.type in o))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 o.Circle:case o.Ellipse:case o.Rect:case o.RoundedRect:case o.Polygon:r=this.createGraphics(t);break;case o.Img:case o.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,[o.Sprite,o.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]?[o.Sprite,o.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 n[t.type])r.push(t.style[e]);e[c[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(t,r){var i,s,a,n,c,p;return a=this,n=void 0,p=function*(){let a;try{const r=this.increaseAsyncId(t.gameObject.id);if(a=yield e.resource.getResource(t.resource),!this.validateAsyncId(t.gameObject.id,r))return}catch(e){throw new Error("mask resource load error")}if(t.type===o.Sprite){const e=t.resource+"_s|r|c_"+t.spriteName,s=null===(i=null==a?void 0:a.instance)||void 0===i?void 0:i[e];s&&(r.image=s)}else(null===(s=null==a?void 0:a.data)||void 0===s?void 0:s.image)&&(r.image=a.data.image);r.sprite.width=t.style.width,r.sprite.height=t.style.height,r.sprite.position.x=t.style.x,r.sprite.position.y=t.style.y},new((c=void 0)||(c=Promise))((function(e,t){function r(e){try{s(p.next(e))}catch(e){t(e)}}function i(e){try{s(p.throw(e))}catch(e){t(e)}}function s(t){t.done?e(t.value):new c((function(e){e(t.value)})).then(r,i)}s((p=p.apply(a,n||[])).next())}))}};p.systemName="Mask",p=s([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],p);var h=p;exports.Mask=a,exports.MaskSystem=h;
|
|
@@ -8,13 +8,74 @@ import { RendererSystem } from '@eva/plugin-renderer';
|
|
|
8
8
|
import { Sprite } from '@eva/renderer-adapter';
|
|
9
9
|
import type { Sprite as Sprite_2 } from 'pixi.js';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 遮罩组件
|
|
13
|
+
*
|
|
14
|
+
* Mask 组件用于裁剪游戏对象的显示区域,只显示遮罩形状内的内容。
|
|
15
|
+
* 支持多种遮罩形状(矩形、圆形、多边形、图片、精灵等),
|
|
16
|
+
* 适用于头像裁剪、窗口遮罩、特殊形状显示等场景。
|
|
17
|
+
*
|
|
18
|
+
* 遮罩类型:
|
|
19
|
+
* - Circle - 圆形遮罩
|
|
20
|
+
* - Ellipse - 椭圆形遮罩
|
|
21
|
+
* - Rect - 矩形遮罩
|
|
22
|
+
* - RoundedRect - 圆角矩形遮罩
|
|
23
|
+
* - Polygon - 多边形遮罩
|
|
24
|
+
* - Img - 图片遮罩(基于图片 alpha 通道)
|
|
25
|
+
* - Sprite - 精灵遮罩
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // 圆形头像遮罩
|
|
30
|
+
* const avatar = new GameObject('avatar');
|
|
31
|
+
* avatar.addComponent(new Img({ resource: 'userAvatar' }));
|
|
32
|
+
* avatar.addComponent(new Mask({
|
|
33
|
+
* type: MASK_TYPE.Circle,
|
|
34
|
+
* style: {
|
|
35
|
+
* x: 50, // 圆心 x
|
|
36
|
+
* y: 50, // 圆心 y
|
|
37
|
+
* radius: 50 // 半径
|
|
38
|
+
* }
|
|
39
|
+
* }));
|
|
40
|
+
*
|
|
41
|
+
* // 矩形遮罩
|
|
42
|
+
* avatar.addComponent(new Mask({
|
|
43
|
+
* type: MASK_TYPE.Rect,
|
|
44
|
+
* style: {
|
|
45
|
+
* x: 0, y: 0,
|
|
46
|
+
* width: 100,
|
|
47
|
+
* height: 100
|
|
48
|
+
* }
|
|
49
|
+
* }));
|
|
50
|
+
*
|
|
51
|
+
* // 使用图片作为遮罩
|
|
52
|
+
* avatar.addComponent(new Mask({
|
|
53
|
+
* type: MASK_TYPE.Img,
|
|
54
|
+
* resource: 'maskImage' // alpha 通道作为遮罩
|
|
55
|
+
* }));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
11
58
|
export declare class Mask extends Component<MaskParams> {
|
|
59
|
+
/** 组件名称 */
|
|
12
60
|
static componentName: string;
|
|
61
|
+
/** 上一次的遮罩类型 */
|
|
13
62
|
_lastType: MaskParams['type'];
|
|
63
|
+
/** 遮罩类型 */
|
|
14
64
|
type: MaskParams['type'];
|
|
65
|
+
/** 遮罩样式配置 */
|
|
15
66
|
style?: MaskParams['style'];
|
|
67
|
+
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
16
68
|
resource?: string;
|
|
69
|
+
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
17
70
|
spriteName?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 初始化组件
|
|
73
|
+
* @param obj - 初始化参数
|
|
74
|
+
* @param obj.type - 遮罩类型
|
|
75
|
+
* @param obj.style - 遮罩样式
|
|
76
|
+
* @param obj.resource - 遮罩资源(可选)
|
|
77
|
+
* @param obj.spriteName - 精灵名称(可选)
|
|
78
|
+
*/
|
|
18
79
|
init(obj?: MaskParams): void;
|
|
19
80
|
}
|
|
20
81
|
|
|
@@ -44,17 +44,77 @@ var MASK_TYPE$1;
|
|
|
44
44
|
MASK_TYPE["Img"] = "Img";
|
|
45
45
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
46
46
|
})(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
|
|
47
|
+
/**
|
|
48
|
+
* 遮罩组件
|
|
49
|
+
*
|
|
50
|
+
* Mask 组件用于裁剪游戏对象的显示区域,只显示遮罩形状内的内容。
|
|
51
|
+
* 支持多种遮罩形状(矩形、圆形、多边形、图片、精灵等),
|
|
52
|
+
* 适用于头像裁剪、窗口遮罩、特殊形状显示等场景。
|
|
53
|
+
*
|
|
54
|
+
* 遮罩类型:
|
|
55
|
+
* - Circle - 圆形遮罩
|
|
56
|
+
* - Ellipse - 椭圆形遮罩
|
|
57
|
+
* - Rect - 矩形遮罩
|
|
58
|
+
* - RoundedRect - 圆角矩形遮罩
|
|
59
|
+
* - Polygon - 多边形遮罩
|
|
60
|
+
* - Img - 图片遮罩(基于图片 alpha 通道)
|
|
61
|
+
* - Sprite - 精灵遮罩
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // 圆形头像遮罩
|
|
66
|
+
* const avatar = new GameObject('avatar');
|
|
67
|
+
* avatar.addComponent(new Img({ resource: 'userAvatar' }));
|
|
68
|
+
* avatar.addComponent(new Mask({
|
|
69
|
+
* type: MASK_TYPE.Circle,
|
|
70
|
+
* style: {
|
|
71
|
+
* x: 50, // 圆心 x
|
|
72
|
+
* y: 50, // 圆心 y
|
|
73
|
+
* radius: 50 // 半径
|
|
74
|
+
* }
|
|
75
|
+
* }));
|
|
76
|
+
*
|
|
77
|
+
* // 矩形遮罩
|
|
78
|
+
* avatar.addComponent(new Mask({
|
|
79
|
+
* type: MASK_TYPE.Rect,
|
|
80
|
+
* style: {
|
|
81
|
+
* x: 0, y: 0,
|
|
82
|
+
* width: 100,
|
|
83
|
+
* height: 100
|
|
84
|
+
* }
|
|
85
|
+
* }));
|
|
86
|
+
*
|
|
87
|
+
* // 使用图片作为遮罩
|
|
88
|
+
* avatar.addComponent(new Mask({
|
|
89
|
+
* type: MASK_TYPE.Img,
|
|
90
|
+
* resource: 'maskImage' // alpha 通道作为遮罩
|
|
91
|
+
* }));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
47
94
|
class Mask$2 extends Component {
|
|
48
95
|
constructor() {
|
|
49
96
|
super(...arguments);
|
|
97
|
+
/** 遮罩样式配置 */
|
|
98
|
+
// @decorators.IDEProp 复杂编辑后续添加
|
|
50
99
|
this.style = {};
|
|
100
|
+
/** 遮罩图片资源名称(用于 Img 类型) */
|
|
51
101
|
this.resource = '';
|
|
102
|
+
/** 遮罩精灵名称(用于 Sprite 类型) */
|
|
52
103
|
this.spriteName = '';
|
|
53
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* 初始化组件
|
|
107
|
+
* @param obj - 初始化参数
|
|
108
|
+
* @param obj.type - 遮罩类型
|
|
109
|
+
* @param obj.style - 遮罩样式
|
|
110
|
+
* @param obj.resource - 遮罩资源(可选)
|
|
111
|
+
* @param obj.spriteName - 精灵名称(可选)
|
|
112
|
+
*/
|
|
54
113
|
init(obj) {
|
|
55
114
|
Object.assign(this, obj);
|
|
56
115
|
}
|
|
57
116
|
}
|
|
117
|
+
/** 组件名称 */
|
|
58
118
|
Mask$2.componentName = 'Mask';
|
|
59
119
|
__decorate([
|
|
60
120
|
type('string')
|
|
@@ -63,7 +123,7 @@ __decorate([
|
|
|
63
123
|
type('string')
|
|
64
124
|
], Mask$2.prototype, "spriteName", void 0);
|
|
65
125
|
|
|
66
|
-
const resourceKeySplit = '_s|r|c_';
|
|
126
|
+
const resourceKeySplit = '_s|r|c_'; // Notice: This key be created by sprite system.
|
|
67
127
|
const propertyForGraphics = {
|
|
68
128
|
Circle: ['x', 'y', 'radius'],
|
|
69
129
|
Ellipse: ['x', 'y', 'width', 'height'],
|
|
@@ -211,6 +271,7 @@ let Mask = class Mask extends Renderer {
|
|
|
211
271
|
for (const key of propertyForGraphics[component.type]) {
|
|
212
272
|
params.push(component.style[key]);
|
|
213
273
|
}
|
|
274
|
+
// @ts-ignore
|
|
214
275
|
graphics[functionForGraphics[component.type]](...params);
|
|
215
276
|
graphics.fill(0x000000);
|
|
216
277
|
}
|
|
@@ -232,6 +293,7 @@ let Mask = class Mask extends Renderer {
|
|
|
232
293
|
this.setSprite(component, sprite);
|
|
233
294
|
}
|
|
234
295
|
setSprite(component, sprite) {
|
|
296
|
+
var _a, _b;
|
|
235
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
298
|
let res;
|
|
237
299
|
try {
|
|
@@ -245,11 +307,15 @@ let Mask = class Mask extends Renderer {
|
|
|
245
307
|
}
|
|
246
308
|
if (component.type === MASK_TYPE.Sprite) {
|
|
247
309
|
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
248
|
-
const texture = res.instance[img];
|
|
249
|
-
|
|
310
|
+
const texture = (_a = res === null || res === void 0 ? void 0 : res.instance) === null || _a === void 0 ? void 0 : _a[img];
|
|
311
|
+
if (texture) {
|
|
312
|
+
sprite.image = texture;
|
|
313
|
+
}
|
|
250
314
|
}
|
|
251
315
|
else {
|
|
252
|
-
|
|
316
|
+
if ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.image) {
|
|
317
|
+
sprite.image = res.data.image;
|
|
318
|
+
}
|
|
253
319
|
}
|
|
254
320
|
sprite.sprite.width = component.style.width;
|
|
255
321
|
sprite.sprite.height = component.style.height;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-mask",
|
|
3
|
-
"version": "2.0.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.30",
|
|
4
4
|
"description": "@eva/plugin-renderer-mask",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-mask.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.1-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.1-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.1-beta.30",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.1-beta.30",
|
|
24
|
+
"@eva/eva.js": "2.0.1-beta.30",
|
|
25
25
|
"pixi.js": "^8.8.1"
|
|
26
26
|
}
|
|
27
27
|
}
|