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 _PROJECTNAME_ to template placeholders #11290

Open
hawkerm opened this issue Dec 5, 2024 · 2 comments
Open

Add _PROJECTNAME_ to template placeholders #11290

hawkerm opened this issue Dec 5, 2024 · 2 comments

Comments

@hawkerm
Copy link

hawkerm commented Dec 5, 2024

Describe the project you are working on

C# Games

Describe the problem or limitation you are having in your project

The default templates don't include a namespace for any of the included projects. It's common for C# files to be placed in a namespace as part of a project. This can help with a variety of patterns and organizations, especially of larger projects.

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

Currently there's no way to have the new class template in Godot generate with a namespace paired with the project you're working on, only static.

It's either you have to type it out each time for new classes you create, or have a fixed namespace which you'd go to change anyway.

This request was asked in the C# discussion of the Discord

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

The script templates for C# would be updated like so, for the base object for instance, it is currently:

// meta-description: Empty template suitable for all Objects

using _BINDINGS_NAMESPACE_;
using System;

public partial class _CLASS_ : _BASE_
{
}

It would become:

// meta-description: Empty template suitable for all Objects

using _BINDINGS_NAMESPACE_;
using System;

namespace _PROJECTNAME_;

public partial class _CLASS_ : _BASE_
{
}

If you have a project named FooBar, then it would then be placed in a namespace of FooBar as well when creating new scripts.

This is also relevant to #1566 as if GDScript gets namespaces as well, it'd be prudent to include the similar option (if not default) for those templates as well.

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

It's just more characters to type for every single new class you create via the editor. It's just one of those things that adds up over time.

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

The information about the project and how templates work seems integrated to the editor itself.

@Calinou Calinou changed the title Add _PROJECTNAME_ to template placeholders Add _PROJECTNAME_ to template placeholders Dec 5, 2024
@Calinou
Copy link
Member

Calinou commented Dec 5, 2024

Since we already have a placeholder with a underscore within it (_BINDINGS_NAMESPACE), should it be _PROJECT_NAME_ instead?

Also, not all project names are suitable identifiers, as they frequently contain spaces, colons or hyphens. The name would likely need to be converted automatically to an identifier-friendly format.

@hawkerm
Copy link
Author

hawkerm commented Dec 14, 2024

@Calinou yeah, that works too. I think I had just copied over the example from the Discord conversation that spawned this proposal.

But yup, good call out that some filtering of special characters would need to occur for edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants