[Jrisk-cvs] SF.net SVN: domination-code:[2528] Domination
Brought to you by:
yuranet
|
From: <yu...@us...> - 2024-05-07 19:53:38
|
Revision: 2528
http://sourceforge.net/p/domination/code/2528
Author: yuranet
Date: 2024-05-07 19:53:35 +0000 (Tue, 07 May 2024)
Log Message:
-----------
even more resilient game loading
Modified Paths:
--------------
Domination/sharedUI/src_mapstore_lobby/net/yura/domination/audio/GameSound.java
Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
Modified: Domination/sharedUI/src_mapstore_lobby/net/yura/domination/audio/GameSound.java
===================================================================
--- Domination/sharedUI/src_mapstore_lobby/net/yura/domination/audio/GameSound.java 2024-05-06 16:56:12 UTC (rev 2527)
+++ Domination/sharedUI/src_mapstore_lobby/net/yura/domination/audio/GameSound.java 2024-05-07 19:53:35 UTC (rev 2528)
@@ -102,10 +102,10 @@
String key = attributes.getValue("name");
String filename = attributes.getValue("file");
- // TODO this check is wrong on android/ios
- if (!new File("sound", filename).exists()) {
- System.out.println("[WARNING!!!!!] File not found: " + filename);
- }
+ // TODO this check is wrong on android/ios, also if 'user.dir' has been changed
+ //if (!new File("sound", filename).exists()) {
+ // System.out.println("[WARNING!!!!!] File not found: " + filename);
+ //}
currentTheme.put(key, folder + "/" + filename);
}
Modified: Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2024-05-06 16:56:12 UTC (rev 2527)
+++ Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2024-05-07 19:53:35 UTC (rev 2528)
@@ -18,7 +18,6 @@
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.ComponentEvent;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
@@ -364,11 +363,16 @@
return new URL( bs.getCodeBase() , a);
}
else {
- return new File(a).toURI().toURL();
+ File file = new File(a);
+ if (file.exists()) {
+ return file.toURI().toURL();
+ }
+ // in case the 'user.dir' has been changed
+ return new File(System.getProperty("user.dir"), a).toURI().toURL();
}
}
catch (Exception e) {
- throw new RuntimeException(e);
+ throw new RuntimeException("unable to get url for: " + a, e);
}
}
@@ -401,39 +405,42 @@
// riskconfig.getProperty("default.map")
final String dmname = RiskGame.getDefaultMap();
- try {
- // if we can not find maps, attempt to get path from jar file
- if ( !(new File(mapsdir1.get(), dmname ).exists()) ) {
+ if ( !(new File(mapsdir1.get(), dmname).exists()) ) {
+ try {
+ // if we can not find maps, attempt to get path from jar file
URL url = RiskUIUtil.class.getProtectionDomain().getCodeSource().getLocation();
File jarFile = new File(url.toURI());
mapsdir1.set(new File(jarFile.getParentFile(), "maps"));
}
- }
- catch (Throwable th) {
- Logger.getLogger(RiskUIUtil.class.getName()).info("failed to get maps dir from jar " + th);
- }
+ catch (Throwable th) {
+ Logger.getLogger(RiskUIUtil.class.getName()).info("failed to get maps dir from jar " + th);
+ }
- while ( !(new File(mapsdir1.get(), dmname ).exists()) ) {
+ // if we still can not find the map, try and ask the user
+ while ( !(new File(mapsdir1.get(), dmname).exists()) ) {
- // on Apple OS X java 1.7 this deadlocks if not on the UI Thread
- SwingUtilities.invokeAndWait(new Runnable() { public void run() {
+ // on Apple OS X java 1.7 this deadlocks if not on the UI Thread
+ SwingUtilities.invokeAndWait(new Runnable() { public void run() {
- JOptionPane.showMessageDialog(null,"Can not find map: "+dmname );
+ JOptionPane.showMessageDialog(null, "Can not find map: " + dmname);
- JFileChooser fc = new JFileChooser( new File(".") );
- fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- fc.setDialogTitle("Select maps directory");
+ JFileChooser fc = new JFileChooser( new File(".") );
+ fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ fc.setDialogTitle("Select maps directory");
- int returnVal = fc.showOpenDialog(null);
- if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
- mapsdir1.set(fc.getSelectedFile());
- }
- else {
- System.exit(0);
- }
+ int returnVal = fc.showOpenDialog(null);
+ if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
+ mapsdir1.set(fc.getSelectedFile());
+ }
+ else {
+ System.exit(0);
+ }
- }});
- }
+ }});
+ }
+
+ System.setProperty("user.dir", mapsdir1.get().getParent());
+ }
mapsdir = mapsdir1.get().toURI().toURL();
}
|