Skip to content

Commit b6ff0d8

Browse files
authored
[break]Feat(scene): add hierarchy node operations (setParent, reorder, copy/paste/duplicate/cut) (cocos#582)
1 parent d3ff9d4 commit b6ff0d8

16 files changed

Lines changed: 1602 additions & 579 deletions

File tree

packages/cocos-cli-types/__tests__/__snapshots__/dts-snapshot.test.ts.snap

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5317,6 +5317,7 @@ export declare interface IBaseCreateNodeParams {
53175317
position?: IVec3;
53185318
keepWorldTransform?: boolean;
53195319
canvasRequired?: boolean;
5320+
unlinkPrefab?: boolean;
53205321
}
53215322
export declare interface IBaseIdentifier {
53225323
assetName: string;
@@ -5361,6 +5362,11 @@ export declare interface ICameraService {
53615362
setOriginAxes3D(config: IOriginAxesConfig): void;
53625363
onUpdate(deltaTime: number): void;
53635364
}
5365+
export declare interface IChangeNodeLockParams {
5366+
paths: string[];
5367+
locked: boolean;
5368+
loop?: boolean;
5369+
}
53645370
export declare interface IChangeNodeOptions {
53655371
source?: 'editor' | 'undo' | 'engine';
53665372
type?: NodeEventType;
@@ -5373,6 +5379,10 @@ export declare interface ICLI {
53735379
Scene: IServiceManager;
53745380
SceneEvents: GlobalEventManager;
53755381
}
5382+
export declare interface IClipboardState {
5383+
type: 'cut' | 'copy' | 'none';
5384+
paths: string[];
5385+
}
53765386
export declare interface ICloseOptions {
53775387
urlOrUUID?: string;
53785388
}
@@ -5406,6 +5416,9 @@ export declare interface IComponentService extends IServiceEvents {
54065416
init(): void;
54075417
unregisterCompMgrEvents(): void;
54085418
}
5419+
export declare interface ICopyParams {
5420+
paths: string[];
5421+
}
54095422
export declare interface ICreateByAssetParams extends IBaseCreateNodeParams {
54105423
dbURL: string;
54115424
}
@@ -5424,13 +5437,19 @@ export declare interface ICreatePrefabFromNodeParams {
54245437
overwrite?: boolean;
54255438
}
54265439
export declare type ICreateType = typeof CREATE_TYPES[number];
5440+
export declare interface ICutParams {
5441+
paths: string[];
5442+
}
54275443
export declare interface IDeleteNodeParams {
54285444
path: string;
54295445
keepWorldTransform?: boolean;
54305446
}
54315447
export declare interface IDeleteNodeResult {
54325448
path: string;
54335449
}
5450+
export declare interface IDuplicateParams {
5451+
paths: string[];
5452+
}
54345453
export declare interface IEditorService extends IServiceEvents {
54355454
getCurrentEditorType(): 'scene' | 'prefab' | 'unknown';
54365455
open(params: IOpenOptions): Promise<TEditorEntity>;
@@ -5529,6 +5548,12 @@ export declare interface ImageMeta {
55295548
uri?: string;
55305549
remap?: string;
55315550
}
5551+
export declare interface IMoveArrayElementParams {
5552+
nodePath: string;
5553+
path: string;
5554+
target: number;
5555+
offset: number;
5556+
}
55325557
export declare interface INode {
55335558
path: string;
55345559
active: IProperty;
@@ -5563,6 +5588,16 @@ export declare interface INodeService extends IServiceEvents {
55635588
updatePropertyFromNull(options: ISetPropertyOptions): Promise<boolean>;
55645589
setNodeAndChildrenLayer(options: ISetPropertyOptions): Promise<void>;
55655590
getPathByUuid(uuid: string): string;
5591+
setParent(params: ISetParentParams): Promise<string[]>;
5592+
reorder(params: IReorderParams): Promise<boolean>;
5593+
copy(params: ICopyParams): Promise<string[]>;
5594+
paste(params: IPasteParams): Promise<string[]>;
5595+
duplicate(params: IDuplicateParams): Promise<string[]>;
5596+
cut(params: ICutParams): Promise<string[]>;
5597+
queryClipboardState(): Promise<IClipboardState>;
5598+
moveArrayElement(params: IMoveArrayElementParams): Promise<boolean>;
5599+
removeArrayElement(params: IRemoveArrayElementParams): Promise<boolean>;
5600+
changeNodeLock(params: IChangeNodeLockParams): Promise<void>;
55665601
}
55675602
export declare interface INodeTreeComponent {
55685603
isCustom: boolean;
@@ -5602,6 +5637,10 @@ export declare interface IOriginAxesConfig {
56025637
y: boolean;
56035638
z: boolean;
56045639
}
5640+
export declare interface IPasteParams {
5641+
parentPath?: string;
5642+
keepWorldTransform?: boolean;
5643+
}
56055644
export declare interface IPrefab {
56065645
uuid: string;
56075646
fileId: string;
@@ -5618,6 +5657,7 @@ export declare interface IPrefabService extends IServiceEvents {
56185657
unpackPrefabInstance(params: IUnpackPrefabInstanceParams): Promise<INode>;
56195658
isPrefabInstance(params: IIsPrefabInstanceParams): Promise<boolean>;
56205659
getPrefabInfo(params: IGetPrefabInfoParams): Promise<IPrefab | null>;
5660+
unlinkPrefab(params: IUnlinkPrefabParams): Promise<boolean>;
56215661
removePrefabInfoFromNode(node: Node_2, removeNested?: boolean): void;
56225662
}
56235663
export declare interface IPrefabStateInfo {
@@ -5702,13 +5742,23 @@ export declare interface IRedirectInfo {
57025742
export declare interface IReloadOptions {
57035743
urlOrUUID?: string;
57045744
}
5745+
export declare interface IRemoveArrayElementParams {
5746+
nodePath: string;
5747+
path: string;
5748+
index: number;
5749+
}
57055750
export declare interface IRemoveComponentOptions {
57065751
path: string;
57075752
}
57085753
export declare interface IRemovedComponentInfo {
57095754
name: string;
57105755
fileID: string;
57115756
}
5757+
export declare interface IReorderParams {
5758+
path: string;
5759+
target: number;
5760+
offset: number;
5761+
}
57125762
export declare interface IRevertToPrefabParams {
57135763
nodePath: string;
57145764
}
@@ -5830,6 +5880,11 @@ export declare interface IServiceManager {
58305880
SceneView: ISceneViewService;
58315881
UI: IUIService;
58325882
}
5883+
export declare interface ISetParentParams {
5884+
paths: string[];
5885+
parentPath: string;
5886+
keepWorldTransform?: boolean;
5887+
}
58335888
export declare interface ISetPropertyOptions {
58345889
nodePath: string;
58355890
path: string;
@@ -5874,6 +5929,10 @@ export declare interface IUndoService {
58745929
reset(): void;
58755930
isDirty(): boolean;
58765931
}
5932+
export declare interface IUnlinkPrefabParams {
5933+
nodePath: string;
5934+
removeNested?: boolean;
5935+
}
58775936
export declare interface IUnpackPrefabInstanceParams {
58785937
nodePath: string;
58795938
recursive?: boolean;
@@ -7209,6 +7268,7 @@ export declare interface IBaseCreateNodeParams {
72097268
position?: IVec3;
72107269
keepWorldTransform?: boolean;
72117270
canvasRequired?: boolean;
7271+
unlinkPrefab?: boolean;
72127272
}
72137273
export declare interface IBaseIdentifier {
72147274
assetName: string;
@@ -7253,6 +7313,11 @@ export declare interface ICameraService {
72537313
setOriginAxes3D(config: IOriginAxesConfig): void;
72547314
onUpdate(deltaTime: number): void;
72557315
}
7316+
export declare interface IChangeNodeLockParams {
7317+
paths: string[];
7318+
locked: boolean;
7319+
loop?: boolean;
7320+
}
72567321
export declare interface IChangeNodeOptions {
72577322
source?: 'editor' | 'undo' | 'engine';
72587323
type?: NodeEventType;
@@ -7269,6 +7334,10 @@ export declare interface ICLI {
72697334
Scene: IServiceManager;
72707335
SceneEvents: GlobalEventManager;
72717336
}
7337+
export declare interface IClipboardState {
7338+
type: 'cut' | 'copy' | 'none';
7339+
paths: string[];
7340+
}
72727341
export declare interface ICloseOptions {
72737342
urlOrUUID?: string;
72747343
}
@@ -7331,6 +7400,9 @@ export declare interface IComponentService extends IServiceEvents {
73317400
export declare interface IConfiguration {
73327401
[key: string]: any;
73337402
}
7403+
export declare interface ICopyParams {
7404+
paths: string[];
7405+
}
73347406
export declare interface ICreateByAssetParams extends IBaseCreateNodeParams {
73357407
dbURL: string;
73367408
}
@@ -7374,6 +7446,9 @@ export declare interface ICustomJointTextureLayout {
73747446
textureLength: number;
73757447
contents: IChunkContent[];
73767448
}
7449+
export declare interface ICutParams {
7450+
paths: string[];
7451+
}
73777452
export declare type IDefaultConfig = {
73787453
key: IDefaultConfigKeys;
73797454
name: string;
@@ -7404,6 +7479,9 @@ export declare interface IDisplayModuleItem extends IFeatureItem {
74047479
_option?: string;
74057480
options?: Record<string, IDisplayModuleItem>;
74067481
}
7482+
export declare interface IDuplicateParams {
7483+
paths: string[];
7484+
}
74077485
export declare interface IEditorService extends IServiceEvents {
74087486
getCurrentEditorType(): 'scene' | 'prefab' | 'unknown';
74097487
open(params: IOpenOptions): Promise<TEditorEntity>;
@@ -7581,6 +7659,12 @@ export declare interface IModuleConfig {
75817659
}
75827660
export declare type IModuleItem = IFeatureItem | IFeatureGroup;
75837661
export declare type IModules = Record<string, IModuleItem>;
7662+
export declare interface IMoveArrayElementParams {
7663+
nodePath: string;
7664+
path: string;
7665+
target: number;
7666+
offset: number;
7667+
}
75847668
export declare function importAsset(source: string, target: string, options?: AssetOperationOption): Promise<IAssetInfo[]>;
75857669
export declare interface ImportMap {
75867670
imports?: Record<string, string>;
@@ -7629,6 +7713,16 @@ export declare interface INodeService extends IServiceEvents {
76297713
updatePropertyFromNull(options: ISetPropertyOptions): Promise<boolean>;
76307714
setNodeAndChildrenLayer(options: ISetPropertyOptions): Promise<void>;
76317715
getPathByUuid(uuid: string): string;
7716+
setParent(params: ISetParentParams): Promise<string[]>;
7717+
reorder(params: IReorderParams): Promise<boolean>;
7718+
copy(params: ICopyParams): Promise<string[]>;
7719+
paste(params: IPasteParams): Promise<string[]>;
7720+
duplicate(params: IDuplicateParams): Promise<string[]>;
7721+
cut(params: ICutParams): Promise<string[]>;
7722+
queryClipboardState(): Promise<IClipboardState>;
7723+
moveArrayElement(params: IMoveArrayElementParams): Promise<boolean>;
7724+
removeArrayElement(params: IRemoveArrayElementParams): Promise<boolean>;
7725+
changeNodeLock(params: IChangeNodeLockParams): Promise<void>;
76327726
}
76337727
export declare interface INodeTreeComponent {
76347728
isCustom: boolean;
@@ -7668,6 +7762,10 @@ export declare interface IOriginAxesConfig {
76687762
y: boolean;
76697763
z: boolean;
76707764
}
7765+
export declare interface IPasteParams {
7766+
parentPath?: string;
7767+
keepWorldTransform?: boolean;
7768+
}
76717769
export declare interface IPhysicsConfig {
76727770
gravity: IVec3Like;
76737771
allowSleep: boolean;
@@ -7711,6 +7809,7 @@ export declare interface IPrefabService extends IServiceEvents {
77117809
unpackPrefabInstance(params: IUnpackPrefabInstanceParams): Promise<INode>;
77127810
isPrefabInstance(params: IIsPrefabInstanceParams): Promise<boolean>;
77137811
getPrefabInfo(params: IGetPrefabInfoParams): Promise<IPrefab | null>;
7812+
unlinkPrefab(params: IUnlinkPrefabParams): Promise<boolean>;
77147813
removePrefabInfoFromNode(node: Node_2, removeNested?: boolean): void;
77157814
}
77167815
export declare interface IPrefabStateInfo {
@@ -7808,13 +7907,23 @@ export declare interface IRedirectInfo {
78087907
export declare interface IReloadOptions {
78097908
urlOrUUID?: string;
78107909
}
7910+
export declare interface IRemoveArrayElementParams {
7911+
nodePath: string;
7912+
path: string;
7913+
index: number;
7914+
}
78117915
export declare interface IRemoveComponentOptions {
78127916
path: string;
78137917
}
78147918
export declare interface IRemovedComponentInfo {
78157919
name: string;
78167920
fileID: string;
78177921
}
7922+
export declare interface IReorderParams {
7923+
path: string;
7924+
target: number;
7925+
offset: number;
7926+
}
78187927
export declare interface IRevertToPrefabParams {
78197928
nodePath: string;
78207929
}
@@ -7936,6 +8045,11 @@ export declare interface IServiceManager {
79368045
SceneView: ISceneViewService;
79378046
UI: IUIService;
79388047
}
8048+
export declare interface ISetParentParams {
8049+
paths: string[];
8050+
parentPath: string;
8051+
keepWorldTransform?: boolean;
8052+
}
79398053
export declare interface ISetPropertyOptions {
79408054
nodePath: string;
79418055
path: string;
@@ -8027,6 +8141,10 @@ export declare interface IUndoService {
80278141
reset(): void;
80288142
isDirty(): boolean;
80298143
}
8144+
export declare interface IUnlinkPrefabParams {
8145+
nodePath: string;
8146+
removeNested?: boolean;
8147+
}
80308148
export declare interface IUnpackPrefabInstanceParams {
80318149
nodePath: string;
80328150
recursive?: boolean;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 记录并管理执行过程中在 globalThis 上新增的属性,
3+
* 在下一次 record 时自动清理上次新增的属性。
4+
*/
5+
export class GlobalEnv {
6+
public async record(fn: () => Promise<void>) {
7+
this.clear();
8+
this._queue.push(async () => {
9+
const beforeKeys = Object.keys(globalThis);
10+
await fn();
11+
const afterKeys = Object.keys(globalThis);
12+
for (const afterKey of afterKeys) {
13+
if (!beforeKeys.includes(afterKey)) {
14+
this._incrementalKeys.add(afterKey);
15+
}
16+
}
17+
});
18+
await this.processQueue();
19+
}
20+
21+
private clear() {
22+
this._queue.push(async () => {
23+
for (const incrementalKey of this._incrementalKeys) {
24+
delete (globalThis as any)[incrementalKey];
25+
}
26+
this._incrementalKeys.clear();
27+
});
28+
}
29+
30+
private async processQueue() {
31+
while (this._queue.length > 0) {
32+
const next = this._queue.shift();
33+
if (next) await next();
34+
}
35+
}
36+
37+
private _incrementalKeys = new Set<string>();
38+
private _queue: (() => Promise<void>)[] = [];
39+
}

0 commit comments

Comments
 (0)