forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprecated.js
584 lines (546 loc) · 17.8 KB
/
deprecated.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
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',
'EScene': 'Scene',
'ENode': 'Node',
'_ComponentInSG': '_RendererUnderSG'
});
/**
* 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;
});
Object.defineProperty(cc._SGComponent.prototype, 'visible', {
get: function () {
cc.warn('The "visible" property of %s is deprecated, use "enabled" instead please.', cc.js.getClassName(this));
return this.enabled;
},
set: function (value) {
var printWarning = this.visible;
this.enabled = value;
}
});
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(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.TYPE', '_ccsg.ParticleSystem.Type');
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.MODE', '_ccsg.ParticleSystem.Mode');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.TYPE', 'cc.ParticleSystem.PositionType');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.EmitterMode');
// deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
deprecateEnum(cc.game, 'cc.game.DEBUG_MODE', 'cc.DebugMode');
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
if (_ccsg.EditBox) {
deprecateEnum(cc, 'cc.KEYBOARD_RETURNTYPE', '_ccsg.EditBox.KeyboardReturnType');
deprecateEnum(cc, 'cc.EDITBOX_INPUT_MODE', '_ccsg.EditBox.InputMode');
deprecateEnum(cc, 'cc.EDITBOX_INPUT_FLAG', '_ccsg.EditBox.InputFlag');
}
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, ownerName) {
var className = ownerName || 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);
});
}
}
}
// cc.loader
markAsRemoved(cc.Pipeline, [
'loadJsWithImg',
'loadCsb',
'getUrl',
'loadAliases',
'register'
], 'cc.loader');
provideClearError(cc.loader, {
loadJs : 'load',
loadTxt : 'load',
loadJson : 'load',
loadImg : 'load'
}, 'cc.loader');
// cc.Node
markAsRemoved(cc.Node, [
'_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',
'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',
'ignoreAnchor',
'isIgnoreAnchorPointForPosition',
'ignoreAnchorPointForPosition'
]);
provideClearError(cc.Node.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',
});
// RENDERERS
function shouldNotUseNodeProp (component) {
var compProto = component.prototype;
for (var prop in cc.Node.prototype) {
(function (prop) {
if (!(prop in compProto) && prop[0] !== '_') {
Object.defineProperty(compProto, prop, {
get: function () {
var compName = cc.js.getClassName(this); // 允许继承
var Info = 'Sorry, ' + compName + '.%s is undefined, please use cc.Node.%s instead.';
cc.error(Info, prop, prop);
},
enumerable: false,
configurable: true, // 允许继承
});
}
})(prop);
}
}
shouldNotUseNodeProp(cc._SGComponent);
// cc.Sprite
markAsRemoved(cc.Sprite, [
'textureLoaded',
'setBlendFunc',
'getBlendFunc',
'setState',
'getState',
'resizableSpriteWithCapInsets',
'flippedX',
'flippedY',
'setFlippedX',
'setFlippedY',
'isFlippedX',
'isFlippedY',
'getCapInsets',
'setCapInsets',
]);
provideClearError(cc.Sprite, {
create: 'node.addComponent',
createWithTexture: 'node.addComponent',
createWithSpriteFrameName: 'node.addComponent',
createWithSpriteFrame: 'node.addComponent',
});
provideClearError(cc.Sprite.prototype, {
getPreferredSize: 'node.getContentSize',
setPreferredSize: 'node.setContentSize',
updateWithSprite: 'spriteFrame',
getSpriteFrame: 'spriteFrame',
setSpriteFrame: 'spriteFrame',
});
// Particle
markAsRemoved(cc.ParticleSystem, [
'batchNode',
'drawMode',
'getDrawMode',
'setDrawMode',
'shapeType',
'getShapeType',
'setShapeType',
'atlasIndex',
'init',
'initParticle',
'updateWithNoTime',
]);
provideClearError(cc.ParticleSystem, {
initWithFile: 'instance.file',
initWithDictionary: 'instance.file',
initWithTotalParticles: 'instance.totalParticles'
});
provideClearError(cc.ParticleSystem.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',
});
js.obsoletes(cc.ParticleSystem, 'cc.ParticleSystem', {
Type: 'PositionType',
Mode: 'EmitterMode'
});
// _ccsg.Node
markAsRemoved(_ccsg.Node, [
'_normalizedPositionDirty',
'_normalizedPosition',
'_usingNormalizedPosition',
'grid',
'userData',
'userObject',
'getNormalizedPosition',
'setNormalizedPosition',
'getCamera',
'getUserData',
'setUserData',
'getUserObject',
'setUserObject',
'getComponent',
'addComponent',
'removeComponent',
'removeAllComponents',
'enumerateChildren',
'setCameraMask',
'getCameraMask'
], '_ccsg.Node');
js.obsoletes(cc.Scale9Sprite.prototype, 'cc.Scale9Sprite', {
setPreferredSize: 'setContentSize',
getPreferredSize: 'getContentSize',
});
//ui
cc.js.obsolete(cc.Layout.prototype, 'Layout.layoutType', 'type');
cc.js.obsolete(cc.Layout.prototype, 'Layout.ResizeType', 'ResizeMode');
cc.js.obsolete(cc.Layout.prototype, 'Layout.resize', 'resizeMode');
markAsRemoved(cc.Scale9Sprite, [
'init',
'resizableSpriteWithCapInsets',
'updateWithSprite',
'getOriginalSize',
'setCapInsets',
'getCapInsets',
'setScale9Enabled',
'isScale9Enabled',
'getSprite',
'setFlippedX',
'isFlippedX',
'setFlippedY',
'isFlippedY'
]);
// SPINE
if (typeof sp !== 'undefined') {
deprecateEnum(sp, 'sp.ANIMATION_EVENT_TYPE', 'sp.AnimationEventType');
js.obsolete(sp, 'sp.SkeletonAnimation', 'Skeleton');
provideClearError(sp.Skeleton, {
create: 'node.addComponent',
});
provideClearError(sp.Skeleton.prototype, {
'*etDebugSlotsEnabled': 'debugSlots',
'*etDebugBonesEnabled': 'debugBones',
'setDebugSolots': 'debugSlots',
'setDebugBones': 'debugBones',
'*etTimeScale': 'timeScale',
});
}
}