enchance deprecated and add some deprecated in animation module (#5055)

This commit is contained in:
jiaxin.lai
2019-08-01 18:00:49 +08:00
committed by Weiliang Wang
parent 75b27045ee
commit 09d432d354
3 changed files with 107 additions and 46 deletions
+39
View File
@@ -0,0 +1,39 @@
import { deprecatedWrapper } from '../deprecated';
import { AnimationComponent } from './animation-component';
import { AnimationClip } from './animation-clip';
import { error } from '../core/platform/CCDebug';
// deprecated
if (CC_DEBUG) {
/**
* API更名
*/
deprecatedWrapper({
oldTarget: AnimationComponent.prototype,
oldPrefix: "AnimationComponent",
newTarget: AnimationComponent.prototype,
newPrefix: "AnimationComponent",
pairs: [
['getAnimationState', 'getState'],
['addClip', 'createState']
]
});
/**
* API更名,以及参数变更
*/
deprecatedWrapper({
oldTarget: AnimationComponent.prototype,
oldPrefix: "AnimationComponent",
pairs: [['removeClip']],
compatible: false,
custom: function (...args: any) {
error("removeClip已经弃用,请使用removeState,并注意两者参数不一致");
let arg0 = args[0] as AnimationClip;
return AnimationComponent.prototype.removeState.call(this, arg0.name);
}
});
}
+2
View File
@@ -16,3 +16,5 @@ export * from './skeletal-animation-clip';
export * from './skeletal-animation-state';
export * from './skeletal-animation-component';
export * from './transform-utils';
import './deprecated';
+66 -46
View File
@@ -2,8 +2,7 @@
* @hidden
*/
import { js } from './core/utils/js';
import { errorID, error, warnID, warn } from './core/platform/CCDebug';
import { error, warn } from './core/platform/CCDebug';
export interface IWrapOptions {
oldTarget: Function | {};
@@ -12,6 +11,7 @@ export interface IWrapOptions {
newTarget?: Function | {};
newPrefix?: string;
custom?: Function;
compatible?: boolean;
}
export let deprecatedWrapper: (option: IWrapOptions) => void;
@@ -23,61 +23,81 @@ if (CC_DEBUG) {
let newPrefix = option.newPrefix;
let deprecatedProps = option.pairs;
let custom = option.custom;
let compatible = (option.compatible == null || option.compatible == true) ? true : false;
let _t0: {};
if (typeof oldTarget == 'function') {
_t0 = oldTarget.prototype;
} else {
_t0 = oldTarget;
}
let _t0 = oldTarget;
let _t1 = newTarget;
let _t1: {};
if (newTarget) {
if (typeof newTarget == 'function') {
_t1 = newTarget.prototype;
} else {
_t1 = newTarget;
}
}
deprecatedProps.forEach(function (prop: string[]) {
let deprecatedProp = prop[0];
let newProp: string;
if (prop.length > 1) {
newProp = prop[1];
}
let _print = () => {
if (custom != null) {
// custom message
custom();
} else if (newProp != null && newPrefix != null) {
// remove but provide a new
warn("'%s' is deprecated, please use '%s' instead.", `${oldPrefix}.${deprecatedProp}`, `${newPrefix}.${newProp}`);
} else {
// remove only
error("'%s.%s' is removed", oldPrefix, deprecatedProp);
if (compatible) {
deprecatedProps.forEach(function (prop: string[]) {
let deprecatedProp = prop[0];
let newProp: string;
if (prop.length > 1) {
newProp = prop[1];
}
};
Object.defineProperty(_t0, deprecatedProp, {
/**
* default log && return
*/
/* eslint-disable-next-line */
get: function () {
_print();
let _default = () => {
if (newProp != null && newPrefix != null) {
// remove but provide a new
warn("'%s' is deprecated, please use '%s' instead.", `${oldPrefix}.${deprecatedProp}`, `${newPrefix}.${newProp}`);
} else if (newTarget != null) {
// remove but will provide a new
warn("'%s' is deprecated.", `${oldPrefix}.${deprecatedProp}`);
} else {
// remove only
error("'%s.%s' is removed", oldPrefix, deprecatedProp);
}
if (newProp != null && _t1 != null && _t1[newProp] != null) {
return _t1[newProp];
}
},
set: function (v: any) {
_print();
if (newProp != null && _t1 != null && _t1[newProp] != null) {
if (typeof _t1[newProp] !== 'function') {
_t1[newProp] = v;
};
Object.defineProperty(_t0, deprecatedProp, {
/* eslint-disable-next-line */
get: function (this) {
if (custom != null) {
return custom.call(this);
} else {
return _default();
}
},
set: function (this, v: any) {
if (custom != null) {
custom.call(this);
} else {
_default();
}
if (newProp != null && _t1 != null && _t1[newProp] != null) {
if (typeof _t1[newProp] !== 'function') {
_t1[newProp] = v;
}
}
}
}
});
});
});
} else {
deprecatedProps.forEach(function (prop: string[]) {
let deprecatedProp = prop[0];
Object.defineProperty(_t0, deprecatedProp, {
/* eslint-disable-next-line */
value: function (this, ...args: any) {
if (custom != null) {
return custom.call(this,
args[0], args[1], args[2],
args[3], args[4], args[5],
args[6], args[7], args[8],
args[9], args[10], args[11]);
}
}
});
});
}
};
} else {
// for compatible