Skip to content

Commit

Permalink
remove legacyCC
Browse files Browse the repository at this point in the history
  • Loading branch information
PPpro committed Sep 12, 2023
1 parent 471fe46 commit 7855fd7
Show file tree
Hide file tree
Showing 128 changed files with 493 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ rules:
# NOTE: We don't want to rely on TS automatic type inference
'@typescript-eslint/no-inferrable-types': off

# TODO: sadly we still rely heavily on legacyCC
# TODO: sadly we still rely heavily on cclegacy
'@typescript-eslint/no-unsafe-assignment': off
'@typescript-eslint/no-unsafe-call': off
'@typescript-eslint/no-unsafe-member-access': off
Expand Down
4 changes: 2 additions & 2 deletions cocos/3d/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import * as utils from './misc';
import { legacyCC } from '../core/global-exports';
import { cclegacy } from '../core/index';

export * from './misc/batch-utils';
export * from './assets';
Expand All @@ -37,4 +37,4 @@ export * from './reflection-probe';
export {
utils,
};
legacyCC.utils = utils;
cclegacy.utils = utils;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { MeshRenderer } from '../../../../../3d';
import { createMesh } from '../../../../../3d/misc';
import { Material } from '../../../../../asset/assets';
import { Color, Vec3 } from '../../../../../core';
import { legacyCC } from '../../../../../core/global-exports';
import { Color, Vec3, cclegacy } from '../../../../../core';
import { PrimitiveMode } from '../../../../../gfx';
import { Node } from '../../../../../scene-graph';

export class TwoBoneIKDebugger {
constructor () {
const node = new Node();
legacyCC.director.getScene().addChild(node);
cclegacy.director.getScene().addChild(node);

const meshRenderer = node.addComponent(MeshRenderer);
meshRenderer.material = ((): Material => {
Expand Down
2 changes: 1 addition & 1 deletion cocos/asset/assets/texture-base.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ textureBaseProto.getSamplerInfo = function () {
const oldDestroy = textureBaseProto.destroy;
textureBaseProto.destroy = function () {
if (cclegacy.director.root?.batcher2D) {
// legacyCC.director.root.batcher2D._releaseDescriptorSetCache(this.getHash());
// cclegacy.director.root.batcher2D._releaseDescriptorSetCache(this.getHash());
cclegacy.director.root.batcher2D._releaseDescriptorSetCache(this.getGFXTexture(), this.getGFXSampler());
}
// dispatch into C++ virtual function CCObject::destroy
Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/texture-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { TextureType, TextureInfo, TextureViewInfo, BufferTextureCopy } from '..
import { ImageAsset } from './image-asset';
import { PresumedGFXTextureInfo, PresumedGFXTextureViewInfo, SimpleTexture } from './simple-texture';
import { ITexture2DCreateInfo, Texture2D } from './texture-2d';
import { legacyCC, ccwindow } from '../../core/global-exports';
import { error, js, sys } from '../../core';
import { ccwindow } from '../../core/global-exports';
import { error, js, sys, cclegacy } from '../../core';
import { OS } from '../../../pal/system-info/enum-type';

export type ITextureCubeCreateInfo = ITexture2DCreateInfo;
Expand Down Expand Up @@ -632,7 +632,7 @@ export class TextureCube extends SimpleTexture {
}
}

legacyCC.TextureCube = TextureCube;
cclegacy.TextureCube = TextureCube;

interface ITextureCubeSerializeData {
base: string;
Expand Down
4 changes: 2 additions & 2 deletions cocos/core/algorithm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { legacyCC } from '../global-exports';
import { cclegacy } from '../index';
import * as easing from './easing';

export * from './murmurhash2_gc';

export { easing };
legacyCC.easing = easing;
cclegacy.easing = easing;
6 changes: 3 additions & 3 deletions cocos/core/curves/bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
THE SOFTWARE.
*/

import { legacyCC } from '../global-exports';
import { cclegacy } from '../index';

export type BezierControlPoints = [ number, number, number, number ];

export function bezier (C1: number, C2: number, C3: number, C4: number, t: number): number {
const t1 = 1 - t;
return t1 * (t1 * (C1 + (C2 * 3 - C1) * t) + C3 * 3 * t * t) + C4 * t * t * t;
}
legacyCC.bezier = bezier;
cclegacy.bezier = bezier;

// var sin = Math.sin;
const cos = Math.cos;
Expand Down Expand Up @@ -160,4 +160,4 @@ export function bezierByTime (controlPoints: BezierControlPoints, x: number): nu
// return bezier(0, p1y, p2y, 1, percent);
return ((1 - percent) * (p1y + (p2y - p1y) * percent) * 3 + percent * percent) * percent;
}
legacyCC.bezierByTime = bezierByTime;
cclegacy.bezierByTime = bezierByTime;
20 changes: 10 additions & 10 deletions cocos/core/data/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { IAcceptableAttributes } from './utils/attribute-defines';
import { preprocessAttrs } from './utils/preprocess-class';
import * as RF from './utils/requiring-frame';

import { legacyCC } from '../global-exports';
import { cclegacy } from '../index';
import { PropertyStash, PropertyStashInternalFlag } from './class-stash';
import { setPropertyEnumTypeOnAttrs } from './utils/attribute-internal';

Expand Down Expand Up @@ -130,7 +130,7 @@ function getDefault (defaultVal): any {
try {
return defaultVal();
} catch (e) {
legacyCC._throw(e);
cclegacy._throw(e);
return undefined;
}
} else {
Expand Down Expand Up @@ -162,7 +162,7 @@ function doDefine (className, baseClass, options): any {
}

function define (className, baseClass, options): any {
const Component = legacyCC.Component;
const Component = cclegacy.Component;
const frame = RF.peek();

if (frame && js.isChildClassOf(baseClass, Component)) {
Expand All @@ -181,9 +181,9 @@ function define (className, baseClass, options): any {

if (EDITOR) {
// for RenderPipeline, RenderFlow, RenderStage
const isRenderPipeline = js.isChildClassOf(baseClass, legacyCC.RenderPipeline);
const isRenderFlow = js.isChildClassOf(baseClass, legacyCC.RenderFlow);
const isRenderStage = js.isChildClassOf(baseClass, legacyCC.RenderStage);
const isRenderPipeline = js.isChildClassOf(baseClass, cclegacy.RenderPipeline);
const isRenderFlow = js.isChildClassOf(baseClass, cclegacy.RenderFlow);
const isRenderStage = js.isChildClassOf(baseClass, cclegacy.RenderStage);
const isRender = isRenderPipeline || isRenderFlow || isRenderStage;
if (isRender) {
let renderName = '';
Expand Down Expand Up @@ -295,7 +295,7 @@ export function CCClass<TFunction> (options: {
// create constructor
const cls = define(name, base, options);
if (!name) {
name = legacyCC.js.getClassName(cls);
name = cclegacy.js.getClassName(cls);
}

cls._sealed = true;
Expand All @@ -309,8 +309,8 @@ export function CCClass<TFunction> (options: {

const editor = options.editor;
if (editor) {
if (js.isChildClassOf(base, legacyCC.Component)) {
legacyCC.Component._registerEditorProps(cls, editor);
if (js.isChildClassOf(base, cclegacy.Component)) {
cclegacy.Component._registerEditorProps(cls, editor);
} else if (DEV) {
warnID(3623, name!);
}
Expand Down Expand Up @@ -607,4 +607,4 @@ CCClass.IDENTIFIER_RE = IDENTIFIER_RE;
// NOTE: the type of getNewValueTypeCode can be ((value: any) => string) or boolean.
CCClass.getNewValueTypeCode = (SUPPORT_JIT && getNewValueTypeCodeJit) as any;

legacyCC.Class = CCClass;
cclegacy.Class = CCClass;
4 changes: 2 additions & 2 deletions cocos/core/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/

import * as _decorator from './class-decorator';
import { legacyCC } from '../global-exports';
import { cclegacy } from '../index';

legacyCC._decorator = _decorator;
cclegacy._decorator = _decorator;
export { _decorator };
export { CCClass, isCCClassOrFastDefined } from './class';
export { CCObject } from './object';
Expand Down
12 changes: 6 additions & 6 deletions cocos/core/data/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SUPPORT_JIT, EDITOR, TEST, JSB, EDITOR_NOT_IN_PREVIEW } from 'internal:
import * as js from '../utils/js';
import { CCClass } from './class';
import { errorID, warnID } from '../platform/debug';
import { legacyCC } from '../global-exports';
import { cclegacy } from '../index';
import { EditorExtendableObject, editorExtrasTag } from './editor-extras-tag';
import { copyAllProperties } from '../utils/js';

Expand Down Expand Up @@ -72,7 +72,7 @@ const objectsToDestroy: CCObject[] = [];
let deferredDestroyTimer: number | null = null;

function compileDestruct (obj, ctor): Function {
const shouldSkipId = obj instanceof legacyCC.Node || obj instanceof legacyCC.Component;
const shouldSkipId = obj instanceof cclegacy.Node || obj instanceof cclegacy.Component;
const idToSkip = shouldSkipId ? '_id' : null;

let key;
Expand All @@ -98,7 +98,7 @@ function compileDestruct (obj, ctor): Function {
}
// Overwrite propsToReset according to Class
if (CCClass._isCCClass(ctor)) {
const attrs = legacyCC.Class.Attr.getClassAttrs(ctor);
const attrs = cclegacy.Class.Attr.getClassAttrs(ctor);
const propList = ctor.__props__;

for (let i = 0; i < propList.length; i++) {
Expand Down Expand Up @@ -302,7 +302,7 @@ class CCObject implements EditorExtendableObject {
this._objFlags |= ToDestroy;
objectsToDestroy.push(this);

if (EDITOR && deferredDestroyTimer === null && legacyCC.engine && !legacyCC.engine._isUpdating) {
if (EDITOR && deferredDestroyTimer === null && cclegacy.engine && !cclegacy.engine._isUpdating) {
// auto destroy immediate in edit mode
deferredDestroyTimer = setTimeout(CCObject._deferredDestroy);
}
Expand Down Expand Up @@ -660,7 +660,7 @@ export function isValid (value: any, strictMode?: boolean): boolean {
return typeof value !== 'undefined';
}
}
legacyCC.isValid = isValid;
cclegacy.isValid = isValid;

if (EDITOR || TEST) {
js.value(CCObject, '_willDestroy', (obj) => !(obj._objFlags & Destroyed) && (obj._objFlags & ToDestroy) > 0);
Expand All @@ -680,5 +680,5 @@ if (JSB) {
(CCObject as unknown as any) = jsb.CCObject;
}

legacyCC.Object = CCObject;
cclegacy.Object = CCObject;
export { CCObject };
26 changes: 13 additions & 13 deletions cocos/core/data/utils/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { EDITOR } from 'internal:constants';
import { log, warnID } from '../../platform/debug';
import { formatStr, get, getClassName, isChildClassOf, value } from '../../utils/js';
import { isPlainEmptyObj_DEV } from '../../utils/misc';
import { legacyCC } from '../../global-exports';
import { cclegacy } from '../../index';

export const DELIMETER = '$_$';

Expand All @@ -47,7 +47,7 @@ export function createAttrs (subclass: any): any {
return createAttrsSingle(instance, getClassAttrs(instance.constructor));
}
let superClass: any;
const chains: any[] = legacyCC.Class.getInheritanceChain(subclass);
const chains: any[] = cclegacy.Class.getInheritanceChain(subclass);
for (let i = chains.length - 1; i >= 0; i--) {
const cls = chains[i];
const attrs = cls.hasOwnProperty('__attrs__') && cls.__attrs__;
Expand Down Expand Up @@ -128,8 +128,8 @@ export class PrimitiveType<T> {
* ```
*/
export const CCInteger = new PrimitiveType('Integer', 0);
legacyCC.Integer = CCInteger;
legacyCC.CCInteger = CCInteger;
cclegacy.Integer = CCInteger;
cclegacy.CCInteger = CCInteger;

/**
* @en
Expand All @@ -150,11 +150,11 @@ legacyCC.CCInteger = CCInteger;
* ```
*/
export const CCFloat = new PrimitiveType('Float', 0.0);
legacyCC.Float = CCFloat;
legacyCC.CCFloat = CCFloat;
cclegacy.Float = CCFloat;
cclegacy.CCFloat = CCFloat;

if (EDITOR) {
get(legacyCC, 'Number', () => {
get(cclegacy, 'Number', () => {
warnID(3603);
return CCFloat;
});
Expand All @@ -178,8 +178,8 @@ if (EDITOR) {
* ```
*/
export const CCBoolean = new PrimitiveType('Boolean', false);
legacyCC.Boolean = CCBoolean;
legacyCC.CCBoolean = CCBoolean;
cclegacy.Boolean = CCBoolean;
cclegacy.CCBoolean = CCBoolean;

/**
* @en
Expand All @@ -200,8 +200,8 @@ legacyCC.CCBoolean = CCBoolean;
* ```
*/
export const CCString = new PrimitiveType('String', '');
legacyCC.String = CCString;
legacyCC.CCString = CCString;
cclegacy.String = CCString;
cclegacy.CCString = CCString;

// Ensures the type matches its default value
export function getTypeChecker_ET (type: string, attributeName: string) {
Expand Down Expand Up @@ -261,8 +261,8 @@ export function getObjTypeChecker_ET (typeCtor) {
getTypeChecker_ET('Object', 'type')(classCtor, mainPropName);
// check ValueType
const defaultDef = getClassAttrs(classCtor)[`${mainPropName + DELIMETER}default`];
const defaultVal = legacyCC.Class.getDefault(defaultDef);
if (!Array.isArray(defaultVal) && isChildClassOf(typeCtor, legacyCC.ValueType)) {
const defaultVal = cclegacy.Class.getDefault(defaultDef);
if (!Array.isArray(defaultVal) && isChildClassOf(typeCtor, cclegacy.ValueType)) {
const typename = getClassName(typeCtor);
const info = formatStr('No need to specify the "type" of "%s.%s" because %s is a child class of ValueType.',
getClassName(classCtor), mainPropName, typename);
Expand Down
18 changes: 9 additions & 9 deletions cocos/core/data/utils/preprocess-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DEV, EDITOR, TEST } from 'internal:constants';
import { error, errorID, warn, warnID } from '../../platform/debug';
import * as js from '../../utils/js';
import { PrimitiveType } from './attribute';
import { legacyCC } from '../../global-exports';
import { cclegacy } from '../../index';

// 增加预处理属性这个步骤的目的是降低 CCClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。

Expand Down Expand Up @@ -85,7 +85,7 @@ function parseType (val, type, className, propName): void {

if (Array.isArray(type)) {
if (STATIC_CHECK && 'default' in val) {
if (!legacyCC.Class.isArray(val.default)) {
if (!cclegacy.Class.isArray(val.default)) {
warnID(5507, className, propName);
}
}
Expand All @@ -98,17 +98,17 @@ function parseType (val, type, className, propName): void {
}
if (typeof type === 'function') {
if (type === String) {
val.type = legacyCC.String;
val.type = cclegacy.String;
if (STATIC_CHECK) {
warnID(3608, `"${className}.${propName}"`);
}
} else if (type === Boolean) {
val.type = legacyCC.Boolean;
val.type = cclegacy.Boolean;
if (STATIC_CHECK) {
warnID(3609, `"${className}.${propName}"`);
}
} else if (type === Number) {
val.type = legacyCC.Float;
val.type = cclegacy.Float;
if (STATIC_CHECK) {
warnID(3610, `"${className}.${propName}"`);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ function parseType (val, type, className, propName): void {
}

if (EDITOR && typeof type === 'function') {
if (legacyCC.Class._isCCClass(type) && val.serializable !== false && !js.getClassId(type, false)) {
if (cclegacy.Class._isCCClass(type) && val.serializable !== false && !js.getClassId(type, false)) {
warnID(5512, className, propName, className, propName);
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ export function getFullFormOfProperty (options, isGetset): {
return _wrapOptions(isGetset, [], options);
} else if (typeof options === 'function') {
const type = options;
return _wrapOptions(isGetset, js.isChildClassOf(type, legacyCC.ValueType) ? new type() : null, type);
return _wrapOptions(isGetset, js.isChildClassOf(type, cclegacy.ValueType) ? new type() : null, type);
} else if (options instanceof PrimitiveType) {
return _wrapOptions(isGetset, undefined, options);
} else {
Expand All @@ -210,7 +210,7 @@ export function preprocessAttrs (properties, className, cls): void {
errorID(5513, className, propName);
} else if (val.set) {
errorID(5514, className, propName);
} else if (legacyCC.Class._isCCClass(val.default)) {
} else if (cclegacy.Class._isCCClass(val.default)) {
val.default = null;
errorID(5515, className, propName);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ export function doValidateMethodWithProps_DEV (func, funcName, className, cls, b
return false;
}
if (funcName === 'destroy'
&& js.isChildClassOf(base, legacyCC.Component)
&& js.isChildClassOf(base, cclegacy.Component)
&& !CALL_SUPER_DESTROY_REG_DEV.test(func)
) {
error(`Overwriting '${funcName}' function in '${className}' class without calling super is not allowed. Call the super function in '${funcName}' please.`);
Expand Down
Loading

0 comments on commit 7855fd7

Please sign in to comment.