Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cocos-cli-types/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe('cocos-cli-types: cli', () => {

it('IServiceManager.Node should have CRUD methods', () => {
type NodeKeys = keyof IServiceManager['Node'];
const nodeMethods: NodeKeys[] = ['createNodeByType', 'createNodeByAsset', 'deleteNode', 'updateNode', 'queryNode', 'queryNodeTree'];
const nodeMethods: NodeKeys[] = ['createByType', 'createByAsset', 'delete', 'update', 'query', 'queryNodeTree'];
expect(nodeMethods.length).toBeGreaterThan(0);
});

it('IServiceManager.Component should have component methods', () => {
type CompKeys = keyof IServiceManager['Component'];
const compMethods: CompKeys[] = ['addComponent', 'removeComponent', 'setProperty', 'queryComponent', 'queryAllComponent'];
const compMethods: CompKeys[] = ['add', 'remove', 'setProperty', 'query', 'queryAll'];
expect(compMethods.length).toBeGreaterThan(0);
});

Expand Down
4 changes: 2 additions & 2 deletions src/api/scene/component-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import type { IComponent } from '../../core/scene';
import type { IComponentInfo } from '../../core/scene';
import { SchemaComponentIdentifier } from '../base/schema-identifier';
import { SchemaCompPrefabInfo } from './prefab-info-schema';

Expand Down Expand Up @@ -109,7 +109,7 @@ export const SchemaSetPropertyOptions = z.object({
)
}).describe('Information required to set component properties'); // 设置组件属性所需要的信息

export const SchemaComponent: z.ZodType<IComponent> = SchemaComponentIdentifier.extend({
export const SchemaComponent: z.ZodType<IComponentInfo> = SchemaComponentIdentifier.extend({
properties: z.record(
z.string().describe('Property name'), // 属性名称
SchemaProperty,
Expand Down
15 changes: 8 additions & 7 deletions src/api/scene/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {

import { description, param, result, title, tool } from '../decorator/decorator.js';
import { COMMON_STATUS, CommonResultType } from '../base/schema-base';
import { Scene, ISetPropertyOptions, IComponent } from '../../core/scene';
import { Scene, IComponentInfo } from '../../core/scene';
import { ISetPropertyOptionsInfo } from '../../core/scene/common/cli/component';

export class ComponentApi {

Expand All @@ -30,7 +31,7 @@ export class ComponentApi {
@result(SchemaComponentResult)
async addComponent(@param(SchemaAddComponentInfo) addComponentInfo: TAddComponentInfo): Promise<CommonResultType<TComponentResult>> {
try {
const component = await Scene.addComponent({ nodePathOrUuid: addComponentInfo.nodePath, component: addComponentInfo.component });
const component = await Scene.Component.create({ nodePath: addComponentInfo.nodePath, component: addComponentInfo.component });
return {
code: COMMON_STATUS.SUCCESS,
data: component
Expand All @@ -52,7 +53,7 @@ export class ComponentApi {
@result(SchemaBooleanResult)
async removeComponent(@param(SchemaRemoveComponent) component: TRemoveComponentOptions): Promise<CommonResultType<boolean>> {
try {
const result = await Scene.removeComponent(component);
const result = await Scene.Component.remove(component);
return {
code: COMMON_STATUS.SUCCESS,
data: result
Expand All @@ -74,13 +75,13 @@ export class ComponentApi {
@result(SchemaComponentResult)
async queryComponent(@param(SchemaQueryComponent) component: TQueryComponentOptions): Promise<CommonResultType<TComponentResult | null>> {
try {
const componentInfo = await Scene.queryComponent(component);
const componentInfo = await Scene.Component.query(component);
if (!componentInfo) {
throw new Error(`component not found: ${component.path}`);
}
return {
code: COMMON_STATUS.SUCCESS,
data: componentInfo as IComponent
data: componentInfo as IComponentInfo
};
} catch (e) {
return {
Expand All @@ -99,7 +100,7 @@ export class ComponentApi {
@result(SchemaBooleanResult)
async setProperty(@param(SchemaSetPropertyOptions) setPropertyOptions?: TSetPropertyOptions): Promise<CommonResultType<boolean>> {
try {
const result = await Scene.setProperty(setPropertyOptions as ISetPropertyOptions);
const result = await Scene.Component.setProperty(setPropertyOptions as ISetPropertyOptionsInfo);
return {
code: COMMON_STATUS.SUCCESS,
data: result
Expand All @@ -121,7 +122,7 @@ export class ComponentApi {
@result(SchemaQueryAllComponentResult)
async queryAllComponent(): Promise<CommonResultType<TQueryAllComponentResult>> {
try {
const components = await Scene.queryAllComponent();
const components = await Scene.Component.queryAll();
return {
code: COMMON_STATUS.SUCCESS,
data: components,
Expand Down
6 changes: 3 additions & 3 deletions src/api/scene/node-schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';

import { NodeType } from '../../core/scene';
import { INode } from '../../core/scene';
import { INodeInfo } from '../../core/scene';
import { SchemaQuat, SchemaVec3 } from '../base/schema-value-types';
import { SchemaNodeIdentifier, SchemaComponentIdentifier } from '../base/schema-identifier';
import { SchemaPrefabInfo } from './prefab-info-schema';
Expand Down Expand Up @@ -34,7 +34,7 @@ export const SchemaComponentOrDetail = z.union([
SchemaComponentIdentifier
]).describe('components on the node'); // 节点上的组件信息

export const SchemaNode: z.ZodType<INode> = SchemaNodeIdentifier.extend({
export const SchemaNode: z.ZodType<INodeInfo> = SchemaNodeIdentifier.extend({
properties: SchemaNodeProperty.describe('Node properties'), // 节点属性
prefab: z.union([SchemaPrefabInfo, z.null()]).describe('Prefab information'), // 预制体信息
children: z.array(z.lazy(() => SchemaNode)).optional().describe('List of child nodes'), // 子节点列表
Expand All @@ -55,7 +55,7 @@ export const SchemaNodeQuery = z.object({
}).describe('To configure options for node query, the Scene must be open first. The result is the intersection of the passed information'); // 查询节点的选项参数,查询结果是传入的信息的交集

// 查询节点的结果
export const SchemaNodeQueryResult: z.ZodType<INode> = SchemaNode;
export const SchemaNodeQueryResult: z.ZodType<INodeInfo> = SchemaNode;

//节点更新的参数
export const SchemaNodeUpdate = z.object({
Expand Down
12 changes: 6 additions & 6 deletions src/api/scene/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './node-schema';
import { description, param, result, title, tool } from '../decorator/decorator.js';
import { COMMON_STATUS, CommonResultType } from '../base/schema-base';
import { ICreateByNodeTypeParams, Scene } from '../../core/scene';
import { ICreateByNodeTypeParams, INodeInfo, Scene } from '../../core/scene';

export class NodeApi {

Expand All @@ -35,7 +35,7 @@ export class NodeApi {
data: undefined,
};
try {
const resultNode = await Scene.createNodeByType(options as ICreateByNodeTypeParams);
const resultNode = await Scene.Node.createByType(options as ICreateByNodeTypeParams);
if (resultNode) {
ret.data = resultNode;
}
Expand All @@ -62,7 +62,7 @@ export class NodeApi {
data: undefined,
};
try {
const resultNode = await Scene.createNodeByAsset(options);
const resultNode = await Scene.Node.createByAsset(options);
if (resultNode) {
ret.data = resultNode;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export class NodeApi {
};

try {
const result = await Scene.deleteNode(options);
const result = await Scene.Node.delete(options);
if (!result) throw new Error(`node not found at path: ${options.path}`);
ret.data = {
path: result.path,
Expand All @@ -114,7 +114,7 @@ export class NodeApi {
@result(SchemaNodeUpdateResult)
async updateNode(@param(SchemaNodeUpdate) options: TUpdateNodeOptions): Promise<CommonResultType<TNodeUpdateResult>> {
try {
const data = await Scene.updateNode(options);
const data = await Scene.Node.update(options);
return {
data: data,
code: COMMON_STATUS.SUCCESS,
Expand Down Expand Up @@ -142,7 +142,7 @@ export class NodeApi {
};

try {
const result = await Scene.queryNode(options);
const result = await Scene.Node.query(options) as INodeInfo | null;
if (!result) throw new Error(`node not found at path: ${options.path}`);
ret.data = result;
} catch (e) {
Expand Down
15 changes: 12 additions & 3 deletions src/core/base/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class I18n {
return i18nextInstance.t(key, obj);
}
/**
* 翻译 title
* @param title 原始 title 或者带有 i18n 开头的 title
* 翻译 name
* @param name 原始 name 或者带有 i18n 开头的 name
*/
transI18nName(name: string): string {
if (!name || typeof name !== 'string') {
Expand All @@ -49,12 +49,21 @@ class I18n {
return name;
}
if (!i18nextInstance.exists(key)) {
console.debug(`${name} is not defined in i18n`);
// 引擎大部分都没翻译,这样会导致每次调用获取节点信息会答应大量的debug信息,这里暂时去掉。
// console.debug(`${name} is not defined in i18n`);
return name;
}
return i18nextInstance.t(key) || name;
}

batchTransI18nName(names: string[]): Record<string, string> {
const result: Record<string, string> = {};
for (const name of names) {
result[name] = this.transI18nName(name);
}
return result;
}

/**
* 动态注册语言包的补丁内容
* @param language 语言代码,例如 zh、en
Expand Down
19 changes: 19 additions & 0 deletions src/core/scene/common/cli/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IComponentIdentifier } from '../component';
import type { IPropertyValueType } from '../../@types/public';
import type { ICompPrefabInfo } from '../prefab';

export interface IComponentInfo extends IComponentIdentifier {
properties: { [key: string]: IPropertyValueType };
prefab: ICompPrefabInfo | null;
}

/**
* CLI 设置组件属性的选项
*/
export interface ISetPropertyOptionsInfo {
componentPath: string;
properties: {
[key: string]: null | undefined | number | boolean | string | object | Array<unknown>;
};
record?: boolean;
}
4 changes: 4 additions & 0 deletions src/core/scene/common/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './node';
export * from './component';
export * from './scene';
export * from './prefab';
17 changes: 17 additions & 0 deletions src/core/scene/common/cli/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { INodeProperties } from '../node';
import type { IComponentInfo } from './component';
import type { IComponentIdentifier } from '../component';
import type { IPrefabInfo } from './prefab';

export interface INodeIdentifier {
nodeId: string;
path: string;
name: string;
}

export interface INodeInfo extends INodeIdentifier {
properties: INodeProperties;
components?: IComponentInfo[] | IComponentIdentifier[];
children?: INodeInfo[];
prefab: IPrefabInfo | null;
}
63 changes: 63 additions & 0 deletions src/core/scene/common/cli/prefab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { INodeIdentifier } from './node';
import type { IComponentIdentifier } from '../component';

export enum OptimizationPolicy {
AUTO = 0,
SINGLE_INSTANCE = 1,
MULTI_INSTANCE = 2,
}

export interface IPrefabInstance {
fileId: string;
prefabRootNode?: INodeIdentifier;
mountedChildren: IMountedChildrenInfo[];
mountedComponents: IMountedComponentsInfo[];
propertyOverrides: IPropertyOverrideInfo[];
removedComponents: ITargetInfo[];
}

export interface IMountedChildrenInfo {
targetInfo: ITargetInfo | null;
nodes: INodeIdentifier[];
}

export interface IPropertyOverrideInfo {
targetInfo: ITargetInfo | null;
propertyPath: string[];
value?: any;
}

export interface ITargetInfo {
localID: string[];
}

export interface IMountedComponentsInfo {
targetInfo: ITargetInfo | null;
components: IComponentIdentifier[];
}

export interface ITargetOverrideDetail {
source: IComponentIdentifier | INodeIdentifier | null;
sourceInfo: ITargetInfo | null;
propertyPath: string[];
target: INodeIdentifier | null;
targetInfo: ITargetInfo | null;
}

export interface IPrefabDetail {
name: string;
uuid: string;
data: INodeIdentifier,
optimizationPolicy: OptimizationPolicy,
persistent: boolean,
}

export interface IPrefabInfo {
/** 关联的预制体资源信息 */
asset?: IPrefabDetail;
root?: INodeIdentifier;
instance?: IPrefabInstance;
fileId: string;
targetOverrides: ITargetOverrideDetail[];
nestedPrefabInstanceRoots: INodeIdentifier[];
}
11 changes: 11 additions & 0 deletions src/core/scene/common/cli/scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { INodeInfo } from './node';
import type { IComponentIdentifier } from '../component';
import type { IBaseIdentifier } from '../editor/base';
import type { IPrefabInfo } from './prefab';

export interface ISceneInfo extends IBaseIdentifier {
name: string;
prefab: IPrefabInfo | null;
children: INodeInfo[];
components: IComponentIdentifier[];
}
Loading
Loading