Validate audio files before trying to load them. (part of #120)

Also fixed an issue where songMenu.resetGameDataOnLoad() sometimes wasn't being called when it should be (e.g. after playing a beatmap, if you move to a different screen, your score won't appear in the song menu right away).  It's now being called more often than necessary, but that should be fine.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-08-20 22:58:45 -05:00
parent 130f9bf445
commit ae5016f3ab
5 changed files with 21 additions and 11 deletions

View File

@ -1472,7 +1472,7 @@ public class GameData {
/**
* Sets whether or not this object is used for gameplay.
* @return true if gameplay, false if score viewing
* @param gameplay true if gameplay, false if score viewing
*/
public void setGameplay(boolean gameplay) { this.isGameplay = gameplay; }

View File

@ -201,12 +201,9 @@ public class Opsu extends StateBasedGame {
SongMenu songMenu = (SongMenu) this.getState(Opsu.STATE_SONGMENU);
if (id == STATE_GAMERANKING) {
GameData data = ((GameRanking) this.getState(Opsu.STATE_GAMERANKING)).getGameData();
if (data != null && data.isGameplay()) {
songMenu.resetGameDataOnLoad();
if (data != null && data.isGameplay())
songMenu.resetTrackOnLoad();
}
} else {
songMenu.resetGameDataOnLoad();
if (id == STATE_GAME) {
MusicController.pause();
MusicController.resume();
@ -215,6 +212,7 @@ public class Opsu extends StateBasedGame {
}
if (UI.getCursor().isSkinned())
UI.getCursor().reset();
songMenu.resetGameDataOnLoad();
this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
return false;
}

View File

@ -22,6 +22,7 @@ import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.ui.UI;
import java.io.File;
import java.io.IOException;
@ -41,6 +42,7 @@ import org.newdawn.slick.MusicListener;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ResourceLoader;
import org.tritonus.share.sampled.file.TAudioFileFormat;
/**
@ -87,6 +89,13 @@ public class MusicController {
public static void play(final Beatmap beatmap, final boolean loop, final boolean preview) {
// new track: load and play
if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
final File audioFile = beatmap.audioFilename;
if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
UI.sendBarNotification(String.format("Could not find track '%s'.", audioFile.getName()));
System.out.println(beatmap);
return;
}
reset();
System.gc();
@ -96,7 +105,7 @@ public class MusicController {
trackLoader = new Thread() {
@Override
public void run() {
loadTrack(beatmap.audioFilename, (preview) ? beatmap.previewTime : 0, loop);
loadTrack(audioFile, (preview) ? beatmap.previewTime : 0, loop);
}
};
trackLoader.start();

View File

@ -243,11 +243,10 @@ public class GameRanking extends BasicGameState {
*/
private void returnToSongMenu() {
SoundController.playSound(SoundEffect.MENUBACK);
if (data.isGameplay()) {
SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
songMenu.resetGameDataOnLoad();
SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
if (data.isGameplay())
songMenu.resetTrackOnLoad();
}
songMenu.resetGameDataOnLoad();
if (UI.getCursor().isSkinned())
UI.getCursor().reset();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));

View File

@ -1318,8 +1318,12 @@ public class SongMenu extends BasicGameState {
return;
SoundController.playSound(SoundEffect.MENUHIT);
MultiClip.destroyExtraClips();
Beatmap beatmap = MusicController.getBeatmap();
if (focusNode == null || beatmap != focusNode.getBeatmapSet().get(focusNode.beatmapIndex)) {
UI.sendBarNotification("Unable to load the beatmap audio.");
return;
}
MultiClip.destroyExtraClips();
Game gameState = (Game) game.getState(Opsu.STATE_GAME);
gameState.loadBeatmap(beatmap);
gameState.setRestart(Game.Restart.NEW);