godot icon indicating copy to clipboard operation
godot copied to clipboard

Allow configuring the script filename casing rule

Open RedMser opened this issue 2 years ago • 3 comments

Supersedes #41991 Closes https://github.com/godotengine/godot-proposals/issues/1211

  • Add a project setting editor/naming/script_name_casing which 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 config and _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_casing for 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_extensions is and how it differs from get_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.

RedMser avatar Jun 11 '23 16:06 RedMser

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.

KoBeWi avatar Sep 30 '23 18:09 KoBeWi

Do you think this can be in for Godot Engine 4.2?

fire avatar Oct 02 '23 05:10 fire

We are in feature freeze, so probably not. But the change seems rather safe.

KoBeWi avatar Oct 02 '23 10:10 KoBeWi

Do you think this can be in for Godot Engine 4.3?

Edited: There are some github actions problems preventing merge.

fire avatar Feb 12 '24 17:02 fire

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.

RedMser avatar Feb 12 '24 17:02 RedMser

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. image
  • When creating a new script from the attach button, converting node names like PascalCaseNode, snake_case_node, and kebab-case-node all 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). image

raulsntos avatar Feb 23 '24 06:02 raulsntos

@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).

RedMser avatar Feb 28 '24 21:02 RedMser

Thanks!

akien-mga avatar Mar 05 '24 09:03 akien-mga