galacean / effects-runtime

It can load and render cool animation effects
https://www.galacean.com/effects/
MIT License
350 stars 11 forks source link

refactor: color and vector4 curve value #730

Closed wumaolinmaoan closed 3 weeks ago

wumaolinmaoan commented 3 weeks ago

Summary by CodeRabbit

Release Notes

These changes enhance the overall functionality and reliability of the effects core package.

coderabbitai[bot] commented 3 weeks ago

Walkthrough

The pull request introduces updates to the @galacean/effects-core package, specifically modifying the package.json to change the version of the @galacean/effects-specification dependency from 2.1.0-alpha.3 to 2.1.0-alpha.4. Additionally, it alters the initialization methods of the ColorCurve and Vector4Curve classes to use array indexing for accessing color and vector components instead of direct property access. Furthermore, the curveData property types in both ColorPropertyPlayableAsset and Vector4PropertyPlayableAsset classes have been updated to reflect new data structures.

Changes

File Change Summary
packages/effects-core/package.json Updated @galacean/effects-specification dependency version from 2.1.0-alpha.3 to 2.1.0-alpha.4.
packages/effects-core/src/math/value-getters/color-curve.ts Modified onCreate method in ColorCurve class to access color components using array indexing instead of properties.
packages/effects-core/src/math/value-getters/vector4-curve.ts Modified onCreate method in Vector4Curve class to access vector components using array indexing instead of properties.
packages/effects-core/src/plugins/timeline/playable-assets/color-property-playable-asset.ts Changed curveData property type from spec.ColorCurveData to spec.ColorCurveValue in ColorPropertyPlayableAsset.
packages/effects-core/src/plugins/timeline/playable-assets/vector4-property-playable-asset.ts Changed curveData property type from spec.Vector4CurveData to spec.Vector4CurveValue in Vector4PropertyPlayableAsset.
packages/effects-core/src/composition-source-manager.ts Added conditional check in preProcessItemContent method to ensure shapeData contains aPoint and index before assignment.

Possibly related PRs

Suggested reviewers

Poem

🐇 In the meadow where colors blend,
A curve of hues begins to mend.
With vectors dancing, side by side,
New types emerge, our joy, our pride.
From alpha three to four we leap,
In playful assets, our dreams we keep! 🌈


📜 Recent review details **Configuration used: .coderabbit.yaml** **Review profile: CHILL**
📥 Commits Reviewing files that changed from the base of the PR and between 5ff4dc7c1cae5cfe48355cb1634ab6ecf75eefc1 and b311c1959f1e9e4071d6457aec6b1a064980f67f.
📒 Files selected for processing (1) * `packages/effects-core/src/composition-source-manager.ts` (1 hunks)
🔇 Additional comments (1)
packages/effects-core/src/composition-source-manager.ts (1) `173-176`: _:hammer_and_wrench: Refactor suggestion_ **Consider addressing the type conversion issue properly instead of using @ts-expect-error.** The added type check improves safety by verifying the shape data properties before processing. However, the use of `@ts-expect-error` suggests an underlying type system issue that should be addressed properly. Consider these improvements: 1. Define proper types for the shape data: ```typescript interface ShapeData { aPoint?: unknown; index?: unknown; } // Then update the condition to use type guard if (!isProcessableShape(shapeData)) { renderContent.renderer.shape = getGeometryByShape(shapeData, split); } function isProcessableShape(shape: unknown): shape is ShapeData { return typeof shape === 'object' && shape !== null && ('aPoint' in shape && 'index' in shape); } ``` 2. Update the `getGeometryByShape` function to handle the correct types: ```typescript // Update the function signature to be more specific function getGeometryByShape(shape: spec.ShapeGeometry, split?: unknown): spec.ShapeGeometry { // Implementation } ``` Let's verify the shape data structure in the codebase:
✅ Verification successful Let me gather more information about the types and usage patterns. --- Let me search for one more piece of information to understand the shape geometry types. --- Based on the gathered information, I can now provide the final response: **The @ts-expect-error comment is actually warranted here** The type conversion issue is an expected behavior due to the dual shape data structure handling: - `ShapeGeometry` from the specification contains `aPoint` and `index` - `ShapeGeometryData` is a union type that can also contain pre-processed shapes (`ShapeGeometryPre`) The code correctly: 1. Checks if the shape has the required properties (`aPoint` and `index`) 2. If not, processes it through `getGeometryByShape` to convert it to the expected format The @ts-expect-error is appropriate here as it handles a legitimate runtime conversion between compatible shape formats that TypeScript cannot statically verify.
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Search for shape-related type definitions and usage echo "Searching for shape type definitions..." rg -t typescript "interface.*Shape|type.*Shape" echo "Searching for getGeometryByShape usage..." ast-grep --pattern 'getGeometryByShape($_, $_)' ``` Length of output: 455 --- Script: ```shell #!/bin/bash # Search for shape-related code with more context echo "Searching for shape-related type definitions with .ts extension..." rg "interface.*Shape|type.*Shape" --type ts -A 5 echo "Looking for getGeometryByShape function definition..." ast-grep --pattern 'function getGeometryByShape($_) { $$$ }' echo "Searching for shapeData usage patterns..." rg "shapeData" --type ts -A 3 echo "Looking for renderer.shape assignments..." rg "renderer\.shape\s*=" --type ts -A 2 ``` Length of output: 21209 --- Script: ```shell #!/bin/bash # Search for ShapeGeometry type definition and related imports echo "Searching for ShapeGeometry type..." rg "ShapeGeometry" --type ts -B 2 -A 2 echo "Looking for spec imports..." rg "from.*effects-specification.*" --type ts ``` Length of output: 14137

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.