Skip to content
Snippets Groups Projects
Commit 0b36c665 authored by Nicklas Persia Tufteland's avatar Nicklas Persia Tufteland
Browse files

Fix: Fix bug where chaosGame is not stored.

parent 33dce6a0
No related branches found
No related tags found
1 merge request!41final delivery
......@@ -31,7 +31,8 @@ public class GameStateManager {
oos.writeObject(game);
LOGGER.log(Level.INFO, "Game state saved successfully in {0}", SERIALIZED_GAME_PATH);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to save game state.", e);
LOGGER.log(Level.WARNING, "Failed to save game state. Next time the application is"
+ " started, the game will be launched in same game state as this time.");
}
}
......@@ -50,7 +51,7 @@ public class GameStateManager {
LOGGER.log(Level.INFO, "Game state loaded successfully.");
return loadedGame;
} catch (IOException | ClassNotFoundException e) {
LOGGER.log(Level.WARNING, "Failed to load game state. Creating new game.", e);
LOGGER.log(Level.WARNING, "Failed to load game state. Creating new game.");
}
} else {
LOGGER.log(Level.WARNING, "No saved game state found. Creating new game.");
......
......@@ -50,7 +50,10 @@ public class MainPageController {
this.customFractalNames = new ArrayList<>(getAllCustomFractalsNames());
this.addingCustomFractal = false;
this.view.render();
Runtime.getRuntime().addShutdownHook(new Thread(() -> GameStateManager.saveGameState(game)));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
game.removeObserver(view);
GameStateManager.saveGameState(game);
}));
LOGGER.log(Level.INFO, "MainPageController initialized successfully.");
}
......
package edu.ntnu.idatt2003.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -23,6 +25,7 @@ public class LoggerUtil {
try {
File logDirectory = new File("logs");
if (!logDirectory.exists() && !logDirectory.mkdirs()) {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(logDirectory));
System.err.println("Failed to create log directory.");
}
FileHandler fileHandler = new FileHandler("logs/application.log", false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment