diff --git a/res/theme.osu b/res/theme.osu deleted file mode 100644 index 9ab29ae2..00000000 --- a/res/theme.osu +++ /dev/null @@ -1,12 +0,0 @@ -[General] -// theme song file name (mp3/ogg supported) -AudioFilename: theme.ogg - -[Metadata] -// theme song title and artist -Title:welcome to osu! -Artist:nekodex - -[HitObjects] -// length of theme song, in ms (third field) -1,1,48000,1,0,0:0:0:0: diff --git a/src/itdelatrisu/opsu/MusicController.java b/src/itdelatrisu/opsu/MusicController.java index 9d191c6d..4084c62a 100644 --- a/src/itdelatrisu/opsu/MusicController.java +++ b/src/itdelatrisu/opsu/MusicController.java @@ -22,7 +22,6 @@ import itdelatrisu.opsu.states.Options; import java.io.File; import java.lang.reflect.Field; -import java.net.URL; import java.nio.IntBuffer; import javazoom.jl.converter.Converter; @@ -35,7 +34,6 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.openal.Audio; import org.newdawn.slick.openal.SoundStore; import org.newdawn.slick.util.Log; -import org.newdawn.slick.util.ResourceLoader; /** * Controller for all music. @@ -261,16 +259,10 @@ public class MusicController { * Plays the theme song. */ public static void playThemeSong() { - try { - URL themeURL = ResourceLoader.getResource(Options.OSU_THEME_NAME); - File themeFile = new File(themeURL.toURI()); - OsuFile osu = OsuParser.parseFile(themeFile, null, false); - URL audioURL = ResourceLoader.getResource(osu.audioFilename.getName()); - osu.audioFilename = new File(audioURL.toURI()); + OsuFile osu = Options.getOsuTheme(); + if (osu != null) { play(osu, true); themePlaying = true; - } catch (Exception e) { - Log.error("Failed to load theme song.", e); } } diff --git a/src/itdelatrisu/opsu/states/Options.java b/src/itdelatrisu/opsu/states/Options.java index 23a06391..4fa40c33 100644 --- a/src/itdelatrisu/opsu/states/Options.java +++ b/src/itdelatrisu/opsu/states/Options.java @@ -21,6 +21,7 @@ package itdelatrisu.opsu.states; import itdelatrisu.opsu.GUIMenuButton; import itdelatrisu.opsu.GameMod; import itdelatrisu.opsu.Opsu; +import itdelatrisu.opsu.OsuFile; import itdelatrisu.opsu.SoundController; import itdelatrisu.opsu.Utils; @@ -83,11 +84,6 @@ public class Options extends BasicGameState { */ public static final String FONT_NAME = "kochi-gothic.ttf"; - /** - * The theme song OsuFile file name. - */ - public static final String OSU_THEME_NAME = "theme.osu"; - /** * The beatmap directory. */ @@ -108,6 +104,12 @@ public class Options extends BasicGameState { */ private static File skinDir; + /** + * The theme song string: + * filename, title, artist, length (ms) + */ + private static String themeString = "theme.ogg,welcome to osu!,nekodex,48000"; + /** * Game options. */ @@ -1289,6 +1291,31 @@ public class Options extends BasicGameState { return skinDir; } + /** + * Returns a dummy OsuFile containing the theme song. + * @return the theme song OsuFile + */ + public static OsuFile getOsuTheme() { + String[] tokens = themeString.split(","); + if (tokens.length != 4) { + Log.error("Theme song string is malformed."); + return null; + } + + OsuFile osu = new OsuFile(null); + osu.audioFilename = new File(tokens[0]); + osu.title = tokens[1]; + osu.artist = tokens[2]; + try { + osu.endTime = Integer.parseInt(tokens[3]); + } catch (NumberFormatException e) { + Log.error("Theme song length is not a valid integer", e); + return null; + } + + return osu; + } + /** * Reads user options from the options file, if it exists. */ @@ -1325,6 +1352,9 @@ public class Options extends BasicGameState { case "Skin": skinDir = new File(value); break; + case "ThemeSong": + themeString = value; + break; case "Port": i = Integer.parseInt(value); if (i > 0 && i <= 65535) @@ -1475,6 +1505,8 @@ public class Options extends BasicGameState { writer.newLine(); writer.write(String.format("Skin = %s", getSkinDir().getAbsolutePath())); writer.newLine(); + writer.write(String.format("ThemeSong = %s", themeString)); + writer.newLine(); writer.write(String.format("Port = %d", port)); writer.newLine(); writer.write(String.format("ScreenResolution = %d", resolutionIndex));