From 1846d6461328e0a2c5b826f6320571a88dc3c159 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 16:21:00 +0800 Subject: [PATCH 1/7] fix type --- cocos/animation/marionette/pose-graph/instantiation.ts | 4 ++-- cocos/serialization/deserialize-dynamic.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/animation/marionette/pose-graph/instantiation.ts b/cocos/animation/marionette/pose-graph/instantiation.ts index ff33b011e1f..0b1db72ed13 100644 --- a/cocos/animation/marionette/pose-graph/instantiation.ts +++ b/cocos/animation/marionette/pose-graph/instantiation.ts @@ -125,9 +125,9 @@ export interface PoseNodeDependencyEvaluation { evaluate(): void; } -function instantiateNode ( +function instantiateNode ( graph: PoseGraph, - node: TNode, + node: EvaluatableNode, instantiationMap: Map, linkContext: PureValueNodeLinkContext, ): RuntimeNodeEvaluation { diff --git a/cocos/serialization/deserialize-dynamic.ts b/cocos/serialization/deserialize-dynamic.ts index 19e1aeb5769..59befaa24bc 100644 --- a/cocos/serialization/deserialize-dynamic.ts +++ b/cocos/serialization/deserialize-dynamic.ts @@ -865,8 +865,8 @@ export function deserializeDynamic (data: SerializedData | CCON, details: Detail return res; } -export function parseUuidDependenciesDynamic (serialized: unknown): never[] { - const depends = []; +export function parseUuidDependenciesDynamic (serialized: unknown): string[] { + const depends: string[] = []; const parseDependRecursively = (data: any, out: string[]): void => { if (!data || typeof data !== 'object' || typeof data.__id__ === 'number') { return; } const uuid = data.__uuid__; From a4c31d30ff9f5fa82ba69b2c62191e6da1e68d9f Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 16:21:10 +0800 Subject: [PATCH 2/7] fix readonly fix readonly --- cocos/animation/marionette/animation-controller.ts | 4 ++-- cocos/animation/marionette/graph-eval.ts | 4 ++-- .../marionette/state-machine/state-machine-eval.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cocos/animation/marionette/animation-controller.ts b/cocos/animation/marionette/animation-controller.ts index 12a3e1e0ff2..1a7d5edf757 100644 --- a/cocos/animation/marionette/animation-controller.ts +++ b/cocos/animation/marionette/animation-controller.ts @@ -226,7 +226,7 @@ export class AnimationController extends Component { * An empty iterable is returned if current state is not a motion state. * @zh 到动画剪辑运作状态的迭代器。若当前状态不是动画状态,则返回一个空的迭代器。 */ - public getCurrentClipStatuses (layer: number): Iterable> { + public getCurrentClipStatuses (layer: number): Readonly> { const { _graphEval: graphEval } = this; assertIsNonNullable(graphEval); return graphEval.getCurrentClipStatuses(layer); @@ -266,7 +266,7 @@ export class AnimationController extends Component { * An empty iterable is returned in case of no transition or next state is not a motion state. * @zh 到下一状态上包含的动画剪辑运作状态的迭代器,若未在进行过渡或下一状态不是动画状态,则返回一个空的迭代器。 */ - public getNextClipStatuses (layer: number): Iterable> { + public getNextClipStatuses (layer: number): Readonly> { const { _graphEval: graphEval } = this; assertIsNonNullable(graphEval); return graphEval.getNextClipStatuses(layer); diff --git a/cocos/animation/marionette/graph-eval.ts b/cocos/animation/marionette/graph-eval.ts index 52558d27d7f..1b8f4668173 100644 --- a/cocos/animation/marionette/graph-eval.ts +++ b/cocos/animation/marionette/graph-eval.ts @@ -169,7 +169,7 @@ export class AnimationGraphEval { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentStateStatus(); } - public getCurrentClipStatuses (layer: number): Iterable> { + public getCurrentClipStatuses (layer: number): Readonly> { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentClipStatuses(); } @@ -185,7 +185,7 @@ export class AnimationGraphEval { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextStateStatus(); } - public getNextClipStatuses (layer: number): Iterable> { + public getNextClipStatuses (layer: number): Readonly> { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextClipStatuses(); } diff --git a/cocos/animation/marionette/state-machine/state-machine-eval.ts b/cocos/animation/marionette/state-machine/state-machine-eval.ts index 7a794dd1e8d..12459639ab4 100644 --- a/cocos/animation/marionette/state-machine/state-machine-eval.ts +++ b/cocos/animation/marionette/state-machine/state-machine-eval.ts @@ -196,7 +196,7 @@ class TopLevelStateMachineEvaluation { } } - public getCurrentClipStatuses (): Iterable { + public getCurrentClipStatuses (): Readonly> { const { _currentNode: currentNode } = this; if (currentNode.kind === NodeKind.animation) { return currentNode.getClipStatuses(currentNode.absoluteWeight); @@ -237,7 +237,7 @@ class TopLevelStateMachineEvaluation { return null; } - public getNextClipStatuses (): Iterable { + public getNextClipStatuses (): Readonly> { const { _activatedTransitions: activatedTransitions } = this; if (activatedTransitions.length === 0) { return emptyClipStatusesIterable; @@ -995,7 +995,7 @@ const emptyClipStatusesIterator: Readonly> = Object.freeze( }, }); -const emptyClipStatusesIterable: Iterable = Object.freeze({ +const emptyClipStatusesIterable: Readonly> = Object.freeze({ [Symbol.iterator] () { return emptyClipStatusesIterator; }, @@ -1286,7 +1286,7 @@ class VMSMEval { this._privateState.addTransition(transition); } - public getClipStatuses (baseWeight: number): Iterable { + public getClipStatuses (baseWeight: number): Readonly> { const { _source: source } = this; if (!source) { return emptyClipStatusesIterable; @@ -1357,7 +1357,7 @@ class VMSMInternalState extends EventifiedStateEval { return stateStatus; } - public getClipStatuses (baseWeight: number): Iterable { + public getClipStatuses (baseWeight: number): Readonly> { return this._container.getClipStatuses(baseWeight); } From 20d6dfdf616d1589eb3fba28ba41d19bea1391b5 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 16:28:44 +0800 Subject: [PATCH 3/7] fix get/set type --- .../components/character-controllers/character-controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/physics/framework/components/character-controllers/character-controller.ts b/cocos/physics/framework/components/character-controllers/character-controller.ts index eeb13cd5a8f..74a98241ca5 100644 --- a/cocos/physics/framework/components/character-controllers/character-controller.ts +++ b/cocos/physics/framework/components/character-controllers/character-controller.ts @@ -203,7 +203,7 @@ export class CharacterController extends Eventify(Component) { return this._center; } - public set center (value: Vec3) { + public set center (value: Readonly) { if (Vec3.equals(this._center, value)) return; Vec3.copy(this._center, value); // if (this._cct) { //update cct position @@ -312,7 +312,7 @@ export class CharacterController extends Eventify(Component) { * @zh * 设置中心的世界坐标。 */ - public set centerWorldPosition (value: Vec3) { + public set centerWorldPosition (value: Readonly) { if (this._isInitialized) this._cct!.setPosition(value); } From aa0fe66aa53c787bd51f50da33505c5dd1c9edf7 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 16:39:05 +0800 Subject: [PATCH 4/7] fix switch type --- cocos/animation/marionette/variable/index.ts | 4 ++-- cocos/animation/marionette/variable/primitive-variable.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/animation/marionette/variable/index.ts b/cocos/animation/marionette/variable/index.ts index bbe24f1e327..4a7647a7e43 100644 --- a/cocos/animation/marionette/variable/index.ts +++ b/cocos/animation/marionette/variable/index.ts @@ -23,7 +23,7 @@ */ import { VariableType, VariableTypeValueTypeMap, VarInstanceBase } from './basic'; -import { PlainVariable } from './primitive-variable'; +import { PlainVariable, PlainVariableType } from './primitive-variable'; import { TriggerVariable } from './trigger-variable'; import { Vec3Variable } from './vec3-variable'; import { QuatVariable } from './quat-variable'; @@ -50,7 +50,7 @@ export function createVariable ( case VariableType.FLOAT: case VariableType.INTEGER: case VariableType.BOOLEAN: - variable = new PlainVariable(type); + variable = new PlainVariable(type as PlainVariableType); break; case VariableType.TRIGGER: variable = new TriggerVariable(); diff --git a/cocos/animation/marionette/variable/primitive-variable.ts b/cocos/animation/marionette/variable/primitive-variable.ts index 8a166bc0077..7bf833388e3 100644 --- a/cocos/animation/marionette/variable/primitive-variable.ts +++ b/cocos/animation/marionette/variable/primitive-variable.ts @@ -3,7 +3,7 @@ import { assertIsTrue } from '../../../core'; import { ccclass, serializable } from '../../../core/data/decorators'; import { BasicVariableDescription, VariableType, createInstanceTag, VarInstanceBase, Value } from './basic'; -type PlainVariableType = VariableType.FLOAT | VariableType.INTEGER | VariableType.BOOLEAN; +export type PlainVariableType = VariableType.FLOAT | VariableType.INTEGER | VariableType.BOOLEAN; @ccclass('cc.animation.PlainVariable') export class PlainVariable { From c43543fa0392cd8121e296f782144e0385ae7969 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 17:32:12 +0800 Subject: [PATCH 5/7] fix eslint --- cocos/serialization/deserialize-dynamic.ts | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/cocos/serialization/deserialize-dynamic.ts b/cocos/serialization/deserialize-dynamic.ts index 59befaa24bc..c8dcd8d27c6 100644 --- a/cocos/serialization/deserialize-dynamic.ts +++ b/cocos/serialization/deserialize-dynamic.ts @@ -85,12 +85,12 @@ type AttributeFormerlySerializedAs = `${AttributeName}${typeof POSTFIX_FORMERLY_ type AttributeDefault = `${AttributeName}${typeof POSTFIX_DEFAULT}`; type AttributeType = `${AttributeName}${typeof POSTFIX_TYPE}`; type AttributeEditorOnly = `${AttributeName}${typeof POSTFIX_EDITOR_ONLY}`; -type AttrResult = { +interface AttrResult { [K: string]: typeof K extends AttributeFormerlySerializedAs ? string : typeof K extends AttributeDefault ? unknown : typeof K extends AttributeType ? AnyFunction : typeof K extends AttributeEditorOnly ? boolean : never; -}; +} function compileDeserializeJIT (self: _Deserializer, klass: CCClassConstructor): CompiledDeserializeFn { const attrs: AttrResult = CCClass.Attr.getClassAttrs(klass); @@ -287,22 +287,22 @@ type TypedArrayViewConstructorName = | 'Uint32Array' | 'Int32Array' | 'Float32Array' | 'Float64Array'; -type SerializedTypedArray = { +interface SerializedTypedArray { __id__: never; __uuid__: never; __type__: 'TypedArray'; array: number[]; ctor: TypedArrayViewConstructorName; -}; +} -type SerializedTypedArrayRef = { +interface SerializedTypedArrayRef { __id__: never; __uuid__: never; __type__: 'TypedArrayRef'; ctor: TypedArrayViewConstructorName; offset: number; length: number; -}; +} type SerializedGeneralTypedObject = { __id__: never; @@ -310,18 +310,18 @@ type SerializedGeneralTypedObject = { __type__?: NotKnownTypeTag; } & Record; -type SerializedObjectReference = { +interface SerializedObjectReference { __type__: never; __uuid__: never; __id__: number; } -type SerializedUUIDReference = { +interface SerializedUUIDReference { __type__: never; __id__: never; __uuid__: string; __expectedType__: string; -}; +} type SerializedObject = SerializedTypedArray | SerializedTypedArrayRef | SerializedGeneralTypedObject; @@ -588,12 +588,10 @@ class _Deserializer { return; } - // cSpell:words Deserializable - - type ClassicCustomizedDeserializable = { _deserialize: (content: unknown, deserializer: _Deserializer) => void; }; + interface ClassicCustomizedDeserializable { _deserialize: (content: unknown, deserializer: _Deserializer) => void; } if ((object as Partial)._deserialize) { // TODO: content check? - (object as ClassicCustomizedDeserializable)._deserialize((value as unknown as { content: unknown }).content, this); + (object as Partial)._deserialize!((value as unknown as { content: unknown }).content, this); return; } @@ -767,18 +765,18 @@ class _Deserializer { klass: SerializableClassConstructor, ): void { if (klass === cclegacy.Vec2) { - type SerializedVec2 = { x?: number; y?: number; }; + interface SerializedVec2 { x?: number; y?: number; } instance.x = (serialized as SerializedVec2).x || 0; instance.y = (serialized as SerializedVec2).y || 0; return; } else if (klass === cclegacy.Vec3) { - type SerializedVec3 = { x?: number; y?: number; z?: number; }; + interface SerializedVec3 { x?: number; y?: number; z?: number; } instance.x = (serialized as SerializedVec3).x || 0; instance.y = (serialized as SerializedVec3).y || 0; instance.z = (serialized as SerializedVec3).z || 0; return; } else if (klass === cclegacy.Color) { - type SerializedColor = { r?: number; g?: number; b?: number; a?: number; }; + interface SerializedColor { r?: number; g?: number; b?: number; a?: number; } instance.r = (serialized as SerializedColor).r || 0; instance.g = (serialized as SerializedColor).g || 0; instance.b = (serialized as SerializedColor).b || 0; @@ -786,7 +784,7 @@ class _Deserializer { instance.a = (a === undefined ? 255 : a); return; } else if (klass === cclegacy.Size) { - type SerializedSize = { width?: number; height?: number; }; + interface SerializedSize { width?: number; height?: number; } instance.width = (serialized as SerializedSize).width || 0; instance.height = (serialized as SerializedSize).height || 0; return; From 171da01fee49ffde9bc8a43bf0c81f16d489a356 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 27 Jun 2023 14:40:29 +0800 Subject: [PATCH 6/7] update --- cocos/animation/marionette/animation-controller.ts | 4 ++-- cocos/animation/marionette/graph-eval.ts | 4 ++-- .../marionette/state-machine/state-machine-eval.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cocos/animation/marionette/animation-controller.ts b/cocos/animation/marionette/animation-controller.ts index 1a7d5edf757..12a3e1e0ff2 100644 --- a/cocos/animation/marionette/animation-controller.ts +++ b/cocos/animation/marionette/animation-controller.ts @@ -226,7 +226,7 @@ export class AnimationController extends Component { * An empty iterable is returned if current state is not a motion state. * @zh 到动画剪辑运作状态的迭代器。若当前状态不是动画状态,则返回一个空的迭代器。 */ - public getCurrentClipStatuses (layer: number): Readonly> { + public getCurrentClipStatuses (layer: number): Iterable> { const { _graphEval: graphEval } = this; assertIsNonNullable(graphEval); return graphEval.getCurrentClipStatuses(layer); @@ -266,7 +266,7 @@ export class AnimationController extends Component { * An empty iterable is returned in case of no transition or next state is not a motion state. * @zh 到下一状态上包含的动画剪辑运作状态的迭代器,若未在进行过渡或下一状态不是动画状态,则返回一个空的迭代器。 */ - public getNextClipStatuses (layer: number): Readonly> { + public getNextClipStatuses (layer: number): Iterable> { const { _graphEval: graphEval } = this; assertIsNonNullable(graphEval); return graphEval.getNextClipStatuses(layer); diff --git a/cocos/animation/marionette/graph-eval.ts b/cocos/animation/marionette/graph-eval.ts index 1b8f4668173..52558d27d7f 100644 --- a/cocos/animation/marionette/graph-eval.ts +++ b/cocos/animation/marionette/graph-eval.ts @@ -169,7 +169,7 @@ export class AnimationGraphEval { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentStateStatus(); } - public getCurrentClipStatuses (layer: number): Readonly> { + public getCurrentClipStatuses (layer: number): Iterable> { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentClipStatuses(); } @@ -185,7 +185,7 @@ export class AnimationGraphEval { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextStateStatus(); } - public getNextClipStatuses (layer: number): Readonly> { + public getNextClipStatuses (layer: number): Iterable> { return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextClipStatuses(); } diff --git a/cocos/animation/marionette/state-machine/state-machine-eval.ts b/cocos/animation/marionette/state-machine/state-machine-eval.ts index 12459639ab4..0be176f5542 100644 --- a/cocos/animation/marionette/state-machine/state-machine-eval.ts +++ b/cocos/animation/marionette/state-machine/state-machine-eval.ts @@ -196,7 +196,7 @@ class TopLevelStateMachineEvaluation { } } - public getCurrentClipStatuses (): Readonly> { + public getCurrentClipStatuses (): Iterable> { const { _currentNode: currentNode } = this; if (currentNode.kind === NodeKind.animation) { return currentNode.getClipStatuses(currentNode.absoluteWeight); @@ -237,7 +237,7 @@ class TopLevelStateMachineEvaluation { return null; } - public getNextClipStatuses (): Readonly> { + public getNextClipStatuses (): Iterable> { const { _activatedTransitions: activatedTransitions } = this; if (activatedTransitions.length === 0) { return emptyClipStatusesIterable; @@ -995,7 +995,7 @@ const emptyClipStatusesIterator: Readonly> = Object.freeze( }, }); -const emptyClipStatusesIterable: Readonly> = Object.freeze({ +const emptyClipStatusesIterable: Iterable> = Object.freeze({ [Symbol.iterator] () { return emptyClipStatusesIterator; }, @@ -1286,7 +1286,7 @@ class VMSMEval { this._privateState.addTransition(transition); } - public getClipStatuses (baseWeight: number): Readonly> { + public getClipStatuses (baseWeight: number): Iterable> { const { _source: source } = this; if (!source) { return emptyClipStatusesIterable; @@ -1357,7 +1357,7 @@ class VMSMInternalState extends EventifiedStateEval { return stateStatus; } - public getClipStatuses (baseWeight: number): Readonly> { + public getClipStatuses (baseWeight: number): Iterable> { return this._container.getClipStatuses(baseWeight); } From 928d3621eb0a447daaaf3accb47bd2ee03bc8593 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 27 Jun 2023 15:30:28 +0800 Subject: [PATCH 7/7] optimize type in state-machine-eval --- .../marionette/state-machine/state-machine-eval.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cocos/animation/marionette/state-machine/state-machine-eval.ts b/cocos/animation/marionette/state-machine/state-machine-eval.ts index 0be176f5542..56114bff2a1 100644 --- a/cocos/animation/marionette/state-machine/state-machine-eval.ts +++ b/cocos/animation/marionette/state-machine/state-machine-eval.ts @@ -986,20 +986,21 @@ function createStateStatusCache (): MotionStateStatus { }; } -const emptyClipStatusesIterator: Readonly> = Object.freeze({ - next (..._args: [] | [undefined]): IteratorResult { +type ReadonlyClipStatus = Readonly; +const emptyClipStatusesIterator: Iterator = { + next (..._args: [] | [undefined]): IteratorResult { return { done: true, value: undefined, }; }, -}); +}; -const emptyClipStatusesIterable: Iterable> = Object.freeze({ +const emptyClipStatusesIterable: Iterable = { [Symbol.iterator] () { return emptyClipStatusesIterator; }, -}); +}; enum NodeKind { entry, exit, any, animation,