Skip to content

Commit

Permalink
Merge pull request #206 from JamesTKhan/loading-improvements
Browse files Browse the repository at this point in the history
Fix issues on loading projects
  • Loading branch information
JamesTKhan authored Aug 3, 2023
2 parents ddff4e9 + 23892cd commit f21643a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions editor/src/main/com/mbrlabs/mundus/editor/Editor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import net.mgsx.gltf.scene3d.shaders.PBRDepthShaderProvider
import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils
import org.lwjgl.opengl.GL11
import java.io.File

/**
* @author Marcus Brummer
Expand Down Expand Up @@ -237,6 +238,14 @@ class Editor : Lwjgl3WindowAdapter(), ApplicationListener,
var path = FileUtils.getUserDirectoryPath()
path = FilenameUtils.concat(path, "MundusProjects")

// If the default project already exists, import it instead of recreate it.
// This can happen if the registry was deleted but the project folder was not.
val defaultProjectPath = FilenameUtils.concat(path, name)
val file = File(defaultProjectPath)
if (file.exists()) {
return projectManager.importProject(defaultProjectPath)
}

return projectManager.createProject(name, path)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ public ProjectContext importProject(String absolutePath) throws ProjectAlreadyIm
UI.INSTANCE.toggleLoadingScreen(true, context.name);
ref.setName(context.name);
registry.getProjects().add(ref);

// Set this import project as last opened to prevent NPE only
// if no project was opened before
if (registry.getLastProject() == null){
registry.setLastProject(ref);
}

kryoManager.saveRegistry(registry);
startAsyncProjectLoad(absolutePath, context);
return context;
Expand Down Expand Up @@ -316,6 +323,14 @@ public void saveProject(ProjectContext projectContext) {
public ProjectContext loadLastProjectAsync() {
ProjectRef lastOpenedProject = registry.getLastOpenedProject();
if (lastOpenedProject != null) {

// Check if file exists first
File file = new File(lastOpenedProject.getPath());
if (!file.exists()) {
Log.error(TAG, "Last opened project does not exist: " + lastOpenedProject.getPath());
return null;
}

try {
return startAsyncProjectLoad(lastOpenedProject);
} catch (FileNotFoundException fnf) {
Expand Down

0 comments on commit f21643a

Please sign in to comment.