1919import me .piitex .renjava .configuration .RenJavaConfiguration ;
2020import me .piitex .renjava .gui .GuiLoader ;
2121import me .piitex .renjava .loggers .ApplicationLogger ;
22+ import me .piitex .renjava .loggers .RenLogger ;
2223import org .reflections .Reflections ;
2324import org .reflections .scanners .Scanners ;
2425import org .reflections .util .ClasspathHelper ;
@@ -34,6 +35,9 @@ public static void main(String[] args) {
3435 // Rough execution time (not accurate)
3536 start = System .currentTimeMillis ();
3637
38+ // Initializes the Ren logger which is separated from the application logger.
39+ RenLogger .init ();
40+
3741 InfoFile buildInfo = new InfoFile (new File (System .getProperty ("user.dir" ) + "/renjava/build.info" ), true );
3842 if (buildInfo .containsKey ("main" )) {
3943 String mainClass = buildInfo .getString ("main" );
@@ -42,10 +46,10 @@ public static void main(String[] args) {
4246 clazz = Class .forName (mainClass );
4347 loadClass (clazz , args , buildInfo );
4448 } catch (ClassNotFoundException e ) {
45- System . err . println ("Failed to load class: " + e .getMessage ());
49+ RenLogger . LOGGER . error ("Failed to load class: {}" , e .getMessage ());
4650 }
4751 } else {
48- System . err . println ("Build info not found. Scanning for RenJava class. This will have noticeable performance impact on low end computers." );
52+ RenLogger . LOGGER . error ("Build info not found. Scanning for RenJava class. This will have noticeable performance impact on low end computers." );
4953 // Scans for all classes in all packages. (We need to do all packages because this allows the author the freedom to do their own package scheme.)
5054 Collection <URL > allPackagePrefixes = Arrays .stream (Package .getPackages ())
5155 .map (Package ::getName )
@@ -69,30 +73,27 @@ public static void main(String[] args) {
6973
7074 private static void loadClass (Class <?> clazz , String [] args , InfoFile infoFile ) {
7175 try {
72- File file = new File ( System . getProperty ( "user.dir" ) + "/renjava/build.info" );
73- if (! file .exists ()) {
74- file . createNewFile ();
76+ if (! infoFile . exists ()) {
77+ RenLogger . LOGGER . error ( "Could not create the 'build.info' file. This might be a first time setup. Once the application opens please exit and relaunch." );
78+ return ; // This will exit the application.
7579 }
76-
7780 String jarPath = Launch .class
7881 .getProtectionDomain ()
7982 .getCodeSource ()
8083 .getLocation ()
8184 .toURI ()
8285 .getPath ();
8386
84- System . out . println ( "Path: " + jarPath );
87+ RenLogger . LOGGER . info ( "Jar path: {}" , jarPath );
8588
8689 String [] split = jarPath .split ("/" );
8790 String fileName = split [split .length - 1 ];
8891
8992 infoFile .write ("main" , clazz .getName ());
9093 infoFile .write ("file" , fileName );
9194
92- } catch (IOException e ) {
93- System .err .println ("Could not create the 'build.info' file. This might be a first time setup. Once the application opens please exit and relaunch." );
9495 } catch (URISyntaxException e ) {
95- System . err . println ("Could retrieve runtime information." );
96+ RenLogger . LOGGER . error ("Could retrieve runtime information." , e );
9697 }
9798
9899 try {
@@ -106,7 +107,7 @@ private static void loadClass(Class<?> clazz, String[] args, InfoFile infoFile)
106107 renJava .author = game .author ();
107108 renJava .version = game .version ();
108109 } else {
109- System . err . println ( "ERROR: Please annotate your main class with 'Game'." );
110+ RenLogger . LOGGER . error ( " Please annotate your main class with 'Game'." );
110111 renJava .name = "Error" ;
111112 renJava .author = "Error" ;
112113 renJava .version = "Error" ;
@@ -118,7 +119,7 @@ private static void loadClass(Class<?> clazz, String[] args, InfoFile infoFile)
118119 RenJavaConfiguration configuration = new RenJavaConfiguration (conf .title ().replace ("{version}" , renJava .version ).replace ("{name}" , renJava .name ).replace ("{author}" , renJava .author ), conf .width (), conf .height (), new ImageLoader (conf .windowIconPath ()));
119120 renJava .setConfiguration (configuration );
120121 } else {
121- System . err . println ( "ERROR: Configuration annotation not found. Please annotate your main class with 'Configuration'" );
122+ RenLogger . LOGGER . error ( " Configuration annotation not found. Please annotate your main class with 'Configuration'" );
122123 RenJavaConfiguration configuration = new RenJavaConfiguration ("Error" , 1920 , 1080 , new ImageLoader ("gui/window_icon.png" ));
123124 renJava .setConfiguration (configuration );
124125 }
@@ -132,7 +133,7 @@ private static void loadClass(Class<?> clazz, String[] args, InfoFile infoFile)
132133 renJava .init (); // Initialize game
133134 launch (args );
134135 } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e ) {
135- System . err . println ( "ERROR: Could initialize the RenJava framework: " + e .getMessage ());
136+ RenLogger . LOGGER . error ( " Could initialize the RenJava framework: {}" , e .getMessage ());
136137 }
137138 }
138139
0 commit comments