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

add checkDepComponentInEditor decorator #17579

Closed
wants to merge 1 commit into from

Conversation

knoxHuang
Copy link
Contributor

@knoxHuang knoxHuang commented Aug 26, 2024

Re: # https://github.com/cocos/3d-tasks/discussions/18458

Depends: https://github.com/cocos/cocos-editor/pull/3127

Changelog

  • add checkDepComponentInEditor decorator
image image

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Greptile Summary

This pull request introduces a new decorator checkDepComponentInEditor to enhance component dependency management in the Cocos Engine editor environment.

  • Added checkDepComponentInEditor decorator in cocos/core/data/decorators/component.ts to check for dependent components before adding a new one
  • Implemented _checkComponentInEditor property setting in cocos/scene-graph/component.ts for editor-related component checks
  • Applied the new decorator to BuiltinPipelineSettings class in editor/assets/default_renderpipeline/builtin-pipeline-settings.ts
  • Added localization strings for dependency warning messages in both English and Chinese (editor/i18n/en/components.js and editor/i18n/zh/components.js)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

* class SpriteCtrl extends Component {}
* ```
*/
export const checkDepComponentInEditor: (component: string | string[]) => ClassDecorator = DEV ? makeEditorClassDecoratorFn('checkDepComponentInEditor') : emptyDecoratorFn;
Copy link

Choose a reason for hiding this comment

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

style: Consider adding a return type annotation for clarity

Copy link

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -20927,8 +20927,23 @@
          * ```
          */
         export const requireComponent: (requiredComponent: Function | Function[]) => ClassDecorator;
         /**
+         * @en Checks for dependent components before adding a component declared as CCClass. If the dependent component does not exist, prompt for it
+         * @zh 为声明为 CCClass 的组件进行添加前检查依赖组件。如果依赖的组件不存在,进行提示
+         * @param checkDepComponentInEditor
+         * @example
+         * ```ts
+         * import { _decorator, Sprite, Component } from cc;
+         * import { ccclass, checkDepComponentInEditor } from _decorator;
+         *
+         * @ccclass
+         * @checkDepComponentInEditor('cc.Sprite')
+         * class SpriteCtrl extends Component {}
+         * ```
+         */
+        export const checkDepComponentInEditor: (component: string | string[]) => ClassDecorator;
+        /**
          * @en Set the component priority, it decides at which order the life cycle functions of components will be invoked. Smaller priority gets invoked before larger priority.
          * This will affect `onLoad`, `onEnable`, `start`, `update` and `lateUpdate`, but `onDisable` and `onDestroy` won't be affected.
          * @zh 设置脚本生命周期方法调用的优先级。优先级小于 0 的组件将会优先执行,优先级大于 0 的组件将会延后执行。优先级仅会影响 onLoad, onEnable, start, update 和 lateUpdate,而 onDisable 和 onDestroy 不受影响。
          * @param priority - The execution order of life cycle methods for Component. Smaller priority gets invoked before larger priority.

@knoxHuang knoxHuang closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant