Skip to content

Commit 2c57012

Browse files
committed
Merge branch 'v4.0.0' into v3.8.8-lg2
2 parents 7d71882 + 57cc800 commit 2c57012

127 files changed

Lines changed: 7745 additions & 183 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cc.config.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,20 @@
434434
"pal/wasm": "pal/wasm/wasm-minigame.ts"
435435
}
436436
},
437+
{
438+
"test": "context.buildTimeConstants && context.buildTimeConstants.NODEJS",
439+
"isVirtualModule": true,
440+
"overrides": {
441+
"pal/minigame": "pal/minigame/non-minigame.ts",
442+
"pal/audio": "pal/audio/nodejs/player.ts",
443+
"pal/system-info": "pal/system-info/nodejs/system-info.ts",
444+
"pal/screen-adapter": "pal/screen-adapter/nodejs/screen-adapter.ts",
445+
"pal/input": "pal/input/nodejs/index.ts",
446+
"pal/env": "pal/env/nodejs/env.ts",
447+
"pal/pacer": "pal/pacer/pacer-nodejs.ts",
448+
"pal/wasm": "pal/wasm/wasm-nodejs.ts"
449+
}
450+
},
437451
{
438452
"test": "context.buildTimeConstants && context.buildTimeConstants.NOT_PACK_PHYSX_LIBS",
439453
"isVirtualModule": false,
@@ -638,6 +652,13 @@
638652
"ccGlobal": true,
639653
"internal": false
640654
},
655+
"NODEJS": {
656+
"comment": "Running in the Node.js environment.",
657+
"type": "boolean",
658+
"value": false,
659+
"ccGlobal": true,
660+
"internal": false
661+
},
641662
"EDITOR": {
642663
"comment": "Running in the editor.",
643664
"type": "boolean",

cocos/2d/assets/sprite-atlas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
THE SOFTWARE.
2424
*/
2525

26-
import { EDITOR, TEST } from 'internal:constants';
26+
import { EDITOR, NODEJS, TEST } from 'internal:constants';
2727
import { ccclass, serializable, editable } from 'cc.decorator';
2828
import { Asset } from '../../asset/assets';
2929
import { SpriteFrame } from './sprite-frame';
@@ -112,7 +112,7 @@ export class SpriteAtlas extends Asset {
112112
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
113113
*/
114114
public _serialize (ctxForExporting: any): any {
115-
if (EDITOR || TEST) {
115+
if (EDITOR || NODEJS || TEST) {
116116
const frames: string[] = [];
117117
for (const key in this.spriteFrames) {
118118
const spriteFrame = this.spriteFrames[key];

cocos/2d/assets/sprite-frame.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
import { ccclass } from 'cc.decorator';
29-
import { EDITOR, TEST, BUILD } from 'internal:constants';
29+
import { EDITOR, NODEJS, TEST, BUILD } from 'internal:constants';
3030
import { Rect, Size, Vec2, Vec3, Vec4, cclegacy, errorID, warnID, js, v3, mat4, rect, v4, v2, size } from '../../core';
3131
import { Asset } from '../../asset/assets/asset';
3232
import { TextureBase } from '../../asset/assets/texture-base';
@@ -649,7 +649,7 @@ export class SpriteFrame extends Asset {
649649
constructor (name?: string) {
650650
super(name);
651651

652-
if (EDITOR) {
652+
if (EDITOR || NODEJS) {
653653
// Atlas asset uuid
654654
this._atlasUuid = '';
655655
}
@@ -1200,7 +1200,7 @@ export class SpriteFrame extends Asset {
12001200
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
12011201
*/
12021202
public _serialize (ctxForExporting: any): any {
1203-
if (EDITOR || TEST) {
1203+
if (EDITOR || TEST || NODEJS) {
12041204
const rect = { x: this._rect.x, y: this._rect.y, width: this._rect.width, height: this._rect.height };
12051205
const offset = { x: this._offset.x, y: this._offset.y };
12061206
const originalSize = this._originalSize;
@@ -1298,7 +1298,7 @@ export class SpriteFrame extends Asset {
12981298
}
12991299
}
13001300

1301-
if (EDITOR) {
1301+
if (EDITOR || NODEJS) {
13021302
self._atlasUuid = data.atlas ? data.atlas : '';
13031303
}
13041304

cocos/animation/exotic-animation/exotic-animation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR, TEST } from 'internal:constants';
25+
import { EDITOR, NODEJS, TEST } from 'internal:constants';
2626
import { binarySearchEpsilon, clamp, lerp, Quat, Vec3, _decorator } from '../../core';
2727
import { assertIsTrue } from '../../core/data/utils/asserts';
2828
import { AnimationClipGraphBindingContext } from '../marionette/animation-graph-animation-clip-binding';
@@ -31,7 +31,7 @@ import { Pose } from '../core/pose';
3131
import { CLASS_NAME_PREFIX_ANIM } from '../define';
3232
import { Binder, RuntimeBinding, TrackBinding, TrackPath } from '../tracks/track';
3333

34-
const SPLIT_METHOD_ENABLED = TEST || EDITOR;
34+
const SPLIT_METHOD_ENABLED = TEST || EDITOR || NODEJS;
3535

3636
const { ccclass, serializable } = _decorator;
3737

cocos/asset/asset-manager/builtin-res-mgr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR, EDITOR_NOT_IN_PREVIEW, TEST } from 'internal:constants';
25+
import { EDITOR, EDITOR_NOT_IN_PREVIEW, NODEJS, TEST } from 'internal:constants';
2626
import { Asset } from '../assets/asset';
2727
import { ImageAsset, ImageSource } from '../assets/image-asset';
2828
import { SpriteFrame } from '../../2d/assets/sprite-frame';
@@ -284,7 +284,7 @@ export class BuiltinResMgr {
284284
resources[spriteFrame._uuid] = spriteFrame;
285285
}
286286

287-
if (EDITOR) {
287+
if (EDITOR || NODEJS) {
288288
const builtinAssets = settings.querySettings<string[]>(SettingsCategory.ENGINE, 'builtinAssets');
289289
const builtinBundle = new Bundle();
290290
builtinBundle.init({

cocos/asset/asset-manager/deserialize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR } from 'internal:constants';
25+
import { EDITOR, NODEJS } from 'internal:constants';
2626
import { Asset } from '../assets/asset';
2727
import { MissingScript } from '../../misc/missing-script';
2828
import { deserialize, Details } from '../../serialization/deserialize';
2929
import { error, js } from '../../core';
3030
import { dependMap, nativeDependMap } from './depend-maps';
3131
import { decodeUuid } from './helper';
3232

33-
const missingClass: any = EDITOR && EditorExtends.MissingReporter.classInstance;
33+
const missingClass: any = (EDITOR || NODEJS) && EditorExtends.MissingReporter.classInstance;
3434

3535
export interface IDependProp {
3636
uuid: string;
@@ -43,7 +43,7 @@ export default function deserializeAsset (json: Record<string, any>, options: Re
4343
__uuid__?: string;
4444
}): Asset {
4545
let classFinder: deserialize.ClassFinder;
46-
if (EDITOR) {
46+
if (EDITOR || NODEJS) {
4747
classFinder = (type, data, owner, propName): Constructor<unknown> => {
4848
const res = missingClass.classFinder(type, data, owner, propName);
4949
if (res) {

cocos/asset/asset-manager/editor-path-replace.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
THE SOFTWARE.
2323
*/
24-
import { EDITOR, NATIVE, PREVIEW, TEST } from 'internal:constants';
25-
import { assert, settings, SettingsCategory } from '../../core';
24+
import { EDITOR, NATIVE, NODEJS, PREVIEW, TEST } from 'internal:constants';
25+
import { assert, settings, SettingsCategory, cclegacy } from '../../core';
2626
import { fetchPipeline, pipeline } from './shared';
2727
import Task from './task';
2828

2929
declare const Editor: any;
30-
if ((EDITOR || PREVIEW) && !TEST) {
31-
const cache: {[uuid: string]: string | null} = {};
30+
if ((EDITOR || PREVIEW || NODEJS) && !TEST) {
31+
const cache: { [uuid: string]: string | null } = {};
3232
const resolveMap: { [uuid: string]: Function[] } = {};
33-
const replaceExtension = (task: Task, done): void => {
33+
const replaceExtension = (task: Task, done): void => {
3434
task.output = task.input;
3535
(async (): Promise<void> => {
3636
for (let i = 0; i < task.input.length; i++) {
@@ -80,12 +80,34 @@ if ((EDITOR || PREVIEW) && !TEST) {
8080
try {
8181
let text = '';
8282
if (EDITOR) {
83-
const info: {library: {['.bin']: any}} = await Editor.Message.request('asset-db', 'query-asset-info', uuid);
83+
const info: { library: { ['.bin']: any } } = await Editor.Message.request('asset-db', 'query-asset-info', uuid);
8484
// Current rule: If an asset has only one .bin file, then it is in CCON format.
8585
if (info && info.library['.bin'] && Object.keys(info.library).length === 1) {
8686
text = '.cconb';
8787
}
88-
} else {
88+
} else if(NODEJS) {
89+
const importBase = cclegacy.assetManager.generalImportBase;
90+
let useAssetDB = true;
91+
if(importBase && (importBase.startsWith('http://') || importBase.startsWith('https://'))) {
92+
// cli:场景使用的是网络路径
93+
const requestUrl = `${importBase}/query-extname/${uuid}`;
94+
try {
95+
text = await fetchText(requestUrl) as string;
96+
useAssetDB = false;
97+
} catch (e) {
98+
console.warn(`Failed to get file type from URL: ${requestUrl}. Error: ${e}`);
99+
text = '';
100+
}
101+
}
102+
// 如果网络路径没有配置,或者不是网络路径,或者请求异常,使用AssetDB
103+
if(useAssetDB && globalThis.AssetDB) {
104+
const meta: { files: string[] } = await globalThis.AssetDB.queryAsset(uuid)?.meta;
105+
// Current rule: If an asset has only one .bin file, then it is in CCON format.
106+
if (meta && meta.files.length === 1 && meta.files[0] === '.bin') {
107+
text = '.cconb';
108+
}
109+
}
110+
} else {
89111
let previewServer = '';
90112
if (NATIVE) {
91113
previewServer = settings.querySettings<string>(SettingsCategory.PATH, 'previewServer') || '';

cocos/asset/asset-manager/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR } from 'internal:constants';
25+
import { EDITOR, NODEJS } from 'internal:constants';
2626
import { ImageAsset } from '../assets/image-asset';
2727
import JsonAsset from '../assets/json-asset';
2828
import { TextAsset } from '../assets/text-asset';
@@ -86,7 +86,7 @@ function createBundle (id: string, data: IConfigOption, options: Record<string,
8686
bundle.init(data);
8787
}
8888
//HACK: Can not import scripts in GameView due to the difference of Scripting System between the GameView and Preview
89-
if (!EDITOR) {
89+
if (!EDITOR && !NODEJS) {
9090
import(`virtual:///prerequisite-imports/${bundle.name}`).then((): void => {
9191
onComplete(null, bundle);
9292
}).catch(onComplete);

cocos/asset/asset-manager/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR } from 'internal:constants';
25+
import { EDITOR, NODEJS } from 'internal:constants';
2626
import { Asset } from '../assets/asset';
2727
import Bundle from './bundle';
2828
import Cache from './cache';
@@ -36,7 +36,7 @@ export const bundles = new Cache<Bundle>();
3636
export const pipeline = new Pipeline('normal load', []);
3737
export const fetchPipeline = new Pipeline('fetch', []);
3838
export const transformPipeline = new Pipeline('transform url', []);
39-
export const references = EDITOR ? new Cache<any[]>() : null;
39+
export const references = (EDITOR || NODEJS) ? new Cache<any[]>() : null;
4040
export const assetsOverrideMap = new Map<string, string>();
4141

4242
export enum RequestType {

cocos/asset/asset-manager/url-transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
import { EDITOR, PREVIEW } from 'internal:constants';
25+
import { EDITOR, NODEJS, PREVIEW } from 'internal:constants';
2626
import { warnID, js, path, cclegacy } from '../../core';
2727
import Config, { IAddressableInfo, IAssetInfo } from './config';
2828
import { decodeUuid } from './helper';
@@ -161,7 +161,7 @@ export function replaceOverrideAsset (task: Task): void {
161161
const item = input[i] as RequestItem;
162162
if (assetsOverrideMap.has(item.uuid)) {
163163
const uuid = assetsOverrideMap.get(item.uuid)!;
164-
if (EDITOR || PREVIEW) {
164+
if (EDITOR || PREVIEW || NODEJS) {
165165
// In EDITOR, there is no bundle, so just change uuid.
166166
item.overrideUuid = uuid;
167167
item.ext = item.isNative ? item.ext : '.json';

0 commit comments

Comments
 (0)