Fixed perspective crash and project paths when creating a new project

This commit is contained in:
antopilo
2023-04-08 21:37:41 -04:00
parent 3519b67a72
commit 076ac59283
2 changed files with 26 additions and 27 deletions

View File

@@ -167,40 +167,32 @@ namespace Nuake
{
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
std::string projectPathWithExtension = selectedProject;
const bool endsWithExtension = String::EndsWith(projectPathWithExtension, ".project");
if(!endsWithExtension)
{
projectPathWithExtension += ".project";
}
auto backslashSplits = String::Split(selectedProject, '\\');
auto fileName = backslashSplits[backslashSplits.size() - 1];
std::string finalPath = selectedProject;
bool endsWithExtension = String::EndsWith(fileName, ".project");
if (!endsWithExtension)
{
// We need to createa folder
auto dirPath = selectedProject;
bool result = std::filesystem::create_directory(dirPath);
if (!result)
{
// Should we continue?
Logger::Log("Failed creating project directoy: " + dirPath);
}
finalPath += "\\" + fileName + ".project";
}
if (selectedProject.empty())
{
return;
}
auto driveSplit = std::string(selectedProject.begin() + 3, selectedProject.end());
auto pathSplit = String::Split(driveSplit, '/');
auto projectFileName = pathSplit[pathSplit.size() - 1];
// We should create a folder now
// We substring minus 8 because we dont want the extension(.project) which is 8 chars.
const std::string directoryName = std::string(driveSplit.begin(), driveSplit.end());
const std::string finalProjectPath =
if(!endsWithExtension)
{
bool dirCreated = std::filesystem::create_directory(selectedProject);
if (!dirCreated)
{
Logger::Log("Failed to create project directory: " + selectedProject);
}
}
const std::string projectFilePath = selectedProject + "/" + projectFileName + ".project";
Ref<Project> project = Project::New(projectFileName, "no description", projectFilePath);
auto project = Project::New(fileName, "no description", finalPath);
Engine::LoadProject(project);
Engine::LoadScene(Scene::New());
project->Save();

View File

@@ -271,6 +271,13 @@ namespace Nuake {
return;
Vector2 size = m_Framebuffer->GetSize();
if (size.x < 1 || size.y < 1)
{
size.x = 1.0;
size.y = 1.0;
}
cam->AspectRatio = size.x / size.y;
m_Scene->m_EditorCamera->OnWindowResize(size.x, size.y);