From: <ev...@us...> - 2011-01-22 15:22:45
|
Revision: 1472 http://rails.svn.sourceforge.net/rails/?rev=1472&view=rev Author: evos Date: 2011-01-22 15:22:39 +0000 (Sat, 22 Jan 2011) Log Message: ----------- Patch by Adam Badura to fix errors with loading from the command line. Modified Paths: -------------- trunk/18xx/rails/util/RunGame.java Modified: trunk/18xx/rails/util/RunGame.java =================================================================== --- trunk/18xx/rails/util/RunGame.java 2011-01-22 15:19:57 UTC (rev 1471) +++ trunk/18xx/rails/util/RunGame.java 2011-01-22 15:22:39 UTC (rev 1472) @@ -10,7 +10,7 @@ public static void main(String[] args) { - // intialize configuration + // Initialize configuration Config.setConfigSelection(); int nargs = 0; @@ -23,13 +23,35 @@ } if (nargs >= 1) { - loadGame (args); + // We have to run loadGame on an AWT EventQueue to make sure + // that NDC will properly initialize game key so that + // GameManager instance can be properly queried for. This is a + // consequence of NDC abuse. + loadGameOnEventQueue(args); } else { /* Start the rails.game selector, which will do all the rest. */ new GameSetupWindow(); } } + static void loadGameOnEventQueue(final String[] args) + { + try { + java.awt.EventQueue.invokeAndWait( + new Runnable() + { + public void run() { + loadGame(args); + } + } + ); + } catch (Exception e) { + System.err.println("Cannot load game: "+e.getMessage()); + e.printStackTrace(System.err); + System.exit(1); + } + } + static void loadGame (String[] args) { Game game = null; @@ -48,6 +70,12 @@ Class.forName(gameUIManagerClassName).asSubclass(GameUIManager.class); gameUIManager = gameUIManagerClass.newInstance(); gameUIManager.init(gameManager); + + String directory = new java.io.File(filepath).getParent(); + if(directory != null) { + gameUIManager.setSaveDirectory(directory); + } + gameUIManager.startLoadedGame(); } catch (Exception e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |