Rename internal usages of global variable 'cc' into 'legacyGlobalExpo… (#6680)

* Rename internal usages of global variable 'cc' into 'legacyGlobalExports'

* Fix CI

* Rename 'legacyGlobalExports' -> 'legacyCC'
This commit is contained in:
Leslie Leigh (李的序)
2020-05-14 15:46:45 +08:00
committed by GitHub
parent 257a500cbb
commit 5e2adea787
215 changed files with 1418 additions and 1243 deletions
-7
View File
@@ -64,13 +64,6 @@ interface HTMLElement{
type ActiveXObject = new (s: string) => any;
declare var ActiveXObject: ActiveXObject;
declare const cc: {
// polyfills: {
// destroyObject? (object: any): void;
// };
[x: string]: any;
};
declare type CompareFunction<T> = (a: T, b: T) => number;
declare type RecursivePartial<T> = {
+2 -1
View File
@@ -33,6 +33,7 @@ import { Enum } from '../../core/value-types';
import { AudioPlayer, PlayingState } from './player';
import { AudioPlayerDOM } from './player-dom';
import { AudioPlayerWeb } from './player-web';
import { legacyCC } from '../../core/global-exports';
export const AudioType = Enum({
WEB_AUDIO: 0,
@@ -131,4 +132,4 @@ export class AudioClip extends Asset {
}
}
cc.AudioClip = AudioClip;
legacyCC.AudioClip = AudioClip;
+7 -6
View File
@@ -29,6 +29,7 @@
import { clamp } from '../../core/math/utils';
import { AudioPlayer, IAudioInfo, PlayingState } from './player';
import { legacyCC } from '../../core/global-exports';
export class AudioPlayerDOM extends AudioPlayer {
protected _volume = 1;
@@ -48,8 +49,8 @@ export class AudioPlayerDOM extends AudioPlayer {
this._remove_cb = () => {
if (!this._cbRegistered) { return; }
cc.game.canvas.removeEventListener('touchend', this._on_gesture);
cc.game.canvas.removeEventListener('mouseup', this._on_gesture);
legacyCC.game.canvas.removeEventListener('touchend', this._on_gesture);
legacyCC.game.canvas.removeEventListener('mouseup', this._on_gesture);
this._cbRegistered = false;
};
@@ -70,7 +71,7 @@ export class AudioPlayerDOM extends AudioPlayer {
if (!promise) { // Chrome50/Firefox53 below
// delay eval here to yield uniform behavior with other platforms
this._state = PlayingState.PLAYING;
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, this._post_gesture);
legacyCC.director.once(legacyCC.Director.EVENT_AFTER_UPDATE, this._post_gesture);
return;
}
promise.then(this._post_gesture);
@@ -88,8 +89,8 @@ export class AudioPlayerDOM extends AudioPlayer {
});
/* play & stop immediately after receiving a gesture so that
we can freely invoke play() outside event listeners later */
cc.game.canvas.addEventListener('touchend', this._on_gesture);
cc.game.canvas.addEventListener('mouseup', this._on_gesture);
legacyCC.game.canvas.addEventListener('touchend', this._on_gesture);
legacyCC.game.canvas.addEventListener('mouseup', this._on_gesture);
this._cbRegistered = true;
}
@@ -100,7 +101,7 @@ export class AudioPlayerDOM extends AudioPlayer {
if (!promise) {
// delay eval here to yield uniform behavior with other platforms
this._state = PlayingState.PLAYING;
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, this._post_play);
legacyCC.director.once(legacyCC.Director.EVENT_AFTER_UPDATE, this._post_play);
return;
}
promise.then(this._post_play).catch(() => { this._interrupted = true; });
+7 -6
View File
@@ -30,6 +30,7 @@
import { clamp } from '../../core/math/utils';
import { sys } from '../../core/platform/sys';
import { AudioPlayer, IAudioInfo, PlayingState } from './player';
import { legacyCC } from '../../core/global-exports';
const audioSupport = sys.__audioSupport;
@@ -65,8 +66,8 @@ export class AudioPlayerWeb extends AudioPlayer {
// Chrome41/Firefox40 below don't have resume
if (this._context.state !== 'running' && this._context.resume) {
cc.game.canvas.addEventListener('touchend', this._onGestureCB);
cc.game.canvas.addEventListener('mouseup', this._onGestureCB);
legacyCC.game.canvas.addEventListener('touchend', this._onGestureCB);
legacyCC.game.canvas.addEventListener('mouseup', this._onGestureCB);
}
}
@@ -150,7 +151,7 @@ export class AudioPlayerWeb extends AudioPlayer {
this._startTime = this._context.currentTime;
this._startInvoked = false;
// delay eval here to yield uniform behavior with other platforms
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, this._playAndEmit, this);
legacyCC.director.once(legacyCC.Director.EVENT_AFTER_UPDATE, this._playAndEmit, this);
/* still not supported by all platforms *
this._sourceNode.onended = this._onEnded;
/* doing it manually for now */
@@ -167,7 +168,7 @@ export class AudioPlayerWeb extends AudioPlayer {
private _doStop () {
// stop can only be called after play
if (this._startInvoked) { this._sourceNode.stop(); }
else { cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this._playAndEmit, this); }
else { legacyCC.director.off(legacyCC.Director.EVENT_AFTER_UPDATE, this._playAndEmit, this); }
}
private _playAndEmit () {
@@ -186,8 +187,8 @@ export class AudioPlayerWeb extends AudioPlayer {
private _onGestureProceed () {
if (this._interrupted) { this._doPlay(); this._interrupted = false; }
cc.game.canvas.removeEventListener('touchend', this._onGestureCB);
cc.game.canvas.removeEventListener('mouseup', this._onGestureCB);
legacyCC.game.canvas.removeEventListener('touchend', this._onGestureCB);
legacyCC.game.canvas.removeEventListener('mouseup', this._onGestureCB);
}
private _onGesture () {
+7 -5
View File
@@ -23,6 +23,8 @@
THE SOFTWARE.
*/
import { legacyCC } from '../../core/global-exports';
/**
* @category component/audio
*/
@@ -63,8 +65,8 @@ export abstract class AudioPlayer {
this.play(); this._interrupted = false;
};
/* handle hide & show */
cc.game.on(cc.Game.EVENT_HIDE, this._onHide);
cc.game.on(cc.Game.EVENT_SHOW, this._onShow);
legacyCC.game.on(legacyCC.Game.EVENT_HIDE, this._onHide);
legacyCC.game.on(legacyCC.Game.EVENT_SHOW, this._onShow);
}
public abstract play (): void;
@@ -80,9 +82,9 @@ export abstract class AudioPlayer {
public getState () { return this._state; }
public getDuration () { return this._duration; }
public destroy () {
cc.game.off(cc.Game.EVENT_HIDE, this._onHide);
cc.game.off(cc.Game.EVENT_SHOW, this._onShow);
legacyCC.game.off(legacyCC.Game.EVENT_HIDE, this._onHide);
legacyCC.game.off(legacyCC.Game.EVENT_SHOW, this._onShow);
}
}
cc.internal.AudioPlayer = AudioPlayer;
legacyCC.internal.AudioPlayer = AudioPlayer;
+2 -1
View File
@@ -30,6 +30,7 @@
import { getError, log } from '../core/platform/debug';
import { sys } from '../core/platform/sys';
import { AudioClip, AudioType } from './assets/clip';
import { legacyCC } from '../core/global-exports';
const __audioSupport = sys.__audioSupport;
const formatSupport = __audioSupport.format;
@@ -76,7 +77,7 @@ function loadWebAudio (item, callback) {
callback(new Error(getError(4926)));
}
const request = cc.loader.getXMLHttpRequest();
const request = legacyCC.loader.getXMLHttpRequest();
request.open('GET', item.url, true);
request.responseType = 'arraybuffer';
+15 -14
View File
@@ -5,6 +5,7 @@ import { Texture2D } from '../../assets/texture-2d';
import { TextureCube } from '../../assets/texture-cube';
import { GFXDevice } from '../../gfx/device';
import effects from './effects';
import { legacyCC } from '../../global-exports';
class BuiltinResMgr {
protected _device: GFXDevice | null = null;
@@ -118,12 +119,12 @@ class BuiltinResMgr {
// builtin effects
effects.forEach((e) => {
const effect = Object.assign(new cc.EffectAsset(), e);
const effect = Object.assign(new legacyCC.EffectAsset(), e);
effect.onLoaded();
});
// standard material
const standardMtl = new cc.Material();
const standardMtl = new legacyCC.Material();
standardMtl._uuid = 'standard-material';
standardMtl.initialize({
effectName: 'builtin-standard',
@@ -131,63 +132,63 @@ class BuiltinResMgr {
resources[standardMtl._uuid] = standardMtl;
// material indicating missing effect (yellow)
const missingEfxMtl = new cc.Material();
const missingEfxMtl = new legacyCC.Material();
missingEfxMtl._uuid = 'missing-effect-material';
missingEfxMtl.initialize({
effectName: 'builtin-unlit',
defines: { USE_COLOR: true },
});
missingEfxMtl.setProperty('mainColor', cc.color('#ffff00'));
missingEfxMtl.setProperty('mainColor', legacyCC.color('#ffff00'));
resources[missingEfxMtl._uuid] = missingEfxMtl;
// material indicating missing material (purple)
const missingMtl = new cc.Material();
const missingMtl = new legacyCC.Material();
missingMtl._uuid = 'missing-material';
missingMtl.initialize({
effectName: 'builtin-unlit',
defines: { USE_COLOR: true },
});
missingMtl.setProperty('mainColor', cc.color('#ff00ff'));
missingMtl.setProperty('mainColor', legacyCC.color('#ff00ff'));
resources[missingMtl._uuid] = missingMtl;
// sprite material
const spriteMtl = new cc.Material();
const spriteMtl = new legacyCC.Material();
spriteMtl._uuid = 'ui-base-material';
spriteMtl.initialize({ defines: { USE_TEXTURE: false }, effectName: 'builtin-sprite' });
resources[spriteMtl._uuid] = spriteMtl;
// sprite material
const spriteColorMtl = new cc.Material();
const spriteColorMtl = new legacyCC.Material();
spriteColorMtl._uuid = 'ui-sprite-material';
spriteColorMtl.initialize({ defines: { USE_TEXTURE: true, IS_GRAY: false }, effectName: 'builtin-sprite' });
resources[spriteColorMtl._uuid] = spriteColorMtl;
// sprite gray material
const spriteGrayMtl = new cc.Material();
const spriteGrayMtl = new legacyCC.Material();
spriteGrayMtl._uuid = 'ui-sprite-gray-material';
spriteGrayMtl.initialize({ defines: { USE_TEXTURE: true, IS_GRAY: true }, effectName: 'builtin-sprite' });
resources[spriteGrayMtl._uuid] = spriteGrayMtl;
// default particle material
const defaultParticleMtl = new cc.Material();
const defaultParticleMtl = new legacyCC.Material();
defaultParticleMtl._uuid = 'default-particle-material';
defaultParticleMtl.initialize({ effectName: 'builtin-particle' });
resources[defaultParticleMtl._uuid] = defaultParticleMtl;
// default particle gpu material
const defaultParticleGPUMtl = new cc.Material();
const defaultParticleGPUMtl = new legacyCC.Material();
defaultParticleGPUMtl._uuid = 'default-particle-gpu-material';
defaultParticleGPUMtl.initialize({ effectName: 'builtin-particle-gpu' });
resources[defaultParticleGPUMtl._uuid] = defaultParticleGPUMtl;
// default particle material
const defaultTrailMtl = new cc.Material();
const defaultTrailMtl = new legacyCC.Material();
defaultTrailMtl._uuid = 'default-trail-material';
defaultTrailMtl.initialize({ effectName: 'builtin-particle-trail' });
resources[defaultTrailMtl._uuid] = defaultTrailMtl;
// default particle material
const defaultBillboardMtl = new cc.Material();
const defaultBillboardMtl = new legacyCC.Material();
defaultBillboardMtl._uuid = 'default-billboard-material';
defaultBillboardMtl.initialize({ effectName: 'builtin-billboard' });
resources[defaultBillboardMtl._uuid] = defaultBillboardMtl;
@@ -198,5 +199,5 @@ class BuiltinResMgr {
}
}
const builtinResMgr = cc.builtinResMgr = new BuiltinResMgr();
const builtinResMgr = legacyCC.builtinResMgr = new BuiltinResMgr();
export { builtinResMgr };
@@ -42,6 +42,7 @@ import { IGFXAttribute } from '../../gfx/input-assembler';
import { Mat4, Vec2, Vec3 } from '../../math';
import { mapBuffer, readBuffer, writeBuffer } from '../misc/buffer';
import { SkinningModelComponent } from './skinning-model-component';
import { legacyCC } from '../../global-exports';
const repeat = (n: number) => n - Math.floor(n);
const batch_id: IGFXAttribute = { name: GFXAttributeName.ATTR_BATCH_ID, format: GFXFormat.R32F, isNormalized: false };
@@ -472,7 +473,7 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent {
}
}
const gfxTex = target.getGFXTexture()!;
const device: GFXDevice = cc.director.root!.device;
const device: GFXDevice = legacyCC.director.root!.device;
if (texBuffers.length > 0) { device.copyBuffersToTexture(texBuffers, gfxTex, texBufferRegions); }
if (texImages.length > 0) { device.copyTexImagesToTexture(texImages, gfxTex, texImageRegions); }
}
@@ -554,10 +555,10 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent {
const srcVertex = src.subarray(oldOffset, oldOffset + oldStride);
newMeshData.set(srcVertex, newOffset);
// insert batch ID
dataView.setFloat32(newOffset + oldStride, unitIdx, cc.sys.isLittleEndian);
dataView.setFloat32(newOffset + oldStride, unitIdx, legacyCC.sys.isLittleEndian);
// insert batch UV
dataView.setFloat32(newOffset + oldStride + 4, uvs[j * 2], cc.sys.isLittleEndian);
dataView.setFloat32(newOffset + oldStride + 8, uvs[j * 2 + 1], cc.sys.isLittleEndian);
dataView.setFloat32(newOffset + oldStride + 4, uvs[j * 2], legacyCC.sys.isLittleEndian);
dataView.setFloat32(newOffset + oldStride + 8, uvs[j * 2 + 1], legacyCC.sys.isLittleEndian);
newOffset += newStride; oldOffset += oldStride;
}
for (let k = 0; k < newMeshStruct.primitives.length; k++) {
+9 -8
View File
@@ -44,6 +44,7 @@ import { Root } from '../../root';
import { Layers, Node, Scene } from '../../scene-graph';
import { Enum } from '../../value-types';
import { TransformBit } from '../../scene-graph/node-enum';
import { legacyCC } from '../../global-exports';
const _temp_vec3_1 = new Vec3();
@@ -443,7 +444,7 @@ export class CameraComponent extends Component {
this._updateTargetTexture();
if (!value && this._camera) {
this._camera.changeTargetWindow(EDITOR ? cc.director.root.tempWindow : null);
this._camera.changeTargetWindow(EDITOR ? legacyCC.director.root.tempWindow : null);
this._camera.isWindowSize = true;
}
}
@@ -469,7 +470,7 @@ export class CameraComponent extends Component {
set inEditorMode (value) {
this._inEditorMode = value;
if (this._camera) {
this._camera.changeTargetWindow(value ? cc.director.root && cc.director.root.mainWindow : cc.director.root && cc.director.root.tempWindow);
this._camera.changeTargetWindow(value ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow);
}
}
@@ -481,7 +482,7 @@ export class CameraComponent extends Component {
}
public onLoad () {
cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneChanged, this);
legacyCC.director.on(legacyCC.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneChanged, this);
this._createCamera();
}
@@ -501,7 +502,7 @@ export class CameraComponent extends Component {
public onDestroy () {
if (this._camera) {
cc.director.root.destroyCamera(this._camera);
legacyCC.director.root.destroyCamera(this._camera);
this._camera = null;
}
@@ -552,8 +553,8 @@ export class CameraComponent extends Component {
const designSize = view.getVisibleSize();
const xoffset = _temp_vec3_1.x - this._camera!.width * 0.5;
const yoffset = _temp_vec3_1.y - this._camera!.height * 0.5;
_temp_vec3_1.x = xoffset / cc.view.getScaleX() + designSize.width * 0.5;
_temp_vec3_1.y = yoffset / cc.view.getScaleY() + designSize.height * 0.5;
_temp_vec3_1.x = xoffset / legacyCC.view.getScaleX() + designSize.width * 0.5;
_temp_vec3_1.y = yoffset / legacyCC.view.getScaleY() + designSize.height * 0.5;
if (cmp) {
cmp.convertToNodeSpaceAR(_temp_vec3_1, out);
@@ -563,12 +564,12 @@ export class CameraComponent extends Component {
}
protected _createCamera () {
this._camera = (cc.director.root as Root).createCamera();
this._camera = (legacyCC.director.root as Root).createCamera();
this._camera.initialize({
name: this.node.name,
node: this.node,
projection: this._projection,
window: this._inEditorMode ? cc.director.root && cc.director.root.mainWindow : cc.director.root && cc.director.root.tempWindow,
window: this._inEditorMode ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow,
priority: this._priority,
flows: this._flows,
});
@@ -8,6 +8,7 @@ import { toRadian } from '../../math';
import { Camera } from '../../renderer';
import { CameraComponent } from './camera-component';
import { CAMERA_EDITOR_MASK } from '../../pipeline/define';
import { legacyCC } from '../../global-exports';
@ccclass('cc.EditorCameraComponent')
export class EditorCameraComponent extends CameraComponent {
@@ -111,7 +112,7 @@ export class EditorCameraComponent extends CameraComponent {
public onEnable () {
super.onEnable();
if (this._uiEditorCamera) {
cc.director.root!.ui.renderScene.addCamera(this._uiEditorCamera);
legacyCC.director.root!.ui.renderScene.addCamera(this._uiEditorCamera);
this._uiEditorCamera.enabled = true;
}
}
@@ -119,14 +120,14 @@ export class EditorCameraComponent extends CameraComponent {
public onDisable () {
super.onDisable();
if (this._uiEditorCamera) {
cc.director.root!.ui.renderScene.removeCamera(this._uiEditorCamera);
legacyCC.director.root!.ui.renderScene.removeCamera(this._uiEditorCamera);
}
}
public onDestroy () {
super.onDestroy();
if (this._uiEditorCamera) {
cc.director.root!.destroyCamera(this._uiEditorCamera);
legacyCC.director.root!.destroyCamera(this._uiEditorCamera);
this._uiEditorCamera = null;
}
}
@@ -137,15 +138,15 @@ export class EditorCameraComponent extends CameraComponent {
if (this._camera !== priorCamera && this._camera) {
if (this._uiEditorCamera) {
cc.director.root!.destroyCamera(this._uiEditorCamera);
legacyCC.director.root!.destroyCamera(this._uiEditorCamera);
this._uiEditorCamera = null;
}
this._uiEditorCamera = cc.director.root!.createCamera();
this._uiEditorCamera = legacyCC.director.root!.createCamera();
this._uiEditorCamera!.initialize({
name: 'Editor UICamera',
node: this._camera.node,
projection: this._projection,
window: cc.director.root!.mainWindow,
window: legacyCC.director.root!.mainWindow,
priority: this._priority + 1,
flows: ['UIFlow'],
});
+12 -12
View File
@@ -27,7 +27,7 @@
/**
* @hidden
*/
import { legacyCC } from '../../global-exports';
import { BatchedSkinningModelComponent, SkinningModelUnit } from './batched-skinning-model-component';
import { CameraComponent } from './camera-component';
import { DirectionalLightComponent } from './directional-light-component';
@@ -55,19 +55,19 @@ export {
};
// cc.AnimationComponent = AnimationComponent;
cc.CameraComponent = CameraComponent;
cc.EditorComponent = EditorCameraComponent;
cc.RenderableComponent = RenderableComponent;
cc.ModelComponent = ModelComponent;
cc.SkinningModelComponent = SkinningModelComponent;
legacyCC.CameraComponent = CameraComponent;
legacyCC.EditorComponent = EditorCameraComponent;
legacyCC.RenderableComponent = RenderableComponent;
legacyCC.ModelComponent = ModelComponent;
legacyCC.SkinningModelComponent = SkinningModelComponent;
cc.BatchedSkinningModelComponent = BatchedSkinningModelComponent;
cc.SkinningModelUnit = SkinningModelUnit;
legacyCC.BatchedSkinningModelComponent = BatchedSkinningModelComponent;
legacyCC.SkinningModelUnit = SkinningModelUnit;
cc.LightComponent = LightComponent;
cc.DirectionalLightComponent = DirectionalLightComponent;
cc.SphereLightComponent = SphereLightComponent;
cc.SpotLightComponent = SpotLightComponent;
legacyCC.LightComponent = LightComponent;
legacyCC.DirectionalLightComponent = DirectionalLightComponent;
legacyCC.SphereLightComponent = SphereLightComponent;
legacyCC.SpotLightComponent = SpotLightComponent;
/** deprecated */
import './deprecated';
+3 -2
View File
@@ -37,6 +37,7 @@ import { Light, LightType } from '../../renderer/scene/light';
import { SphereLight } from '../../renderer/scene/sphere-light';
import { SpotLight } from '../../renderer/scene/spot-light';
import { Root } from '../../root';
import { legacyCC } from '../../global-exports';
export const PhotometricTerm = Enum({
LUMINOUS_POWER: 0,
@@ -177,7 +178,7 @@ export class LightComponent extends Component {
protected _createLight () {
if (!this._light) {
this._light = (cc.director.root as Root).createLight(this._lightType);
this._light = (legacyCC.director.root as Root).createLight(this._lightType);
}
this.color = this._color;
this.useColorTemperature = this._useColorTemperature;
@@ -187,7 +188,7 @@ export class LightComponent extends Component {
protected _destroyLight () {
if (this._light) {
cc.director.root.destroyLight(this);
legacyCC.director.root.destroyLight(this);
this._light = null;
}
}
+3 -2
View File
@@ -40,6 +40,7 @@ import { Enum } from '../../value-types';
import { builtinResMgr } from '../builtin';
import { RenderableComponent } from './renderable-component';
import { MorphRenderingInstance } from '../../assets/morph';
import { legacyCC } from '../../global-exports';
/**
* @en Shadow projection mode.
@@ -244,7 +245,7 @@ export class ModelComponent extends RenderableComponent {
public onDestroy () {
if (this._model) {
cc.director.root.destroyModel(this._model);
legacyCC.director.root.destroyModel(this._model);
this._model = null;
this._models.length = 0;
}
@@ -294,7 +295,7 @@ export class ModelComponent extends RenderableComponent {
}
protected _createModel () {
this._model = (cc.director.root as Root).createModel(this._modelType);
this._model = (legacyCC.director.root as Root).createModel(this._modelType);
this._model.visFlags = this.visibility;
this._model.initialize(this.node);
this._models.length = 0;
@@ -36,6 +36,7 @@ import { SkinningModel } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { ModelComponent } from './model-component';
import { SkeletalAnimationComponent } from '../../animation/skeletal-animation-component';
import { legacyCC } from '../../global-exports';
/**
* @en The Skinning Model Component.
@@ -118,7 +119,7 @@ export class SkinningModelComponent extends ModelComponent {
this._modelType = modelType;
const modelCreated = !!this._model;
if (modelCreated) {
cc.director.root.destroyModel(this._model);
legacyCC.director.root.destroyModel(this._model);
this._model = null;
this._models.length = 0;
}
+2 -1
View File
@@ -30,8 +30,9 @@
export * from './builtin';
export * from './framework';
import * as utils from './misc/utils';
import { legacyCC } from '../global-exports';
export {
utils,
};
cc.utils = utils;
legacyCC.utils = utils;
+3 -2
View File
@@ -17,6 +17,7 @@ import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { ComponentPath, HierarchyPath, TargetPath } from './target-path';
import { WrapMode as AnimationWrapMode } from './types';
import { IValueProxyFactory } from './value-proxy';
import { legacyCC } from '../global-exports';
export interface IObjectCurveData {
[propertyName: string]: IPropertyCurveData;
@@ -308,7 +309,7 @@ export class AnimationClip extends Asset {
}
public destroy () {
(cc.director.root.dataPoolManager as DataPoolManager).releaseAnimationClip(this);
(legacyCC.director.root.dataPoolManager as DataPoolManager).releaseAnimationClip(this);
SkelAnimDataHub.destroy(this);
return super.destroy();
}
@@ -394,4 +395,4 @@ export class AnimationClip extends Asset {
}
}
cc.AnimationClip = AnimationClip;
legacyCC.AnimationClip = AnimationClip;
+2 -1
View File
@@ -40,6 +40,7 @@ import { AnimationClip } from './animation-clip';
import { AnimationState } from './animation-state';
import { CrossFade } from './cross-fade';
import { EDITOR, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* @en The event type supported by Animation
@@ -510,7 +511,7 @@ applyMixins(AnimationComponent, [CallbacksInvoker, EventTarget]);
AnimationComponent.prototype.on = on;
AnimationComponent.prototype.off = off;
cc.AnimationComponent = AnimationComponent;
legacyCC.AnimationComponent = AnimationComponent;
function equalClips (clip1: AnimationClip | null, clip2: AnimationClip | null) {
if (clip1 === clip2) {
+4 -3
View File
@@ -9,6 +9,7 @@ import { ValueType } from '../value-types';
import { bezierByTime, BezierControlPoints } from './bezier';
import * as easing from './easing';
import { ILerpable, isLerpable } from './types';
import { legacyCC } from '../global-exports';
/**
* 表示曲线值,曲线值可以是任意类型,但必须符合插值方式的要求。
@@ -100,7 +101,7 @@ export class RatioSampler {
return this._findRatio(this.ratios, ratio);
}
}
cc.RatioSampler = RatioSampler;
legacyCC.RatioSampler = RatioSampler;
/**
* 动画曲线。
@@ -243,7 +244,7 @@ export class AnimCurve {
return this._values.length === 1;
}
}
cc.AnimCurve = AnimCurve;
legacyCC.AnimCurve = AnimCurve;
export class EventInfo {
public events: any[] = [];
@@ -281,7 +282,7 @@ export function sampleAnimationCurve (curve: AnimCurve, sampler: RatioSampler, r
}
return curve.valueAt(index);
}
cc.sampleAnimationCurve = sampleAnimationCurve;
legacyCC.sampleAnimationCurve = sampleAnimationCurve;
/**
* Compute a new ratio by curve type.
+2 -1
View File
@@ -12,6 +12,7 @@ import { MutableForwardIterator, remove } from '../utils/array';
import { BlendStateBuffer } from './skeletal-animation-blending';
import { AnimationState } from './animation-state';
import { CrossFade } from './cross-fade';
import { legacyCC } from '../global-exports';
@ccclass
export class AnimationManager extends System {
@@ -90,4 +91,4 @@ director.on(Director.EVENT_INIT, () => {
director.registerSystem(AnimationManager.ID, animationManager, Scheduler.PRIORITY_SYSTEM);
});
cc.AnimationManager = AnimationManager;
legacyCC.AnimationManager = AnimationManager;
+7 -6
View File
@@ -39,6 +39,7 @@ import { error } from '../platform/debug';
import { EDITOR } from 'internal:constants';
import { HierarchyPath, TargetPath, evaluatePath } from './target-path';
import { BlendStateBuffer, createBlendStateWriter, IBlendStateWriter } from './skeletal-animation-blending';
import { legacyCC } from '../global-exports';
enum PropertySpecialization {
NodePosition,
@@ -329,7 +330,7 @@ export class AnimationState extends Playable {
this._curveLoaded = true;
this._destroyBlendStateWriters();
this._samplerSharedGroups.length = 0;
this._blendStateBuffer = cc.director.getAnimationManager()?.blendState ?? null;
this._blendStateBuffer = legacyCC.director.getAnimationManager()?.blendState ?? null;
this._targetNode = root;
const clip = this._clip;
@@ -428,7 +429,7 @@ export class AnimationState extends Playable {
for (let i = 0, l = args.length; i < l; i++) {
args[i] = restargs[i];
}
cc.director.getAnimationManager().pushDelayEvent(this, '_emit', args);
legacyCC.director.getAnimationManager().pushDelayEvent(this, '_emit', args);
}
public on<K extends string> (type: K, callback: EventCallbackOf<K, IAnimationEventDefinitionMap>, target?: any): void;
@@ -817,7 +818,7 @@ export class AnimationState extends Playable {
lastIndex += direction;
cc.director.getAnimationManager().pushDelayEvent(this, '_fireEvent', [lastIndex]);
legacyCC.director.getAnimationManager().pushDelayEvent(this, '_fireEvent', [lastIndex]);
} while (lastIndex !== eventIndex && lastIndex > -1 && lastIndex < length);
}
@@ -854,11 +855,11 @@ export class AnimationState extends Playable {
}
this._isBlendStateWriterInitialized = true;
}
cc.director.getAnimationManager().addAnimation(this);
legacyCC.director.getAnimationManager().addAnimation(this);
}
private _onPauseOrStop () {
cc.director.getAnimationManager().removeAnimation(this);
legacyCC.director.getAnimationManager().removeAnimation(this);
}
private _destroyBlendStateWriters () {
@@ -899,4 +900,4 @@ function wrapIterations (iterations: number) {
return iterations | 0;
}
cc.AnimationState = AnimationState;
legacyCC.AnimationState = AnimationState;
+4 -2
View File
@@ -3,6 +3,8 @@
* @category animation
*/
import { legacyCC } from '../global-exports';
export type BezierControlPoints = [ number, number, number, number ];
export function bezier (C1: number, C2: number, C3: number, C4: number, t: number) {
@@ -12,7 +14,7 @@ export function bezier (C1: number, C2: number, C3: number, C4: number, t: numbe
C3 * 3 * t1 * t * t +
C4 * t * t * t;
}
cc.bezier = bezier;
legacyCC.bezier = bezier;
// var sin = Math.sin;
const cos = Math.cos;
@@ -161,4 +163,4 @@ export function bezierByTime (controlPoints: BezierControlPoints, x: number) {
p2y * 3 * percent * percent * t1 +
p3y * percent * percent * percent;
}
cc.bezierByTime = bezierByTime;
legacyCC.bezierByTime = bezierByTime;
+5 -4
View File
@@ -6,6 +6,7 @@ import { clamp01 } from '../math/utils';
import { remove } from '../utils/array';
import { AnimationState } from './animation-state';
import { Playable } from './playable';
import { legacyCC } from '../global-exports';
interface IManagedState {
state: AnimationState | null;
@@ -127,7 +128,7 @@ export class CrossFade extends Playable {
protected onPlay () {
super.onPlay();
cc.director.getAnimationManager().addCrossFade(this);
legacyCC.director.getAnimationManager().addCrossFade(this);
}
/**
@@ -135,7 +136,7 @@ export class CrossFade extends Playable {
*/
protected onPause () {
super.onPause();
cc.director.getAnimationManager().removeCrossFade(this);
legacyCC.director.getAnimationManager().removeCrossFade(this);
for (let iManagedState = 0; iManagedState < this._managedStates.length; ++iManagedState) {
const state = this._managedStates[iManagedState].state;
if (state) {
@@ -149,7 +150,7 @@ export class CrossFade extends Playable {
*/
protected onResume () {
super.onResume();
cc.director.getAnimationManager().addCrossFade(this);
legacyCC.director.getAnimationManager().addCrossFade(this);
for (let iManagedState = 0; iManagedState < this._managedStates.length; ++iManagedState) {
const state = this._managedStates[iManagedState].state;
if (state) {
@@ -163,7 +164,7 @@ export class CrossFade extends Playable {
*/
protected onStop () {
super.onStop();
cc.director.getAnimationManager().removeCrossFade(this);
legacyCC.director.getAnimationManager().removeCrossFade(this);
this.clear();
}
}
+6 -5
View File
@@ -6,6 +6,7 @@
import { ccclass, property } from '../data/class-decorator';
import { Quat, Vec2, Vec3, Vec4 } from '../math';
import { ILerpable } from './types';
import { legacyCC } from '../global-exports';
interface ICubicSplineValue<T> extends ILerpable {
dataPoint: T;
@@ -85,19 +86,19 @@ function makeCubicSplineValueConstructor<T> (
export const CubicSplineVec2Value = makeCubicSplineValueConstructor(
'cc.CubicSplineVec2Value', Vec2, Vec2.multiplyScalar, Vec2.scaleAndAdd);
cc.CubicSplineVec2Value = CubicSplineVec2Value;
legacyCC.CubicSplineVec2Value = CubicSplineVec2Value;
export const CubicSplineVec3Value = makeCubicSplineValueConstructor(
'cc.CubicSplineVec3Value', Vec3, Vec3.multiplyScalar, Vec3.scaleAndAdd);
cc.CubicSplineVec3Value = CubicSplineVec3Value;
legacyCC.CubicSplineVec3Value = CubicSplineVec3Value;
export const CubicSplineVec4Value = makeCubicSplineValueConstructor(
'cc.CubicSplineVec4Value', Vec4, Vec4.multiplyScalar, Vec4.scaleAndAdd);
cc.CubicSplineVec4Value = CubicSplineVec4Value;
legacyCC.CubicSplineVec4Value = CubicSplineVec4Value;
export const CubicSplineQuatValue = makeCubicSplineValueConstructor(
'cc.CubicSplineQuatValue', Quat, Quat.multiplyScalar, Quat.scaleAndAdd);
cc.CubicSplineQuatValue = CubicSplineQuatValue;
legacyCC.CubicSplineQuatValue = CubicSplineQuatValue;
@ccclass('cc.CubicSplineNumberValue')
export class CubicSplineNumberValue implements ICubicSplineValue<number> {
@@ -135,4 +136,4 @@ export class CubicSplineNumberValue implements ICubicSplineValue<number> {
return this.dataPoint;
}
}
cc.CubicSplineNumberValue = CubicSplineNumberValue;
legacyCC.CubicSplineNumberValue = CubicSplineNumberValue;
+9 -8
View File
@@ -8,8 +8,9 @@ import * as easing from './easing';
import { ComponentPath, HierarchyPath, ICustomTargetPath, TargetPath } from './target-path';
import { IValueProxyFactory } from './value-proxy';
import { UniformProxyFactory } from './value-proxy-factories/uniform';
import { legacyCC } from '../global-exports';
cc.easing = easing;
legacyCC.easing = easing;
export * from './bezier';
export { easing };
export * from './animation-curve';
@@ -37,7 +38,7 @@ export * from './cubic-spline-value';
*/
@ccclass('cc.HierachyModifier')
export class HierachyModifier extends HierarchyPath {}
cc.HierachyModifier = HierachyModifier;
legacyCC.HierachyModifier = HierachyModifier;
/**
* Alias of `ComponentPath`.
@@ -45,7 +46,7 @@ cc.HierachyModifier = HierachyModifier;
*/
@ccclass('cc.ComponentModifier')
export class ComponentModifier extends ComponentPath {}
cc.ComponentModifier = ComponentModifier;
legacyCC.ComponentModifier = ComponentModifier;
/**
* Implements `IValueProxyFactory` but do nothing.
@@ -61,7 +62,7 @@ export class CurveValueAdapter implements IValueProxyFactory {
};
}
}
cc.CurveValueAdapter = CurveValueAdapter;
legacyCC.CurveValueAdapter = CurveValueAdapter;
/**
* Alias of `UniformProxyFactory`.
@@ -69,7 +70,7 @@ cc.CurveValueAdapter = CurveValueAdapter;
*/
@ccclass('cc.UniformCurveValueAdapter')
export class UniformCurveValueAdapter extends UniformProxyFactory {}
cc.UniformCurveValueAdapter = UniformCurveValueAdapter;
legacyCC.UniformCurveValueAdapter = UniformCurveValueAdapter;
/**
* Alias of `isPropertyPath(path) && typeof path === 'string'`.
@@ -78,7 +79,7 @@ cc.UniformCurveValueAdapter = UniformCurveValueAdapter;
export function isPropertyModifier (path: TargetPath): path is string {
return typeof path === 'string';
}
cc.isPropertyModifier = isPropertyModifier;
legacyCC.isPropertyModifier = isPropertyModifier;
/**
* Alias of `isPropertyPath(path) && typeof path === 'number'`.
@@ -87,7 +88,7 @@ cc.isPropertyModifier = isPropertyModifier;
export function isElementModifier (path: TargetPath): path is number {
return typeof path === 'number';
}
cc.isElementModifier = isElementModifier;
legacyCC.isElementModifier = isElementModifier;
/**
* Alias of `isCustomPath()`.
@@ -96,4 +97,4 @@ cc.isElementModifier = isElementModifier;
export function isCustomTargetModifier<T extends ICustomTargetPath> (path: TargetPath, constructor: Constructor<T>): path is T {
return path instanceof constructor;
}
cc.isCustomTargetModifier = isCustomTargetModifier;
legacyCC.isCustomTargetModifier = isCustomTargetModifier;
@@ -37,6 +37,7 @@ import { AnimationComponent } from './animation-component';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { SkeletalAnimationState } from './skeletal-animation-state';
import { getWorldTransformUntilRoot } from './transform-utils';
import { legacyCC } from '../global-exports';
@ccclass('cc.SkeletalAnimationComponent.Socket')
export class Socket {
@@ -148,7 +149,7 @@ export class SkeletalAnimationComponent extends AnimationComponent {
public onDestroy () {
super.onDestroy();
(cc.director.root.dataPoolManager as DataPoolManager).jointAnimationInfo.destroy(this.node.uuid);
(legacyCC.director.root.dataPoolManager as DataPoolManager).jointAnimationInfo.destroy(this.node.uuid);
}
public start () {
@@ -213,4 +214,4 @@ export class SkeletalAnimationComponent extends AnimationComponent {
}
}
cc.SkeletalAnimationComponent = SkeletalAnimationComponent;
legacyCC.SkeletalAnimationComponent = SkeletalAnimationComponent;
@@ -31,6 +31,7 @@ import { clamp01, Mat4, Quat, Vec3 } from '../math';
import { DataPoolManager } from '../renderer/data-pool-manager';
import { AnimationClip, IObjectCurveData } from './animation-clip';
import { HierarchyPath, isCustomPath, isPropertyPath } from './target-path';
import { legacyCC } from '../global-exports';
type CurveData = Vec3 | Quat | Mat4;
type ConvertedProps = Record<string, IPropertyCurve>;
@@ -57,7 +58,7 @@ export class SkelAnimDataHub {
let data = SkelAnimDataHub.pool.get(clip);
if (!data || data.info.sample !== clip.sample) {
// release outdated render data
if (data) { (cc.director.root.dataPoolManager as DataPoolManager).releaseAnimationClip(clip); }
if (data) { (legacyCC.director.root.dataPoolManager as DataPoolManager).releaseAnimationClip(clip); }
data = convertToSkeletalCurves(clip);
SkelAnimDataHub.pool.set(clip, data);
}
@@ -37,6 +37,7 @@ import { AnimationState } from './animation-state';
import { SkeletalAnimationComponent, Socket } from './skeletal-animation-component';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { getWorldTransformUntilRoot } from './transform-utils';
import { legacyCC } from '../global-exports';
const m4_1 = new Mat4();
const m4_2 = new Mat4();
@@ -68,7 +69,7 @@ export class SkeletalAnimationState extends AnimationState {
constructor (clip: AnimationClip, name = '') {
super(clip, name);
this._animInfoMgr = cc.director.root.dataPoolManager.jointAnimationInfo;
this._animInfoMgr = legacyCC.director.root.dataPoolManager.jointAnimationInfo;
}
public initialize (root: Node) {
@@ -169,7 +170,7 @@ export class SkeletalAnimationState extends AnimationState {
private _sampleCurvesRealTime (ratio: number) {
super._sampleCurves(ratio);
const stamp = cc.director.getTotalFrames();
const stamp = legacyCC.director.getTotalFrames();
for (let i = 0; i < this._sockets.length; ++i) {
const { target, transform } = this._sockets[i];
target.matrix = getWorldMatrix(transform, stamp);
@@ -13,6 +13,7 @@ import { getDefaultFromType } from '../../renderer/core/pass-utils';
import { samplerLib } from '../../renderer/core/sampler-lib';
import { IValueProxy, IValueProxyFactory } from '../value-proxy';
import { warn } from '../../platform/debug';
import { legacyCC } from '../../global-exports';
@ccclass('cc.animation.UniformProxyFactory')
export class UniformProxyFactory implements IValueProxyFactory {
@@ -74,7 +75,7 @@ export class UniformProxyFactory implements IValueProxyFactory {
if (!tv || !tv.texture.width || !tv.texture.height) { return; }
pass.bindTextureView(binding, tv);
if (value instanceof TextureBase) {
pass.bindSampler(binding, samplerLib.getSampler(cc.game._gfxDevice, value.getSamplerHash()));
pass.bindSampler(binding, samplerLib.getSampler(legacyCC.game._gfxDevice, value.getSamplerHash()));
}
},
};
+27 -26
View File
@@ -39,6 +39,7 @@ import { SubPackPipe } from '../load-pipeline/subpackage-pipe';
import { Asset } from './asset';
import * as debug from '../platform/debug';
import { EDITOR, TEST, BUILD } from 'internal:constants';
import { legacyCC } from '../global-exports';
// tslint:disable: max-line-length
@@ -49,7 +50,7 @@ let _rawAssetsBase = ''; // The base dir for raw assets in runtime
const _uuidToRawAsset = createMap(true);
function isScene (asset) {
return asset && (asset.constructor === cc.SceneAsset || asset instanceof cc.Scene);
return asset && (asset.constructor === legacyCC.SceneAsset || asset instanceof legacyCC.Scene);
}
// types
@@ -112,17 +113,17 @@ const AssetLibrary = {
if (options && options.existingAsset) {
item.existingAsset = options.existingAsset;
}
cc.loader.load(item, (error, asset) => {
legacyCC.loader.load(item, (error, asset) => {
if (error || !asset) {
error = new Error('[AssetLibrary] loading JSON or dependencies failed: ' + (error ? error.message : 'Unknown error'));
}
else {
if (asset.constructor === cc.SceneAsset) {
if (asset.constructor === legacyCC.SceneAsset) {
if (EDITOR && !asset.scene) {
debug.error('Sorry, the scene data of "%s" is corrupted!', uuid);
}
else {
const key = cc.loader._getReferenceKey(uuid);
const key = legacyCC.loader._getReferenceKey(uuid);
asset.scene.dependAssets = getDependsRecursively(key);
}
}
@@ -165,7 +166,7 @@ const AssetLibrary = {
return callback(loadError);
}
const ctor = cc.js.getClassByName(info.type);
const ctor = legacyCC.js.getClassByName(info.type);
if (ctor) {
const isRawAsset = !isChildClassOf(ctor, Asset);
const url = `import://${info.uuid.substr(0, 2)}/${info.uuid}.json`;
@@ -186,7 +187,7 @@ const AssetLibrary = {
_getAssetInfoInRuntime (uuid, result?: any) {
result = result || {url: null, raw: false};
const info = _uuidToRawAsset[uuid];
if (info && !isChildClassOf(info.type, cc.Asset)) {
if (info && !isChildClassOf(info.type, legacyCC.Asset)) {
// backward compatibility since 1.10
result.url = _rawAssetsBase + info.url;
result.raw = true;
@@ -238,12 +239,12 @@ const AssetLibrary = {
let uuid = '';
const isImported = url.startsWith(_libraryBase);
if (isImported) {
const dir = cc.path.dirname(url);
const dirBasename = cc.path.basename(dir);
const dir = legacyCC.path.dirname(url);
const dirBasename = legacyCC.path.basename(dir);
const isAssetUrl = dirBasename.length === 2;
if (isAssetUrl) {
uuid = cc.path.basename(url);
uuid = legacyCC.path.basename(url);
const index = uuid.indexOf('.');
if (index !== -1) {
uuid = uuid.slice(0, index);
@@ -273,20 +274,20 @@ const AssetLibrary = {
uuid: randomUuid,
type: 'uuid',
content: json,
skips: [ cc.loader.assetLoader.id, cc.loader.downloader.id ],
skips: [ legacyCC.loader.assetLoader.id, legacyCC.loader.downloader.id ],
};
cc.loader.load(item, (error, asset) => {
legacyCC.loader.load(item, (error, asset) => {
if (error) {
error = new Error('[AssetLibrary] loading JSON or dependencies failed: ' + error.message);
}
else {
if (asset.constructor === cc.SceneAsset) {
const key = cc.loader._getReferenceKey(randomUuid);
if (asset.constructor === legacyCC.SceneAsset) {
const key = legacyCC.loader._getReferenceKey(randomUuid);
asset.scene.dependAssets = getDependsRecursively(key);
}
if (EDITOR || isScene(asset)) {
const id = cc.loader._getReferenceKey(randomUuid);
cc.loader.removeItem(id);
const id = legacyCC.loader._getReferenceKey(randomUuid);
legacyCC.loader.removeItem(id);
}
}
asset._uuid = '';
@@ -325,7 +326,7 @@ const AssetLibrary = {
*/
init (options) {
if (EDITOR && _libraryBase) {
cc.errorID(6402);
legacyCC.errorID(6402);
return;
}
@@ -333,7 +334,7 @@ const AssetLibrary = {
// 不使用 url.format 的原因是 windows 不支持 file:// 和 /// 开头的协议,所以只能用 replace 操作直接把路径转成 URL。
let libraryPath = options.libraryPath;
libraryPath = libraryPath.replace(/\\/g, '/');
_libraryBase = cc.path.stripSep(libraryPath) + '/';
_libraryBase = legacyCC.path.stripSep(libraryPath) + '/';
_rawAssetsBase = options.rawAssetsBase;
@@ -365,21 +366,21 @@ const AssetLibrary = {
}
const md5Pipe = new MD5Pipe(md5ImportMap, md5RawAssetsMap, _libraryBase);
cc.loader.insertPipeAfter(cc.loader.assetLoader, md5Pipe);
cc.loader.md5Pipe = md5Pipe;
legacyCC.loader.insertPipeAfter(legacyCC.loader.assetLoader, md5Pipe);
legacyCC.loader.md5Pipe = md5Pipe;
}
const subPackages = options.subPackages;
if (subPackages) {
cc.loader.downloader.setSubPackages(subPackages);
legacyCC.loader.downloader.setSubPackages(subPackages);
const subPackPipe = new SubPackPipe(subPackages);
cc.loader.insertPipeAfter(cc.loader.assetLoader, subPackPipe);
cc.loader.subPackPipe = subPackPipe;
legacyCC.loader.insertPipeAfter(legacyCC.loader.assetLoader, subPackPipe);
legacyCC.loader.subPackPipe = subPackPipe;
}
// init raw assets
const assetTables = cc.loader._assetTables;
const assetTables = legacyCC.loader._assetTables;
// tslint:disable: forin
for (const mount in assetTables) {
assetTables[mount].reset();
@@ -395,7 +396,7 @@ const AssetLibrary = {
const typeId = info[1];
const type = _getClassById(typeId);
if (!type) {
cc.error('Cannot get', typeId);
legacyCC.error('Cannot get', typeId);
continue;
}
// backward compatibility since 1.10
@@ -417,7 +418,7 @@ const AssetLibrary = {
}
// init cc.url
cc.url._init((options.mountPaths && options.mountPaths.assets) || _rawAssetsBase + 'assets');
legacyCC.url._init((options.mountPaths && options.mountPaths.assets) || _rawAssetsBase + 'assets');
},
};
@@ -431,5 +432,5 @@ const AssetLibrary = {
// }
// };
cc.AssetLibrary = AssetLibrary;
legacyCC.AssetLibrary = AssetLibrary;
export default AssetLibrary;
+6 -5
View File
@@ -36,6 +36,7 @@ import { applyMixins, IEventTarget } from '../event/event-target-factory';
import { createMap } from '../utils/js-typed';
import { RawAsset } from './raw-asset';
import { Node } from '../scene-graph';
import { legacyCC } from '../global-exports';
/**
* @en
@@ -88,7 +89,7 @@ export class Asset extends RawAsset implements IEventTarget {
* @return {Asset}
*/
public static deserialize (data) {
return cc.deserialize(data);
return legacyCC.deserialize(data);
}
/**
@@ -158,8 +159,8 @@ export class Asset extends RawAsset implements IEventTarget {
// not imported in library, just created on-the-fly
return name.slice(1);
}
if (cc.AssetLibrary) {
const base = cc.AssetLibrary.getLibUrlNoExt(this._uuid, true);
if (legacyCC.AssetLibrary) {
const base = legacyCC.AssetLibrary.getLibUrlNoExt(this._uuid, true);
if (name.charCodeAt(0) === 46) { // '.'
// imported in dir where json exist
return base + name;
@@ -170,7 +171,7 @@ export class Asset extends RawAsset implements IEventTarget {
}
}
else {
cc.errorID(6400);
legacyCC.errorID(6400);
}
}
return '';
@@ -275,4 +276,4 @@ type CreateNodeCallback = (error: Error | null, node: Node) => void;
// @ts-ignore
Asset.prototype.createNode = null;
cc.Asset = Asset;
legacyCC.Asset = Asset;
+2 -1
View File
@@ -31,6 +31,7 @@
import { ccclass, property } from '../data/class-decorator';
import { Font } from './font';
import { SpriteFrame } from './sprite-frame';
import { legacyCC } from '../global-exports';
export interface IConfig {
[key: string]: any;
@@ -73,4 +74,4 @@ export class BitmapFont extends Font {
public fntConfig: IConfig | null = null;
}
cc.BitmapFont = BitmapFont;
legacyCC.BitmapFont = BitmapFont;
+4 -3
View File
@@ -38,6 +38,7 @@ import { IDefineMap } from '../renderer/core/pass-utils';
import { programLib } from '../renderer/core/program-lib';
import { Asset } from './asset';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
export interface IPropertyInfo {
type: number; // auto-extracted from shader
@@ -183,12 +184,12 @@ export class EffectAsset extends Asset {
*/
public onLoaded () {
this.shaders.forEach((s) => programLib.define(s));
if (!EDITOR) { cc.game.once(cc.Game.EVENT_ENGINE_INITED, this._precompile, this); }
if (!EDITOR) { legacyCC.game.once(legacyCC.Game.EVENT_ENGINE_INITED, this._precompile, this); }
EffectAsset.register(this);
}
protected _precompile () {
const root = cc.director.root as Root;
const root = legacyCC.director.root as Root;
for (let i = 0; i < this.shaders.length; i++) {
const shader = this.shaders[i];
const combination = this.combinations[i];
@@ -204,4 +205,4 @@ export class EffectAsset extends Asset {
}
}
cc.EffectAsset = EffectAsset;
legacyCC.EffectAsset = EffectAsset;
+2 -1
View File
@@ -30,6 +30,7 @@
import {ccclass} from '../data/class-decorator';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* @en
@@ -43,4 +44,4 @@ import { Asset } from './asset';
export class Font extends Asset {
}
cc.Font = Font;
legacyCC.Font = Font;
+8 -7
View File
@@ -33,6 +33,7 @@ import { GFXDevice, GFXFeature } from '../gfx/device';
import { Asset } from './asset';
import { PixelFormat } from './asset-enum';
import { EDITOR, MINIGAME } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* 内存图像源。
@@ -123,7 +124,7 @@ export class ImageAsset extends Asset {
get _texture () {
if (!this._tex) {
const tex = new cc.Texture2D();
const tex = new legacyCC.Texture2D();
tex.name = this._url;
tex.image = this;
this._tex = tex;
@@ -193,7 +194,7 @@ export class ImageAsset extends Asset {
this._onDataComplete();
});
data.addEventListener('error', (err) => {
cc.warnID(3119, err.message);
legacyCC.warnID(3119, err.message);
});
}
}
@@ -249,7 +250,7 @@ export class ImageAsset extends Asset {
let preferedExtensionIndex = Number.MAX_VALUE;
let format = this._format;
let ext = '';
const SupportTextureFormats = cc.macro.SUPPORT_TEXTURE_FORMATS as string[];
const SupportTextureFormats = legacyCC.macro.SUPPORT_TEXTURE_FORMATS as string[];
for (const extensionID of extensionIDs) {
const extFormat = extensionID.split('@');
@@ -267,7 +268,7 @@ export class ImageAsset extends Asset {
} else if ((fmt === PixelFormat.RGB_ETC2 || fmt === PixelFormat.RGBA_ETC2) &&
(!device || !device.hasFeature(GFXFeature.FORMAT_ETC2))) {
continue;
} else if (tmpExt === '.webp' && !cc.sys.capabilities.webp) {
} else if (tmpExt === '.webp' && !legacyCC.sys.capabilities.webp) {
continue;
}
preferedExtensionIndex = index;
@@ -297,8 +298,8 @@ export class ImageAsset extends Asset {
}
function _getGlobalDevice (): GFXDevice | null {
if (cc.director.root) {
return cc.director.root.device;
if (legacyCC.director.root) {
return legacyCC.director.root.device;
} else {
return null;
}
@@ -313,4 +314,4 @@ function _getGlobalDevice (): GFXDevice | null {
* @event loads
*/
cc.ImageAsset = ImageAsset;
legacyCC.ImageAsset = ImageAsset;
+2 -2
View File
@@ -27,7 +27,7 @@
/**
* @hidden
*/
import { legacyCC } from '../global-exports';
export { RawAsset } from './raw-asset';
export { Asset } from './asset';
export {default as Prefab} from './prefab';
@@ -46,7 +46,7 @@ export { LabelAtlas } from './label-atlas';
export { BitmapFont } from './bitmap-font';
export { Font } from './font';
import * as textureUtil from './texture-util';
cc.textureUtil = textureUtil;
legacyCC.textureUtil = textureUtil;
export { textureUtil };
export { EffectAsset } from './effect-asset';
export { Material } from './material';
+2 -1
View File
@@ -29,6 +29,7 @@
import {ccclass, property} from '../data/class-decorator';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* @zh
@@ -44,4 +45,4 @@ export default class JsonAsset extends Asset {
public json: object | null = null;
}
cc.JsonAsset = JsonAsset;
legacyCC.JsonAsset = JsonAsset;
+2 -1
View File
@@ -30,6 +30,7 @@
import { ccclass } from '../data/class-decorator';
import { BitmapFont } from './bitmap-font';
import { legacyCC } from '../global-exports';
/**
* @en
* Class for LabelAtlas handling.
@@ -43,4 +44,4 @@ import { BitmapFont } from './bitmap-font';
export class LabelAtlas extends BitmapFont{
}
cc.LabelAtlas = LabelAtlas;
legacyCC.LabelAtlas = LabelAtlas;
+4 -3
View File
@@ -41,6 +41,7 @@ import { Asset } from './asset';
import { EffectAsset } from './effect-asset';
import { SpriteFrame } from './sprite-frame';
import { TextureBase } from './texture-base';
import { legacyCC } from '../global-exports';
/**
* @en
@@ -365,7 +366,7 @@ export class Material extends Asset {
if (passInfo.switch && !defs[passInfo.switch]) { continue; }
passInfo.stateOverrides = this._states.length > k ? this._states[k] : {};
passInfo.idxInTech = k;
const pass = new Pass(cc.director.root.device);
const pass = new Pass(legacyCC.director.root.device);
pass.initialize(passInfo);
passes.push(pass);
}
@@ -425,7 +426,7 @@ export class Material extends Asset {
}
pass.bindTextureView(binding, textureView);
if (val instanceof TextureBase) {
pass.bindSampler(binding, samplerLib.getSampler(cc.director.root.device, val.getSamplerHash()));
pass.bindSampler(binding, samplerLib.getSampler(legacyCC.director.root.device, val.getSamplerHash()));
}
} else if (!val) {
pass.resetTexture(name);
@@ -448,4 +449,4 @@ export class Material extends Asset {
}
}
cc.Material = Material;
legacyCC.Material = Material;
+7 -6
View File
@@ -52,6 +52,7 @@ import { Asset } from './asset';
import { Skeleton } from './skeleton';
import { postLoadMesh } from './utils/mesh-utils';
import { Morph, createMorphRendering, MorphRendering } from './morph';
import { legacyCC } from '../global-exports';
function getIndexStrideCtor (stride: number) {
switch (stride) {
@@ -139,7 +140,7 @@ export class RenderingSubMesh {
const indices = mesh.readIndices(index) as Uint16Array;
const max = new Vec3();
const min = new Vec3();
const pAttri = this.attributes.find(element => element.name == cc.GFXAttributeName.ATTR_POSITION);
const pAttri = this.attributes.find(element => element.name == legacyCC.GFXAttributeName.ATTR_POSITION);
if (pAttri) {
const conut = GFXFormatInfos[pAttri.format].count;
if (conut == 2) {
@@ -221,7 +222,7 @@ export class RenderingSubMesh {
}
let jointFormat: GFXFormat;
let jointOffset: number;
const device: GFXDevice = cc.director.root.device;
const device: GFXDevice = legacyCC.director.root.device;
for (let i = 0; i < prim.vertexBundelIndices.length; i++) {
const bundle = struct.vertexBundles[prim.vertexBundelIndices[i]];
jointOffset = 0;
@@ -465,8 +466,8 @@ export class Mesh extends Asset {
set _nativeAsset (value: ArrayBuffer) {
if (this._data && this._data.byteLength === value.byteLength) {
this._data.set(new Uint8Array(value));
if (cc.loader._cache[this.nativeUrl]) {
cc.loader._cache[this.nativeUrl].content = this._data.buffer;
if (legacyCC.loader._cache[this.nativeUrl]) {
legacyCC.loader._cache[this.nativeUrl].content = this._data.buffer;
}
}
else {
@@ -564,7 +565,7 @@ export class Mesh extends Asset {
postLoadMesh(this);
}
const buffer = this._data.buffer;
const gfxDevice: GFXDevice = cc.director.root.device;
const gfxDevice: GFXDevice = legacyCC.director.root.device;
const vertexBuffers = this._createVertexBuffers(gfxDevice, buffer);
const indexBuffers: GFXBuffer[] = [];
const subMeshes: RenderingSubMesh[] = [];
@@ -1275,7 +1276,7 @@ export class Mesh extends Asset {
public morphRendering: MorphRendering | null = null;
}
cc.Mesh = Mesh;
legacyCC.Mesh = Mesh;
function getOffset (attributes: IGFXAttribute[], attributeIndex: number) {
let result = 0;
+5 -4
View File
@@ -9,6 +9,7 @@ import { MorphRendering, SubMeshMorph, Morph, MorphRenderingInstance } from './m
import { assertIsNonNullable, assertIsTrue } from '../data/utils/asserts';
import { nextPow2 } from '../math/bits';
import { IMacroPatch } from '../renderer';
import { legacyCC } from '../global-exports';
/**
* True if force to use cpu computing based sub-mesh rendering.
@@ -415,7 +416,7 @@ class CpuComputingRenderingInstance implements SubMeshMorphRenderingInstance {
if (false) {
for (let i = 0; i <myAttribute.local.length; ++i) {
if (i % 3 === 1) {
myAttribute.local[i] = (cc.director.getTotalFrames() % 500) * 0.001;
myAttribute.local[i] = (legacyCC.director.getTotalFrames() % 500) * 0.001;
} else {
myAttribute.local[i] = 0;
}
@@ -503,13 +504,13 @@ class MorphUniforms {
public setWeights (weights: number[]) {
assertIsTrue(weights.length === this._targetCount);
for (let iWeight = 0; iWeight < weights.length; ++iWeight) {
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_WEIGHTS + 4 * iWeight, weights[iWeight], cc.sys.isLittleEndian);
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_WEIGHTS + 4 * iWeight, weights[iWeight], legacyCC.sys.isLittleEndian);
}
}
public setMorphTextureInfo (width: number, height: number) {
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_WIDTH, width, cc.sys.isLittleEndian);
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_HEIGHT, height, cc.sys.isLittleEndian);
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_WIDTH, width, legacyCC.sys.isLittleEndian);
this._localBuffer.setFloat32(UBOMorph.OFFSET_OF_DISPLACEMENT_TEXTURE_HEIGHT, height, legacyCC.sys.isLittleEndian);
}
public commit () {
+6 -5
View File
@@ -34,6 +34,7 @@ import { obsolete } from '../utils/js';
import { Enum } from '../value-types';
import { Asset } from './asset';
import { SUPPORT_JIT, ALIPAY, RUNTIME_BASED } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* Prefab 创建实例所用的优化策略,配合 [[optimizationPolicy]] 使用。
@@ -118,7 +119,7 @@ export default class Prefab extends Asset {
}
public createNode (cb: Function): void {
const node = cc.instantiate(this);
const node = legacyCC.instantiate(this);
node.name = this.name;
cb(null, node);
}
@@ -147,7 +148,7 @@ export default class Prefab extends Asset {
}
else {
// temp guard code
cc.warnID(3700);
legacyCC.warnID(3700);
}
if (!this._createFunction) {
this.compileCreateFunction();
@@ -188,9 +189,9 @@ export default class Prefab extends Asset {
}
}
cc.Prefab = Prefab;
legacyCC.Prefab = Prefab;
if (ALIPAY || RUNTIME_BASED) {
cc._Prefab = Prefab;
legacyCC._Prefab = Prefab;
} else {
obsolete(cc, 'cc._Prefab', 'Prefab');
obsolete(legacyCC, 'cc._Prefab', 'Prefab');
}
+3 -2
View File
@@ -31,6 +31,7 @@
import { ccclass } from '../data/class-decorator';
import { CCObject } from '../data/object';
import { isChildClassOf } from '../utils/js';
import { legacyCC } from '../global-exports';
/**
* 原生资源的基类。内部使用。
@@ -42,7 +43,7 @@ export class RawAsset extends CCObject {
* 内部使用。
*/
public static isRawAssetType (ctor: Function) {
return isChildClassOf(ctor, cc.RawAsset) && !isChildClassOf(ctor, cc.Asset);
return isChildClassOf(ctor, legacyCC.RawAsset) && !isChildClassOf(ctor, legacyCC.Asset);
}
/**
@@ -62,4 +63,4 @@ export class RawAsset extends CCObject {
}
}
cc.RawAsset = RawAsset;
legacyCC.RawAsset = RawAsset;
+2 -1
View File
@@ -5,6 +5,7 @@
import { ccclass, property } from '../data/class-decorator';
import { RenderPipeline } from '../pipeline/render-pipeline';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
@ccclass('cc.RenderPipelineAsset')
export default class RenderPipelineAsset extends Asset {
@@ -14,4 +15,4 @@ export default class RenderPipelineAsset extends Asset {
public renderPipeline: RenderPipeline | null = null;
}
cc.RenderPipelineAsset = RenderPipelineAsset;
legacyCC.RenderPipelineAsset = RenderPipelineAsset;
+4 -3
View File
@@ -9,6 +9,7 @@ import { GFXWindow } from '../gfx/window';
import { ccenum } from '../value-types/enum';
import { DepthStencilFormat, PixelFormat } from './asset-enum';
import { TextureBase } from './texture-base';
import { legacyCC } from '../global-exports';
export interface IRenderTextureCreateInfo {
name?: string;
@@ -93,7 +94,7 @@ export class RenderTexture extends TextureBase {
public destroy () {
if (this._window) {
cc.director.root!.destroyWindow(this._window);
legacyCC.director.root!.destroyWindow(this._window);
this._window = null;
}
@@ -153,10 +154,10 @@ export class RenderTexture extends TextureBase {
return this._window;
}
this._window = cc.director.root!.createWindow(config);
this._window = legacyCC.director.root!.createWindow(config);
this.loaded = true;
this.emit('load');
}
}
cc.RenderTexture = RenderTexture;
legacyCC.RenderTexture = RenderTexture;
+2 -1
View File
@@ -31,6 +31,7 @@
import {ccclass, property} from '../data/class-decorator';
import { Scene } from '../scene-graph';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* @en Class for scene handling.
@@ -57,4 +58,4 @@ export default class SceneAsset extends Asset {
public asyncLoadAssets = false;
}
cc.SceneAsset = SceneAsset;
legacyCC.SceneAsset = SceneAsset;
+4 -3
View File
@@ -30,6 +30,7 @@
import {ccclass} from '../data/class-decorator';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* @zh
@@ -38,7 +39,7 @@ import { Asset } from './asset';
@ccclass('cc.Script')
export class Script extends Asset {
}
cc._Script = Script;
legacyCC._Script = Script;
/**
* @zh
@@ -47,7 +48,7 @@ cc._Script = Script;
@ccclass('cc.JavaScript')
export class JavaScript extends Script {
}
cc._JavaScript = JavaScript;
legacyCC._JavaScript = JavaScript;
/**
* @zh
@@ -56,4 +57,4 @@ cc._JavaScript = JavaScript;
@ccclass('cc.TypeScript')
export class TypeScript extends Script {
}
cc._TypeScript = TypeScript;
legacyCC._TypeScript = TypeScript;
+4 -3
View File
@@ -12,6 +12,7 @@ import { Filter } from './asset-enum';
import { ImageAsset } from './image-asset';
import { TextureBase } from './texture-base';
import { DEV } from 'internal:constants';
import { legacyCC } from '../global-exports';
const _regions: GFXBufferTextureCopy[] = [{
buffOffset: 0,
@@ -160,10 +161,10 @@ export class SimpleTexture extends TextureBase {
upload();
});
if (!this.isCompressed) {
const defaultImg = cc.builtinResMgr.get('black-texture').image as ImageAsset;
const defaultImg = legacyCC.builtinResMgr.get('black-texture').image as ImageAsset;
this.uploadData(defaultImg.data as HTMLCanvasElement, level, arrayIndex);
}
cc.textureUtil.postLoadImage(image);
legacyCC.textureUtil.postLoadImage(image);
}
}
@@ -259,4 +260,4 @@ export class SimpleTexture extends TextureBase {
}
}
cc.SimpleTexture = SimpleTexture;
legacyCC.SimpleTexture = SimpleTexture;
+3 -2
View File
@@ -33,6 +33,7 @@ import { Mat4 } from '../../core/math';
import { murmurhash2_32_gc } from '../../core/utils/murmurhash2_gc';
import { DataPoolManager } from '../renderer/data-pool-manager';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* 骨骼资源。
@@ -90,9 +91,9 @@ export class Skeleton extends Asset {
}
public destroy () {
(cc.director.root.dataPoolManager as DataPoolManager).releaseSkeleton(this);
(legacyCC.director.root.dataPoolManager as DataPoolManager).releaseSkeleton(this);
return super.destroy();
}
}
cc.Skeleton = Skeleton;
legacyCC.Skeleton = Skeleton;
+2 -1
View File
@@ -32,6 +32,7 @@ import { ccclass, property } from '../data/class-decorator';
import * as js from '../utils/js';
import { Asset } from './asset';
import { SpriteFrame } from './sprite-frame';
import { legacyCC } from '../global-exports';
interface ISpriteAtlasSerializeData{
name: string;
@@ -136,4 +137,4 @@ export class SpriteAtlas extends Asset {
}
}
cc.SpriteAtlas = SpriteAtlas;
legacyCC.SpriteAtlas = SpriteAtlas;
+4 -3
View File
@@ -37,6 +37,7 @@ import { Asset } from './asset';
import { RenderTexture } from './render-texture';
import { TextureBase } from './texture-base';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
const INSET_LEFT = 0;
const INSET_TOP = 1;
@@ -662,12 +663,12 @@ export class SpriteFrame extends Asset {
}
if (maxX > texture.width) {
cc.errorID(3300, this.name + '/' + texture.name, maxX, texture.width);
legacyCC.errorID(3300, this.name + '/' + texture.name, maxX, texture.width);
return false;
}
if (maxY > texture.height) {
cc.errorID(3301, this.name + '/' + texture.name, maxY, texture.height);
legacyCC.errorID(3301, this.name + '/' + texture.name, maxY, texture.height);
return false;
}
@@ -952,4 +953,4 @@ export class SpriteFrame extends Asset {
}
}
cc.SpriteFrame = SpriteFrame;
legacyCC.SpriteFrame = SpriteFrame;
+2 -1
View File
@@ -30,6 +30,7 @@
import {ccclass, property} from '../data/class-decorator';
import { Asset } from './asset';
import { legacyCC } from '../global-exports';
/**
* @en Class for text file.
@@ -52,4 +53,4 @@ export default class TextAsset extends Asset {
}
}
cc.TextAsset = TextAsset;
legacyCC.TextAsset = TextAsset;
+2 -1
View File
@@ -33,6 +33,7 @@ import { GFXTextureType, GFXTextureViewType } from '../gfx/define';
import { PixelFormat } from './asset-enum';
import { ImageAsset } from './image-asset';
import { PresumedGFXTextureInfo, PresumedGFXTextureViewInfo, SimpleTexture } from './simple-texture';
import { legacyCC } from '../global-exports';
/**
* 贴图创建选项。
@@ -275,7 +276,7 @@ export class Texture2D extends SimpleTexture {
}
}
cc.Texture2D = Texture2D;
legacyCC.Texture2D = Texture2D;
export interface ITexture2DSerializeData {
base: string;
+4 -3
View File
@@ -37,6 +37,7 @@ import IDGenerator from '../utils/id-generator';
import { Asset } from './asset';
import { Filter, PixelFormat, WrapMode } from './asset-enum';
import { GFXSampler } from '../gfx';
import { legacyCC } from '../global-exports';
const CHAR_CODE_1 = 49; // '1'
@@ -269,7 +270,7 @@ export class TextureBase extends Asset {
if (this._gfxDevice) {
this._gfxSampler = samplerLib.getSampler(this._gfxDevice, this._samplerHash);
} else {
cc.errorID(9302);
legacyCC.errorID(9302);
}
}
return this._gfxSampler;
@@ -314,7 +315,7 @@ export class TextureBase extends Asset {
}
protected _getGFXDevice (): GFXDevice | null {
return cc.director.root && cc.director.root.device;
return legacyCC.director.root && legacyCC.director.root.device;
}
protected _getGFXFormat () {
@@ -326,4 +327,4 @@ export class TextureBase extends Asset {
}
}
cc.TextureBase = TextureBase;
legacyCC.TextureBase = TextureBase;
+2 -1
View File
@@ -32,6 +32,7 @@ import { GFXTextureFlagBit, GFXTextureType, GFXTextureViewType } from '../gfx/de
import { ImageAsset } from './image-asset';
import { PresumedGFXTextureInfo, PresumedGFXTextureViewInfo, SimpleTexture } from './simple-texture';
import { ITexture2DCreateInfo, Texture2D } from './texture-2d';
import { legacyCC } from '../global-exports';
export type ITextureCubeCreateInfo = ITexture2DCreateInfo;
@@ -275,7 +276,7 @@ export class TextureCube extends SimpleTexture {
}
cc.TextureCube = TextureCube;
legacyCC.TextureCube = TextureCube;
interface ITextureCubeSerializeData {
base: string;
+2 -1
View File
@@ -30,6 +30,7 @@
import {ccclass, property, string} from '../data/class-decorator';
import { Font } from './font';
import { legacyCC } from '../global-exports';
/**
* @en
@@ -56,4 +57,4 @@ export class TTFFont extends Font {
}
}
cc.TTFFont = TTFFont;
legacyCC.TTFFont = TTFFont;
+2 -1
View File
@@ -23,6 +23,7 @@
THE SOFTWARE.
*/
import { Mesh } from '../mesh';
import { legacyCC } from '../../global-exports';
export function postLoadMesh (mesh: Mesh, callback?: Function) {
if (mesh.loaded) {
if (callback) {
@@ -37,7 +38,7 @@ export function postLoadMesh (mesh: Mesh, callback?: Function) {
return;
}
// load image
cc.loader.load({
legacyCC.loader.load({
url: mesh.nativeUrl,
}, (err, arrayBuffer) => {
if (arrayBuffer) {
@@ -43,6 +43,7 @@ import { ccclass, help, menu } from '../data/class-decorator';
import { Component } from './component';
import { Event } from '../event';
import { SystemEventType } from '../platform/event-manager/event-enum';
import { legacyCC } from '../global-exports';
const BlockEvents = [SystemEventType.TOUCH_START, SystemEventType.TOUCH_END, SystemEventType.TOUCH_MOVE,
SystemEventType.MOUSE_DOWN, SystemEventType.MOUSE_MOVE, SystemEventType.MOUSE_UP,
@@ -71,4 +72,4 @@ export class BlockInputEventsComponent extends Component {
}
}
cc.BlockInputEventsComponent = BlockInputEventsComponent;
legacyCC.BlockInputEventsComponent = BlockInputEventsComponent;
@@ -30,6 +30,7 @@
import {ccclass, property} from '../data/class-decorator';
import { Node } from '../scene-graph';
import { legacyCC } from '../global-exports';
/**
* @zh
@@ -80,7 +81,7 @@ export class EventHandler {
* @zh
* 目标节点。
*/
@property(cc.Node)
@property(legacyCC.Node)
public target: Node | null = null;
/**
* @zh
@@ -123,13 +124,13 @@ export class EventHandler {
*/
public emit (params: any[]) {
const target = this.target;
if (!cc.isValid(target)) { return; }
if (!legacyCC.isValid(target)) { return; }
this._genCompIdIfNeeded();
const compType = cc.js._getClassById(this._componentId);
const compType = legacyCC.js._getClassById(this._componentId);
const comp = target!.getComponent(compType);
if (!cc.isValid(comp)) { return; }
if (!legacyCC.isValid(comp)) { return; }
const handler = comp![this.handler];
if (typeof(handler) !== 'function') { return; }
@@ -143,13 +144,13 @@ export class EventHandler {
}
private _compName2Id (compName) {
const comp = cc.js.getClassByName(compName);
return cc.js._getClassId(comp);
const comp = legacyCC.js.getClassByName(compName);
return legacyCC.js._getClassId(comp);
}
private _compId2Name (compId) {
const comp = cc.js._getClassById(compId);
return cc.js.getClassName(comp);
const comp = legacyCC.js._getClassById(compId);
return legacyCC.js.getClassName(comp);
}
// to be deprecated in the future
@@ -161,4 +162,4 @@ export class EventHandler {
}
}
cc.Component.EventHandler = EventHandler;
legacyCC.Component.EventHandler = EventHandler;
+17 -16
View File
@@ -40,6 +40,7 @@ import { Rect } from '../math';
import * as RF from '../data/utils/requiring-frame';
import { Node } from '../scene-graph';
import { EDITOR, TEST, DEV } from 'internal:constants';
import { legacyCC } from '../global-exports';
const idGenerator = new IDGenerator('Comp');
// @ts-ignore
@@ -131,7 +132,7 @@ class Component extends CCObject {
if (this._enabled !== value) {
this._enabled = value;
if (this.node.activeInHierarchy) {
const compScheduler = cc.director._compScheduler;
const compScheduler = legacyCC.director._compScheduler;
if (value) {
compScheduler.enableComp(this);
}
@@ -361,13 +362,13 @@ class Component extends CCObject {
// @ts-ignore
const depend = this.node._getDependComponent(this);
if (depend) {
return cc.errorID(3626,
return legacyCC.errorID(3626,
getClassName(this), getClassName(depend));
}
}
if (super.destroy()) {
if (this._enabled && this.node.activeInHierarchy) {
cc.director._compScheduler.disableComp(this);
legacyCC.director._compScheduler.disableComp(this);
}
}
}
@@ -391,7 +392,7 @@ class Component extends CCObject {
}
// onDestroy
cc.director._nodeActivator.destroyComp(this);
legacyCC.director._nodeActivator.destroyComp(this);
// do remove component
this.node._removeComponent(this);
@@ -399,7 +400,7 @@ class Component extends CCObject {
public _instantiate (cloned) {
if (!cloned) {
cloned = cc.instantiate._clone(this, this);
cloned = legacyCC.instantiate._clone(this, this);
}
cloned.node = null;
return cloned;
@@ -427,15 +428,15 @@ class Component extends CCObject {
* this.schedule(timeCallback, 1);
* ```
*/
public schedule (callback, interval: number = 0, repeat: number = cc.macro.REPEAT_FOREVER, delay: number = 0) {
cc.assertID(callback, 1619);
cc.assertID(interval >= 0, 1620);
public schedule (callback, interval: number = 0, repeat: number = legacyCC.macro.REPEAT_FOREVER, delay: number = 0) {
legacyCC.assertID(callback, 1619);
legacyCC.assertID(interval >= 0, 1620);
interval = interval || 0;
repeat = isNaN(repeat) ? cc.macro.REPEAT_FOREVER : repeat;
repeat = isNaN(repeat) ? legacyCC.macro.REPEAT_FOREVER : repeat;
delay = delay || 0;
const scheduler = cc.director.getScheduler();
const scheduler = legacyCC.director.getScheduler();
// should not use enabledInHierarchy to judge whether paused,
// because enabledInHierarchy is assigned after onEnable.
@@ -479,7 +480,7 @@ class Component extends CCObject {
return;
}
cc.director.getScheduler().unschedule(callback_fn, this);
legacyCC.director.getScheduler().unschedule(callback_fn, this);
}
/**
@@ -494,7 +495,7 @@ class Component extends CCObject {
* ```
*/
public unscheduleAllCallbacks () {
cc.director.getScheduler().unscheduleAllForTarget(this);
legacyCC.director.getScheduler().unscheduleAllForTarget(this);
}
// LIFECYCLE METHODS
@@ -706,7 +707,7 @@ if (EDITOR || TEST) {
// COMPONENT HELPERS
// TODO Keep temporarily, compatible with old version
cc._componentMenuItems = [];
legacyCC._componentMenuItems = [];
}
// we make this non-enumerable, to prevent inherited by sub classes.
@@ -735,7 +736,7 @@ value(Component, '_registerEditorProps', function (cls, props) {
cls._playOnFocus = true;
}
else {
cc.warnID(3601, name);
legacyCC.warnID(3601, name);
}
}
break;
@@ -772,12 +773,12 @@ value(Component, '_registerEditorProps', function (cls, props) {
break;
default:
cc.warnID(3602, key, name);
legacyCC.warnID(3602, key, name);
break;
}
}
}
});
cc.Component = Component;
legacyCC.Component = Component;
export { Component };
+4 -3
View File
@@ -33,6 +33,7 @@ import {_getClassById} from '../utils/js';
import {BUILTIN_CLASSID_RE} from '../utils/misc';
import { Component } from './component';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* @en
@@ -80,7 +81,7 @@ export default class MissingScript extends Component {
return cls;
}
if (id) {
cc.deserialize.reportMissingClass(id);
legacyCC.deserialize.reportMissingClass(id);
return MissingScript.getMissingWrapper(id, data);
}
return null;
@@ -116,8 +117,8 @@ export default class MissingScript extends Component {
}
public onLoad () {
cc.warnID(4600, this.node.name);
legacyCC.warnID(4600, this.node.name);
}
}
cc._MissingScript = MissingScript;
legacyCC._MissingScript = MissingScript;
@@ -44,6 +44,7 @@ import { Enum } from '../../value-types';
import { Component } from '../component';
import { UITransformComponent } from './ui-transform-component';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../../global-exports';
const _worldPos = new Vec3();
@@ -343,7 +344,7 @@ export class CanvasComponent extends Component {
designSize = view.getDesignResolutionSize();
const policy = view.getResolutionPolicy();
// const clipTopRight = !this.fitHeight && !this.fitWidth;
const clipTopRight = policy === cc.view._rpNoBorder;
const clipTopRight = policy === legacyCC.view._rpNoBorder;
let offsetX = 0;
let offsetY = 0;
if (clipTopRight) {
@@ -423,4 +424,4 @@ export class CanvasComponent extends Component {
}
}
cc.CanvasComponent = CanvasComponent;
legacyCC.CanvasComponent = CanvasComponent;
@@ -43,6 +43,7 @@ import { UI } from '../../renderer/ui/ui';
import { Node } from '../../scene-graph';
import { TransformBit } from '../../scene-graph/node-enum';
import { UIComponent } from './ui-component';
import { legacyCC } from '../../global-exports';
// hack
ccenum(GFXBlendFactor);
@@ -461,4 +462,4 @@ export class UIRenderComponent extends UIComponent {
protected _flushAssembler? (): void;
}
cc.UIRenderComponent = UIRenderComponent;
legacyCC.UIRenderComponent = UIRenderComponent;
@@ -36,6 +36,7 @@ import { aabb } from '../../geometry';
import { CanvasComponent } from './canvas-component';
import { Node } from '../../scene-graph';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../../global-exports';
const _vec2a = new Vec2();
const _vec2b = new Vec2();
@@ -211,7 +212,7 @@ export class UITransformComponent extends Component {
}
if (this._canvas && this._canvas.node === this.node) {
cc.warn(9200);
legacyCC.warn(9200);
return;
}
@@ -388,7 +389,7 @@ export class UITransformComponent extends Component {
canvas.node.getWorldRT(_mat4_temp);
const m12 = _mat4_temp.m12;
const m13 = _mat4_temp.m13;
const center = cc.visibleRect.center;
const center = legacyCC.visibleRect.center;
_mat4_temp.m12 = center.x - (_mat4_temp.m00 * m12 + _mat4_temp.m04 * m13);
_mat4_temp.m13 = center.y - (_mat4_temp.m01 * m12 + _mat4_temp.m05 * m13);
Mat4.invert(_mat4_temp, _mat4_temp);
@@ -408,7 +409,7 @@ export class UITransformComponent extends Component {
for (let i = 0; parent && i < mask.index; ++i, parent = parent.parent) {
}
if (parent === mask.node) {
const comp = parent.getComponent(cc.MaskComponent);
const comp = parent.getComponent(legacyCC.MaskComponent);
return (comp && comp.enabledInHierarchy) ? comp.isHit(cameraPt) : true;
} else {
listener.mask = null;
@@ -641,4 +642,4 @@ export class UITransformComponent extends Component {
}
}
cc.UITransformComponent = UITransformComponent;
legacyCC.UITransformComponent = UITransformComponent;
+5 -4
View File
@@ -55,6 +55,7 @@ import { doValidateMethodWithProps_DEV, getFullFormOfProperty } from './utils/pr
import { CCString, CCInteger, CCFloat, CCBoolean, PrimitiveType } from './utils/attribute';
import { error, errorID, warnID } from '../platform/debug';
import { DEV } from 'internal:constants';
import { legacyCC } from '../global-exports';
// caches for class construction
const CACHE_KEY = '__ccclassCache__';
@@ -93,7 +94,7 @@ function _checkNormalArgument (validator_DEV, decorate, decoratorName) {
}
const checkCompArgument = _checkNormalArgument.bind(null, DEV && function (arg, decoratorName) {
if (!cc.Class._isCCClass(arg)) {
if (!legacyCC.Class._isCCClass(arg)) {
error('The parameter for %s is missing.', decoratorName);
return false;
}
@@ -101,7 +102,7 @@ const checkCompArgument = _checkNormalArgument.bind(null, DEV && function (arg,
function _argumentChecker (type) {
return _checkNormalArgument.bind(null, DEV && function (arg, decoratorName) {
if (arg instanceof cc.Component || arg === undefined) {
if (arg instanceof legacyCC.Component || arg === undefined) {
error('The parameter for %s is missing.', decoratorName);
return false;
}
@@ -116,7 +117,7 @@ const checkNumberArgument = _argumentChecker('number');
// var checkBooleanArgument = _argumentChecker('boolean');
function getClassCache (ctor, decoratorName?) {
if (DEV && cc.Class._isCCClass(ctor)) {
if (DEV && legacyCC.Class._isCCClass(ctor)) {
error('`@%s` should be used after @ccclass for class "%s"', decoratorName, js.getClassName(ctor));
return null;
}
@@ -289,7 +290,7 @@ export const ccclass = checkCtorArgument(function (ctor, name) {
ctor[CACHE_KEY] = undefined;
}
const res = cc.Class(proto);
const res = legacyCC.Class(proto);
// validate methods
if (DEV) {
+13 -12
View File
@@ -47,6 +47,7 @@ import { preprocessAttrs, validateMethodWithProps } from './utils/preprocess-cla
import * as RF from './utils/requiring-frame';
import { error } from '../platform/debug';
import { DEV, EDITOR, SUPPORT_JIT, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
const DELIMETER = attributeUtils.DELIMETER;
@@ -235,7 +236,7 @@ function getDefault (defaultVal) {
return defaultVal();
}
catch (e) {
cc._throw(e);
legacyCC._throw(e);
return undefined;
}
}
@@ -354,7 +355,7 @@ function doDefine (className, baseClass, mixins, options) {
}
function define (className, baseClass, mixins, options) {
const Component = cc.Component;
const Component = legacyCC.Component;
const frame = RF.peek();
if (frame && js.isChildClassOf(baseClass, Component)) {
@@ -377,9 +378,9 @@ function define (className, baseClass, mixins, options) {
const cls = doDefine(className, baseClass, mixins, options);
// for RenderPipeline, RenderFlow, RenderStage
const isRenderPipeline = js.isChildClassOf(baseClass, cc.RenderPipeline);
const isRenderFlow = js.isChildClassOf(baseClass, cc.RenderFlow);
const isRenderStage = js.isChildClassOf(baseClass, cc.RenderStage);
const isRenderPipeline = js.isChildClassOf(baseClass, legacyCC.RenderPipeline);
const isRenderFlow = js.isChildClassOf(baseClass, legacyCC.RenderFlow);
const isRenderStage = js.isChildClassOf(baseClass, legacyCC.RenderStage);
const isRender = isRenderPipeline || isRenderFlow || isRenderStage || false;
@@ -499,7 +500,7 @@ function getInitPropsJit (attrs, propList) {
let expression;
const def = attrs[attrKey];
if (typeof def === 'object' && def) {
if (def instanceof cc.ValueType) {
if (def instanceof legacyCC.ValueType) {
expression = getNewValueTypeCodeJit(def);
}
else if (Array.isArray(def)) {
@@ -577,7 +578,7 @@ function getInitProps (attrs, propList) {
let expression;
const def = advancedValues[i];
if (typeof def === 'object') {
if (def instanceof cc.ValueType) {
if (def instanceof legacyCC.ValueType) {
expression = def.clone();
}
else if (Array.isArray(def)) {
@@ -594,7 +595,7 @@ function getInitProps (attrs, propList) {
expression = def();
}
catch (err) {
cc._throw(err);
legacyCC._throw(err);
continue;
}
}
@@ -993,7 +994,7 @@ function CCClass (options) {
// create constructor
const cls = define(name, base, mixins, options);
if (!name) {
name = cc.js.getClassName(cls);
name = legacyCC.js.getClassName(cls);
}
cls._sealed = true;
@@ -1053,8 +1054,8 @@ function CCClass (options) {
const editor = options.editor;
if (editor) {
if (js.isChildClassOf(base, cc.Component)) {
cc.Component._registerEditorProps(cls, editor);
if (js.isChildClassOf(base, legacyCC.Component)) {
legacyCC.Component._registerEditorProps(cls, editor);
}
else if (DEV) {
warnID(3623, name);
@@ -1321,4 +1322,4 @@ CCClass.getNewValueTypeCode = (SUPPORT_JIT && getNewValueTypeCodeJit) as ((value
export default CCClass;
cc.Class = CCClass;
legacyCC.Class = CCClass;
+27 -26
View File
@@ -35,6 +35,7 @@ import CCClass from './class';
import * as Attr from './utils/attribute';
import MissingScript from '../components/missing-script';
import { EDITOR, TEST, DEV, JSB, PREVIEW, SUPPORT_JIT } from 'internal:constants';
import { legacyCC } from '../global-exports';
// HELPERS
@@ -169,7 +170,7 @@ function _dereference (self) {
}
function compileObjectTypeJit (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue, stillUseUrl) {
if (defaultValue instanceof cc.ValueType) {
if (defaultValue instanceof legacyCC.ValueType) {
// fast case
if (!assumeHavePropIfIsValue) {
sources.push('if(prop){');
@@ -245,10 +246,10 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
let isPrimitiveType;
const userType = attrs[propName + TYPE];
if (defaultValue === undefined && userType) {
isPrimitiveType = userType === cc.String ||
userType === cc.Integer ||
userType === cc.Float ||
userType === cc.Boolean;
isPrimitiveType = userType === legacyCC.String ||
userType === legacyCC.Integer ||
userType === legacyCC.Float ||
userType === legacyCC.Boolean;
}
else {
const defaultType = typeof defaultValue;
@@ -273,9 +274,9 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
}
sources.push('}');
}
if (cc.js.isChildClassOf(klass, cc._BaseNode) || cc.js.isChildClassOf(klass, cc.Component)) {
if (legacyCC.js.isChildClassOf(klass, legacyCC._BaseNode) || legacyCC.js.isChildClassOf(klass, legacyCC.Component)) {
if (PREVIEW || (EDITOR && self._ignoreEditorOnly)) {
const mayUsedInPersistRoot = js.isChildClassOf(klass, cc.Node);
const mayUsedInPersistRoot = js.isChildClassOf(klass, legacyCC.Node);
if (mayUsedInPersistRoot) {
sources.push('d._id&&(o._id=d._id);');
}
@@ -293,7 +294,7 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
return Function('s', 'o', 'd', 'k', 't', sources.join(''));
} : (self, klass) => {
const fastMode = misc.BUILTIN_CLASSID_RE.test(js._getClassId(klass));
const shouldCopyId = cc.js.isChildClassOf(klass, cc._BaseNode) || cc.js.isChildClassOf(klass, cc.Component);
const shouldCopyId = legacyCC.js.isChildClassOf(klass, legacyCC._BaseNode) || legacyCC.js.isChildClassOf(klass, legacyCC.Component);
let shouldCopyRawData;
const simpleProps: any = [];
@@ -327,10 +328,10 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
if (fastMode) {
const userType = attrs[propName + TYPE];
if (defaultValue === undefined && userType) {
isPrimitiveType = userType === cc.String ||
userType === cc.Integer ||
userType === cc.Float ||
userType === cc.Boolean;
isPrimitiveType = userType === legacyCC.String ||
userType === legacyCC.Integer ||
userType === legacyCC.Float ||
userType === legacyCC.Boolean;
}
else {
const defaultType = typeof defaultValue;
@@ -357,7 +358,7 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
advancedPropsToRead.push(propNameToRead);
}
advancedPropsUseUrl.push(stillUseUrl);
advancedPropsValueType.push((defaultValue instanceof cc.ValueType) && defaultValue.constructor);
advancedPropsValueType.push((defaultValue instanceof legacyCC.ValueType) && defaultValue.constructor);
}
}
})();
@@ -448,7 +449,7 @@ function _deserializeFireClass (self, obj, serialized, klass, target) {
deserialize(self, obj, serialized, klass, target);
// if preview or build worker
if (PREVIEW || (EDITOR && self._ignoreEditorOnly)) {
if (klass === cc._PrefabInfo && !obj.sync) {
if (klass === legacyCC._PrefabInfo && !obj.sync) {
unlinkUnusedPrefab(self, serialized, obj);
}
}
@@ -590,7 +591,7 @@ class _Deserializer {
if (!klass) {
const notReported = this._classFinder === js._getClassById;
if (notReported) {
cc.deserialize.reportMissingClass(type);
legacyCC.deserialize.reportMissingClass(type);
}
return null;
}
@@ -613,7 +614,7 @@ class _Deserializer {
obj._deserialize(serialized.content, self);
return;
}
if (cc.Class._isCCClass(klass)) {
if (legacyCC.Class._isCCClass(klass)) {
_deserializeFireClass(self, obj, serialized, klass, target);
}
else {
@@ -629,12 +630,12 @@ class _Deserializer {
catch (e) {
console.error('deserialize ' + klass.name + ' failed, ' + e.stack);
klass = MissingScript.getMissingWrapper(type, serialized);
cc.deserialize.reportMissingClass(type);
legacyCC.deserialize.reportMissingClass(type);
deserializeByType();
}
}
if (EDITOR && cc.js.isChildClassOf(klass, cc.Component)) {
if (EDITOR && legacyCC.js.isChildClassOf(klass, legacyCC.Component)) {
checkDeserializeByType();
}
else {
@@ -746,23 +747,23 @@ class _Deserializer {
}
private _deserializeTypedObject (instance, serialized, klass) {
if (klass === cc.Vec2) {
if (klass === legacyCC.Vec2) {
instance.x = serialized.x || 0;
instance.y = serialized.y || 0;
return;
} else if (klass === cc.Vec3) {
} else if (klass === legacyCC.Vec3) {
instance.x = serialized.x || 0;
instance.y = serialized.y || 0;
instance.z = serialized.z || 0;
return;
} else if (klass === cc.Color) {
} else if (klass === legacyCC.Color) {
instance.r = serialized.r || 0;
instance.g = serialized.g || 0;
instance.b = serialized.b || 0;
const a = serialized.a;
instance.a = (a === undefined ? 255 : a);
return;
} else if (klass === cc.Size) {
} else if (klass === legacyCC.Size) {
instance.width = serialized.width || 0;
instance.height = serialized.height || 0;
return;
@@ -849,7 +850,7 @@ function deserialize (data, details, options) {
options = options || {};
const classFinder = options.classFinder || js._getClassById;
// 启用 createAssetRefs 后,如果有 url 属性则会被统一强制设置为 { uuid: 'xxx' },必须后面再特殊处理
const createAssetRefs = options.createAssetRefs || cc.sys.platform === cc.sys.EDITOR_CORE;
const createAssetRefs = options.createAssetRefs || legacyCC.sys.platform === legacyCC.sys.EDITOR_CORE;
const target = (EDITOR || TEST) && options.target;
const customEnv = options.customEnv;
const ignoreEditorOnly = options.ignoreEditorOnly;
@@ -865,9 +866,9 @@ function deserialize (data, details, options) {
// @ts-ignore
const deserializer: any = _Deserializer.pool.get(details, target, classFinder, customEnv, ignoreEditorOnly);
cc.game._isCloning = true;
legacyCC.game._isCloning = true;
const res = deserializer.deserialize(data);
cc.game._isCloning = false;
legacyCC.game._isCloning = false;
_Deserializer.pool.put(deserializer);
if (createAssetRefs) {
@@ -894,6 +895,6 @@ deserialize.reportMissingClass = (id) => {
warnID(5302, id);
}
};
cc.deserialize = deserialize;
legacyCC.deserialize = deserialize;
export default deserialize;
+2 -1
View File
@@ -28,7 +28,8 @@
*/
import * as _decorator from './class-decorator';
cc._decorator = _decorator;
import { legacyCC } from '../global-exports';
legacyCC._decorator = _decorator;
export { _decorator };
export { default as CCClass } from './class';
export { CCObject, isValid } from './object';
+14 -13
View File
@@ -36,6 +36,7 @@ import { CCObject } from './object';
import * as Attr from './utils/attribute';
import {flattenCodeArray} from './utils/compiler';
import { TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
// @ts-ignore
const Destroyed = CCObject.Flags.Destroyed;
@@ -329,7 +330,7 @@ class Parser {
if (equalsToDefault(defaultValue, val)) {
continue;
}
if (typeof val === 'object' && val instanceof cc.ValueType) {
if (typeof val === 'object' && val instanceof legacyCC.ValueType) {
defaultValue = CCClass.getDefault(defaultValue);
if (defaultValue && defaultValue.constructor === val.constructor) {
// fast case
@@ -417,7 +418,7 @@ class Parser {
// codeArray - the source code array for this object
public enumerateObject (codeArray, obj) {
const klass = obj.constructor;
if (cc.Class._isCCClass(klass)) {
if (legacyCC.Class._isCCClass(klass)) {
this.enumerateCCClass(codeArray, obj, klass);
}
else {
@@ -439,10 +440,10 @@ class Parser {
}
public instantiateObj (obj) {
if (obj instanceof cc.ValueType) {
if (obj instanceof legacyCC.ValueType) {
return CCClass.getNewValueTypeCode(obj);
}
if (obj instanceof cc.Asset) {
if (obj instanceof legacyCC.Asset) {
// register to asset list and just return the reference.
return this.getObjRef(obj);
}
@@ -453,21 +454,21 @@ class Parser {
let createCode;
const ctor = obj.constructor;
if (cc.Class._isCCClass(ctor)) {
if (legacyCC.Class._isCCClass(ctor)) {
if (this.parent) {
if (this.parent instanceof cc.Component) {
if (obj instanceof cc._BaseNode || obj instanceof cc.Component) {
if (this.parent instanceof legacyCC.Component) {
if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) {
return this.getObjRef(obj);
}
}
else if (this.parent instanceof cc._BaseNode) {
if (obj instanceof cc._BaseNode) {
else if (this.parent instanceof legacyCC._BaseNode) {
if (obj instanceof legacyCC._BaseNode) {
if (!obj.isChildOf(this.parent)) {
// should not clone other nodes if not descendant
return this.getObjRef(obj);
}
}
else if (obj instanceof cc.Component) {
else if (obj instanceof legacyCC.Component) {
if (!obj.node.isChildOf(this.parent)) {
// should not clone other component if not descendant
return this.getObjRef(obj);
@@ -519,7 +520,7 @@ export function equalsToDefault (def, value) {
return true;
}
if (def && value) {
if (def instanceof cc.ValueType && def.equals(value)) {
if (def instanceof legacyCC.ValueType && def.equals(value)) {
return true;
}
if ((Array.isArray(def) && Array.isArray(value)) ||
@@ -536,13 +537,13 @@ export function equalsToDefault (def, value) {
}
export function compile (node) {
const root = (node instanceof cc._BaseNode) && node;
const root = (node instanceof legacyCC._BaseNode) && node;
const parser = new Parser(node, root);
return parser.result;
}
if (TEST) {
cc._Test.IntantiateJit = {
legacyCC._Test.IntantiateJit = {
equalsToDefault,
compile,
};
+17 -16
View File
@@ -34,6 +34,7 @@ import { CCObject } from './object';
import { js } from '../utils';
import { errorID, warn } from '../platform/debug';
import { DEV } from 'internal:constants';
import { legacyCC } from '../global-exports';
// @ts-ignore
const Destroyed = CCObject.Flags.Destroyed;
@@ -77,13 +78,13 @@ function instantiate (original, internal_force?) {
}
return null;
}
if (!cc.isValid(original)) {
if (!legacyCC.isValid(original)) {
if (DEV) {
errorID(6902);
}
return null;
}
if (DEV && original instanceof cc.Component) {
if (DEV && original instanceof legacyCC.Component) {
warn('Should not instantiate a single cc.Component directly, you must instantiate the entire node.');
}
}
@@ -98,12 +99,12 @@ function instantiate (original, internal_force?) {
// no need to create new object by itself.
// @returns {Object} - the instantiated object
if (original._instantiate) {
cc.game._isCloning = true;
legacyCC.game._isCloning = true;
clone = original._instantiate();
cc.game._isCloning = false;
legacyCC.game._isCloning = false;
return clone;
}
else if (original instanceof cc.Asset) {
else if (original instanceof legacyCC.Asset) {
// 不允许用通用方案实例化资源
if (DEV) {
errorID(6903);
@@ -112,9 +113,9 @@ function instantiate (original, internal_force?) {
}
}
cc.game._isCloning = true;
legacyCC.game._isCloning = true;
clone = doInstantiate(original);
cc.game._isCloning = false;
legacyCC.game._isCloning = false;
return clone;
}
@@ -199,7 +200,7 @@ function enumerateObject (obj, clone, parent) {
js.value(obj, '_iN$t', clone, true);
objsToClearTmpVar.push(obj);
const klass = obj.constructor;
if (cc.Class._isCCClass(klass)) {
if (legacyCC.Class._isCCClass(klass)) {
enumerateCCClass(klass, obj, clone, parent);
}
else {
@@ -236,7 +237,7 @@ function instantiateObj (obj, parent) {
if (obj instanceof ValueType) {
return obj.clone();
}
if (obj instanceof cc.Asset) {
if (obj instanceof legacyCC.Asset) {
// 所有资源直接引用,不需要拷贝
return obj;
}
@@ -264,21 +265,21 @@ function instantiateObj (obj, parent) {
}
const ctor = obj.constructor;
if (cc.Class._isCCClass(ctor)) {
if (legacyCC.Class._isCCClass(ctor)) {
if (parent) {
if (parent instanceof cc.Component) {
if (obj instanceof cc._BaseNode || obj instanceof cc.Component) {
if (parent instanceof legacyCC.Component) {
if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) {
return obj;
}
}
else if (parent instanceof cc._BaseNode) {
if (obj instanceof cc._BaseNode) {
else if (parent instanceof legacyCC._BaseNode) {
if (obj instanceof legacyCC._BaseNode) {
if (!obj.isChildOf(parent)) {
// should not clone other nodes if not descendant
return obj;
}
}
else if (obj instanceof cc.Component) {
else if (obj instanceof legacyCC.Component) {
if (!obj.node.isChildOf(parent)) {
// should not clone other component if not descendant
return obj;
@@ -303,5 +304,5 @@ function instantiateObj (obj, parent) {
}
instantiate._clone = doInstantiate;
cc.instantiate = instantiate;
legacyCC.instantiate = instantiate;
export default instantiate;
+8 -7
View File
@@ -31,6 +31,7 @@ import * as js from '../utils/js';
import CCClass from './class';
import { errorID, warnID } from '../platform/debug';
import { SUPPORT_JIT, EDITOR, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
// definitions for CCObject.Flags
@@ -72,7 +73,7 @@ const objectsToDestroy: any = [];
let deferredDestroyTimer = null;
function compileDestruct (obj, ctor) {
const shouldSkipId = obj instanceof cc._BaseNode || obj instanceof cc.Component;
const shouldSkipId = obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component;
const idToSkip = shouldSkipId ? '_id' : null;
let key;
@@ -95,12 +96,12 @@ function compileDestruct (obj, ctor) {
}
// Overwrite propsToReset according to Class
if (CCClass._isCCClass(ctor)) {
const attrs = cc.Class.Attr.getClassAttrs(ctor);
const attrs = legacyCC.Class.Attr.getClassAttrs(ctor);
const propList = ctor.__props__;
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < propList.length; i++) {
key = propList[i];
const attrKey = key + cc.Class.Attr.DELIMETER + 'default';
const attrKey = key + legacyCC.Class.Attr.DELIMETER + 'default';
if (attrKey in attrs) {
if (shouldSkipId && key === '_id') {
continue;
@@ -281,7 +282,7 @@ class CCObject {
this._objFlags |= ToDestroy;
objectsToDestroy.push(this);
if (EDITOR && deferredDestroyTimer === null && cc.engine && ! cc.engine._isUpdating) {
if (EDITOR && deferredDestroyTimer === null && legacyCC.engine && ! legacyCC.engine._isUpdating) {
// auto destroy immediate in edit mode
// @ts-ignore
deferredDestroyTimer = setImmediate(CCObject._deferredDestroy);
@@ -332,7 +333,7 @@ class CCObject {
this._onPreDestroy();
}
if ((TEST ? (/* make EDITOR mockable*/ Function('return !EDITOR'))() : !EDITOR) || cc.engine._isPlaying) {
if ((TEST ? (/* make EDITOR mockable*/ Function('return !EDITOR'))() : !EDITOR) || legacyCC.engine._isPlaying) {
this._destruct();
}
@@ -559,7 +560,7 @@ export function isValid (value: any, strictMode?: boolean) {
return typeof value !== 'undefined';
}
}
cc.isValid = isValid;
legacyCC.isValid = isValid;
if (EDITOR || TEST) {
js.value(CCObject, '_willDestroy', (obj) => {
@@ -571,5 +572,5 @@ if (EDITOR || TEST) {
});
}
cc.Object = CCObject;
legacyCC.Object = CCObject;
export { CCObject };
+14 -13
View File
@@ -31,6 +31,7 @@ import { errorID, log, warnID } from '../../platform/debug';
import { extend, formatStr, get, getClassName, isChildClassOf, value } from '../../utils/js';
import { isPlainEmptyObj_DEV } from '../../utils/misc';
import { EDITOR, DEV, SUPPORT_JIT } from 'internal:constants';
import { legacyCC } from '../../global-exports';
export const DELIMETER = '$_$';
@@ -62,7 +63,7 @@ export function createAttrsSingle (owner: Object, ownerConstructor: Function, su
*/
export function createAttrs (subclass: any) {
let superClass: any;
const chains: any[] = cc.Class.getInheritanceChain(subclass);
const chains: any[] = legacyCC.Class.getInheritanceChain(subclass);
for (let i = chains.length - 1; i >= 0; i--) {
const cls = chains[i];
const attrs = cls.hasOwnProperty('__attrs__') && cls.__attrs__;
@@ -185,8 +186,8 @@ export class PrimitiveType<T> {
* ```
*/
export const CCInteger = new PrimitiveType('Integer', 0);
cc.Integer = CCInteger;
cc.CCInteger = CCInteger;
legacyCC.Integer = CCInteger;
legacyCC.CCInteger = CCInteger;
/**
* 指定编辑器以浮点数形式对待该属性或数组元素。
@@ -204,11 +205,11 @@ cc.CCInteger = CCInteger;
* ```
*/
export const CCFloat = new PrimitiveType('Float', 0.0);
cc.Float = CCFloat;
cc.CCFloat = CCFloat;
legacyCC.Float = CCFloat;
legacyCC.CCFloat = CCFloat;
if (EDITOR) {
get(cc, 'Number', function () {
get(legacyCC, 'Number', function () {
warnID(3603);
return CCFloat;
});
@@ -230,8 +231,8 @@ if (EDITOR) {
* ```
*/
export const CCBoolean = new PrimitiveType('Boolean', false);
cc.Boolean = CCBoolean;
cc.CCBoolean = CCBoolean;
legacyCC.Boolean = CCBoolean;
legacyCC.CCBoolean = CCBoolean;
/**
* 指定编辑器以字符串形式对待该属性或数组元素。
@@ -249,8 +250,8 @@ cc.CCBoolean = CCBoolean;
* ```
*/
export const CCString = new PrimitiveType('String', '');
cc.String = CCString;
cc.CCString = CCString;
legacyCC.String = CCString;
legacyCC.CCString = CCString;
/*
BuiltinAttributes: {
@@ -311,7 +312,7 @@ export function getTypeChecker (type: string, attributeName: string) {
}
} else if (defaultType !== 'function') {
if (type === CCString.default && defaultVal == null) {
if (!isChildClassOf(mainPropAttrs.ctor, cc.RawAsset)) {
if (!isChildClassOf(mainPropAttrs.ctor, legacyCC.RawAsset)) {
warnID(3607, propInfo);
}
} else {
@@ -330,8 +331,8 @@ export function getObjTypeChecker (typeCtor) {
getTypeChecker('Object', 'type')(classCtor, mainPropName);
// check ValueType
const defaultDef = getClassAttrs(classCtor)[mainPropName + DELIMETER + 'default'];
const defaultVal = cc.Class.getDefault(defaultDef);
if (!Array.isArray(defaultVal) && isChildClassOf(typeCtor, cc.ValueType)) {
const defaultVal = legacyCC.Class.getDefault(defaultDef);
if (!Array.isArray(defaultVal) && isChildClassOf(typeCtor, legacyCC.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);
+16 -15
View File
@@ -28,6 +28,7 @@ import { error, errorID, warn, warnID } from '../../platform/debug';
import * as js from '../../utils/js';
import { PrimitiveType } from './attribute';
import { DEV, EDITOR, TEST } from 'internal:constants';
import { legacyCC } from '../../global-exports';
// 增加预处理属性这个步骤的目的是降低 CCClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。
@@ -107,10 +108,10 @@ function checkUrl (val, className, propName, url) {
if (url == null) {
return warnID(5503, className, propName);
}
if (typeof url !== 'function' || !js.isChildClassOf(url, cc.RawAsset)) {
if (typeof url !== 'function' || !js.isChildClassOf(url, legacyCC.RawAsset)) {
return errorID(5504, className, propName);
}
if (url === cc.RawAsset) {
if (url === legacyCC.RawAsset) {
warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
'the use of declaring a property in CCClass as a URL has been deprecated.\n' +
'For example, if property is cc.RawAsset, the previous definition is:\n' +
@@ -133,8 +134,8 @@ function checkUrl (val, className, propName, url) {
'sorry for the inconvenience. \uD83D\uDE30 )',
propName, className, propName, propName, propName, propName, propName);
}
else if (js.isChildClassOf(url, cc.Asset)) {
return errorID(5505, className, propName, cc.js.getClassName(url));
else if (js.isChildClassOf(url, legacyCC.Asset)) {
return errorID(5505, className, propName, legacyCC.js.getClassName(url));
}
if (val.type) {
return warnID(5506, className, propName);
@@ -149,12 +150,12 @@ function checkUrl (val, className, propName, url) {
function parseType (val, type, className, propName) {
if (Array.isArray(type)) {
if ((EDITOR || TEST) && 'default' in val) {
if (!cc.Class.isArray(val.default)) {
if (!legacyCC.Class.isArray(val.default)) {
warnID(5507, className, propName);
}
}
if (type.length > 0) {
if (cc.RawAsset.isRawAssetType(type[0])) {
if (legacyCC.RawAsset.isRawAssetType(type[0])) {
val.url = type[0];
delete val.type;
return;
@@ -167,16 +168,16 @@ function parseType (val, type, className, propName) {
}
if (EDITOR || TEST) {
if (typeof type === 'function') {
if (cc.RawAsset.isRawAssetType(type)) {
if (legacyCC.RawAsset.isRawAssetType(type)) {
warnID(5509, className, propName, js.getClassName(type));
} else if (type === String) {
val.type = cc.String;
val.type = legacyCC.String;
warnID(3608, `"${className}.${propName}"`);
} else if (type === Boolean) {
val.type = cc.Boolean;
val.type = legacyCC.Boolean;
warnID(3609, `"${className}.${propName}"`);
} else if (type === Number) {
val.type = cc.Float;
val.type = legacyCC.Float;
warnID(3610, `"${className}.${propName}"`);
}
} else {
@@ -206,7 +207,7 @@ function parseType (val, type, className, propName) {
function postCheckType (val, type, className, propName) {
if (EDITOR && typeof type === 'function') {
if (cc.Class._isCCClass(type) && val.serializable !== false && !js._getClassId(type, false)) {
if (legacyCC.Class._isCCClass(type) && val.serializable !== false && !js._getClassId(type, false)) {
warnID(5512, className, propName, className, propName);
}
}
@@ -240,9 +241,9 @@ export function getFullFormOfProperty (options, propname_dev?, classname_dev?) {
};
} else if (typeof options === 'function') {
const type = options;
if (!cc.RawAsset.isRawAssetType(type)) {
if (!legacyCC.RawAsset.isRawAssetType(type)) {
return {
default: js.isChildClassOf(type, cc.ValueType) ? new type() : null,
default: js.isChildClassOf(type, legacyCC.ValueType) ? new type() : null,
type,
_short: true,
};
@@ -283,7 +284,7 @@ export function preprocessAttrs (properties, className, cls, es6) {
else if (val.set) {
errorID(5514, className, propName);
}
else if (cc.Class._isCCClass(val.default)) {
else if (legacyCC.Class._isCCClass(val.default)) {
val.default = null;
errorID(5515, className, propName);
}
@@ -334,7 +335,7 @@ export function doValidateMethodWithProps_DEV (func, funcName, className, cls, b
return false;
}
if (funcName === 'destroy' &&
js.isChildClassOf(base, cc.Component) &&
js.isChildClassOf(base, legacyCC.Component) &&
!CALL_SUPER_DESTROY_REG_DEV.test(func)
) {
// tslint:disable-next-line: max-line-length
+3 -2
View File
@@ -25,6 +25,7 @@
*/
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../../global-exports';
/**
*
@@ -66,14 +67,14 @@ export function peek () {
return requiringFrames[requiringFrames.length - 1];
}
cc._RF = {
legacyCC._RF = {
push,
pop,
peek,
};
if (EDITOR) {
cc._RF.reset = () => {
legacyCC._RF.reset = () => {
requiringFrames = [];
};
}
+2 -1
View File
@@ -7,6 +7,7 @@ import * as math from './math';
import { Scheduler } from './scheduler';
import { CameraComponent } from './3d';
import { EventTouch } from './platform';
import { legacyCC } from './global-exports';
// VMATH
@@ -163,7 +164,7 @@ replaceProperty(vmath,'vmath',[
},
]);
cc.vmath = vmath;
legacyCC.vmath = vmath;
export { vmath };
+50 -49
View File
@@ -46,6 +46,7 @@ import NodeActivator from './scene-graph/node-activator';
import { Scheduler } from './scheduler';
import { js } from './utils';
import { DEBUG, EDITOR, BUILD } from 'internal:constants';
import { legacyCC } from './global-exports';
// ----------------------------------------------------------------------------------------------------------------------
@@ -301,11 +302,11 @@ export class Director extends EventTarget {
this._systems = [];
cc.game.on(Game.EVENT_SHOW, () => {
legacyCC.game.on(Game.EVENT_SHOW, () => {
this._lastUpdate = performance.now();
});
cc.game.once(Game.EVENT_RENDERER_INITED, this._initOnRendererInitialized, this);
legacyCC.game.once(Game.EVENT_RENDERER_INITED, this._initOnRendererInitialized, this);
}
/**
@@ -331,8 +332,8 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public convertToGL (uiPoint: Vec2) {
const container = cc.game.container;
const view = cc.view;
const container = legacyCC.game.container;
const view = legacyCC.view;
const box = container.getBoundingClientRect();
const left = box.left + window.pageXOffset - container.clientLeft;
const top = box.top + window.pageYOffset - container.clientTop;
@@ -350,8 +351,8 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public convertToUI (glPoint: Vec2) {
const container = cc.game.container;
const view = cc.view;
const container = legacyCC.game.container;
const view = legacyCC.view;
const box = container.getBoundingClientRect();
const left = box.left + window.pageXOffset - container.clientLeft;
const top = box.top + window.pageYOffset - container.clientTop;
@@ -382,7 +383,7 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public getWinSize () {
return size(cc.winSize);
return size(legacyCC.winSize);
}
/**
@@ -397,7 +398,7 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public getWinSizeInPixels () {
return size(cc.winSize);
return size(legacyCC.winSize);
}
/**
@@ -421,7 +422,7 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public purgeCachedData () {
cc.loader.releaseAll();
legacyCC.loader.releaseAll();
}
/**
@@ -445,7 +446,7 @@ export class Director extends EventTarget {
// cc.renderer.clear();
if (!EDITOR) {
if (cc.isValid(this._scene)) {
if (legacyCC.isValid(this._scene)) {
this._scene!.destroy();
}
this._scene = null;
@@ -459,7 +460,7 @@ export class Director extends EventTarget {
this._root = null;
// Clear all caches
cc.loader.releaseAll();
legacyCC.loader.releaseAll();
}
/**
@@ -488,11 +489,11 @@ export class Director extends EventTarget {
* @param onLaunched - The function invoked at the scene after launch.
*/
public runSceneImmediate (scene: Scene, onBeforeLoadScene?: Director.OnBeforeLoadScene, onLaunched?: Director.OnSceneLaunched) {
cc.assertID(scene instanceof cc.Scene, 1216);
legacyCC.assertID(scene instanceof legacyCC.Scene, 1216);
const uuid = cc.loader._getReferenceKey(scene.uuid);
const uuid = legacyCC.loader._getReferenceKey(scene.uuid);
// Scene cannot be cached in loader, because it will be destroyed after switching.
cc.loader.removeItem(uuid);
legacyCC.loader.removeItem(uuid);
if (BUILD && DEBUG) {
console.time('InitScene');
@@ -506,13 +507,13 @@ export class Director extends EventTarget {
if (BUILD && DEBUG) {
console.time('AttachPersist');
}
const persistNodeList = Object.keys(cc.game._persistRootNodes).map((x) => {
return cc.game._persistRootNodes[x];
const persistNodeList = Object.keys(legacyCC.game._persistRootNodes).map((x) => {
return legacyCC.game._persistRootNodes[x];
});
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < persistNodeList.length; i++) {
const node = persistNodeList[i];
node.emit(cc.Node.SCENE_CHANGED_FOR_PERSISTS, scene.renderScene);
node.emit(legacyCC.Node.SCENE_CHANGED_FOR_PERSISTS, scene.renderScene);
const existNode = scene.getChildByUuid(node.uuid);
if (existNode) {
// scene also contains the persist node, select the old one
@@ -544,7 +545,7 @@ export class Director extends EventTarget {
if (BUILD && DEBUG) {
console.time('Destroy');
}
if (cc.isValid(oldScene)) {
if (legacyCC.isValid(oldScene)) {
oldScene!.destroy();
}
@@ -557,7 +558,7 @@ export class Director extends EventTarget {
if (onBeforeLoadScene) {
onBeforeLoadScene();
}
this.emit(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, scene);
this.emit(legacyCC.Director.EVENT_BEFORE_SCENE_LAUNCH, scene);
// Run an Entity Scene
this._scene = scene;
@@ -579,7 +580,7 @@ export class Director extends EventTarget {
if (onLaunched) {
onLaunched(null, scene);
}
this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene);
this.emit(legacyCC.Director.EVENT_AFTER_SCENE_LAUNCH, scene);
}
/**
@@ -593,15 +594,15 @@ export class Director extends EventTarget {
* @private
*/
public runScene (scene: Scene, onBeforeLoadScene?: Director.OnBeforeLoadScene, onLaunched?: Director.OnSceneLaunched) {
cc.assertID(scene, 1205);
cc.assertID(scene instanceof cc.Scene, 1216);
legacyCC.assertID(scene, 1205);
legacyCC.assertID(scene instanceof legacyCC.Scene, 1216);
// ensure scene initialized
// @ts-ignore
scene._load();
// Delay run / replace scene to the end of the frame
this.once(cc.Director.EVENT_AFTER_UPDATE, () => {
this.once(legacyCC.Director.EVENT_AFTER_UPDATE, () => {
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
});
}
@@ -609,7 +610,7 @@ export class Director extends EventTarget {
// @Scene loading section
public _getSceneUuid (key: string | number) {
const scenes = cc.game._sceneInfos;
const scenes = legacyCC.game._sceneInfos;
if (typeof key === 'string') {
if (!key.endsWith('.scene')) {
key += '.scene';
@@ -631,11 +632,11 @@ export class Director extends EventTarget {
return scenes[key];
}
else {
cc.errorID(1206, key);
legacyCC.errorID(1206, key);
}
}
else {
cc.errorID(1207, key);
legacyCC.errorID(1207, key);
}
return null;
}
@@ -650,19 +651,19 @@ export class Director extends EventTarget {
*/
public loadScene (sceneName: string, onLaunched?: Director.OnSceneLaunched, onUnloaded?: Director.OnUnload) {
if (this._loadingScene) {
cc.errorID(1208, sceneName, this._loadingScene);
legacyCC.errorID(1208, sceneName, this._loadingScene);
return false;
}
const info = this._getSceneUuid(sceneName);
if (info) {
const uuid = info.uuid;
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
this.emit(legacyCC.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
this._loadingScene = sceneName;
this._loadSceneByUuid(uuid, onLaunched, onUnloaded);
return true;
}
else {
cc.errorID(1209, sceneName);
legacyCC.errorID(1209, sceneName);
return false;
}
}
@@ -714,12 +715,12 @@ export class Director extends EventTarget {
const info = this._getSceneUuid(sceneName);
if (info) {
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
cc.loader.load({ uuid: info.uuid, type: 'uuid' },
this.emit(legacyCC.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
legacyCC.loader.load({ uuid: info.uuid, type: 'uuid' },
onProgress,
(error: null | Error, asset: SceneAsset) => {
if (error) {
cc.errorID(1210, sceneName, error.message);
legacyCC.errorID(1210, sceneName, error.message);
}
if (onLoaded) {
onLoaded(error, asset);
@@ -731,7 +732,7 @@ export class Director extends EventTarget {
if (onLoaded) {
onLoaded(new Error(error));
}
cc.error('preloadScene: ' + error);
legacyCC.error('preloadScene: ' + error);
}
}
@@ -770,16 +771,16 @@ export class Director extends EventTarget {
// cc.AssetLibrary.unloadAsset(uuid); // force reload
console.time('LoadScene ' + uuid);
cc.AssetLibrary.loadAsset(uuid, (error, sceneAsset) => {
legacyCC.AssetLibrary.loadAsset(uuid, (error, sceneAsset) => {
console.timeEnd('LoadScene ' + uuid);
const self = director;
self._loadingScene = '';
if (error) {
error = 'Failed to load scene: ' + error;
cc.error(error);
legacyCC.error(error);
}
else {
if (sceneAsset instanceof cc.SceneAsset) {
if (sceneAsset instanceof legacyCC.SceneAsset) {
const scene = sceneAsset.scene;
scene._id = sceneAsset._uuid;
scene._name = sceneAsset._name;
@@ -801,7 +802,7 @@ export class Director extends EventTarget {
}
else {
error = 'The asset ' + uuid + ' is not a scene';
cc.error(error);
legacyCC.error(error);
}
}
if (onLaunched) {
@@ -821,7 +822,7 @@ export class Director extends EventTarget {
this._lastUpdate = performance.now();
if (!this._lastUpdate) {
cc.logID(1200);
legacyCC.logID(1200);
}
this._paused = false;
@@ -836,10 +837,10 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public setDepthTest (value: boolean) {
if (!cc.Camera.main) {
if (!legacyCC.Camera.main) {
return;
}
cc.Camera.main.depth = !!value;
legacyCC.Camera.main.depth = !!value;
}
/**
@@ -852,10 +853,10 @@ export class Director extends EventTarget {
* @deprecated since v2.0
*/
public setClearColor (clearColor: Color) {
if (!cc.Camera.main) {
if (!legacyCC.Camera.main) {
return;
}
cc.Camera.main.backgroundColor = clearColor;
legacyCC.Camera.main.backgroundColor = clearColor;
}
get root () {
@@ -891,7 +892,7 @@ export class Director extends EventTarget {
* @deprecated since v2.0.
*/
public getAnimationInterval () {
return 1000 / cc.game.getFrameRate();
return 1000 / legacyCC.game.getFrameRate();
}
/**
@@ -903,7 +904,7 @@ export class Director extends EventTarget {
* @param value - The animation interval desired.
*/
public setAnimationInterval (value: number) {
cc.game.setFrameRate(Math.round(1000 / value));
legacyCC.game.setFrameRate(Math.round(1000 / value));
}
/**
@@ -991,7 +992,7 @@ export class Director extends EventTarget {
* @deprecated
*/
public getAnimationManager (): any {
return this.getSystem(cc.AnimationManager.ID);
return this.getSystem(legacyCC.AnimationManager.ID);
}
// Loop management
@@ -1081,8 +1082,8 @@ export class Director extends EventTarget {
}
private _init () {
cc.loader.init(this);
this._root = new Root(cc.game._gfxDevice);
legacyCC.loader.init(this);
this._root = new Root(legacyCC.game._gfxDevice);
const rootInfo = {};
if (!this._root.initialize(rootInfo)) {
return false;
@@ -1109,10 +1110,10 @@ export declare namespace Director {
export type OnLoadSceneProgress = (completedCount: number, totalCount: number, item: any) => void;
}
cc.Director = Director;
legacyCC.Director = Director;
/**
* 导演类。
* @property director
*/
export const director: Director = Director.instance = cc.director = new Director();
export const director: Director = Director.instance = legacyCC.director = new Director();
+2 -1
View File
@@ -31,6 +31,7 @@
import { Pool } from '../memop';
import { array, createMap } from '../utils/js';
import { TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
const fastRemoveAt = array.fastRemoveAt;
function empty (){}
@@ -335,5 +336,5 @@ export class CallbacksInvoker {
}
if (TEST) {
cc._Test.CallbacksInvoker = CallbacksInvoker;
legacyCC._Test.CallbacksInvoker = CallbacksInvoker;
}
+4 -3
View File
@@ -30,6 +30,7 @@
import * as js from '../utils/js';
import { CallbacksInvoker } from './callbacks-invoker';
import { legacyCC } from '../global-exports';
const fastRemove = js.array.fastRemove;
@@ -85,7 +86,7 @@ export class EventTarget extends CallbacksInvoker {
*/
public on (type: string, callback: Function, target?: Object) {
if (!callback) {
cc.errorID(6800);
legacyCC.errorID(6800);
return;
}
@@ -174,7 +175,7 @@ export class EventTarget extends CallbacksInvoker {
*/
public once (type: string, callback: Function, target?: Object) {
if (!callback) {
cc.errorID(6800);
legacyCC.errorID(6800);
return;
}
@@ -194,4 +195,4 @@ export class EventTarget extends CallbacksInvoker {
}
}
cc.EventTarget = EventTarget;
legacyCC.EventTarget = EventTarget;
+3 -1
View File
@@ -24,6 +24,8 @@
THE SOFTWARE.
*/
import { legacyCC } from '../global-exports';
/**
* 事件相关
* @category event
@@ -284,4 +286,4 @@ export default class Event {
}
/* tslint:disable:no-string-literal */
cc.Event = Event;
legacyCC.Event = Event;
+43 -42
View File
@@ -38,6 +38,7 @@ import inputManager from './platform/event-manager/input-manager';
import { sys } from './platform/sys';
import { macro } from './platform/macro';
import { ICustomJointTextureLayout } from './renderer';
import { legacyCC } from './global-exports';
/**
* @zh
@@ -418,7 +419,7 @@ export class Game extends EventTarget {
* @zh 执行一帧游戏循环。
*/
public step () {
cc.director.mainLoop();
legacyCC.director.mainLoop();
}
/**
@@ -443,7 +444,7 @@ export class Game extends EventTarget {
if (--swapbuffers > 1) {
window.requestAnimationFrame(cb);
}
const root = cc.director.root;
const root = legacyCC.director.root;
root.frameMove(0); root.device.present();
};
window.requestAnimationFrame(cb);
@@ -476,20 +477,20 @@ export class Game extends EventTarget {
* @zh 重新开始游戏
*/
public restart () {
cc.director.once(cc.Director.EVENT_AFTER_DRAW, () => {
legacyCC.director.once(legacyCC.Director.EVENT_AFTER_DRAW, () => {
// tslint:disable-next-line: forin
for (const id in cc.game._persistRootNodes) {
cc.game.removePersistRootNode(cc.game._persistRootNodes[id]);
for (const id in legacyCC.game._persistRootNodes) {
legacyCC.game.removePersistRootNode(legacyCC.game._persistRootNodes[id]);
}
// Clear scene
cc.director.getScene().destroy();
cc.Object._deferredDestroy();
legacyCC.director.getScene().destroy();
legacyCC.Object._deferredDestroy();
cc.director.purgeDirector();
legacyCC.director.purgeDirector();
cc.director.reset();
cc.game.onStart();
legacyCC.director.reset();
legacyCC.game.onStart();
});
}
@@ -580,11 +581,11 @@ export class Game extends EventTarget {
this._initEvents();
}
if (!EDITOR && !PREVIEW && cc.internal.SplashScreenWebgl && this.canvas) {
cc.internal.SplashScreenWebgl.instance.main(this.canvas);
if (!EDITOR && !PREVIEW && legacyCC.internal.SplashScreenWebgl && this.canvas) {
legacyCC.internal.SplashScreenWebgl.instance.main(this.canvas);
}
cc.director.root.dataPoolManager.jointTexturePool.registerCustomTextureLayouts(config.customJointTextureLayouts);
legacyCC.director.root.dataPoolManager.jointTexturePool.registerCustomTextureLayouts(config.customJointTextureLayouts);
return this._inited;
}
@@ -612,7 +613,7 @@ export class Game extends EventTarget {
inputManager.registerSystemEvent(game.canvas);
}
const splashScreen = cc.internal.SplashScreenWebgl && cc.internal.SplashScreenWebgl.instance;
const splashScreen = legacyCC.internal.SplashScreenWebgl && legacyCC.internal.SplashScreenWebgl.instance;
const useSplash = (!EDITOR && !PREVIEW && splashScreen);
if (useSplash) {
splashScreen.setOnFinish(() => {
@@ -622,7 +623,7 @@ export class Game extends EventTarget {
// Load render pipeline if needed
const renderPipeline = this.config.renderPipeline;
if (renderPipeline) {
cc.loader.load({ uuid: renderPipeline }, (err, asset) => {
legacyCC.loader.load({ uuid: renderPipeline }, (err, asset) => {
// failed load renderPipeline
if (err || !(asset instanceof RenderPipeline)) {
console.warn(`Failed load renderpipeline: ${renderPipeline}, engine failed to initialize, all process stopped`);
@@ -662,18 +663,18 @@ export class Game extends EventTarget {
* @param {Node} node - The node to be made persistent
*/
public addPersistRootNode (node: { uuid: any; parent: any; _persistNode: boolean; }) {
if (!cc.Node.isNode(node) || !node.uuid) {
if (!legacyCC.Node.isNode(node) || !node.uuid) {
debug.warnID(3800);
return;
}
const id = node.uuid;
if (!this._persistRootNodes[id]) {
const scene = cc.director._scene;
if (cc.isValid(scene)) {
const scene = legacyCC.director._scene;
if (legacyCC.isValid(scene)) {
if (!node.parent) {
node.parent = scene;
}
else if (!(node.parent instanceof cc.Scene)) {
else if (!(node.parent instanceof legacyCC.Scene)) {
debug.warnID(3801);
return;
}
@@ -714,11 +715,11 @@ export class Game extends EventTarget {
private _initEngine () {
this._initDevice();
cc.director._init();
legacyCC.director._init();
this.setRenderPipeline();
// Log engine version
console.log('Cocos Creator 3D v' + cc.ENGINE_VERSION);
console.log('Cocos Creator 3D v' + legacyCC.ENGINE_VERSION);
this.emit(Game.EVENT_ENGINE_INITED);
this._inited = true;
}
@@ -728,7 +729,7 @@ export class Game extends EventTarget {
// @Time ticker section
private _setAnimFrame () {
this._lastTime = new Date();
const frameRate = cc.game.config.frameRate;
const frameRate = legacyCC.game.config.frameRate;
this._frameTime = 1000 / frameRate;
if (JSB) {
@@ -762,9 +763,9 @@ export class Game extends EventTarget {
}
private _stTime (callback) {
const currTime = new Date().getTime();
const timeToCall = Math.max(0, cc.game._frameTime - (currTime - cc.game._lastTime));
const timeToCall = Math.max(0, legacyCC.game._frameTime - (currTime - legacyCC.game._lastTime));
const id = window.setTimeout(callback, timeToCall);
cc.game._lastTime = currTime + timeToCall;
legacyCC.game._lastTime = currTime + timeToCall;
return id;
}
private _ctTime (id: number | undefined) {
@@ -774,7 +775,7 @@ export class Game extends EventTarget {
private _runMainLoop () {
let callback: FrameRequestCallback;
const config = this.config;
const director = cc.director;
const director = legacyCC.director;
let skip: boolean = true;
const frameRate = config.frameRate;
@@ -842,20 +843,20 @@ export class Game extends EventTarget {
let supportRender = false;
if (userRenderMode === 0) {
if (cc.sys.capabilities.opengl) {
if (legacyCC.sys.capabilities.opengl) {
this.renderType = Game.RENDER_TYPE_WEBGL;
supportRender = true;
}
else if (cc.sys.capabilities.canvas) {
else if (legacyCC.sys.capabilities.canvas) {
this.renderType = Game.RENDER_TYPE_CANVAS;
supportRender = true;
}
}
else if (userRenderMode === 1 && cc.sys.capabilities.canvas) {
else if (userRenderMode === 1 && legacyCC.sys.capabilities.canvas) {
this.renderType = Game.RENDER_TYPE_CANVAS;
supportRender = true;
}
else if (userRenderMode === 2 && cc.sys.capabilities.opengl) {
else if (userRenderMode === 2 && legacyCC.sys.capabilities.opengl) {
this.renderType = Game.RENDER_TYPE_WEBGL;
supportRender = true;
}
@@ -887,10 +888,10 @@ export class Game extends EventTarget {
}
// useWebGL2 = false;
if (useWebGL2 && cc.WebGL2GFXDevice) {
this._gfxDevice = new cc.WebGL2GFXDevice();
} else if (cc.WebGLGFXDevice) {
this._gfxDevice = new cc.WebGLGFXDevice();
if (useWebGL2 && legacyCC.WebGL2GFXDevice) {
this._gfxDevice = new legacyCC.WebGL2GFXDevice();
} else if (legacyCC.WebGLGFXDevice) {
this._gfxDevice = new legacyCC.WebGLGFXDevice();
}
const opts = {
@@ -903,7 +904,7 @@ export class Game extends EventTarget {
};
// fallback if WebGL2 is actually unavailable (usually due to driver issues)
if (!this._gfxDevice!.initialize(opts) && useWebGL2) {
this._gfxDevice = new cc.WebGLGFXDevice();
this._gfxDevice = new legacyCC.WebGLGFXDevice();
this._gfxDevice!.initialize(opts);
}
}
@@ -916,7 +917,7 @@ export class Game extends EventTarget {
}
this.canvas!.oncontextmenu = () => {
if (!cc._isContextMenuEnable) { return false; }
if (!legacyCC._isContextMenuEnable) { return false; }
};
}
@@ -939,13 +940,13 @@ export class Game extends EventTarget {
function onHidden () {
if (!hidden) {
hidden = true;
cc.game.emit(Game.EVENT_HIDE);
legacyCC.game.emit(Game.EVENT_HIDE);
}
}
function onShown () {
if (hidden) {
hidden = false;
cc.game.emit(Game.EVENT_SHOW);
legacyCC.game.emit(Game.EVENT_SHOW);
}
}
@@ -990,10 +991,10 @@ export class Game extends EventTarget {
}
this.on(Game.EVENT_HIDE, () => {
cc.game.pause();
legacyCC.game.pause();
});
this.on(Game.EVENT_SHOW, () => {
cc.game.resume();
legacyCC.game.resume();
});
}
@@ -1002,7 +1003,7 @@ export class Game extends EventTarget {
rppl = new ForwardPipeline();
rppl.initialize(ForwardPipeline.initInfo);
}
if (!cc.director.root.setRenderPipeline(rppl)) {
if (!legacyCC.director.root.setRenderPipeline(rppl)) {
this.setRenderPipeline();
}
@@ -1011,5 +1012,5 @@ export class Game extends EventTarget {
}
}
cc.Game = Game;
export const game = cc.game = new Game();
legacyCC.Game = Game;
export const game = legacyCC.game = new Game();
+3 -2
View File
@@ -4,11 +4,12 @@
import { Mat4, Vec3, Vec4 } from '../math';
import enums from './enums';
import { legacyCC } from '../global-exports';
const v1 = new Vec3(0, 0, 0);
const v2 = new Vec3(0, 0, 0);
const temp_mat = cc.mat4();
const temp_vec4 = cc.v4();
const temp_mat = legacyCC.mat4();
const temp_vec4 = legacyCC.v4();
/**
* @en
+15 -14
View File
@@ -16,6 +16,7 @@ import { GFXSampler } from './sampler';
import { GFXShader } from './shader';
import { GFXTexture } from './texture';
import { GFXTextureView } from './texture-view';
import { legacyCC } from '../global-exports';
export * from './binding-layout';
export * from './buffer';
@@ -35,18 +36,18 @@ export * from './texture-view';
export * from './texture';
export * from './window';
cc.GFXDevice = GFXDevice;
cc.GFXBuffer = GFXBuffer;
cc.GFXTexture = GFXTexture;
cc.GFXTextureView = GFXTextureView;
cc.GFXSampler = GFXSampler;
cc.GFXShader = GFXShader;
cc.GFXInputAssembler = GFXInputAssembler;
cc.GFXRenderPass = GFXRenderPass;
cc.GFXFramebuffer = GFXFramebuffer;
cc.GFXPipelineLayout = GFXPipelineLayout;
cc.GFXPipelineState = GFXPipelineState;
cc.GFXCommandBuffer = GFXCommandBuffer;
cc.GFXQueue = GFXQueue;
legacyCC.GFXDevice = GFXDevice;
legacyCC.GFXBuffer = GFXBuffer;
legacyCC.GFXTexture = GFXTexture;
legacyCC.GFXTextureView = GFXTextureView;
legacyCC.GFXSampler = GFXSampler;
legacyCC.GFXShader = GFXShader;
legacyCC.GFXInputAssembler = GFXInputAssembler;
legacyCC.GFXRenderPass = GFXRenderPass;
legacyCC.GFXFramebuffer = GFXFramebuffer;
legacyCC.GFXPipelineLayout = GFXPipelineLayout;
legacyCC.GFXPipelineState = GFXPipelineState;
legacyCC.GFXCommandBuffer = GFXCommandBuffer;
legacyCC.GFXQueue = GFXQueue;
Object.assign(cc, GFXDefines);
Object.assign(legacyCC, GFXDefines);
+116
View File
@@ -0,0 +1,116 @@
/*
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import {
ALIPAY,
BAIDU,
BUILD,
COCOSPLAY,
DEBUG,
DEV,
EDITOR,
JSB,
MINIGAME,
PHYSICS_AMMO,
PHYSICS_BUILTIN,
PHYSICS_CANNON,
PREVIEW,
RUNTIME_BASED,
SUPPORT_JIT,
TEST,
WECHAT,
XIAOMI,
} from 'internal:constants';
/**
* !#en
* The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.
* !#zh
* Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。
* @deprecated
*/
export const legacyCC: Record<string, any> = {};
// For internal usage
legacyCC.internal = {};
// @ts-ignore
const _global = typeof window === 'undefined' ? global : window;
legacyCC._global = _global;
if (BUILD) {
// Supports dynamically access from external scripts such as adapters and debugger.
// So macros should still defined in global even if inlined in engine.
_global.CC_BUILD = BUILD;
_global.CC_TEST = TEST;
_global.CC_EDITOR = EDITOR;
_global.CC_PREVIEW = PREVIEW;
_global.CC_DEV = DEV;
_global.CC_DEBUG = DEBUG;
_global.CC_JSB = JSB;
_global.CC_WECHAT = WECHAT;
_global.CC_ALIPAY = ALIPAY;
_global.CC_XIAOMI = XIAOMI;
_global.CC_BAIDU = BAIDU;
_global.CC_COCOSPLAY = COCOSPLAY;
_global.CC_MINIGAME = MINIGAME;
_global.CC_RUNTIME_BASED = RUNTIME_BASED;
_global.CC_SUPPORT_JIT = SUPPORT_JIT;
_global.CC_PHYSICS_BUILTIN = PHYSICS_BUILTIN;
_global.CC_PHYSICS_CANNON = PHYSICS_CANNON;
_global.CC_PHYSICS_AMMO = PHYSICS_AMMO;
}
if (DEV) {
/**
* contains internal apis for unit tests
* @expose
*/
legacyCC._Test = {};
}
/**
* deprecated
*/
// TODO: ALIPAY and runtime will redefine
if (!(RUNTIME_BASED || ALIPAY)) {
Object.defineProperty(_global, 'CC_PHYSICS_BUILT_IN', {
get: () => {
console.warn('CC_PHYSICS_BUILT_IN is deprecated, please using CC_PHYSICS_BUILTIN instead.');
return _global.CC_PHYSICS_BUILTIN;
},
});
}
/**
* The current version of Cocos2d being used.<br/>
* Please DO NOT remove this String, it is an important flag for bug tracking.<br/>
* If you post a bug to forum, please attach this flag.
*/
const engineVersion = '1.1.0';
_global.CocosEngine = legacyCC.ENGINE_VERSION = engineVersion;
_global.cc = legacyCC;
+6 -2
View File
@@ -26,12 +26,14 @@
/**
* @category core
*/
import { legacyCC } from './global-exports';
import * as geometry from './geometry';
import * as math from './math';
import * as memop from './memop';
cc.math = math;
cc.geometry = geometry;
legacyCC.math = math;
legacyCC.geometry = geometry;
export { math, memop, geometry };
@@ -61,3 +63,5 @@ export * from './utils/profiler/profiler';
import './deprecated';
// import './splash-image';
import './splash-screen-webgl';
+12 -11
View File
@@ -4,6 +4,7 @@
import * as debug from './platform/debug';
import { _normalize, basename, changeBasename, changeExtname, dirname, extname, getSeperator, join, mainFileName, stripSep } from './utils/path';
import { legacyCC } from './global-exports';
// import Pipeline from './load-pipeline/pipeline';
// import Url from './load-pipeline/url';
@@ -12,19 +13,19 @@ import { _normalize, basename, changeBasename, changeExtname, dirname, extname,
// cc.AssetLibrary = AssetLibrary;
// CCDebug.js
cc.log = debug.log;
cc.warn = debug.warn;
cc.error = debug.error;
cc.assert = debug.assert;
cc._throw = debug._throw;
cc.logID = debug.logID;
cc.warnID = debug.warnID;
cc.errorID = debug.errorID;
cc.assertID = debug.assertID;
cc.debug = debug;
legacyCC.log = debug.log;
legacyCC.warn = debug.warn;
legacyCC.error = debug.error;
legacyCC.assert = debug.assert;
legacyCC._throw = debug._throw;
legacyCC.logID = debug.logID;
legacyCC.warnID = debug.warnID;
legacyCC.errorID = debug.errorID;
legacyCC.assertID = debug.assertID;
legacyCC.debug = debug;
// path.js
cc.path = {
legacyCC.path = {
join,
extname,
mainFileName,
+20 -19
View File
@@ -44,6 +44,7 @@ import { LoadingItems } from './loading-items';
import { Pipeline } from './pipeline';
import ReleasedAssetChecker from './released-asset-checker';
import { DEBUG, EDITOR, DEV } from 'internal:constants';
import { legacyCC } from '../global-exports';
const assetTables = Object.create(null);
assetTables.assets = new AssetTable();
@@ -81,8 +82,8 @@ function getResWithUrl (res) {
result = {};
id = res;
}
isUuid = result.type ? result.type === 'uuid' : cc.AssetLibrary._uuidInSettings(id);
cc.AssetLibrary._getAssetInfoInRuntime(id, _info);
isUuid = result.type ? result.type === 'uuid' : legacyCC.AssetLibrary._uuidInSettings(id);
legacyCC.AssetLibrary._getAssetInfoInRuntime(id, _info);
result.url = !isUuid ? id : _info.url;
if (_info.url && result.type === 'uuid' && _info.raw) {
result.type = null;
@@ -199,7 +200,7 @@ export class CCLoader extends Pipeline {
public init (director) {
if (DEBUG) {
const self = this;
director.on(cc.Director.EVENT_AFTER_UPDATE, () => {
director.on(legacyCC.Director.EVENT_AFTER_UPDATE, () => {
self._releasedAssetChecker_DEBUG.checkCouldRelease(self._cache);
});
}
@@ -291,7 +292,7 @@ export class CCLoader extends Pipeline {
*/
public load (resources, progressCallback, completeCallback?) {
if (DEV && !resources) {
return cc.error('[cc.loader.load] resources must be non-nil.');
return legacyCC.error('[cc.loader.load] resources must be non-nil.');
}
if (completeCallback === undefined) {
@@ -317,7 +318,7 @@ export class CCLoader extends Pipeline {
const resource = resources[i];
// Backward compatibility
if (resource && resource.id) {
cc.warnID(4920, resource.id);
legacyCC.warnID(4920, resource.id);
if (!resource.uuid && !resource.url) {
resource.url = resource.id;
}
@@ -582,7 +583,7 @@ export class CCLoader extends Pipeline {
// To show users the exact structure in asset panel, we need to return the spriteFrame assets in spriteAtlas
const assetResLength = assetRes.length;
for (let i = 0; i < assetResLength; ++i) {
if (assetRes[i] instanceof cc.SpriteAtlas) {
if (assetRes[i] instanceof legacyCC.SpriteAtlas) {
const spriteFrames = assetRes[i].getSpriteFrames();
// tslint:disable: forin
for (const k in spriteFrames) {
@@ -808,7 +809,7 @@ export class CCLoader extends Pipeline {
if (item) {
const removed = this.removeItem(id);
asset = item.content;
if (asset instanceof cc.Asset) {
if (asset instanceof legacyCC.Asset) {
const nativeUrl = asset.nativeUrl;
if (nativeUrl) {
this.release(nativeUrl); // uncache loading item of native asset
@@ -852,7 +853,7 @@ export class CCLoader extends Pipeline {
this.release(uuid);
}
else {
cc.errorID(4914, url);
legacyCC.errorID(4914, url);
}
}
@@ -935,7 +936,7 @@ export class CCLoader extends Pipeline {
this._autoReleaseSetting[key] = !!autoRelease;
}
else if (DEV) {
cc.warnID(4902);
legacyCC.warnID(4902);
}
}
@@ -983,7 +984,7 @@ export class CCLoader extends Pipeline {
}
}
else if (DEV) {
cc.warnID(4902);
legacyCC.warnID(4902);
}
}
@@ -1030,13 +1031,13 @@ export class CCLoader extends Pipeline {
}
uuid = assetTable.getUuid(url, type);
if (!uuid) {
const extname = cc.path.extname(url);
const extname = legacyCC.path.extname(url);
if (extname) {
// strip extname
url = url.slice(0, - extname.length);
uuid = assetTable.getUuid(url, type);
if (uuid && !quiet) {
cc.warnID(4901, url, extname);
legacyCC.warnID(4901, url, extname);
}
}
}
@@ -1044,7 +1045,7 @@ export class CCLoader extends Pipeline {
}
if (!uuid && type) {
if (isChildClassOf(type, SpriteFrame) || isChildClassOf(type, Texture2D) || isChildClassOf(type, TextureCube)) {
cc.warnID(4934);
legacyCC.warnID(4934);
}
}
return uuid;
@@ -1065,10 +1066,10 @@ export class CCLoader extends Pipeline {
key = this._getResUuid(assetOrUrlOrUuid, null, null, true) || assetOrUrlOrUuid;
}
if (!key) {
cc.warnID(4800, assetOrUrlOrUuid);
legacyCC.warnID(4800, assetOrUrlOrUuid);
return key;
}
cc.AssetLibrary._getAssetInfoInRuntime(key, _info);
legacyCC.AssetLibrary._getAssetInfoInRuntime(key, _info);
return this._cache[_info.url!] ? _info.url : key;
}
@@ -1078,7 +1079,7 @@ export class CCLoader extends Pipeline {
*/
private _urlNotFound (url, type, completeCallback) {
callInNextTick(() => {
url = cc.url.normalize(url);
url = legacyCC.url.normalize(url);
const info = `${type ? getClassName(type) : 'Asset'} in "resources/${url}" does not exist.`;
if (completeCallback) {
completeCallback(new Error(info), []);
@@ -1097,7 +1098,7 @@ export class CCLoader extends Pipeline {
*/
private _parseLoadResArgs (type, onProgress, onComplete) {
if (onComplete === undefined) {
const isValidType = isChildClassOf(type, cc.RawAsset);
const isValidType = isChildClassOf(type, legacyCC.RawAsset);
if (onProgress) {
onComplete = onProgress;
if (isValidType) {
@@ -1175,10 +1176,10 @@ export class CCLoader extends Pipeline {
}
}
export const loader = cc.loader = new CCLoader();
export const loader = legacyCC.loader = new CCLoader();
if (EDITOR) {
cc.loader.refreshUrl = function (uuid, oldUrl, newUrl) {
legacyCC.loader.refreshUrl = function (uuid, oldUrl, newUrl) {
let item = this._cache[uuid];
if (item) {
item.url = newUrl;
+2 -1
View File
@@ -32,6 +32,7 @@ import * as debug from '../platform/debug';
import { Pipeline, IPipe } from './pipeline';
import { LoadingItems } from './loading-items';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
const ID = 'AssetLoader';
let reusedArray:Array<any> = [];
@@ -48,7 +49,7 @@ export default class AssetLoader implements IPipe {
return item.content || null;
}
cc.AssetLibrary.queryAssetInfo(uuid, (error, url, isRawAsset) => {
legacyCC.AssetLibrary.queryAssetInfo(uuid, (error, url, isRawAsset) => {
if (error) {
callback(error);
}
@@ -29,9 +29,10 @@
import {createMap} from '../utils/js';
import { RawAsset } from '../assets/raw-asset';
import { legacyCC } from '../global-exports';
function parseDepends (key, parsed) {
let item = cc.loader.getItem(key);
let item = legacyCC.loader.getItem(key);
if (item) {
let depends = item.dependKeys;
if (depends) {
@@ -51,7 +52,7 @@ function visitAsset (asset, excludeMap) {
if (!asset._uuid) {
return;
}
let key = cc.loader._getReferenceKey(asset);
let key = legacyCC.loader._getReferenceKey(asset);
if ( !excludeMap[key] ) {
excludeMap[key] = true;
parseDepends(key, excludeMap);
@@ -98,7 +99,7 @@ function visitNode (node, excludeMap) {
// do auto release
export function autoRelease (oldSceneAssets, nextSceneAssets, persistNodes) {
let releaseSettings = cc.loader._autoReleaseSetting;
let releaseSettings = legacyCC.loader._autoReleaseSetting;
let excludeMap = createMap();
// collect next scene assets
@@ -118,7 +119,7 @@ export function autoRelease (oldSceneAssets, nextSceneAssets, persistNodes) {
for (let i = 0; i < oldSceneAssets.length; i++) {
let key = oldSceneAssets[i];
if (releaseSettings[key] !== false && !excludeMap[key]) {
cc.loader.release(key);
legacyCC.loader.release(key);
}
}
}
@@ -129,7 +130,7 @@ export function autoRelease (oldSceneAssets, nextSceneAssets, persistNodes) {
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (releaseSettings[key] === true && !excludeMap[key]) {
cc.loader.release(key);
legacyCC.loader.release(key);
}
}
}
@@ -27,9 +27,11 @@
* @category loader
*/
import { legacyCC } from '../global-exports';
export default function downloadBinary (item, callback) {
var url = item.url;
var xhr = cc.loader.getXMLHttpRequest(),
var xhr = legacyCC.loader.getXMLHttpRequest(),
errInfo = 'Load binary data failed: ' + url + '';
xhr.open('GET', url, true);
xhr.responseType = "arraybuffer";
+3 -2
View File
@@ -35,6 +35,7 @@ import downloadBinary from './binary-downloader';
import downloadText from './text-downloader';
import {urlAppendTimestamp} from './utils';
import { downloadAudio } from '../../audio/audio-downloader';
import { legacyCC } from '../global-exports';
function skip () {
return null;
@@ -239,7 +240,7 @@ export default class Downloader implements IPipe {
}
_handleLoadQueue () {
while (this._curConcurrent < cc.macro.DOWNLOAD_MAX_CONCURRENT) {
while (this._curConcurrent < legacyCC.macro.DOWNLOAD_MAX_CONCURRENT) {
let nextOne = this._loadQueue.shift();
if (!nextOne) {
break;
@@ -260,7 +261,7 @@ export default class Downloader implements IPipe {
let self = this;
let downloadFunc = this.extMap[item.type] || this.extMap['default'];
let syncRet = undefined;
if (this._curConcurrent < cc.macro.DOWNLOAD_MAX_CONCURRENT) {
if (this._curConcurrent < legacyCC.macro.DOWNLOAD_MAX_CONCURRENT) {
this._curConcurrent++;
syncRet = downloadFunc.call(this, item, function (err, result) {
self._curConcurrent = Math.max(0, self._curConcurrent - 1);
+3 -2
View File
@@ -28,6 +28,7 @@
*/
import {safeMeasureText} from '../utils/text-utils';
import { legacyCC } from '../global-exports';
interface IFontLoadHandle {
fontFamilyName;
@@ -109,7 +110,7 @@ function nativeCheckFontLoaded (start, font, callback) {
}
callback(null, font);
}, function () {
cc.warnID(4933, font);
legacyCC.warnID(4933, font);
callback(null, font);
});
}
@@ -123,7 +124,7 @@ function _checkFontLoaded () {
let fontFamily = fontLoadHandle.fontFamilyName;
// load timeout
if (now - fontLoadHandle.startTime > _timeout) {
cc.warnID(4933, fontFamily);
legacyCC.warnID(4933, fontFamily);
fontLoadHandle.callback(null, fontFamily);
_loadingFonts.splice(i, 1);
continue;
+5 -4
View File
@@ -34,6 +34,7 @@ import plistParser from './plist-parser';
import { Pipeline, IPipe } from './pipeline';
import {loadUuid} from './uuid-loader';
import {loadFont} from './font-loader';
import { legacyCC } from '../global-exports';
function loadNothing () {
return null;
@@ -54,14 +55,14 @@ function loadJSON (item) {
}
function loadImage (item) {
let loadByDeserializedAsset = (item._owner instanceof cc.Asset);
let loadByDeserializedAsset = (item._owner instanceof legacyCC.Asset);
if (loadByDeserializedAsset) {
// already has cc.Asset
return null;
}
let image = item.content;
if (cc.sys.platform !== cc.sys.FB_PLAYABLE_ADS && !(image instanceof Image)) {
if (legacyCC.sys.platform !== legacyCC.sys.FB_PLAYABLE_ADS && !(image instanceof Image)) {
return new Error('Image Loader: Input item doesn\'t contain Image content');
}
@@ -78,13 +79,13 @@ function loadImage (item) {
// If audio is loaded by url directly, than this loader will wrap it into a new cc.AudioClip object.
// If audio is loaded by deserialized AudioClip, than this loader will be skipped.
function loadAudioAsAsset (item, callback) {
let loadByDeserializedAsset = (item._owner instanceof cc.Asset);
let loadByDeserializedAsset = (item._owner instanceof legacyCC.Asset);
if (loadByDeserializedAsset) {
// already has cc.Asset
return null;
}
let audioClip = new cc.AudioClip();
let audioClip = new legacyCC.AudioClip();
audioClip._setRawAsset(item.rawUrl, false);
audioClip._nativeAsset = item.content;
return audioClip;
+4 -3
View File
@@ -31,6 +31,7 @@
import {CallbacksInvoker} from '../event/callbacks-invoker';
import {extname} from '../utils/path';
import {createMap, mixin} from '../utils/js';
import { legacyCC } from '../global-exports';
let _qid = (0|(Math.random()*998));
let _queues = createMap(true);
@@ -93,7 +94,7 @@ function createItem (id, queueId) {
complete: false,
states: {},
deps: null,
isScene: id.uuid && cc.game._sceneInfos.find((info) => info.uuid === id.uuid),
isScene: id.uuid && legacyCC.game._sceneInfos.find((info) => info.uuid === id.uuid),
};
if (typeof id === 'object') {
@@ -196,7 +197,7 @@ export class LoadingItems extends CallbacksInvoker {
/**
* @property {Number} ERROR
*/
static ItemState = new cc.Enum(ItemState);
static ItemState = new legacyCC.Enum(ItemState);
/**
* @en This is a callback which will be invoked while an item flow out the pipeline.
@@ -781,4 +782,4 @@ export class LoadingItems extends CallbacksInvoker {
}
}
cc.LoadingItems = LoadingItems;
legacyCC.LoadingItems = LoadingItems;
+3 -2
View File
@@ -29,6 +29,7 @@
*/
import { Pipeline, IPipe } from './pipeline';
import { legacyCC } from '../global-exports';
const ID = 'MD5Pipe';
const ExtnameRegex = /(\.[^.\n\\/]*)$/;
@@ -79,8 +80,8 @@ export default class MD5Pipe implements IPipe {
let hashValue = map[uuid];
if (hashValue) {
if (hashPatchInFolder) {
let dirname = cc.path.dirname(url);
let basename = cc.path.basename(url);
let dirname = legacyCC.path.dirname(url);
let basename = legacyCC.path.basename(url);
url = `${dirname}.${hashValue}/${basename}`;
} else {
let matched = false;
+4 -3
View File
@@ -35,6 +35,7 @@ import { errorID } from '../platform/debug';
import { js } from '../utils';
import { Texture2D } from '../assets/texture-2d';
import { DEBUG, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
// when more than one package contains the required asset,
// choose to load from the package with the largest state value.
@@ -85,8 +86,8 @@ export function initPacks (packs) {
}
export function _loadNewPack (uuid, packUuid, callback) {
var packUrl = cc.AssetLibrary.getLibUrlNoExt(packUuid) + '.json';
cc.loader.load({ url: packUrl, ignoreMaxConcurrency: true }, function (err, packJson) {
var packUrl = legacyCC.AssetLibrary.getLibUrlNoExt(packUuid) + '.json';
legacyCC.loader.load({ url: packUrl, ignoreMaxConcurrency: true }, function (err, packJson) {
if (err) {
errorID(4916, uuid);
return callback(err);
@@ -205,7 +206,7 @@ export function load (item, callback) {
}
if (TEST) {
cc._Test.PackDownloader = {
legacyCC._Test.PackDownloader = {
initPacks,
_loadNewPack,
_doPreload,
+5 -4
View File
@@ -31,6 +31,7 @@
import {createMap} from '../utils/js';
import { LoadingItems, IItem } from './loading-items';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
const ItemState = LoadingItems.ItemState;
export interface IPipe {
@@ -171,12 +172,12 @@ export class Pipeline {
insertPipe (pipe, index) {
// Must have handle and id, handle for flow, id for state flag
if (!pipe.handle || !pipe.id || index > this._pipes.length) {
cc.warnID(4921);
legacyCC.warnID(4921);
return;
}
if (this._pipes.indexOf(pipe) > 0) {
cc.warnID(4922);
legacyCC.warnID(4922);
return;
}
@@ -394,7 +395,7 @@ export class Pipeline {
if (EDITOR) {
let references = removed.references;
if (references) {
let dependListener = cc.AssetLibrary.dependListener;
let dependListener = legacyCC.AssetLibrary.dependListener;
if (dependListener) {
for (let uuid in references) {
dependListener.off(uuid, references[uuid]);
@@ -423,4 +424,4 @@ export class Pipeline {
}
}
cc.Pipeline = Pipeline;
legacyCC.Pipeline = Pipeline;
+2 -1
View File
@@ -26,6 +26,7 @@
*/
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* @category loader
@@ -89,7 +90,7 @@ class PlistParser extends SAXParser {
let xmlDoc = this._parseXML(xmlTxt);
let plist = xmlDoc.documentElement;
if (plist.tagName !== 'plist') {
cc.warnID(5100);
legacyCC.warnID(5100);
return {};
}
@@ -29,6 +29,7 @@
*/
import {createMap, getClassName, clear} from '../utils/js';
import { legacyCC } from '../global-exports';
let _tmpInfo:any = null;
@@ -37,7 +38,7 @@ function getItemDesc (item) {
if (!_tmpInfo) {
_tmpInfo = { path: "", type: null };
}
if (cc.loader._assetTables.assets._getInfo_DEBUG(item.uuid, _tmpInfo)) {
if (legacyCC.loader._assetTables.assets._getInfo_DEBUG(item.uuid, _tmpInfo)) {
_tmpInfo.path = 'resources/' + _tmpInfo.path;
return `"${_tmpInfo.path}" (type: ${getClassName(_tmpInfo.type)}, uuid: ${item.uuid})`;
}
@@ -53,7 +54,7 @@ function getItemDesc (item) {
function doCheckCouldRelease (releasedKey, refOwnerItem, caches) {
var loadedAgain = caches[releasedKey];
if (!loadedAgain) {
cc.log(`"${releasedKey}" was released but maybe still referenced by ${getItemDesc(refOwnerItem)}`);
legacyCC.log(`"${releasedKey}" was released but maybe still referenced by ${getItemDesc(refOwnerItem)}`);
}
}
+2 -1
View File
@@ -28,12 +28,13 @@
*/
import {urlAppendTimestamp} from './utils';
import { legacyCC } from '../global-exports';
export default function (item, callback) {
let url = item.url;
url = urlAppendTimestamp(url);
let xhr = cc.loader.getXMLHttpRequest(),
let xhr = legacyCC.loader.getXMLHttpRequest(),
errInfo = 'Load text file failed: ' + url;
xhr.open('GET', url, true);
if (xhr.overrideMimeType) xhr.overrideMimeType('text/plain; charset=utf-8');
+5 -3
View File
@@ -24,6 +24,8 @@
THE SOFTWARE.
*/
import { legacyCC } from '../global-exports';
/**
* @category loader
*/
@@ -37,7 +39,7 @@ export class JsonUnpacker {
*/
load (indices, packedJson) {
if (packedJson.length !== indices.length) {
cc.errorID(4915);
legacyCC.errorID(4915);
}
for (let i = 0; i < indices.length; i++) {
let key = indices[i];
@@ -62,7 +64,7 @@ export class TextureUnpacker {
load (indices, packedJson) {
let datas = packedJson.data;
if (datas.length !== indices.length) {
cc.errorID(4915);
legacyCC.errorID(4915);
}
for (let i = 0; i < indices.length; i++) {
this.contents[indices[i]] = {base: datas[i][0], mipmaps: datas[i][1]};
@@ -73,7 +75,7 @@ export class TextureUnpacker {
let content = this.contents[key];
if (content) {
return {
__type__: cc.js._getClassId(cc.Texture2D),
__type__: legacyCC.js._getClassId(legacyCC.Texture2D),
content: content
};
}
+7 -6
View File
@@ -25,6 +25,7 @@
*/
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
/**
* 加载相关模块
@@ -70,20 +71,20 @@ let url = {
*/
raw: function (url) {
if (EDITOR && !this._rawAssets) {
cc.errorID(7000);
legacyCC.errorID(7000);
return '';
}
url = this.normalize(url);
if ( !url.startsWith('resources/') ) {
cc.errorID(EDITOR ? 7001 : 7002, url);
legacyCC.errorID(EDITOR ? 7001 : 7002, url);
}
else {
// Compatible with versions lower than 1.10
var uuid = cc.loader._getResUuid(url.slice(10), cc.Asset, null, true);
var uuid = legacyCC.loader._getResUuid(url.slice(10), legacyCC.Asset, null, true);
if (uuid) {
return cc.AssetLibrary.getLibUrlNoExt(uuid, true) + cc.path.extname(url);
return legacyCC.AssetLibrary.getLibUrlNoExt(uuid, true) + legacyCC.path.extname(url);
}
}
@@ -91,10 +92,10 @@ let url = {
},
_init: function (assets) {
this._rawAssets = cc.path.stripSep(assets) + '/';
this._rawAssets = legacyCC.path.stripSep(assets) + '/';
}
}
cc.url = url;
legacyCC.url = url;
export default url;

Some files were not shown because too many files have changed in this diff Show More