Added ErrorHandler class to handle all critical errors.

This mostly replaces the Slick2D Log class for error reporting.  Most game errors will now trigger the error popup.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-01-15 21:55:26 -05:00
parent f8dad2889f
commit 553f091693
11 changed files with 192 additions and 71 deletions

View File

@@ -18,6 +18,7 @@
package itdelatrisu.opsu.states;
import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.GameScore;
@@ -52,7 +53,6 @@ import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.EmptyTransition;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;
import org.newdawn.slick.util.Log;
/**
* "Game" state.
@@ -643,7 +643,7 @@ public class Game extends BasicGameState {
enter(container, game);
skipIntro();
} catch (SlickException e) {
Log.error("Failed to restart game.", e);
ErrorHandler.error("Failed to restart game.", e, false);
}
}
break;
@@ -681,7 +681,7 @@ public class Game extends BasicGameState {
;
objectIndex--;
} catch (SlickException e) {
Log.error("Failed to load checkpoint.", e);
ErrorHandler.error("Failed to load checkpoint.", e, false);
}
}
break;
@@ -948,7 +948,7 @@ public class Game extends BasicGameState {
score.setDrainRate(HPDrainRate);
score.setDifficulty(overallDifficulty);
} catch (SlickException e) {
Log.error("Error while setting map modifiers.", e);
ErrorHandler.error("Error while setting map modifiers.", e, true);
}
}

View File

@@ -18,6 +18,7 @@
package itdelatrisu.opsu.states;
import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.MenuButton;
@@ -226,7 +227,7 @@ public class Options extends BasicGameState {
try {
Utils.loadCursor();
} catch (SlickException e) {
Log.error("Failed to load cursor.", e);
ErrorHandler.error("Failed to load cursor.", e, true);
}
}
},
@@ -1290,7 +1291,7 @@ public class Options extends BasicGameState {
public static OsuFile getOsuTheme() {
String[] tokens = themeString.split(",");
if (tokens.length != 4) {
Log.error("Theme song string is malformed.");
ErrorHandler.error("Theme song string is malformed.", null, false);
return null;
}
@@ -1301,7 +1302,7 @@ public class Options extends BasicGameState {
try {
osu.endTime = Integer.parseInt(tokens[3]);
} catch (NumberFormatException e) {
Log.error("Theme song length is not a valid integer", e);
ErrorHandler.error("Theme song length is not a valid integer", e, false);
return null;
}
@@ -1468,7 +1469,7 @@ public class Options extends BasicGameState {
}
}
} catch (IOException e) {
Log.error(String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()), e);
ErrorHandler.error(String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false);
} catch (NumberFormatException e) {
Log.warn("Format error in options file.", e);
return;
@@ -1562,7 +1563,7 @@ public class Options extends BasicGameState {
writer.newLine();
writer.close();
} catch (IOException e) {
Log.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()), e);
ErrorHandler.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false);
}
}
}