godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Make script templates file a text file. #10960

Open JourneyHans opened 1 month ago

JourneyHans commented 1 month ago

Describe the project you are working on

The tutorial I am studying mentions the feature of script templates, but it uses GDScript while I am using C#. I am confused about how to create the script templates.

Describe the problem or limitation you are having in your project

Script templates should not be actual script files, they should be text files because they shouldn’t participate in compilation, they are just templates. Additionally, this can lead to naming conflict issues in C#. For example, the two script templates I created below both use the CLASS placeholder, but this clearly causes compilation errors. Therefore, I had to add suffixes to differentiate them. However, this means I need to modify the class name each time I create a script. image

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Just change the script template files to text files, like other engines or tools do.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

NaN

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, add suffixes to differentiate them, and modify class name when create a script.

Is there a reason why this should be core and not an add-on in the asset library?

  1. Template files no longer participate in compilation.
  2. Resolve the issue of renaming placeholders.
HolonProduction commented 1 month ago

The docs recommend excluding the folder from the build and adding a .gdignore file.

Not opposed to scanning for templates with a .template suffix as well though.

JourneyHans commented 1 month ago

The docs recommend excluding the folder from the build and adding a .gdignore file.文档建议从构建中排除该文件夹并添加.gdignore文件。

Not opposed to scanning for templates with a .template suffix as well though.不过,也不反对扫描带有.template后缀的模板。

This is an effective solution that I overlooked. Thank you for the reminder. It indeed addresses the issue of script templates participating in compilation. I believe resolving this issue should take priority over the naming conflict problem.