From 8a8a1230ba4e569437fca85a791029790be5934a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Thu, 29 Jul 2021 10:06:36 +0800 Subject: [PATCH] Rename TrackPath methods (#9086) --- cocos/core/animation/animation-clip.ts | 2 +- .../exotic-animation/exotic-animation.ts | 2 +- cocos/core/animation/legacy-clip-data.ts | 10 +++++----- cocos/core/animation/tracks/track.ts | 15 +++++++++------ tests/animation/animation-clip-3.x.test.ts | 6 +++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cocos/core/animation/animation-clip.ts b/cocos/core/animation/animation-clip.ts index 0d94cc20f0..163e0c16d1 100644 --- a/cocos/core/animation/animation-clip.ts +++ b/cocos/core/animation/animation-clip.ts @@ -107,7 +107,7 @@ export class AnimationClip extends Asset { clip.duration = spriteFrames.length / clip.sample; const step = 1 / clip.sample; const track = new ObjectTrack(); - track.path = new TrackPath().component('cc.Sprite').property('spriteFrame'); + track.path = new TrackPath().toComponent('cc.Sprite').toProperty('spriteFrame'); const curve = track.channels()[0].curve; curve.assignSorted(spriteFrames.map((spriteFrame, index) => [step * index, spriteFrame])); return clip; diff --git a/cocos/core/animation/exotic-animation/exotic-animation.ts b/cocos/core/animation/exotic-animation/exotic-animation.ts index 7ea71bbf56..cb68d3ffc5 100644 --- a/cocos/core/animation/exotic-animation/exotic-animation.ts +++ b/cocos/core/animation/exotic-animation/exotic-animation.ts @@ -785,7 +785,7 @@ function createExoticTrackEvaluationRecord ( binder: Binder, ) { const trackBinding = new TrackBinding(); - trackBinding.path = new TrackPath().hierarchy(path).property(property); + trackBinding.path = new TrackPath().toHierarchy(path).toProperty(property); const runtimeBinding = binder(trackBinding); if (!runtimeBinding) { return null; diff --git a/cocos/core/animation/legacy-clip-data.ts b/cocos/core/animation/legacy-clip-data.ts index d215e46896..ae2a795ad6 100644 --- a/cocos/core/animation/legacy-clip-data.ts +++ b/cocos/core/animation/legacy-clip-data.ts @@ -189,15 +189,15 @@ export class AnimationClipLegacyData { const trackPath = new TrackPath(); for (const modifier of modifiers) { if (typeof modifier === 'string') { - trackPath.property(modifier); + trackPath.toProperty(modifier); } else if (typeof modifier === 'number') { - trackPath.element(modifier); + trackPath.toElement(modifier); } else if (modifier instanceof HierarchyPath) { - trackPath.hierarchy(modifier.path); + trackPath.toHierarchy(modifier.path); } else if (modifier instanceof ComponentPath) { - trackPath.component(modifier.component); + trackPath.toComponent(modifier.component); } else { - trackPath.customized(modifier); + trackPath.toCustomized(modifier); } } track.path = trackPath; diff --git a/cocos/core/animation/tracks/track.ts b/cocos/core/animation/tracks/track.ts index 18982a0620..8ddb443404 100644 --- a/cocos/core/animation/tracks/track.ts +++ b/cocos/core/animation/tracks/track.ts @@ -150,28 +150,31 @@ class TrackPath { return this._paths.length; } - public property (name: string) { + public toProperty (name: string) { this._paths.push(name); return this; } - public element (index: number) { + public toElement (index: number) { this._paths.push(index); return this; } - public hierarchy (nodePath: string) { + public toHierarchy (nodePath: string) { this._paths.push(new HierarchyPath(nodePath)); return this; } - public component (constructor: Constructor | string) { + public toComponent (constructor: Constructor | string) { const path = new ComponentPath(typeof constructor === 'string' ? constructor : js.getClassName(constructor)); this._paths.push(path); return this; } - public customized (resolver: CustomizedTrackPathResolver) { + /** + * @internal Reserved for backward compatibility. DO NOT USE IT IN YOUR CODE. + */ + public toCustomized (resolver: CustomizedTrackPathResolver) { this._paths.push(resolver); return this; } @@ -222,7 +225,7 @@ class TrackPath { return trackPath; } - public follow (object: unknown, beginIndex?: number, endIndex?: number) { + public trace (object: unknown, beginIndex?: number, endIndex?: number) { beginIndex ??= 0; endIndex ??= this._paths.length; return this[normalizedFollowTag](object, beginIndex, endIndex); diff --git a/tests/animation/animation-clip-3.x.test.ts b/tests/animation/animation-clip-3.x.test.ts index 13abaf4cf8..65bf97b889 100644 --- a/tests/animation/animation-clip-3.x.test.ts +++ b/tests/animation/animation-clip-3.x.test.ts @@ -36,7 +36,7 @@ describe('Animation Clip', () => { function createClipWithPath (path: TargetPath[]) { const clip = new AnimationClip(); const track = new RealTrack(); - track.path = new TrackPath().hierarchy('Foo'); + track.path = new TrackPath().toHierarchy('Foo'); clip.addTrack(track); return clip; } @@ -47,7 +47,7 @@ describe('Animation Clip', () => { const clip = new AnimationClip(); for (const path of paths) { const track = new VectorTrack(); - track.path = new TrackPath().hierarchy(path).property('position'); + track.path = new TrackPath().toHierarchy(path).toProperty('position'); clip.addTrack(track); } return clip[searchForRootBonePathSymbol](); @@ -70,7 +70,7 @@ describe('Animation Clip', () => { const rootBoneTranslationTrack = new VectorTrack(); { rootBoneTranslationTrack.componentsCount = 3; - rootBoneTranslationTrack.path = new TrackPath().hierarchy(rootJointName).property('position'); + rootBoneTranslationTrack.path = new TrackPath().toHierarchy(rootJointName).toProperty('position'); const [x, _y, _z] = rootBoneTranslationTrack.channels(); x.curve.assignSorted([ [0.4, ({ value: 0.4 })],