-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. That would make it more semantic. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, mixing To salvage the problem with whether it should create a folder by default, maybe this: would allow to create project named would create a project inside current directory. Or just omitting the path argument would force to create a folder named the same as project: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that the So:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be within |
||
OS::get_singleton()->print(" -s, --script <script> Run a script.\n"); | ||
OS::get_singleton()->print(" --check-only Only parse for errors and quit (use with --script).\n"); | ||
#ifdef TOOLS_ENABLED | ||
|
@@ -427,6 +428,55 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph | |
print_line(get_full_version_string()); | ||
goto error; | ||
|
||
} else if (I->get() == "-i" || I->get() == "--init") { // Init new project | ||
|
||
String dir = "."; | ||
String project_name; | ||
|
||
if (I->next()) { | ||
project_name = I->next()->get(); | ||
N = I->next()->next(); | ||
|
||
// Parse the optional argument: the path of the project. | ||
if (N && !N->get().begins_with("-")) { | ||
String arg_str = N->get(); | ||
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); | ||
Error err = d->make_dir_recursive(arg_str); | ||
|
||
if (err == OK) { | ||
dir = arg_str; | ||
N = N->next(); | ||
} else { | ||
OS::get_singleton()->print("Error attempting to create dir: %s.\n", arg_str.utf8().get_data()); | ||
goto error; | ||
} | ||
memdelete(d); | ||
} | ||
} else { | ||
OS::get_singleton()->print("Missing init argument, aborting.\n"); | ||
goto error; | ||
} | ||
ProjectSettings::CustomMap initial_settings = ProjectSettings::get_default_settings(project_name); | ||
|
||
if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) { | ||
|
||
OS::get_singleton()->print("Couldn't create project.godot in project path.\n"); | ||
|
||
} else { | ||
|
||
Ref<Image> icon = memnew(Image(app_icon_png)); | ||
icon->save_png(dir.plus_file(ProjectSettings::get_default_icon_name())); | ||
|
||
FileAccess *f = FileAccess::open(dir.plus_file(ProjectSettings::get_default_env_name()), FileAccess::WRITE); | ||
if (!f) { | ||
OS::get_singleton()->print("Couldn't create project.godot in project path.\n"); | ||
} else { | ||
f->store_line(ProjectSettings::get_default_env_content()); | ||
memdelete(f); | ||
} | ||
} | ||
goto error; | ||
|
||
} else if (I->get() == "--resolution") { // force resolution | ||
|
||
if (I->next()) { | ||
|
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
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?