-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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 --init cli argument to create new projects #25925
Conversation
I wonder if the directory should be created by passing |
@Calinou yeah I though about it. The problem is the name of the folder doesn't have to be the same as the name of the project. |
Optional arguments are usually indicated using |
Ok, I'm adding the optional path. |
It is ready now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs some work. I don't think it's a good idea to hardcode the contents of these files. Godot already does something when saving a project for the first time, that is what it should do in this case also.
default_env_str += "[resource]\n"; | ||
default_env_str += "background_mode = 2\n"; | ||
default_env_str += "background_sky = SubResource( 1 )\n"; | ||
return default_env_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the correct approach. This means that if we change anything in the 'real' default environment we now have to change it in two places. This should serialize a normal default environment instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved the code from project_manager.cpp as it was.
See:
godot/editor/project_manager.cpp
Lines 496 to 500 in 07498d3
f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]"); | |
f->store_line("[sub_resource type=\"ProceduralSky\" id=1]"); | |
f->store_line("[resource]"); | |
f->store_line("background_mode = 2"); | |
f->store_line("background_sky = SubResource( 1 )"); |
Where can I find the default environment configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that it was hard coded before, maybe default environment could be instanced and serialized to file that way?
@@ -276,6 +276,7 @@ void Main::print_help(const char *p_binary) { | |||
OS::get_singleton()->print("\n"); | |||
|
|||
OS::get_singleton()->print("Standalone tools:\n"); | |||
OS::get_singleton()->print(" -i, --init <name> [<path>] Create a new project.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have a --path parameter. Should we reuse that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make it more semantic.
I wonder if we should have a CLI parser to validate input and format so we can separate that from the logic based on the content. The actual code handling the cli arguments feels a bit convoluted and hardcoded.
That would make easier to have proper error handling and not opening the editor when you pass an invalid argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lupoDharkael See #20000 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, mixing godot -i test test
and I don't really know which one is path and which one is project name, so seems logical...
To salvage the problem with whether it should create a folder by default, maybe this:
godot --init test --path
(would this be empty?)
would allow to create project named test
and making a directory for it, while
godot --init test --path .
would create a project inside current directory.
Or just omitting the path argument would force to create a folder named the same as project:
godot --init test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the --init
command should not take an optional path argument.
It should also not default to creating a folder, unless the path given does not exist, in which .ase it should try to create it.
So:
// Create "test" project in current working directory
godot --init test
// Create "test" project in previously created "myfolder" directory
mkdir myfolder
godot --init test --path myfolder
// Create "test" project in myother/folder subdirectory, creating them as needed
godot --init test --path myother/folder
I tried this: Expected to run editor after init, but nothing happens. Of course it would make more sense with godot --init test --path . --editor # create in current dir, name project as "test", run editor
godot --init test --editor # mkdir "test" automatically, name project as "test", run editor |
I'm waiting for #26213 to be reviewed and tested before I continue with this PR |
@@ -276,6 +276,7 @@ void Main::print_help(const char *p_binary) { | |||
OS::get_singleton()->print("\n"); | |||
|
|||
OS::get_singleton()->print("Standalone tools:\n"); | |||
OS::get_singleton()->print(" -i, --init <name> [<path>] Create a new project.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be within #ifdef TOOLS_ENABLED
(and same for the parsing of -i
and --init
).
Moving to the next milestone as this PR still needs some work. |
Since this PR depends on #26213, I will close this for now. It can be re-opened or re-created later. |
Solves #25797
I works as
git init
but you have to pass the name of the project as an argument. I creates project.godot, icon.png and default_env.tres in the directory you call this command.