godot
godot copied to clipboard
Allow configuring the script filename casing rule
Supersedes #41991 Closes https://github.com/godotengine/godot-proposals/issues/1211
- Add a project setting
editor/naming/script_name_casingwhich works similar to the scene equivalent.- Defaults to "Auto", which detects the casing based on the preference of the currently selected language (C# for example prefers PascalCase whereas GDScript prefers snake_case).
- Also simplify the code a bit. It seemed to do path reformatting logic in both
configand_language_changed. And the logic was also overly complex, with the amount of helper methods available to manipulate strings as file paths. - Finally, add kebab-case to
editor/naming/scene_name_casingfor consistency, as it has also been added for script name.
TODO
- [x] Add kebab casing, since some languages like JavaScript and TypeScript would need this.
- [ ] Test the logic with multiple languages in the dropdown (I'd be thankful if someone who's running Linux could try the Mono build).
- [x] ~~Find out what
get_recognized_extensionsis and how it differs fromget_extension.~~ One is for the resource loader/saver, the other is for the script language. - [x] ~~ScriptLanguageExtension changes cause an error that I can not figure out.~~ Needed to bind the enum, fixed.
There is a minor issue where adding script to Node2D with pascal case will name the script Node2d. Not sure how to fix it best tbh. Probably it's not important, because scripts are supposed to have different name.
Do you think this can be in for Godot Engine 4.2?
We are in feature freeze, so probably not. But the change seems rather safe.
Do you think this can be in for Godot Engine 4.3?
Edited: There are some github actions problems preventing merge.
There are some github actions problems preventing merge.
It does not seem related to my changes, so I assume it's a problem with the tests. I don't see an option to retry the pipeline, so I will do another rebase to latest master.
Tried the Mono build on Linux and found these issues:
- Since the logic is no longer re-executed when changing the language, and GDScript is the default language, the first time a user creates a C# script they have to manually fix the script path.
- When creating a new script from the attach button, converting node names like
PascalCaseNode,snake_case_node, andkebab-case-nodeall works when the selected language is GDScript (it converts them all to snake_case). But when the selected language is C#, it fails to convert kebab-case to PascalCase (the others were converted successfully to PascalCase).
@raulsntos Thanks for testing! I believe I've fixed both issues, as well as cleaning up the code further (it had a confusingly named variable "current_language" which contained outdated values after my changes).
Thanks!