diff --git a/.gitignore b/.gitignore index 53a8747..ab252d5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /build/out/*.jar /build/in/*.jar *.log -.attach_pid* \ No newline at end of file +.attach_pid* +*~ diff --git a/build/Makefile b/build/Makefile index 1a089a4..300d96a 100644 --- a/build/Makefile +++ b/build/Makefile @@ -34,7 +34,7 @@ $(OUT): $(IN) $(STUB) run: $(OUT) - java -jar $(OUT) + java -jar $(OUT) -w ../.rogue-save clean: rm -rf $(OUT) diff --git a/build/stub-old.jar b/build/stub-old.jar new file mode 100644 index 0000000..56ed3e2 Binary files /dev/null and b/build/stub-old.jar differ diff --git a/build/stub.jar b/build/stub.jar index 56ed3e2..4b0cf7f 100644 Binary files a/build/stub.jar and b/build/stub.jar differ diff --git a/src/mightypork/gamecore/app/BaseApp.java b/src/mightypork/gamecore/app/BaseApp.java index b61895c..a9f7be9 100644 --- a/src/mightypork/gamecore/app/BaseApp.java +++ b/src/mightypork/gamecore/app/BaseApp.java @@ -67,9 +67,6 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { */ initLock(); - // hook - preInit(); - /* * Setup logging */ @@ -79,9 +76,12 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log)); } - // only here it makes sense to log. Log.i("=== Starting initialization sequence ==="); + // hook + preInit(); + + /* * Ionizables diff --git a/src/mightypork/gamecore/util/files/OsUtils.java b/src/mightypork/gamecore/util/files/OsUtils.java index 18b63b9..7429bfc 100644 --- a/src/mightypork/gamecore/util/files/OsUtils.java +++ b/src/mightypork/gamecore/util/files/OsUtils.java @@ -112,16 +112,16 @@ public class OsUtils { switch (getOs()) { case linux: case solaris: - file = new File(userhome, "." + dirname + '/'); + file = new File(userhome, dirname + '/'); break; case windows: final String appdata = System.getenv("APPDATA"); if (appdata != null) { - file = new File(appdata, "." + dirname + '/'); + file = new File(appdata, dirname + '/'); } else { - file = new File(userhome, "." + dirname + '/'); + file = new File(userhome, dirname + '/'); } break; diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 6a22148..241306d 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -2,6 +2,7 @@ package mightypork.rogue; import java.io.File; +import java.util.Arrays; import java.util.Locale; import mightypork.gamecore.app.BaseApp; @@ -18,6 +19,7 @@ import mightypork.gamecore.logging.writers.LogWriter; import mightypork.gamecore.render.DisplaySystem; import mightypork.gamecore.resources.loading.AsyncResourceLoader; import mightypork.gamecore.util.ion.Ion; +import mightypork.gamecore.util.strings.StringUtils; import mightypork.rogue.GameStateManager.GameState; import mightypork.rogue.events.ActionRequest; import mightypork.rogue.events.ActionRequest.RequestType; @@ -47,6 +49,32 @@ public final class App extends BaseApp { */ public static void main(String[] args) { + Log.f3(Arrays.toString(args)); + + try { + boolean lwd = false; + String lwdDir = null; + + for (int i = 0; i < args.length; i++) { + if (args[i].equals("--workdir") || args[i].equals("-w")) { + lwd = true; + lwdDir = args[i + 1]; + i++; + } + } + + if (!lwd) { + Paths.init(); + } else { + Paths.init(lwdDir); + } + + } catch (ArrayIndexOutOfBoundsException e) { + Log.e("Malformed arguments."); + } + + Log.i("Using workdir: " + Paths.WORKDIR.getAbsolutePath()); + (new App()).start(); } diff --git a/src/mightypork/rogue/Paths.java b/src/mightypork/rogue/Paths.java index 6eddd35..91e0a8b 100644 --- a/src/mightypork/rogue/Paths.java +++ b/src/mightypork/rogue/Paths.java @@ -3,25 +3,63 @@ package mightypork.rogue; import java.io.File; +import mightypork.gamecore.util.files.OsUtils; + public final class Paths { - public static final File WORKDIR = new File("./.rogue-save");//OsUtils.getWorkDir(APPDIR_NAME); + private static final String WORKDIR_NAME = ".rogue-save"; + + public static File WORKDIR; + public static File LOG_FILE; + public static File SCREENSHOTS; + public static File CONFIG; + public static File LOCK; + + public static File SAVE_SLOT_1; + public static File SAVE_SLOT_2; + public static File SAVE_SLOT_3; - public static final File LOG_FILE = new File(WORKDIR, "runtime.log"); - public static final File SCREENSHOTS = new File(WORKDIR, "screenshots"); + /** + * Initialize for local workdir + * + * @param local_wd_name workdir name + */ + public static void init(String local_wd_name) + { + init(true, local_wd_name); + } - public static final File CONFIG = new File(WORKDIR, "config.ini"); - public static final File LOCK = new File(WORKDIR, ".lock"); + /** + * Initialize for gloal workdir + */ + public static void init() + { + init(false, WORKDIR_NAME); + } - public static final String DIR_EFFECTS = "res/sounds/effects/"; - public static final String DIR_MUSIC = "res/sounds/music/"; - public static final String DIR_LOOPS = "res/sounds/loops/"; - public static final File SAVE_SLOT_1 = new File(WORKDIR, "saves/slot_1.ion"); - public static final File SAVE_SLOT_2 = new File(WORKDIR, "saves/slot_2.ion"); - public static final File SAVE_SLOT_3 = new File(WORKDIR, "saves/slot_3.ion"); + private static void init(boolean local_workdir, String workdir_name) + { + if (local_workdir) { + WORKDIR = new File(workdir_name); + } else { + WORKDIR = OsUtils.getWorkDir(workdir_name); + } + + LOG_FILE = new File(WORKDIR, "runtime.log"); + + SCREENSHOTS = new File(WORKDIR, "screenshots"); + + CONFIG = new File(WORKDIR, "config.ini"); + + LOCK = new File(WORKDIR, ".lock"); + + SAVE_SLOT_1 = new File(WORKDIR, "saves/slot_1.ion"); + SAVE_SLOT_2 = new File(WORKDIR, "saves/slot_2.ion"); + SAVE_SLOT_3 = new File(WORKDIR, "saves/slot_3.ion"); + } }