mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
505 lines
16 KiB
JavaScript
505 lines
16 KiB
JavaScript
if (CC_DEV) {
|
|
var js = cc.js;
|
|
|
|
var INFO = cc._LogInfos.deprecated;
|
|
|
|
/**
|
|
* Inject all of the properties in source objects to target object and return the target object.
|
|
* @param {object} target
|
|
* @param {object} *sources
|
|
* @name cc.inject
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @returns {object}
|
|
*/
|
|
js.get(cc, "inject", function () {
|
|
cc.warn(INFO + " The first argument should be the destination object", 'cc.inject', 'cc.js.addon');
|
|
return js.addon;
|
|
});
|
|
|
|
/**
|
|
* Copy all of the properties in source objects to target object and return the target object.
|
|
* @param {object} target
|
|
* @param {object} *sources
|
|
* @name cc.extend
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @returns {object}
|
|
*/
|
|
js.get(cc, "extend", function () {
|
|
cc.warn(INFO, 'cc.extend', 'cc.js.mixin');
|
|
return js.mixin;
|
|
});
|
|
|
|
/**
|
|
* Create new DOM element by tag name
|
|
* @name cc.newElement
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @returns {object}
|
|
*/
|
|
js.get(cc, "newElement", function () {
|
|
cc.warn(INFO, 'cc.newElement', 'document.createElement');
|
|
return document.createElement;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is function or not
|
|
* @name cc.isFunction
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isFunction", function () {
|
|
cc.warn(INFO, 'cc.isFunction', 'cc.js.isFunction');
|
|
return js.isFunction;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is number or not
|
|
* @name cc.isNumber
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isNumber", function () {
|
|
cc.warn(INFO, 'cc.isNumber', 'cc.js.isNumber');
|
|
return js.isNumber;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is string or not
|
|
* @name cc.isString
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isString", function () {
|
|
cc.warn(INFO, 'cc.isString', 'cc.js.isString');
|
|
return js.isString;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is array or not
|
|
* @name cc.isArray
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isArray", function () {
|
|
cc.warn(INFO, 'cc.isArray', 'cc.js.isArray');
|
|
return js.isArray;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is undefined or not
|
|
* @name cc.isUndefined
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isUndefined", function () {
|
|
cc.warn(INFO, 'cc.isUndefined', 'cc.js.isUndefined');
|
|
return js.isUndefined;
|
|
});
|
|
|
|
/**
|
|
* Check the obj whether is object or not
|
|
* @name cc.isObject
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {*} obj
|
|
* @returns {boolean}
|
|
*/
|
|
js.get(cc, "isObject", function () {
|
|
cc.warn(INFO, 'cc.isObject', 'cc.js.isObject');
|
|
return js.isObject;
|
|
});
|
|
|
|
/**
|
|
* cc.Point is the class for point object, please do not use its constructor to create points, use cc.p() alias function instead.
|
|
* @class cc.Point
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Number} x
|
|
* @param {Number} y
|
|
* @see cc.Vec2
|
|
*/
|
|
js.obsoletes(cc, 'cc', {
|
|
"Point": 'Vec2'
|
|
});
|
|
|
|
/**
|
|
* Verify Array's Type
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Array} arr
|
|
* @param {function} type
|
|
* @return {Boolean}
|
|
* @function
|
|
*/
|
|
js.get(cc, 'arrayVerifyType', function () {
|
|
cc.warn(INFO, 'cc.arrayVerifyType', 'cc.js.array.verifyType');
|
|
return cc.js.array.verifyType;
|
|
});
|
|
|
|
/**
|
|
* Searches for the first occurance of object and removes it. If object is not found the function has no effect.
|
|
* @function
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Array} arr Source Array
|
|
* @param {*} delObj remove object
|
|
*/
|
|
js.get(cc, 'arrayRemoveObject', function () {
|
|
cc.warn(INFO, 'cc.arrayRemoveObject', 'cc.js.array.remove');
|
|
return cc.js.array.remove;
|
|
});
|
|
|
|
/**
|
|
* Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed.
|
|
* @function
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Array} arr Source Array
|
|
* @param {Array} minusArr minus Array
|
|
*/
|
|
js.get(cc, 'arrayRemoveArray', function () {
|
|
cc.warn(INFO, 'cc.arrayRemoveArray', 'cc.js.array.removeArray');
|
|
return cc.js.array.removeArray;
|
|
});
|
|
|
|
/**
|
|
* Inserts some objects at index
|
|
* @function
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Array} arr
|
|
* @param {Array} addObjs
|
|
* @param {Number} index
|
|
* @return {Array}
|
|
*/
|
|
js.get(cc, 'arrayAppendObjectsToIndex', function() {
|
|
cc.warn(INFO, 'cc.arrayAppendObjectsToIndex', 'cc.js.array.appendObjectsAt');
|
|
return cc.js.array.appendObjectsAt;
|
|
});
|
|
|
|
/**
|
|
* Copy an array's item to a new array (its performance is better than Array.slice)
|
|
* @memberof cc
|
|
* @deprecated
|
|
* @param {Array} arr
|
|
* @return {Array}
|
|
*/
|
|
js.get(cc, 'copyArray', function() {
|
|
cc.warn(INFO, 'cc.copyArray', 'cc.js.array.copy');
|
|
return cc.js.array.copy;
|
|
});
|
|
|
|
function deprecateEnum (obj, oldPath, newPath, hasTypePrefixBefore) {
|
|
hasTypePrefixBefore = hasTypePrefixBefore !== false;
|
|
var enumDef = eval(newPath);
|
|
var entries = cc.Enum.getList(enumDef);
|
|
var delimiter = hasTypePrefixBefore ? '_' : '.';
|
|
for (var i = 0; i < entries.length; i++) {
|
|
var entry = entries[i].name;
|
|
var oldPropName;
|
|
if (hasTypePrefixBefore) {
|
|
var oldTypeName = oldPath.split('.').slice(-1)[0];
|
|
oldPropName = oldTypeName + '_' + entry;
|
|
}
|
|
else {
|
|
oldPropName = entry;
|
|
}
|
|
js.get(obj, oldPropName, function (entry) {
|
|
cc.warn(INFO, oldPath + delimiter + entry, newPath + '.' + entry);
|
|
return enumDef[entry];
|
|
}.bind(null, entry));
|
|
}
|
|
}
|
|
|
|
deprecateEnum(cc, 'cc.TEXT_ALIGNMENT', 'cc.TextAlignment');
|
|
deprecateEnum(cc, 'cc.VERTICAL_TEXT_ALIGNMENT', 'cc.VerticalTextAlignment');
|
|
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.TYPE', 'cc.ParticleSystem.Type');
|
|
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.Mode');
|
|
deprecateEnum(cc.EParticleSystem, 'cc.EParticleSystem.TYPE', 'cc.EParticleSystem.PositionType');
|
|
deprecateEnum(cc.EParticleSystem, 'cc.EParticleSystem.MODE', 'cc.EParticleSystem.EmitterMode');
|
|
deprecateEnum(ccui.ScrollView, 'ccui.ScrollView.DIR', 'ccui.ScrollView.Dir');
|
|
deprecateEnum(ccui.ScrollView, 'ccui.ScrollView.EVENT', 'ccui.ScrollView.Event');
|
|
deprecateEnum(ccui.Layout, 'ccui.Layout', 'ccui.Layout.Type', false);
|
|
deprecateEnum(ccui.LoadingBar, 'ccui.LoadingBar.TYPE', 'ccui.LoadingBar.Type');
|
|
deprecateEnum(ccui.RelativeLayoutParameter, 'ccui.RelativeLayoutParameter', 'ccui.RelativeLayoutParameter.Type', false);
|
|
deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
|
|
deprecateEnum(cc.game, 'cc.game.DEBUG_MODE', 'cc.DebugMode');
|
|
if (cc.EditBox) {
|
|
deprecateEnum(cc, 'cc.KEYBOARD_RETURNTYPE', 'cc.KeyboardReturnType');
|
|
deprecateEnum(cc, 'cc.EDITBOX_INPUT_MODE', 'cc.EditBox.InputMode');
|
|
deprecateEnum(cc, 'cc.EDITBOX_INPUT_FLAG', 'cc.EditBox.InputFlag');
|
|
}
|
|
cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
|
|
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
|
|
});
|
|
|
|
function markAsRemoved (ownerCtor, removedProps, ownerName) {
|
|
ownerName = ownerName || js.getClassName(ownerCtor);
|
|
removedProps.forEach(function (prop) {
|
|
function error () {
|
|
cc.error('Sorry, %s.%s is removed.', ownerName, prop);
|
|
}
|
|
js.getset(ownerCtor.prototype, prop, error, error);
|
|
});
|
|
}
|
|
|
|
function provideClearError (owner, obj) {
|
|
var className = cc.js.getClassName(owner);
|
|
var Info = 'Sorry,' + className + '.%s is removed, please use %s instead.';
|
|
for (var prop in obj) {
|
|
function define (prop, getset) {
|
|
function accessor (newProp) {
|
|
cc.error(Info, prop, newProp);
|
|
}
|
|
if (!Array.isArray(getset)) {
|
|
getset = getset.split(',')
|
|
.map(function (x) {
|
|
return x.trim();
|
|
});
|
|
}
|
|
js.getset(owner, prop, accessor.bind(null, getset[0]), getset[1] && accessor.bind(null, getset[1]));
|
|
}
|
|
var getset = obj[prop];
|
|
if (prop[0] === '*') {
|
|
// get set
|
|
var etProp = prop.slice(1);
|
|
define('g' + etProp, getset);
|
|
define('s' + etProp, getset);
|
|
}
|
|
else {
|
|
prop.split(',')
|
|
.map(function (x) {
|
|
return x.trim();
|
|
})
|
|
.forEach(function (x) {
|
|
define(x, getset);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
function shouldNotUseNodeProp (component) {
|
|
var compName = cc.js.getClassName(component);
|
|
var Info = 'Sorry, ' + compName + '.%s is removed, please use cc.ENode.%s instead.';
|
|
var compProto = component.prototype;
|
|
for (var prop in cc.ENode.prototype) {
|
|
(function (prop) {
|
|
if (!(prop in compProto) && prop[0] !== '_') {
|
|
js.getset(compProto, prop,
|
|
function () {
|
|
cc.error(Info, prop, prop);
|
|
},
|
|
function () {
|
|
cc.error(Info, prop, prop);
|
|
}
|
|
);
|
|
}
|
|
})(prop);
|
|
}
|
|
}
|
|
|
|
// cc.ENode
|
|
|
|
markAsRemoved(cc.ENode, [
|
|
'_componentContainer',
|
|
'_camera',
|
|
'_additionalTransform',
|
|
'_scheduler',
|
|
'_actionManager',
|
|
'actionManager',
|
|
'_isTransitionFinished',
|
|
'_additionalTransformDirty',
|
|
'_shaderProgram',
|
|
'shaderProgram',
|
|
'_reorderChildDirty',
|
|
'_normalizedPositionDirty',
|
|
'_normalizedPosition',
|
|
'_usingNormalizedPosition',
|
|
'_renderCmd',
|
|
'_vertexZ',
|
|
'_showNode',
|
|
'_arrayMakeObjectsPerformSelector',
|
|
'getActionManager',
|
|
'setActionManager',
|
|
'getScheduler',
|
|
'setScheduler',
|
|
'sortAllChildren',
|
|
'reorderChild',
|
|
'draw',
|
|
'transformAncestors',
|
|
'onEnter',
|
|
'onEnterTransitionDidFinish',
|
|
'onExitTransitionDidStart',
|
|
'onExit',
|
|
'runAction',
|
|
'stopAllActions',
|
|
'stopAction',
|
|
'stopActionByTag',
|
|
'getActionByTag',
|
|
'getNumberOfRunningActions',
|
|
'scheduleUpdate',
|
|
'scheduleUpdateWithPriority',
|
|
'unscheduleUpdate',
|
|
'schedule',
|
|
'scheduleOnce',
|
|
'unschedule',
|
|
'unscheduleAllCallbacks',
|
|
'resumeSchedulerAndActions',
|
|
'resume',
|
|
'pauseSchedulerAndActions',
|
|
'pause',
|
|
'setAdditionalTransform',
|
|
'updateTransform',
|
|
'retain',
|
|
'release',
|
|
'visit',
|
|
'transform',
|
|
'getCamera',
|
|
'grid',
|
|
'getGrid',
|
|
'setGrid',
|
|
'getShaderProgram',
|
|
'setShaderProgram',
|
|
'getGLServerState',
|
|
'setGLServerState',
|
|
'_initRendererCmd',
|
|
'_createRenderCmd',
|
|
'updateDisplayedOpacity',
|
|
'updateDisplayedColor',
|
|
'userData',
|
|
'userObject',
|
|
'_cascadeColorEnabled',
|
|
'cascadeColor'
|
|
]);
|
|
provideClearError(cc.ENode.prototype, {
|
|
arrivalOrder: 'getSiblingIndex, setSiblingIndex',
|
|
_visible: '_activeInHierarchy, active',
|
|
_running: '_activeInHierarchy, active',
|
|
running: 'activeInHierarchy, active',
|
|
_realOpacity: '_opacity, _opacity',
|
|
_realColor: '_color, _color',
|
|
getZOrder: 'getLocalZOrder',
|
|
setZOrder: 'setLocalZOrder',
|
|
getOrderOfArrival: 'getSiblingIndex',
|
|
setOrderOfArrival: 'setSiblingIndex',
|
|
boundingBox: 'getBoundingBox',
|
|
removeFromParentAndCleanup: 'removeFromParent',
|
|
removeAllChildrenWithCleanup: 'removeAllChildren',
|
|
parentToNodeTransform: 'getParentToNodeTransform',
|
|
nodeToWorldTransform: 'getNodeToWorlshaderProgramdTransform',
|
|
worldToNodeTransform: 'getWorldToNodeTransform',
|
|
nodeToParentTransform: 'getNodeToParentTransform',
|
|
removeAllComponents: 'removeComponent',
|
|
getNodeToParentAffineTransform: 'getNodeToParentTransform',
|
|
});
|
|
|
|
// cc.SpriteRenderer
|
|
|
|
markAsRemoved(cc.SpriteRenderer, [
|
|
'textureLoaded',
|
|
'setBlendFunc',
|
|
'getBlendFunc',
|
|
'setState',
|
|
'getState',
|
|
]);
|
|
provideClearError(cc.SpriteRenderer, {
|
|
create: 'node.addComponent',
|
|
createWithTexture: 'node.addComponent',
|
|
createWithSpriteFrameName: 'node.addComponent',
|
|
createWithSpriteFrame: 'node.addComponent',
|
|
});
|
|
provideClearError(cc.SpriteRenderer.prototype, {
|
|
ignoreAnchorPointForPosition: 'instance.ignoreAnchor',
|
|
});
|
|
shouldNotUseNodeProp(cc.SpriteRenderer);
|
|
|
|
// Particle
|
|
markAsRemoved(cc.EParticleSystem, [
|
|
'batchNode',
|
|
'drawMode',
|
|
'getDrawMode',
|
|
'setDrawMode',
|
|
'shapeType',
|
|
'getShapeType',
|
|
'setShapeType',
|
|
'atlasIndex',
|
|
'init',
|
|
'initParticle',
|
|
'updateWithNoTime',
|
|
]);
|
|
provideClearError(cc.EParticleSystem, {
|
|
initWithFile: 'instance.file',
|
|
initWithDictionary: 'instance.file',
|
|
initWithTotalParticles: 'instance.totalParticles'
|
|
});
|
|
provideClearError(cc.EParticleSystem.prototype, {
|
|
destroyParticleSystem: 'destroy',
|
|
clone: 'cc.instantiate',
|
|
isActive: 'active',
|
|
'*etParticleCount': 'particleCount',
|
|
'*etDuration': 'duration',
|
|
'*etSourcePosition': 'sourcePos',
|
|
'*etPosVar': 'posVar',
|
|
'*etGravity': 'gravity',
|
|
'*etSpeed': 'speed',
|
|
'*etSpeedVar': 'speedVar',
|
|
'*etTangentialAccel': 'tangentialAccel',
|
|
'*etTangentialAccelVar': 'tangentialAccelVar',
|
|
'*etRadialAccel': 'radialAccel',
|
|
'*etRadialAccelVar': 'radialAccelVar',
|
|
'*etRotationIsDir': 'rotationIsDir',
|
|
'*etStartRadius': 'startRadius',
|
|
'*etStartRadiusVar': 'startRadiusVar',
|
|
'*etEndRadius': 'endRadius',
|
|
'*etEndRadiusVar': 'endRadiusVar',
|
|
'*etRotatePerSecond': 'rotatePerS',
|
|
'*etRotatePerSecondVar': 'rotatePerSVar',
|
|
'*etStartColor': 'startColor',
|
|
'*etStartColorVar': 'startColorVar',
|
|
'*etEndColor': 'endColor',
|
|
'*etEndColorVar': 'endColorVar',
|
|
'*etTotalParticles': 'totalParticles',
|
|
'*etTexture': 'texture',
|
|
});
|
|
shouldNotUseNodeProp(cc.EParticleSystem);
|
|
js.obsoletes(cc.EParticleSystem, 'cc.EParticleSystem', {
|
|
Type: 'PositionType',
|
|
Mode: 'EmitterMode'
|
|
});
|
|
|
|
// cc.Node
|
|
markAsRemoved(cc.Node, [
|
|
'_normalizedPositionDirty',
|
|
'_normalizedPosition',
|
|
'_usingNormalizedPosition',
|
|
'grid',
|
|
'userData',
|
|
'userObject',
|
|
'getNormalizedPosition',
|
|
'setNormalizedPosition',
|
|
'getCamera',
|
|
'getUserData',
|
|
'setUserData',
|
|
'getUserObject',
|
|
'setUserObject',
|
|
'getComponent',
|
|
'addComponent',
|
|
'removeComponent',
|
|
'removeAllComponents',
|
|
'enumerateChildren'
|
|
], 'cc.Node');
|
|
|
|
}
|