Better error handling for Replay.load().

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-12 01:18:50 -04:00
parent c53679fe63
commit 87323533af
3 changed files with 23 additions and 15 deletions

View File

@ -118,20 +118,17 @@ public class Replay {
/**
* Loads the replay data.
* @throws IOException failure to load the data
*/
public void load() {
public void load() throws IOException {
if (loaded)
return;
try {
OsuReader reader = new OsuReader(file);
loadHeader(reader);
loadData(reader);
reader.close();
loaded = true;
} catch (IOException e) {
ErrorHandler.error("Could not load replay data.", e, true);
}
}
/**

View File

@ -1186,7 +1186,7 @@ public class Game extends BasicGameState {
this.replay = null;
} else {
if (replay.frames == null) {
ErrorHandler.error("Invalid replay.", null, false);
ErrorHandler.error("Attempting to set a replay with no frames.", null, false);
return;
}
this.isReplay = true;

View File

@ -31,6 +31,9 @@ import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.replay.Replay;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.opengl.Display;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
@ -42,6 +45,7 @@ import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;
import org.newdawn.slick.util.Log;
/**
* "Game Ranking" (score card) state.
@ -168,10 +172,17 @@ public class GameRanking extends BasicGameState {
if (replayButton.contains(x, y)) {
Replay r = data.getReplay(null);
if (r != null) {
try {
r.load();
gameState.setReplay(r);
gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW);
returnToGame = true;
} catch (FileNotFoundException e) {
UI.sendBarNotification("Replay file not found.");
} catch (IOException e) {
Log.error("Failed to load replay data.", e);
UI.sendBarNotification("Failed to load replay data. See log for details.");
}
} else
UI.sendBarNotification("Replay file not found.");
}