Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some GUI issues #2504

Merged
merged 284 commits into from
Jan 14, 2025
Merged

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jan 14, 2025

  • Parse UITransform
  • Fix distanceForSort calculation error
  • Fix Transition destruction error

Summary by CodeRabbit

Release Notes

  • New Features

    • Added optional transform configuration for entities.
    • Enhanced UI canvas bounds management.
    • Introduced raycastEnabled for Text components.
    • Improved UI component registration mechanism with new components.
    • Added a new method for dynamic GUI component registration.
  • Improvements

    • Refined UI interaction and transition handling.
    • Updated raycasting and rendering logic for UI elements.
    • More flexible entity transformation parsing.
    • Enhanced state handling logic for color transitions.
  • Bug Fixes

    • Corrected sprite transition logic for setting target sprites.

These updates enhance the UI framework's flexibility, interaction handling, and rendering capabilities.

luzhuang and others added 8 commits January 8, 2025 16:55
Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request introduces enhancements to resource deserialization and UI components across multiple files. The changes focus on improving entity transformation handling, adding new properties to UI components, and refining interaction mechanisms. Key modifications include updates to the HierarchyParser and ReflectionParser to support more flexible transformation configurations, the addition of a new optional transform property in the IBasicEntity interface, and the introduction of a registration function for GUI components in the main index file.

Changes

File Change Summary
packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts Updated _parseEntity and _applyEntityData methods to handle transformation configurations more flexibly.
packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts Modified parseEntity and _getEntityByConfig to support dynamic transformation handling.
packages/loader/src/resource-deserialize/resources/schema/BasicSchema.ts Added optional transform property to IBasicEntity interface.
packages/ui/src/component/UICanvas.ts Added _center and _centerDirtyFlag properties, updated _updateSortDistance method, and introduced _getCenter method.
packages/ui/src/component/advanced/Text.ts Added raycastEnabled property.
packages/ui/src/component/interactive/UIInteractive.ts Modified onDestroy method to iterate transitions in reverse.
packages/ui/src/component/interactive/transition/ColorTransition.ts Updated state change method logic for color transitions.
packages/ui/src/component/interactive/transition/SpriteTransition.ts Modified _applyValue method to change sprite assignment logic.
packages/ui/src/index.ts Added new UI components and registerGUI function for component registration.
packages/ui/src/input/UIPointerEventEmitter.ts Updated processRaycast method with camera transformation handling.
packages/ui/src/component/index.ts Introduced multiple exports from UI components for enhanced modularity.

Possibly related PRs

  • Support GUI #2375: The changes in the main PR regarding the HierarchyParser class and its handling of entity transformations are related to the modifications in the ReflectionParser class, which also enhances the handling of entity transformations and includes similar updates to method signatures and logic.
  • Fix the mesh was not restored after context lost. #2418: The changes in the main PR about entity transformation handling are relevant to the updates in the ReflectionParser, which also deals with parsing and managing entity configurations, including transformations.
  • PBR shader support Iridescence #2425: The modifications in the main PR regarding the handling of entity transformations and configurations are connected to the changes in the PBRMaterial class, which also involves managing properties related to rendering and transformations.

Suggested labels

GUI, enhancement, high priority

Suggested reviewers

  • GuoLei1990
  • zhuxudong

Poem

🐰 Hop, skip, and transform we go,
Code leaps forward, watch it grow!
Entities dance with newfound grace,
UI components find their place.
Rabbit's magic makes code shine bright! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48f94f7 and 35cfef7.

📒 Files selected for processing (2)
  • packages/ui/src/component/index.ts (1 hunks)
  • packages/ui/src/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui/src/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: codecov
  • GitHub Check: e2e (22.x)
🔇 Additional comments (4)
packages/ui/src/component/index.ts (4)

1-11: Well-organized exports with clear categorization.

The exports are logically grouped into basic components, advanced components, and transitions, making the module structure clear and maintainable.


5-7: Consider documenting component dependencies.

The advanced components (Button, Image, Text) are well-organized in a separate directory. However, it would be beneficial to document their dependencies and usage patterns.

✅ Verification successful

Component dependencies are well-structured

The advanced components follow a clean dependency pattern:

  • They properly build upon base UI components (UIInteractive, UIRenderer, UITransform)
  • No problematic circular dependencies exist
  • The component organization promotes good architectural practices
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential circular dependencies between basic and advanced components

# Look for imports of advanced components in basic component files
echo "Checking for potential circular dependencies:"
rg -l "import.*{.*(?:Button|Image|Text).*}.*from" "./UICanvas.ts" "./UIGroup.ts" "./UIRenderer.ts" "./UITransform.ts"

Length of output: 345


Script:

#!/bin/bash
# First, find the actual paths of the files
echo "Finding component files:"
fd -e ts -e tsx "Button|Image|Text" packages/ui/src

echo -e "\nChecking advanced component implementations:"
for file in $(fd -e ts -e tsx "Button|Image|Text" packages/ui/src/component/advanced); do
  echo -e "\n=== $file ==="
  # Show imports to understand dependencies
  rg "^import .* from" "$file"
done

echo -e "\nChecking for circular dependencies:"
# Search for imports of advanced components in all UI files except the advanced directory
rg "from ['\"].*advanced/(Button|Image|Text)" packages/ui/src -g '!**/advanced/*'

Length of output: 2404


1-4: Verify UITransform changes across the codebase.

Given that this PR addresses UITransform parsing fixes, let's ensure all usages are compatible with the changes.

✅ Verification successful

UITransform export and usage patterns are consistent

The UITransform component is properly integrated across the UI system, with consistent usage patterns in Text, Image, UICanvas, and UIRenderer components. All imports and type-casting patterns are uniform, and the modification flags are handled appropriately throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all UITransform usages and imports to verify compatibility
# Look for any custom parsing or transformation logic that might need updates

# Find files importing UITransform
echo "Files importing UITransform:"
rg -l "import.*UITransform.*from.*['\"].*component" 

# Find UITransform usage patterns
echo -e "\nUITransform usage patterns:"
ast-grep --pattern 'new UITransform($$$)'

Length of output: 237


Script:

#!/bin/bash
# Broader search for UITransform
echo "All UITransform references:"
rg "UITransform"

echo -e "\nUITransform class/interface definitions:"
ast-grep --pattern 'class UITransform {
  $$$
}'

ast-grep --pattern 'interface UITransform {
  $$$
}'

echo -e "\nUITransform imports (any pattern):"
rg "import.*UITransform"

Length of output: 4361


8-11: Verify transition destruction handling.

Since this PR addresses a Transition destruction error, ensure proper cleanup is implemented across all transition types.

✅ Verification successful

Destruction handling properly implemented across transition types

The codebase shows proper cleanup implementation:

  • Base Transition class handles component detachment and reference cleanup
  • SpriteTransition extends base cleanup with proper sprite resource management
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze transition cleanup and destruction patterns

# Look for destruction/cleanup patterns in transition files
echo "Checking transition cleanup patterns:"
rg -A 5 "(?:destroy|dispose|cleanup|onDestroy)" "./interactive/transition/"

# Find transition usage patterns to verify proper disposal
echo -e "\nChecking transition usage patterns:"
ast-grep --pattern 'new $_(ColorTransition|ScaleTransition|SpriteTransition|Transition)($$$)'

Length of output: 409


Script:

#!/bin/bash
# Description: Analyze transition cleanup patterns with corrected paths

echo "Checking transition cleanup patterns:"
rg -A 5 "(?:destroy|dispose|cleanup|onDestroy)" "packages/ui/src/component/interactive/transition/"

echo -e "\nChecking transition-related tests:"
fd ".*Transition.*\.(test|spec)\.(ts|js|tsx|jsx)$" packages/ui/

echo -e "\nChecking lifecycle methods in transitions:"
ast-grep --pattern 'class $_ extends $_ {
  $$$
  componentWillUnmount() {
    $$$
  }
  $$$
}'

Length of output: 1667

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 34.06593% with 60 lines in your changes missing coverage. Please review.

Project coverage is 68.51%. Comparing base (a8414f9) to head (35cfef7).
Report is 1 commits behind head on dev/1.4.

Files with missing lines Patch % Lines
packages/ui/src/component/UICanvas.ts 29.62% 19 Missing ⚠️
...omponent/interactive/transition/ColorTransition.ts 0.00% 16 Missing ⚠️
...e-deserialize/resources/parser/ReflectionParser.ts 7.69% 12 Missing ⚠️
packages/ui/src/index.ts 69.23% 4 Missing ⚠️
packages/ui/src/input/UIPointerEventEmitter.ts 0.00% 4 Missing ⚠️
...ce-deserialize/resources/parser/HierarchyParser.ts 85.71% 2 Missing ⚠️
packages/ui/src/component/index.ts 0.00% 0 Missing and 1 partial ⚠️
...ages/ui/src/component/interactive/UIInteractive.ts 0.00% 1 Missing ⚠️
...mponent/interactive/transition/SpriteTransition.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/1.4    #2504      +/-   ##
===========================================
+ Coverage    68.50%   68.51%   +0.01%     
===========================================
  Files          956      957       +1     
  Lines       100007   100068      +61     
  Branches      8545     8548       +3     
===========================================
+ Hits         68506    68560      +54     
- Misses       31245    31252       +7     
  Partials       256      256              
Flag Coverage Δ
unittests 68.51% <34.06%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8414f9 and eed17b3.

📒 Files selected for processing (10)
  • packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts (3 hunks)
  • packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts (3 hunks)
  • packages/loader/src/resource-deserialize/resources/schema/BasicSchema.ts (1 hunks)
  • packages/ui/src/component/UICanvas.ts (7 hunks)
  • packages/ui/src/component/advanced/Text.ts (1 hunks)
  • packages/ui/src/component/interactive/UIInteractive.ts (1 hunks)
  • packages/ui/src/component/interactive/transition/ColorTransition.ts (1 hunks)
  • packages/ui/src/component/interactive/transition/SpriteTransition.ts (1 hunks)
  • packages/ui/src/index.ts (2 hunks)
  • packages/ui/src/input/UIPointerEventEmitter.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui/src/component/UICanvas.ts

[error] 308-308: Don't use 'Boolean' as a type.

Use lowercase primitives for consistency.
Safe fix: Use 'boolean' instead

(lint/complexity/noBannedTypes)


[error] 317-317: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: e2e (22.x)
  • GitHub Check: codecov
🔇 Additional comments (17)
packages/ui/src/component/interactive/transition/SpriteTransition.ts (1)

47-47: Simplified sprite assignment logic.

The removal of the fallback to this._normal makes the assignment more direct and predictable.

Let's verify that this change doesn't introduce null sprite issues:

✅ Verification successful

Direct sprite assignment is safe and consistent with codebase patterns.

The simplified assignment aligns with the established sprite handling patterns across the codebase, where components are designed to handle null sprites gracefully and proper cleanup is implemented in destroy methods.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for null checks before sprite assignments
rg -A 2 "sprite\s*=\s*(?!null)[^;]+" --type ts

Length of output: 291


Script:

#!/bin/bash
# Find sprite assignments using ast-grep
ast-grep --pattern 'sprite = $_'

# Find sprite-related error handling
rg -B2 -A2 "sprite.*(?:null|undefined|Error)" --pcre2 --type ts

# Look for sprite property access patterns
ast-grep --pattern '$_.sprite'

Length of output: 19273

packages/loader/src/resource-deserialize/resources/schema/BasicSchema.ts (1)

41-41: Good addition of explicit transform support.

Adding a dedicated transform property to IBasicEntity improves the clarity of entity transformation handling. This aligns well with the PR objective of enhancing UITransform parsing.

Let's verify the transform property usage:

✅ Verification successful

Transform property integration verified successfully

The optional transform property in IBasicEntity is well-integrated into the codebase:

  • Used consistently across UI components (UICanvas, Image, Text)
  • Properly supports UITransform implementation
  • Maintains backward compatibility with existing component system
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for transform property usage in entity parsing
ast-grep --pattern 'transform?: IComponent' 

Length of output: 45


Script:

#!/bin/bash
# Search for IBasicEntity interface usage and UITransform references
echo "=== Searching for IBasicEntity usage ==="
rg "IBasicEntity" -A 2

echo -e "\n=== Searching for UITransform references ==="
rg "UITransform" -A 2

echo -e "\n=== Searching for transform property handling ==="
rg "transform.*IComponent" -A 2

Length of output: 9802

packages/ui/src/component/interactive/transition/ColorTransition.ts (1)

36-39: Improved state handling with consistent pattern.

The changes enhance state management by:

  1. Using proper state comparison
  2. Ensuring _finalValue is set before update
  3. Using ||= for safe assignment
  4. Maintaining consistent pattern across all state handlers

Let's verify the state handling consistency:

Also applies to: 43-46, 50-53, 57-60

✅ Verification successful

Verified: State handling patterns are consistent across all interactive states

The codebase shows identical state handling patterns for Normal, Hover, Pressed, and Disable states, each following the same structure for state comparison, value assignment, and update.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar state handling patterns
ast-grep --pattern 'if (this._finalState === $_) {
  this._finalValue ||= this.$_;
  this._updateValue();
}'

Length of output: 1769

packages/ui/src/index.ts (2)

Line range hint 1-1: Verify distanceForSort calculation fix.

The PR objective mentions fixing the distanceForSort calculation, but this change is not visible in the provided files.

Let's search for the calculation:


124-138: Well-structured GUI component registration.

The registerGUI function provides a centralized way to register all UI components, including the newly supported UITransform. This enhances maintainability and ensures consistent component registration.

Let's verify the component availability:

✅ Verification successful

Component registration and implementation verified successfully.

All UI components registered in registerGUI() are properly implemented and follow consistent inheritance patterns. The registration is centralized and matches the component implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for component class definitions
ast-grep --pattern 'export class $_ extends $_'

Length of output: 49


Script:

#!/bin/bash
# Find component files
echo "=== Component Files ==="
fd -e ts -e tsx

# Search for class definitions with more flexible pattern
echo -e "\n=== Class Definitions ==="
rg "class (Text|Image|Button|UIGroup|UICanvas|UITransform|ScaleTransition|ColorTransition|SpriteTransition)" -A 1

# Check export statements
echo -e "\n=== Export Statements ==="
rg "export.*(Text|Image|Button|UIGroup|UICanvas|UITransform|ScaleTransition|ColorTransition|SpriteTransition)"

Length of output: 123658


Script:

#!/bin/bash
# Check component implementations
echo "=== Text Component ==="
rg "class Text" -A 10 packages/ui/src/component/advanced/Text.ts

echo -e "\n=== UITransform Component ==="
rg "class UITransform" -A 10 packages/ui/src/component/UITransform.ts

echo -e "\n=== UICanvas Component ==="
rg "class UICanvas" -A 10 packages/ui/src/component/UICanvas.ts

echo -e "\n=== Component Registration ==="
rg "registerClass|Loader\.register" packages/ui/src/

Length of output: 2504

packages/ui/src/component/interactive/UIInteractive.ts (1)

157-159: LGTM! Safer transition cleanup.

The change from forward to backward iteration when destroying transitions is a good practice. It prevents potential issues with array index shifting during element removal.

packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts (2)

29-38: LGTM! Enhanced transform handling.

The new transform handling logic provides better flexibility by:

  1. Supporting explicit transform configuration through transformConfig
  2. Maintaining backward compatibility with direct position/rotation/scale properties

171-172: LGTM! Dynamic transform class resolution.

Good enhancement to support custom transform classes while defaulting to the standard Transform class when not specified.

packages/ui/src/input/UIPointerEventEmitter.ts (3)

69-72: LGTM! Improved camera transform handling.

Good enhancement to extract camera properties once and reuse them, improving code readability and potentially performance.


76-76: LGTM! Enhanced sort distance calculation.

The addition of isOrthographic and cameraForward parameters provides better context for accurate distance calculations.


86-86: LGTM! More robust render check.

Replacing direct camera comparison with _canRender method allows for more complex render eligibility logic.

packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts (2)

223-224: LGTM! Consistent transform handling.

Good alignment with ReflectionParser's transform handling, maintaining consistency across the codebase.


292-302: LGTM! Enhanced entity data application.

The changes provide a more flexible approach to applying transform data:

  1. Support for explicit transform configuration
  2. Fallback to direct property copying
  3. Clean handling of the layer property
packages/ui/src/component/advanced/Text.ts (1)

231-231: LGTM! Good default value for raycastEnabled.

Setting raycastEnabled to false by default is a good practice as text components are typically not interactive, improving performance by skipping unnecessary raycasting operations.

packages/ui/src/component/UICanvas.ts (3)

2-3: LGTM! Required imports for the new functionality.

The imports are correctly ordered and necessary for the new bounding box functionality.


96-99: LGTM! Well-structured property declarations.

The properties are correctly marked with @ignoreClone and initialized appropriately for managing the canvas bounds.


592-605: LGTM! Well-implemented bounds calculation with dirty flag pattern.

The method efficiently calculates and caches the canvas bounds, using the dirty flag pattern to avoid unnecessary recalculations.

@@ -297,7 +305,7 @@
/**
* @internal
*/
_updateSortDistance(cameraPosition: Vector3): void {
_updateSortDistance(isOrthographic: Boolean, cameraPosition: Vector3, cameraForward: Vector3): void {
Copy link

@coderabbitai coderabbitai bot Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use lowercase 'boolean' type instead of 'Boolean'.

For consistency with TypeScript conventions, use the primitive type boolean instead of the object type Boolean.

Apply this diff:

-  _updateSortDistance(isOrthographic: Boolean, cameraPosition: Vector3, cameraForward: Vector3): void {
+  _updateSortDistance(isOrthographic: boolean, cameraPosition: Vector3, cameraForward: Vector3): void {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_updateSortDistance(isOrthographic: Boolean, cameraPosition: Vector3, cameraForward: Vector3): void {
_updateSortDistance(isOrthographic: boolean, cameraPosition: Vector3, cameraForward: Vector3): void {
🧰 Tools
🪛 Biome (1.9.4)

[error] 308-308: Don't use 'Boolean' as a type.

Use lowercase primitives for consistency.
Safe fix: Use 'boolean' instead

(lint/complexity/noBannedTypes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cptbtptpbcptdtptp Thanks for making the change! 🎉


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Comment on lines 317 to 323
const boundsCenter = this._getBounds().getCenter(UICanvas._tempVec3);
if (isOrthographic) {
Vector3.subtract(boundsCenter, cameraPosition, boundsCenter);
this._sortDistance = Vector3.dot(boundsCenter, cameraForward);
} else {
this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Wrap switch case declarations in a block.

To prevent accidental access to the declarations from other switch cases, wrap the code in a block.

Apply this diff:

       case CanvasRenderMode.WorldSpace: {
         const boundsCenter = this._getBounds().getCenter(UICanvas._tempVec3);
         if (isOrthographic) {
           Vector3.subtract(boundsCenter, cameraPosition, boundsCenter);
           this._sortDistance = Vector3.dot(boundsCenter, cameraForward);
         } else {
           this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
         }
         break;
+      }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome (1.9.4)

[error] 317-317: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

@cptbtptpbcptdtptp cptbtptpbcptdtptp added bug Something isn't working 2D labels Jan 14, 2025
@cptbtptpbcptdtptp cptbtptpbcptdtptp added this to the 1.4 milestone Jan 14, 2025
@GuoLei1990 GuoLei1990 added the ignore for release ignore for release label Jan 14, 2025
@GuoLei1990 GuoLei1990 merged commit 6ce548a into galacean:dev/1.4 Jan 14, 2025
8 of 9 checks passed
This was referenced Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2D bug Something isn't working ignore for release ignore for release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants