diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | tools/tmwcon/.gitignore | 3 | ||||
-rw-r--r-- | tools/tmwcon/MANIFEST.MF | 2 | ||||
-rw-r--r-- | tools/tmwcon/README | 28 | ||||
-rwxr-xr-x | tools/tmwcon/build.xml | 3 | ||||
-rw-r--r-- | tools/tmwcon/src/Converter.java | 54 | ||||
-rw-r--r-- | tools/tmwcon/src/converter/Main.java | 42 | ||||
-rw-r--r-- | tools/tmwcon/src/converter/Process.java | 37 | ||||
-rw-r--r-- | tools/tmwcon/src/converter/WLKInterface.java | 2 |
10 files changed, 51 insertions, 125 deletions
@@ -2,3 +2,4 @@ log/ gm.log.* online.* +/converter.txt diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..dc5b5e29 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: maps +maps: + ant -f tools/tmwcon/build.xml + java -jar tools/tmwcon/converter.jar client-data/ world/map/ diff --git a/tools/tmwcon/.gitignore b/tools/tmwcon/.gitignore index c7da1337..056686cf 100644 --- a/tools/tmwcon/.gitignore +++ b/tools/tmwcon/.gitignore @@ -1,3 +1,2 @@ -*.class -/summary.txt +/build /converter.jar diff --git a/tools/tmwcon/MANIFEST.MF b/tools/tmwcon/MANIFEST.MF index 954575d7..2cdfdcd8 100644 --- a/tools/tmwcon/MANIFEST.MF +++ b/tools/tmwcon/MANIFEST.MF @@ -1 +1,3 @@ +Manifest-Version: 1.0 Main-Class: converter.Main +Class-Path: tiled-core.jar tmw.jar diff --git a/tools/tmwcon/README b/tools/tmwcon/README index a48fc836..e3a4a31a 100644 --- a/tools/tmwcon/README +++ b/tools/tmwcon/README @@ -2,26 +2,10 @@ Dependencies: * ant (recent version) * J2SE 5 or higher (or equivalent) - * Tiled or Tiled core jar file (in this directory) - * TMW Tiled plugin jar (in this directory or the plugins directory) + * Tiled core jar file (in this directory) + * TMW Tiled plugin jar (in this directory) -Compilation: - - Run ant from this directory. - -Usage: - - * Create a directory called tmwdata containing the client data - (can be symlink) - - * Output will be in a directory called server-data - (usually you make this a symlink to eathena-data) - - * If the aforementioned jar files are in class path you can run the - converter jar file directly: - - java -jar converter.jar - - Otherwise, the Converter class can handle that for you: - - java Converter +Compilation and Usage: + Run + make maps + from the top level of the server data. diff --git a/tools/tmwcon/build.xml b/tools/tmwcon/build.xml index b2937e66..26497f8e 100755 --- a/tools/tmwcon/build.xml +++ b/tools/tmwcon/build.xml @@ -13,8 +13,7 @@ <target name="compile" depends="init" description="Compile the source"> <javac source="1.5" target="1.5" srcdir="src" destdir="build" - deprecation="on" classpath="tiled.jar;tiled-core.jar;plugins/tmw.jar;tmw.jar"/> - <copy file="build/Converter.class" todir="."/> + deprecation="on" classpath="tiled-core.jar;tmw.jar"/> </target> <target name="dist" depends="compile" description="Generate the distribution"> diff --git a/tools/tmwcon/src/Converter.java b/tools/tmwcon/src/Converter.java deleted file mode 100644 index 0f245aa3..00000000 --- a/tools/tmwcon/src/Converter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * TMWServ to eAthena Converter (c) 2008 Jared Adams - * License: GPL, v2 or later - */ - -import java.io.*; -import java.lang.reflect.*; -import java.net.*; -import java.util.*; - -public abstract class Converter { - static String[] tiledJars = {"tiled-core.jar", "tiled.jar"}; - static String[] wlkJars = {"plugins/tmw.jar", "tmw.jar"}; - - public static void main(String[] args) throws Exception { - List<URL> urls = new ArrayList<URL>(); - - File tiled = null; - for (String s : tiledJars) { - tiled = new File(s); - if (tiled.exists()) break; - } - if (tiled == null || !tiled.exists()) { - System.err.println("Unable to find a Tiled jar file! Exiting."); - System.exit(-5); - } - urls.add(tiled.toURI().toURL()); - - File wlkWriter = null; - for (String s : wlkJars) { - wlkWriter = new File(s); - if (wlkWriter.exists()) break; - } - if (wlkWriter == null || !wlkWriter.exists()) { - System.err.println("Unable to find the tmw plugin for Tiled! No wlk files will be made!"); - } else { - urls.add(wlkWriter.toURI().toURL()); - } - - File self = new File("converter.jar"); - if (!self.exists()) { - System.err.println("Unable to find a the converter jar! Exiting."); - System.exit(-5); - } - urls.add(self.toURI().toURL()); - - URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[0])); - Class c = loader.loadClass("converter.Main"); - Method m = c.getMethod("run", String[].class, Integer.TYPE); - System.out.println("Starting"); - - m.invoke(null, args, 0); - } -} diff --git a/tools/tmwcon/src/converter/Main.java b/tools/tmwcon/src/converter/Main.java index 80dfe30e..ab7786a9 100644 --- a/tools/tmwcon/src/converter/Main.java +++ b/tools/tmwcon/src/converter/Main.java @@ -66,45 +66,35 @@ public class Main { return name; } - public static void run(String[] args, int unused) { - reader = new XMLMapTransformer(); + public static void main(String[] args) throws IOException { + if (args.length != 2) { + System.out.println("Usage: java Converter client-data-dir server-data-dir"); + System.exit(1); + } - PrintWriter summary = null; + File client_data = new File(args[0]); + File server_data = new File(args[1]); - try { - File temp = new File("summary.txt"); - temp.createNewFile(); - summary = new PrintWriter(temp); - } catch (Exception e) { - System.out.println("Problem opening summary file for writing:"); - e.printStackTrace(); - } + reader = new XMLMapTransformer(); + + PrintWriter summary = new PrintWriter("converter.txt"); - File folder = new File("server-data/data/"); - folder.mkdirs(); - Process.prepWLK(folder); + Process.setServerData(server_data); - folder = new File("tmwdata/maps/"); + File folder = new File(client_data, "maps/"); Collection<File> tmxs = getTMXFiles(folder); - Vector<String> folders = new Vector<String>(); + ArrayList<String> folders = new ArrayList<String>(); String name; for (File f : tmxs) { name = getName(folder, f); System.out.printf("== %s ==\n", name); - if (summary != null) summary.printf("== %s ==\n", name); folders.add(Process.processMap(name, loadMap(f), f, summary)); } - if (summary != null) { - summary.flush(); - summary.close(); - } - - Process.writeMasterImport(folders.toArray(new String[0])); - } + summary.flush(); + summary.close(); - public static void main(String[] args) { - run(args, 0); + Process.writeMasterImport(folders); } } diff --git a/tools/tmwcon/src/converter/Process.java b/tools/tmwcon/src/converter/Process.java index 92fa3da4..ab2eb801 100644 --- a/tools/tmwcon/src/converter/Process.java +++ b/tools/tmwcon/src/converter/Process.java @@ -18,21 +18,20 @@ import tiled.core.*; import tiled.plugins.tmw.*; public class Process { - private static final String baseFolder = "server-data/"; - private static final File _baseFolder = new File(baseFolder); - private static final String scriptDirectory = "npc/"; private static final String mobFile = "_mobs.txt"; private static final String warpFile = "_warps.txt"; private static final String importFile = "_import.txt"; + private static File server_data; + private static File script_directory; private static File wlkFolder; private static WLKInterface wlk = null; - public static void prepWLK(File folder) { - wlkFolder = folder; - try { - wlk = new WLKInterface(); - } catch (NoClassDefFoundError ncdfe) {} + public static void setServerData(File folder) { + server_data = folder; + script_directory = new File(server_data, "npc/"); + wlkFolder = new File(server_data, "data/"); + wlk = new WLKInterface(); } private static String getProp(Properties props, String name, String def) { @@ -81,7 +80,8 @@ public class Process { if (y < 0) return; int[] shape = resolveBounds(bounds, true); System.out.printf("Usable warp found: %s\n", name); - out.printf("%s.gat,%d,%d\twarp\t%s\t%d,%d,%s.gat,%d,%d\n", map, shape[0], shape[1], name, shape[2], shape[3], dest, x / 32, y / 32); + out.printf("%s.gat,%d,%d\twarp\t%s\t%d,%d,%s.gat,%d,%d\n", + map, shape[0], shape[1], name, shape[2], shape[3], dest, x / 32, y / 32); } private static int handleMob(PrintWriter out, String map, String name, Rectangle bounds, Properties props) { @@ -94,7 +94,8 @@ public class Process { int time2 = getProp(props, "eA_death", 0); int[] shape = resolveBounds(bounds, false); System.out.printf("Usable mob found: %s (%d)\n", name, mob); - out.printf("%s.gat,%d,%d,%d,%d\tmonster\t%s\t%d,%d,%d,%d,Mob%s::On%d\n", map, shape[0], shape[1], shape[2], shape[3], name, mob, max, time1, time2, map, mob); + out.printf("%s.gat,%d,%d,%d,%d\tmonster\t%s\t%d,%d,%d,%d,Mob%s::On%d\n", + map, shape[0], shape[1], shape[2], shape[3], name, mob, max, time1, time2, map, mob); return mob; } @@ -126,7 +127,7 @@ public class Process { if (f.isDirectory()) { processFiles(folder, out); } else if (!f.getName().equals(importFile)) { - out.add("npc: " + f.getPath().substring(_baseFolder.getPath().length() + 1)); + out.add("npc: " + f.getPath().substring(server_data.getPath().length() + 1)); } } } @@ -137,7 +138,8 @@ public class Process { processFiles(folder, output_elements); PrintWriter importOut = Main.getWriter(_import); importOut.printf("// Map %s: %s\n", name, title); - importOut.printf("// This file is generated automatically. All manually changes will be removed when running the Converter.\nmap: %s.gat\n", name); + importOut.printf("// This file is generated automatically. All manually changes will be removed when running the Converter.\n"); + importOut.printf("map: %s.gat\n", name); Collections.sort(output_elements); for (String s : output_elements) importOut.println(s); @@ -152,10 +154,9 @@ public class Process { Properties props = map.getProperties(); String title = getProp(props, "name", ""); - String folderName = scriptDirectory + name; + String folderName = "npc/" + name; - File folder = new File(baseFolder + folderName); - folder.mkdirs(); + File folder = new File(script_directory, name); System.out.println(title); @@ -209,8 +210,8 @@ public class Process { return folderName; } - public static void writeMasterImport(String[] folders) { - File master = new File(baseFolder + scriptDirectory + "_import.txt"); + public static void writeMasterImport(ArrayList<String> folders) { + File master = new File(script_directory, importFile); PrintWriter out = Main.getWriter(master); if (out == null) return; @@ -224,7 +225,7 @@ public class Process { Collections.sort(output_elements); for (String s : output_elements) - out.println(s); + out.println(s); out.flush(); out.close(); diff --git a/tools/tmwcon/src/converter/WLKInterface.java b/tools/tmwcon/src/converter/WLKInterface.java index b9e0cb20..16735244 100644 --- a/tools/tmwcon/src/converter/WLKInterface.java +++ b/tools/tmwcon/src/converter/WLKInterface.java @@ -22,7 +22,7 @@ public class WLKInterface { WLKWriter.writeMap(map, new FileOutputStream(wlk)); System.out.println("WLK written"); } catch (Exception e) { - System.out.println("Prolem writing WLK file:"); + System.out.println("Problem writing WLK file:"); e.printStackTrace(); } } |