Ts使用Js拓展常用功能篇
注解:分享一些Typescript中常用到的,但是需要js拓展的知识
Object:
示例:
let type: Object = {};
type.deepClone()
拓展:
interface Object {
/**
* 获取属性描述
*/
getPropertyDescriptor(property: string): PropertyDescriptor;
/**
* 浅拷贝当前对象
* 注意: 仅浅拷贝属性, 继承原型链和方法等均会丢失
*/
shallowClone(): Object;
/**
* 浅拷贝所有属性
* 注意: 仅浅拷贝属性, 继承原型链和方法等均会丢失
*/
shallowCloneTo(target: Object): void;
/**
* 深拷贝当前对象
* 注意: 仅深拷贝属性, 继承原型链和方法等均会丢失
*/
deepClone(): Object;
/**
* 深拷贝所有属性
* 注意: 仅深拷贝属性, 继承原型链和方法等均会丢失
*/
deepCloneTo(target: Object): void;
/**
* 清除所有属性
*/
clearAllProperty(): void;
}
(function () {
let p;
p = Object.prototype;
Object.defineProperties(p, {
getPropertyDescriptor: {
value: function (property: string) {
let pd = Object.getOwnPropertyDescriptor(this, property);
if (pd) {
return pd;
}
let prototype = Object.getPrototypeOf(this);
if (prototype) {
return prototype.getPropertyDescriptor(property);
}
return undefined;
},
enumerable: false
},
shallowClone: {
value: function () {
let result = {};
this.shallowCloneTo(result);
return result;
},
enumerable: false
},
shallowCloneTo: {
value: function (target: Object) {
for (let key in this) {
if (key in target) {
let pd: PropertyDescriptor = target.getPropertyDescriptor(key);
if (pd && (pd.set || pd.writable)) {
target[key] = this[key];
}
} else {
target[key] = this[key];
}
}
},
enumerable: false
},
deepClone: {
value: function () {
let jsonStr = JSON.stringify(this);
return JSON.parse(jsonStr);
},
enumerable: false
},
deepCloneTo: {
value: function (target: Object) {
let obj = this.deepClone();
for (let key in obj) {
if (key in target) {
let pd: PropertyDescriptor = target.getPropertyDescriptor(key);
if (pd && (pd.set || pd.writable)) {
target[key] = obj[key];
}
} else {
target[key] = obj[key];
}
}
},
enumerable: false
},
clearAllProperty: {
value: function () {
for (let key in this) {
delete this[key];
}
},
enumerable: false
}
});
String:
示例:
let type: string = '';
type.splitNum()
拓展:
interface String {
/**
* 根据分割符拆分字符串为数组且元素转换为数字
*/
splitNum(separator: string, limit?: number): number[];
splitNum(separator: RegExp, limit?: number): number[];
}
Egret:
拓展:
declare module egret {
interface IEventDispatcher {
/**
* 简写, 等同于 addEventListener
*/
on(type: string, listener: Function, thisObject: any, useCapture?: boolean, priority?: number): void;
/**
* 简写, 等同于 dispatchEventWith
*/
// dispatch(type: string | number, bubbles?: boolean, data?: any, cancelable?: boolean): boolean;
/**
* 简写, 等同于 removeEventListener
*/
off(type: string, listener: Function, thisObject: any, useCapture?: boolean): void;
}
interface EventDispatcher {
/**
* 简写, 等同于 addEventListener
*/
on(type: string, listener: Function, thisObject: any, useCapture?: boolean, priority?: number): void;
/**
* 简写, 等同于 dispatchEventWith
*/
dispatch(type: string | number, bubbles?: boolean, data?: any, cancelable?: boolean): boolean;
/**
* 简写, 等同于 removeEventListener
*/
off(type: string, listener: Function, thisObject: any, useCapture?: boolean): void;
}
module DisplayObject {
/**
* 标记是附带了中介类的视图
*/
var __isMediatorView: boolean;
}
interface DisplayObject {
/**
* 抛出添加事件
*/
__dispatchAddedEvent(event?: egret.Event): boolean;
/**
* 移除自身
*/
removeSelf(): void;
}
}
(function () {
eui.Image.prototype.dispose = function () {
this.source = null;
this["parseSource"]();
}
let f, p, t;
p = String.prototype;
Object.defineProperties(p, {
splitNum: {
value: function (separator: string | RegExp, limit?: number) {
let arr = this.split(separator, limit);
for (let i = 0, len = arr.length; i < len; i++) {
arr[i] = parseFloat(arr[i]);
}
return arr;
},
enumerable: false
},
});
p = egret.EventDispatcher.prototype;
p.on = p.addEventListener;
// p.dispatch = p.dispatchEventWith;
p.off = p.removeEventListener;
p = egret.ByteArray.prototype;
Object.defineProperties(p, {
decodeUTF8: {
value: function (data: Uint8Array): string {
let fatal: boolean = false;
let pos: number = 0;
let result: string[] = [];
let code_point: number;
let utf8_code_point = 0;
let utf8_bytes_needed = 0;
let utf8_bytes_seen = 0;
let utf8_lower_boundary = 0;
while (data.length > pos) {
let _byte = data[pos++];
if (_byte == this.EOF_byte) {
if (utf8_bytes_needed != 0) {
code_point = this.decoderError(fatal);
} else {
code_point = this.EOF_code_point;
}
} else {
if (utf8_bytes_needed == 0) {
if (this.inRange(_byte, 0x00, 0x7F)) {
code_point = _byte;
} else {
if (this.inRange(_byte, 0xC2, 0xDF)) {
utf8_bytes_needed = 1;
utf8_lower_boundary = 0x80;
utf8_code_point = _byte - 0xC0;
} else if (this.inRange(_byte, 0xE0, 0xEF)) {
utf8_bytes_needed = 2;
utf8_lower_boundary = 0x800;
utf8_code_point = _byte - 0xE0;
} else if (this.inRange(_byte, 0xF0, 0xF4)) {
utf8_bytes_needed = 3;
utf8_lower_boundary = 0x10000;
utf8_code_point = _byte - 0xF0;
} else {
this.decoderError(fatal);
}
utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed);
code_point = null;
}
} else if (!this.inRange(_byte, 0x80, 0xBF)) {
utf8_code_point = 0;
utf8_bytes_needed = 0;
utf8_bytes_seen = 0;
utf8_lower_boundary = 0;
pos--;
code_point = this.decoderError(fatal, _byte);
} else {
utf8_bytes_seen += 1;
utf8_code_point = utf8_code_point + (_byte - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen);
if (utf8_bytes_seen !== utf8_bytes_needed) {
code_point = null;
} else {
let cp = utf8_code_point;
let lower_boundary = utf8_lower_boundary;
utf8_code_point = 0;
utf8_bytes_needed = 0;
utf8_bytes_seen = 0;
utf8_lower_boundary = 0;
if (this.inRange(cp, lower_boundary, 0x10FFFF) && !this.inRange(cp, 0xD800, 0xDFFF)) {
code_point = cp;
} else {
code_point = this.decoderError(fatal, _byte);
}
}
}
}
//Decode string
if (code_point !== null && code_point !== this.EOF_code_point) {
if (code_point <= 0xFFFF) {
if (code_point > 0) result.push(String.fromCharCode(code_point));
} else {
code_point -= 0x10000;
result.push(String.fromCharCode(0xD800 + ((code_point >> 10) & 0x3ff)));
result.push(String.fromCharCode(0xDC00 + (code_point & 0x3ff)));
}
}
}
return result.join("");
},
enumerable: false
}
});
p = egret.DisplayObject.prototype;
Object.defineProperties(p, {
__dispatchAddedEvent: {
value: function (event?: egret.Event): boolean {
return this.dispatchEventWith(egret.Event.ADDED, true);
},
enumerable: false
},
removeSelf: {
value: function () {
if (this.parent) {
this.parent.removeChild(this);
}
},
enumerable: false
}
});
//看看是哪个图集有资源缺失
p = egret.BitmapText.prototype;
Object.defineProperties(p, {
$updateRenderNode: {
value: function () {
var self = this;
var textLines = this.$getTextLines();
var length = textLines.length;
if (length == 0) {
if (egret.nativeRender && self.$font) {
self.$nativeDisplayObject.setDataToBitmapNode(self.$nativeDisplayObject.id, self.$font.$texture, []);
self.$nativeDisplayObject.setWidth(0);
self.$nativeDisplayObject.setHeight(0);
}
return;
}
var drawArr = [];
var textLinesWidth = this.$textLinesWidth;
var bitmapFont = self.$font;
var node;
if (!egret.nativeRender) {
node = this.$renderNode;
if (bitmapFont.$texture) {
node.image = bitmapFont.$texture.$bitmapData;
}
node.smoothing = self.$smoothing;
}
var emptyHeight = bitmapFont._getFirstCharHeight();
var emptyWidth = Math.ceil(emptyHeight * egret.BitmapText.EMPTY_FACTOR);
var hasSetHeight = !isNaN(self.$textFieldHeight);
var textWidth = self.$textWidth;
var textFieldWidth = self.$textFieldWidth;
var textFieldHeight = self.$textFieldHeight;
var align = self.$textAlign;
var yPos = this.$textOffsetY + this.$textStartY;
var lineHeights = this.$lineHeights;
for (var i = 0; i < length; i++) {
var lineHeight = lineHeights[i];
if (hasSetHeight && i > 0 && yPos + lineHeight > textFieldHeight) {
break;
}
var line = textLines[i];
var len = line.length;
var xPos = this.$textOffsetX;
if (align != egret.HorizontalAlign.LEFT) {
var countWidth = textFieldWidth > textWidth ? textFieldWidth : textWidth;
if (align == egret.HorizontalAlign.RIGHT) {
xPos += countWidth - textLinesWidth[i];
}
else if (align == egret.HorizontalAlign.CENTER) {
xPos += Math.floor((countWidth - textLinesWidth[i]) / 2);
}
}
for (var j = 0; j < len; j++) {
var character = line.charAt(j);
var texture = bitmapFont.getTexture(character);
if (!texture) {
if (character == " ") {
xPos += emptyWidth;
}
else {
//看看是哪个图集有资源缺失
egret.$warn(1046, character + (bitmapFont.$resourceInfo && bitmapFont.$resourceInfo.name ? bitmapFont.$resourceInfo.name : ""));
}
continue;
}
var bitmapWidth = texture.$bitmapWidth;
var bitmapHeight = texture.$bitmapHeight;
if (egret.nativeRender) {
drawArr.push(texture.$bitmapX, texture.$bitmapY, bitmapWidth, bitmapHeight, xPos + texture.$offsetX, yPos + texture.$offsetY, texture.$getScaleBitmapWidth(), texture.$getScaleBitmapHeight(), texture.$sourceWidth, texture.$sourceHeight);
}
else {
node.imageWidth = texture.$sourceWidth;
node.imageHeight = texture.$sourceHeight;
node.drawImage(texture.$bitmapX, texture.$bitmapY, bitmapWidth, bitmapHeight, xPos + texture.$offsetX, yPos + texture.$offsetY, texture.$getScaleBitmapWidth(), texture.$getScaleBitmapHeight());
}
xPos += (bitmapFont.getConfig(character, "xadvance") || texture.$getTextureWidth()) + self.$letterSpacing;
}
yPos += lineHeight + self.$lineSpacing;
}
if (egret.nativeRender) {
self.$nativeDisplayObject.setDataToBitmapNode(self.$nativeDisplayObject.id, bitmapFont.$texture, drawArr);
var bounds = self.$getContentBounds();
self.$nativeDisplayObject.setWidth(bounds.width);
self.$nativeDisplayObject.setHeight(bounds.height);
}
},
}
});
p = egret.Sprite.prototype;
Object.defineProperties(p, {
$hitTest: {
value: function (stageX, stageY) {
if (!this.$visible) {
return null;
}
var m = this.$getInvertedConcatenatedMatrix();
var localX = m.a * stageX + m.c * stageY + m.tx;
var localY = m.b * stageX + m.d * stageY + m.ty;
var rect = this.$scrollRect ? this.$scrollRect : this.$maskRect;
if (rect && !rect.contains(localX, localY)) {
return null;
}
if (this.$mask && !this.$mask.$hitTest(stageX, stageY)) {
return null;
}
var children = this.$children;
var found = false;
var target = null;
for (var i = children.length - 1; i >= 0; i--) {
var child = children[i];
if (child == null || child.$maskedObject) {//判断child是不是正经的
continue;
}
target = child.$hitTest(stageX, stageY);
if (target) {
found = true;
if (target.$touchEnabled) {
break;
}
else {
target = null;
}
}
}
if (target) {
if (this.$touchChildren) {
return target;
}
return this;
}
if (found) {
return this;
}
target = egret.DisplayObject.prototype.$hitTest.call(this, stageX, stageY);
if (target) {
target = this.$graphics.$hitTest(stageX, stageY);
}
return target;
}
},
});
RES.on = RES.addEventListener;
RES.off = RES.removeEventListener;
p = egret.DisplayObjectContainer.prototype;
t = p.$doAddChild;
Object.defineProperties(p, {
$doAddChild: {
value: function (child: egret.DisplayObject, index: number, notifyListeners: boolean = true): egret.DisplayObject {
// 下面的代码用于带有中介类的 View 添加到还没有添加到舞台的父容器时的额外处理, 该 View 已经不会发送 ADDED 事件
// 除上面的情况外, 直接添加到舞台或已存在舞台的父容器时普通显示对象和 EUI 组件逻辑均正常
let p = Object.getPrototypeOf(child);
let hasMediator = p.constructor.__isMediatorView;
if (hasMediator && !this.stage) {
// EUI 特殊处理下, 保证第一次打开时 createChildren 和 childrenCreated 方法都执行完毕后再执行 onRegister 方法
if (child instanceof eui.Component && !child.$UIComponent[eui.sys.UIKeys.initialized]) {
child.once(eui.UIEvent.CREATION_COMPLETE, (event: eui.UIEvent) => {
child.on(egret.Event.ADDED_TO_STAGE, child.__dispatchAddedEvent, child);
child.__dispatchAddedEvent();
}, this);
}
// 非 EUI 直接监听添加到舞台的事件即可
else {
child.on(egret.Event.ADDED_TO_STAGE, child.__dispatchAddedEvent, child);
}
}
return t.call(this, child, index, notifyListeners);
},
enumerable: false
},
$hitTest: {
value: function (stageX, stageY) {
if (!this.$visible) {
return null;
}
var m = this.$getInvertedConcatenatedMatrix();
var localX = m.a * stageX + m.c * stageY + m.tx;
var localY = m.b * stageX + m.d * stageY + m.ty;
var rect = this.$scrollRect ? this.$scrollRect : this.$maskRect;
if (rect && !rect.contains(localX, localY)) {
return null;
}
if (this.$mask && !this.$mask.$hitTest(stageX, stageY)) {
return null;
}
var children = this.$children;
var found = false;
var target = null;
for (var i = children.length - 1; i >= 0; i--) {
var child = children[i];
if (child == null || child.$maskedObject) {//判断child是不是正经的
continue;
}
target = child.$hitTest(stageX, stageY);
if (target) {
found = true;
if (target.$touchEnabled) {
break;
}
else {
target = null;
}
}
}
if (target) {
if (this.$touchChildren) {
return target;
}
return this;
}
if (found) {
return this;
}
return egret.DisplayObject.prototype.$hitTest.call(this, stageX, stageY);
}
},
});
/**
* 项呈示器被移除
* @param renderer 移除的项呈示器
* @param index 项呈示器的索引
* @param item 项呈示器对应的数据
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
eui.DataGroup.prototype["rendererRemoved"] = function (renderer, index, item) {
renderer.off(egret.TouchEvent.TOUCH_BEGIN, this.onRendererTouchBegin, this);
renderer.off(egret.TouchEvent.TOUCH_END, this.onRendererTouchEnd, this);
renderer.off(egret.TouchEvent.TOUCH_CANCEL, this.onRendererTouchCancle, this);
if (renderer["dispose"]) {
renderer["dispose"]();
}
};
eui.ListBase.prototype["rendererRemoved"] = function (renderer, index, item) {
renderer.off(egret.TouchEvent.TOUCH_BEGIN, this.onRendererTouchBegin, this);
renderer.off(egret.TouchEvent.TOUCH_END, this.onRendererTouchEnd, this);
renderer.off(egret.TouchEvent.TOUCH_CANCEL, this.onRendererTouchCancle, this);
if (renderer["dispose"]) {
renderer["dispose"]();
}
};
eui.ItemRenderer.prototype["disposeSkin"] = function (view) {
var i, numChildren, j;//,totalFrames:int;
numChildren = view.numChildren;
for (i = 0; i < numChildren; i++) {
var mc: any = view.getChildAt(i);
if (mc) {
//0:图片,1:九宫格,2:按钮
if (mc instanceof eui.List) {
// this.disposeSkin(mc);
mc.$DataGroup[10] = true;
mc["removeAllRenderers"]();
mc.dataProvider = null;
mc.itemRenderer = null;
} else if (mc instanceof eui.Image) {
(mc as eui.Image).source = null;
mc["parseSource"]();
} else if (mc instanceof NameMovieClip) {
mc.stop();
mc.data = null;
} else {
this.disposeSkin(mc);
}
}
}
}
eui.ItemRenderer.prototype["dispose"] = function () {
this.disposeSkin(this);
}
eui.DataGroup.prototype["measureRendererSize"] = function () {
var values = this.$DataGroup;
if (values[12 /* typicalItem */] == undefined) {
this.setTypicalLayoutRect(null);
return;
}
var typicalRenderer = this.createVirtualRenderer(values[12 /* typicalItem */]);
if (!typicalRenderer) {
this.setTypicalLayoutRect(null);
return;
}
this.updateRenderer(typicalRenderer, 0, values[12 /* typicalItem */]);
typicalRenderer.validateNow();
var bounds = egret.$TempRectangle;
typicalRenderer.getPreferredBounds(bounds);
var rect = new egret.Rectangle(0, 0, bounds.width, bounds.height);
if (this.$layout && this.$layout.$useVirtualLayout) {
if (values[4 /* createNewRendererFlag */]) {
this.rendererAdded(typicalRenderer, 0, values[12 /* typicalItem */]);
}
this.doFreeRenderer(typicalRenderer);
}
else {
this.rendererRemoved(typicalRenderer, typicalRenderer.itemIndex, typicalRenderer.data);
this.removeChild(typicalRenderer);
}
this.setTypicalLayoutRect(rect);
values[4 /* createNewRendererFlag */] = false;
};
eui.Scroller.prototype["onRemoveListeners"] = function () {
var stage = this.tempStage || this.$stage;
this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this, true);
stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
this.removeEventListener(egret.TouchEvent.TOUCH_CANCEL, this.onTouchCancel, this);
this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoveListeners, this);
var values = this.$Scroller;
var touchScrollH = 8; //touchScrollH
var touchScrollV = 9; //touchScrollV
var viewport = this.$Scroller[10 /* viewport */];
var uiValues = viewport.$UIComponent;
if (values[touchScrollH].isStarted()) {
values[touchScrollH].finish(viewport.scrollH, viewport.contentWidth - uiValues[eui.sys.UIKeys.width]);
}
if (values[touchScrollV].isStarted()) {
values[touchScrollV].finish(viewport.scrollV, viewport.contentHeight - uiValues[eui.sys.UIKeys.height]);
}
}
Long.prototype["_toNumber"] = function () {
return this._high * ((1 << 16) * (1 << 16)) + (this._low >>> 0);
}
egret.Tween.removeTweens = function (target) {
if (!target) {
return;
}
if (!target.tween_count) {
return;
}
var tweens = egret.Tween["_tweens"];
for (var i = tweens.length - 1; i >= 0; i--) {
if (tweens[i]._target == target) {
tweens[i].paused = true;
tweens.splice(i, 1);
}
}
target.tween_count = 0;
};
/**
* @private
* 解析source
*/
eui.Image.prototype["parseSource"] = function () {
var _this = this;
this.sourceChanged = false;
if (this.lastSource != this._source) {
if (this.lastSource) {
ImageCacheManager.Instance.returnAutoReleaseTexture(_this.lastSource);
}
this.lastSource = _this._source;
var thizzSource = _this._source;
if (_this._source) {
if (typeof _this._source == "string") {
var result = RES.config.getResourceWithSubkey(thizzSource);
if (result && result.r && result.r.extra != 1) {
let data = RES.getRes(thizzSource);
if (data) {
_this.$setBitmapData(data);
_this.dispatchEventWith(egret.Event.COMPLETE);
}
else {
RES.getResAsync(thizzSource, function (data) {
if (thizzSource !== _this._source)
return;
if (!egret.is(data, "egret.Texture")) {
return;
}
_this.$setBitmapData(data);
if (data) {
_this.dispatchEventWith(egret.Event.COMPLETE);
}
else if (true) {
egret.$warn(2301, thizzSource);
}
}, this);
}
} else {
ImageCacheManager.Instance.addAutoReleaseTextureCount(_this._source);
if (ImageCacheManager.Instance.hasAutoReleaseTexture(_this._source)) {
var cacheTexture = ImageCacheManager.Instance.getAutoReleaseTexture(_this._source);
_this.$setBitmapData(cacheTexture);
if (cacheTexture) {
_this.dispatchEventWith(egret.Event.COMPLETE);
}
} else {
RES.getResByUrl(thizzSource, (data, url) => {
let refernceCount = ImageCacheManager.Instance.getRefrenceCount(thizzSource);
if (refernceCount <= 0 || refernceCount == undefined && data) {
// data.dispose();
// return;
}
if (!egret.is(data, "egret.Texture")) {
return;
}
ImageCacheManager.Instance.setAutoReleaseTexture(thizzSource, data);
if (thizzSource !== _this._source)
return;
_this.$setBitmapData(data);
if (data) {
_this.dispatchEventWith(egret.Event.COMPLETE);
}
else if (true) {
egret.$warn(2301, thizzSource);
}
}, this, RES.NCImg);
}
}
} else {
this.$setBitmapData(thizzSource);
}
// if (App.asset.hasAutoReleaseBmp(url))
// bmpLoaded(this, url, App.asset.getAutoReleaseBmp(url));
// else {
// App.mloader3.loadBMD(realUrl, 1, new Handler(bmpLoaded, [this, url]), null, null, false);
// }
} else {
this.$setBitmapData(null);
}
}
};
egret.web["WebGLRenderContext"].blendModesForGL["lighter"] = [775, 1];
// egret.web["blendModes"] = ["source-over", "lighter", "destination-out", "screen"];
/**
* 输入文本,聚焦和失焦 处理键盘快捷键
*/
egret.InputController.prototype["focusHandler"] = function (event) {
//不再显示竖线,并且输入框显示最开始
if (!this._isFocus) {
PcKeyBoardManager.canUseKB = false;
this._isFocus = true;
if (!event["showing"]) {
this._text.$setIsTyping(true);
}
this._text.dispatchEvent(new egret.FocusEvent(egret.FocusEvent.FOCUS_IN, true));
}
};
egret.InputController.prototype["blurHandler"] = function (event) {
if (this._isFocus) {
PcKeyBoardManager.canUseKB = true;
//不再显示竖线,并且输入框显示最开始
this._isFocus = false;
this.tempStage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onStageDownHandler, this);
this._text.$setIsTyping(false);
//失去焦点后调用
this.stageText.$onBlur();
this._text.dispatchEvent(new egret.FocusEvent(egret.FocusEvent.FOCUS_OUT, true));
}
};
})();
declare module RES.processor {
var pvrProcessor: Processor;
}
RES.processor.pvrProcessor = {
onLoadStart: function (host, resource) {
return host.load(resource, "ktx").then(function (colorTex) {
if (!colorTex) {
return null;
}
if (resource['etc1_alpha_url']) {
var r_1 = RES.processor.makeEtc1SeperatedAlphaResourceInfo(resource);
return host.load(r_1, "ktx")
.then(function (alphaMaskTex) {
if (colorTex && colorTex.$bitmapData && alphaMaskTex.$bitmapData) {
colorTex.$bitmapData.etcAlphaMask = alphaMaskTex.$bitmapData;
host.save(r_1, alphaMaskTex);
}
else {
host.remove(r_1);
}
return colorTex;
}, function (e) {
host.remove(r_1);
throw e;
});
}
return colorTex;
}, function (e) {
host.remove(resource);
throw e;
});
},
onRemoveStart: function (host, resource) {
var colorTex = host.get(resource);
if (colorTex) {
colorTex.dispose();
}
if (resource['etc1_alpha_url']) {
var r = RES.processor.makeEtc1SeperatedAlphaResourceInfo(resource);
var alphaMaskTex = host.get(r);
if (alphaMaskTex) {
alphaMaskTex.dispose();
}
host.unload(r); //这里其实还会再删除一次,不过无所谓了。alphaMaskTex已经显示删除了
}
}
};
RES.processor["_map"]["pvrtc.ktx"] = RES.processor.pvrProcessor;
//文本是2个字,中间加空格
Object.defineProperty(eui.Button.prototype, "label", {
/**
* Text to appear on the Button control.
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 要在按钮上显示的文本。
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
get: function () {
return this._label;
},
set: function (value) {
if (typeof value === "string" && value.length === 2) {
value = `${value[0]} ${value[1]}`;
}
this._label = value;
if (this.labelDisplay) {
this.labelDisplay.text = value;
}
},
enumerable: true,
configurable: true
});
山重水复疑无路,柳暗花明又一村!
专注填坑,少走弯路!