Merge pull request #14 from antopilo/feature/NK-73-creating-new-project-doesnt-add-project-suffix

Creating New Project doesn't add .project
This commit is contained in:
Antoine Pilote
2023-07-07 19:13:52 -04:00
committed by GitHub
4 changed files with 24 additions and 11 deletions

View File

@@ -1248,14 +1248,18 @@ namespace Nuake {
void NewProject()
{
if (Engine::GetProject())
if (Engine::GetProject() && Engine::GetProject()->FileExist())
Engine::GetProject()->Save();
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
if (selectedProject == "") // Hit cancel
if(!String::EndsWith(selectedProject, ".project"))
selectedProject += ".project";
if (selectedProject.empty()) // Hit cancel
return;
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject + ".project");
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject);
Engine::LoadProject(project);
Engine::LoadScene(Scene::New());
}

View File

@@ -166,28 +166,31 @@ namespace Nuake
if (ImGui::Button("New Project", buttonSize))
{
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
if (!selectedProject.empty())
{
if(!String::EndsWith(selectedProject, ".project"))
selectedProject += ".project";
auto backslashSplits = String::Split(selectedProject, '\\');
auto fileName = backslashSplits[backslashSplits.size() - 1];
std::string finalPath = selectedProject;
std::string finalPath = String::Split(selectedProject, '.')[0];
if (String::EndsWith(fileName, ".project"))
{
// We need to create a folder
if (const auto& dirPath = selectedProject;
std::filesystem::create_directory(dirPath))
if (const auto& dirPath = finalPath;
!std::filesystem::create_directory(dirPath))
{
// Should we continue?
Logger::Log("Failed creating project directory: " + dirPath);
}
finalPath += "\\" + fileName + ".project";
finalPath += "\\" + fileName;
}
auto project = Project::New(fileName, "no description", finalPath);
auto project = Project::New(String::Split(fileName, '.')[0], "no description", finalPath);
Engine::LoadProject(project);
Engine::LoadScene(Scene::New());
project->Save();

View File

@@ -53,6 +53,11 @@ namespace Nuake
projectFile.close();
}
bool Project::FileExist()
{
return std::filesystem::exists(this->FullPath.c_str());
}
Ref<Project> Project::New(const std::string& Name, const std::string& Description, const std::string& FullPath)
{
return CreateRef<Project>(Name, Description, FullPath);

View File

@@ -26,6 +26,7 @@ namespace Nuake
void Save();
void SaveAs(const std::string& FullPath);
bool FileExist();
static Ref<Project> New(const std::string& Name, const std::string& Description, const std::string& FullPath);
static Ref<Project> New();