MCPcopy Create free account
hub / github.com/Crain99/cc-reverse / parseBundleConfig

Function parseBundleConfig

src/core/cocos3x/bundleConfig.js:22–122  ·  view source on GitHub ↗

* Inflate a raw config.json per the same logic the runtime uses at load time. * * @param {object} raw Parsed config.json. * @param {string} baseDir Absolute path to the bundle directory (the one that * contains config.json + import/ + native/). * @returns {BundleConf

(raw, baseDir)

Source from the content-addressed store, hash-verified

20 * @returns {BundleConfig}
21 */
22function parseBundleConfig(raw, baseDir) {
23 const debug = raw.debug === true;
24 const importBase = raw.importBase || 'import';
25 const nativeBase = raw.nativeBase || 'native';
26 const name = raw.name || path.basename(baseDir);
27 const types = Array.isArray(raw.types) ? raw.types : [];
28 const deps = Array.isArray(raw.deps) ? raw.deps : [];
29 const uuidsRaw = Array.isArray(raw.uuids) ? raw.uuids : [];
30
31 // Expand compressed uuids unless the config is in debug mode.
32 const uuids = uuidsRaw.map(u => (debug ? u : uuidUtils.decodeUuid(u)));
33
34 // Versions: flat [idx, ver, idx, ver, ...] arrays per kind.
35 const importVersions = indexedVersionMap(raw.versions && raw.versions.import, uuids);
36 const nativeVersions = indexedVersionMap(raw.versions && raw.versions.native, uuids);
37
38 // Paths: { "<uuidIndex>": [relPath, typeIndex, subAssetFlag?] }
39 const rawPaths = raw.paths && typeof raw.paths === 'object' ? raw.paths : {};
40 const paths = {};
41 for (const key of Object.keys(rawPaths)) {
42 const entry = rawPaths[key];
43 const uuidIdx = parseInt(key, 10);
44 if (!Array.isArray(entry) || Number.isNaN(uuidIdx)) continue;
45 const uuid = uuids[uuidIdx];
46 if (!uuid) continue;
47 const relPath = entry[0];
48 const typeIndex = entry[1];
49 const subAssetFlag = entry[2];
50 paths[uuid] = {
51 path: relPath,
52 type: typeIndex != null ? types[typeIndex] : null,
53 subAsset: subAssetFlag === 1 || subAssetFlag === true,
54 };
55 }
56
57 // Scenes: { name: "<uuidIndex>" } -> { name: uuid }
58 const rawScenes = raw.scenes && typeof raw.scenes === 'object' ? raw.scenes : {};
59 const scenes = {};
60 for (const sceneName of Object.keys(rawScenes)) {
61 const idx = parseInt(rawScenes[sceneName], 10);
62 const uuid = Number.isNaN(idx) ? rawScenes[sceneName] : uuids[idx];
63 if (uuid) scenes[sceneName] = uuid;
64 }
65
66 // Packs: { packUuid(compressed): [childUuidIdx or childUuid] }
67 const rawPacks = raw.packs && typeof raw.packs === 'object' ? raw.packs : {};
68 const packs = {};
69 for (const packKey of Object.keys(rawPacks)) {
70 const packUuid = debug ? packKey : uuidUtils.decodeUuid(packKey);
71 const children = rawPacks[packKey];
72 if (!Array.isArray(children)) continue;
73 packs[packUuid] = children.map(c => {
74 const idx = parseInt(c, 10);
75 if (!Number.isNaN(idx) && uuids[idx]) return uuids[idx];
76 return debug ? c : uuidUtils.decodeUuid(c);
77 });
78 }
79

Callers 2

unpackBundleFunction · 0.85

Calls 1

indexedVersionMapFunction · 0.85

Tested by

no test coverage detected