Fix ProjectSettings Name casing Options and missing String Methods
Godot gained the ability to automatically switch to various name-casing schemes in ProjectSettings. The Options in those Settings however are not consistent. While Node Naming is missing a "kebab-case" option, Scene- and Script Naming are missing a "camelCase" Option.
Also while "to_pascal_case", "to_camel_case" and "to_snake_case" are available as String and StringName Methods, "to_kebab_case" is not.
This patch tries to fix above issues.
- refactored and renamed String::_camelcase_to_underscore to String:_separate_compound_words
- refactored String::to_snake_case to work with the refactored String::_separate_compound_words
- created String::to_kebab_case using the new String::_separate_compound_words
- created corresponding Documentation in String and StringName
- hooked up the ConnectionsDialog
- simplified both switch statements in EditorNode and ProjectDialog
- created and refactored Mono Runtime Interop Functions
- added new kebab-casing Option for Node Names in ProjectSettings
- added missing camelCase Options to Scene- and Node-Names in ProjectSettings
- created additional Unit Tests
Note that the Scene- and the Script-Options changed their Enum Indices in order to be consistent with the Node Options, which unfortunately means that existing ProjectSettings change their Meaning.
I opted to be consistent here, but this can of course be changed to be Backward compatible with existing Projects.
I don't think consistency matters enough here that it justifies changing the order, they don't align anyway as is so we should maintain value ordering IMO
I don't think consistency matters enough here that it justifies changing the order, they don't align anyway as is so we should maintain value ordering IMO
Allright. I will change it to be Backwards compatible then.
Rebased and tested - still works as expected
See also https://github.com/godotengine/godot-proposals/issues/10727. The existing casing options seem to the ones which are actually used as part of some recommeneded style (plus kebab-case which might been added speculatively in https://github.com/godotengine/godot/pull/78119; I can't find any prior issues, PRs, or proposals that specifically want kebab-case available).
Unifying the available casing options in the various project settings seems fine but be careful you're not adding a casing option to a place where it shouldn't be used for some reason
Thanks for the heads up, @tetrapod00!
See also godotengine/godot-proposals#10727. The existing casing options seem to the ones which are actually used as part of some recommeneded style
I build this patch out of necessity to comply with our internal naming conventions at work where we use kebab-case everywhere, and since it doesn't really matter how resources, scripts or objects are named in Godot, except for some best practices guidelines (GDScript) or language-specific naming conventions (C#), I opted to include the missing options for all cases - namely kebab-case for nodes and camel-case for node and scenes. The rest is just some re-factoring, integration, documentation and additional tests.
(plus
kebab-casewhich might been added speculatively in #78119;
Correct me if I am wrong, but that PR is already merged and this one just builds on top of it and expands the possible options.
I can't find any prior issues, PRs, or proposals that specifically want
kebab-caseavailable).Unifying the available casing options in the various project settings seems fine but be careful you're not adding a casing option to a place where it shouldn't be used for some reason
See above. We use it internally at work in multiple projects and are happy with it, but I can totally understand if this is too much of a stretch.
Seems good then. I don't really have an objection to unifying the casing options available in these settings.
that PR is already merged
Yeah, and it looked like the kebab-case was added speculatively instead of driven by known demand, which is unusual for Godot. But it seemed to have worked out, and if it's being used it should be supported across the multiple settings.
Fixed an oversight from the conversion of string::_separate_compound_words where it would still return a pointer to the string itself in case the length of the string was zero. Now it returns an empty PackedStringArray.
I also created char_utils::is_hyphen to catch all hyphen variants in kebab-case conversion and switched the C# implementation of String.Capitalize to just do what ToPascalCase, ToCamelCase, ToSnakeCase and ToKebabCase do - getting the result from the C++ side, which allows us to completely get rid of the custom C# implementation of SeparateCompoundWords. See this comment in the discussion above.
Thanks! Congratulations on your first merged contribution! 🎉