From e6cad7f280c3e4c5ef1ad16d69fc341320777834 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Thu, 1 Feb 2018 23:28:43 +0100 Subject: Handling of -Dlevels option and default map when launching from a command line --- src/main/java/fr/umlv/java/wallj/Main.java | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/main/java/fr') diff --git a/src/main/java/fr/umlv/java/wallj/Main.java b/src/main/java/fr/umlv/java/wallj/Main.java index 5f0ca99..946a61c 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java @@ -8,26 +8,29 @@ import fr.umlv.zen5.Application; import java.awt.*; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; public class Main { - private static Path getResourcePath(String str) throws URISyntaxException { - return Paths.get(Main.class.getResource(str).toURI()); - } - - private static java.util.List getResourcePaths(String[] args) throws URISyntaxException { + private static final String DEFAULT_MAP_NAME = "/maps/level0.txt"; + private static java.util.List getResourcePaths(String[] args) throws URISyntaxException,IOException { LinkedList paths = new LinkedList<>(); - if (args.length > 0) { - for (String string : args) { - paths.add(Paths.get(string)); - } + String strFolder = System.getProperty("levels"); + if (strFolder != null) { + Path pathFolder = Paths.get(strFolder); + Files.newDirectoryStream(pathFolder).forEach(paths::add); } else { - paths.add(getResourcePath("/maps/level0.txt")); + final URI uri = Main.class.getResource(DEFAULT_MAP_NAME).toURI(); + Map env = new HashMap<>(); + env.put("create", "true"); + FileSystem zipfs = FileSystems.newFileSystem(uri, env); + paths.add(Paths.get(uri)); } return paths; } -- cgit v1.2.3