mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
committed by
GitHub
parent
998869fbb4
commit
6b2a2d1859
@@ -0,0 +1,131 @@
|
||||
module.exports.mixin = function(result, ...args) {
|
||||
for (const arg of args) {
|
||||
mixinObject(result, arg);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports.link = function(root) {
|
||||
const visited = new Set();
|
||||
|
||||
link(root);
|
||||
|
||||
return root;
|
||||
|
||||
function link(o) {
|
||||
if (visited.has(o)) {
|
||||
return;
|
||||
}
|
||||
visited.add(o);
|
||||
|
||||
const __extends__ = o.__extends__;
|
||||
const extended = {};
|
||||
if (typeof __extends__ === 'string') {
|
||||
const base = find(__extends__);
|
||||
if (!base) {
|
||||
console.error(`Can not find the __extends__ ${__extends__}`);
|
||||
} else {
|
||||
link(base);
|
||||
mixinObject(extended, base);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [k, v] of Object.entries(o)) {
|
||||
if (typeof v === 'object' && v) {
|
||||
link(v);
|
||||
}
|
||||
}
|
||||
|
||||
mixinObject(o, extended);
|
||||
}
|
||||
|
||||
function find(path) {
|
||||
const items = path.split('.');
|
||||
if (items.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
let result = root;
|
||||
for (const item of items) {
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
if (!(item in result)) {
|
||||
return undefined;
|
||||
}
|
||||
const r = result[item];
|
||||
if (typeof r !== 'object' || !r) {
|
||||
return undefined;
|
||||
}
|
||||
result = r;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
function mixinObject(o1, o2, o1FullPath, o2FullPath) {
|
||||
for (const [k, v2] of Object.entries(o2)) {
|
||||
if (typeof v2 !== 'object' || !v2) {
|
||||
if (k in o1) {
|
||||
reportMixinFailure(k);
|
||||
} else {
|
||||
o1[k] = v2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Array.isArray(v2)) {
|
||||
let v1;
|
||||
if (!(k in o1)) {
|
||||
v1 = o1[k] = [];
|
||||
} else if (Array.isArray(o1[k])) {
|
||||
v1 = o1[k];
|
||||
} else {
|
||||
reportMixinFailure(k);
|
||||
continue;
|
||||
}
|
||||
v1.push(...v2);
|
||||
continue;
|
||||
}
|
||||
|
||||
// v2 is object
|
||||
{
|
||||
let v1;
|
||||
if (!(k in o1)) {
|
||||
v1 = o1[k] = {};
|
||||
} else {
|
||||
v1 = o1[k];
|
||||
if (typeof v1 !== 'object' || !v1) {
|
||||
reportMixinFailure(k);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mixinObject(v1, v2, getFullPath(o1FullPath, k), getFullPath(o2FullPath, k));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
function reportMixinFailure(k) {
|
||||
console.error(
|
||||
`Can not mix `
|
||||
+ `${getFullPath(o2FullPath, k)}(type: ${getLogType(o2[k])}) `
|
||||
+ `into `
|
||||
+ `${getFullPath(o1FullPath, k)}(type: ${getLogType(o1[k])})`
|
||||
);
|
||||
}
|
||||
|
||||
function getFullPath(prefix, k) {
|
||||
return `${prefix}['${k}']`;
|
||||
}
|
||||
|
||||
function getLogType(v) {
|
||||
if (typeof v !== 'object') {
|
||||
return typeof v;
|
||||
} else if (!v) {
|
||||
return 'null';
|
||||
} else if (Array.isArray(v)) {
|
||||
return 'array';
|
||||
} else {
|
||||
return 'object';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* eslint-disable quote-props */
|
||||
|
||||
module.exports = {
|
||||
classes: {
|
||||
'cc': {
|
||||
'animation': {
|
||||
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,11 +1,18 @@
|
||||
/* eslint-disable quote-props */
|
||||
const pkg = require('../../../package.json');
|
||||
const { mixin, link } = require('../../i18n-utils');
|
||||
const version = pkg.version.replace(/(^\d+\.\d+)\..*$/, (str, a) => {
|
||||
return a;
|
||||
});
|
||||
|
||||
const url = 'https://docs.cocos.com/creator';
|
||||
|
||||
module.exports = {
|
||||
module.exports = link(mixin({
|
||||
|
||||
classes: {
|
||||
'cc': { },
|
||||
},
|
||||
|
||||
help: {
|
||||
cc: {
|
||||
Node: `${url}/${version}/manual/en/concepts/scene/node-component.html`,
|
||||
@@ -1227,4 +1234,8 @@ module.exports = {
|
||||
color_grading: {
|
||||
originalMap: 'The builtin lut texture path is internal/dependencies/textures/lut/.',
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
require('./animation'),
|
||||
|
||||
));
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/* eslint-disable quote-props */
|
||||
|
||||
module.exports = {
|
||||
classes: {
|
||||
'cc': {
|
||||
'animation': {
|
||||
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,11 +1,18 @@
|
||||
/* eslint-disable quote-props */
|
||||
const pkg = require('../../../package.json');
|
||||
const { mixin, link } = require('../../i18n-utils');
|
||||
const version = pkg.version.replace(/(^\d+\.\d+)\..*$/, (str, a) => {
|
||||
return a;
|
||||
});
|
||||
|
||||
const url = 'https://docs.cocos.com/creator';
|
||||
|
||||
module.exports = {
|
||||
module.exports = link(mixin({
|
||||
|
||||
classes: {
|
||||
'cc': { },
|
||||
},
|
||||
|
||||
help: {
|
||||
cc: {
|
||||
Node: `${url}/${version}/manual/zh/concepts/scene/node-component.html`,
|
||||
@@ -1208,4 +1215,8 @@ module.exports = {
|
||||
color_grading: {
|
||||
originalMap: '内置lut贴图路径internal/dependencies/textures/lut/。',
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
require('./animation'),
|
||||
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user