@@ -216,21 +216,24 @@ public static ArrayList<Sample> getSamples(File f) throws Exception {
216216 return output ;
217217 }
218218
219- public static int getMode (File f ) throws Exception {
220- int mode = -1 ;
221- System .out .println (f .getAbsolutePath ());
219+ private static int parsMode (String line ) {
220+ return Integer .parseInt (line .replace ("Mode:" , "" ).trim ());
221+ }
222+
223+ public static int getMode (File f ) {
224+ log .info ("getting mode from file: {}" , f .getAbsolutePath ());
222225 try (BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (f ), "UTF-8" ))) {
223226 String line ;
224227 while ((line = br .readLine ()) != null ) {
225228 // read line by line
226- if (line .contains ("Mode: " )) {
227- mode = Integer . parseInt (line . substring ( 6 ) );
229+ if (line .contains ("Mode:" )) {
230+ return parsMode (line );
228231 }
229232 }
230233 } catch (Exception e ) {
231- e . printStackTrace ( );
234+ log . error ( "failed to get the mode with error {}" , e . getMessage (), e );
232235 }
233- return mode ;
236+ throw new RuntimeException ( " mode not found in file" ) ;
234237 }
235238
236239 public static String [] getAllInfo (File f ) throws Exception {
@@ -254,8 +257,8 @@ public static String[] getAllInfo(File f) throws Exception {
254257 if (line .contains ("Storyboard Sound Samples" )) {
255258 sectionID = 1 ;
256259 sampleInfo += line + nl ;
257- } else if (line .contains ("Mode :" )) {
258- int mode = Integer . parseInt (line . substring ( 6 ) );
260+ } else if (line .contains ("Mode:" )) {
261+ int mode = parsMode (line );
259262 if (mode != SUPPORTED_PLAY_MODE ) {
260263 String errMsg = "The currently supported mode is mania" ;
261264 JOptionPane .showMessageDialog (null , errMsg );
@@ -314,31 +317,6 @@ public static File getOsuFile(String path) {
314317 return f ;
315318 }
316319
317- /**
318- * @param a
319- * @param b
320- * @param c
321- * @return the 2 roots, 0 = small root, 1 = big root
322- */
323- public static double [] quadraticFormula (double a , double b , double c ) {
324- double d = b * b - 4 * a * c ;
325- if (d < 0 ) {
326- System .out .println ("Discriminant < 0, no real solutions" );
327- System .out .println ("b^2 = " + Math .pow (b , 2 ));
328- System .out .println ("4ac = " + 4 * a * c );
329- }
330- double [] output = new double [2 ];
331- output [1 ] = (-b + Math .sqrt (Math .pow (b , 2 ) - (4 * a * c ))) / (2 * a );
332- output [0 ] = (-b - Math .sqrt (Math .pow (b , 2 ) - (4 * a * c ))) / (2 * a );
333- return output ;
334- }
335-
336- public static double getImageToSBSize (String fullBGPath ) {
337- double safetyRange = 1.1 ;
338- double verticalScale = 480.0 / OsuUtils .getImageDim (fullBGPath ).getHeight () * safetyRange ;
339- return verticalScale ;
340- }
341-
342320 public static long [] getLastNoteTimingOfEachSection (File f ) throws Exception {
343321 ArrayList <Timing > redTiming = OsuUtils .getRedTimingPoints (f );
344322 int i = 0 ;
0 commit comments