summaryrefslogtreecommitdiff
path: root/tools/tmwcon/src/converter/Main.java
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2008-11-11 14:39:23 +0000
committerJared Adams <jaxad0127@gmail.com>2008-11-11 14:39:23 +0000
commit515f38e52100eac09275f0821e93e0eaf3e2cc3c (patch)
tree135d7d54c114e8a4e9c2c6882f72206819bf747e /tools/tmwcon/src/converter/Main.java
parentc38bbf027133f6e50947a7405b3a64dcbca3b0b9 (diff)
downloadserverdata-515f38e52100eac09275f0821e93e0eaf3e2cc3c.tar.gz
serverdata-515f38e52100eac09275f0821e93e0eaf3e2cc3c.tar.bz2
serverdata-515f38e52100eac09275f0821e93e0eaf3e2cc3c.tar.xz
serverdata-515f38e52100eac09275f0821e93e0eaf3e2cc3c.zip
Add a tool to convert from TMWServ format
This tool will convert warps and monster spawns from TMWServ format (tmx files) into eAthena format. It will also generate the wlk files needed by eAthena.
Diffstat (limited to 'tools/tmwcon/src/converter/Main.java')
-rw-r--r--tools/tmwcon/src/converter/Main.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/tmwcon/src/converter/Main.java b/tools/tmwcon/src/converter/Main.java
new file mode 100644
index 00000000..4f3a6947
--- /dev/null
+++ b/tools/tmwcon/src/converter/Main.java
@@ -0,0 +1,86 @@
+//
+
+package converter;
+
+import java.io.*;
+import java.util.*;
+
+import tiled.io.xml.*;
+
+public class Main extends Thread {
+ public static XMLMapTransformer reader = null;
+
+ private static tiled.core.Map loadMap(File file) {
+ tiled.core.Map map = null;
+ try {
+ map = reader.readMap(file.getAbsolutePath());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return map;
+ }
+
+ public static boolean isTMX(File in) {
+ if (in.isDirectory()) return false;
+
+ return in.getName().matches(".*\\.tmx(\\.gz)?$");
+ }
+
+ public static Collection<File> getTMXFiles(File directory) {
+ if (!directory.isDirectory()) return Collections.emptyList();
+
+ List<File> ret = new Vector<File>();
+
+ for (File f : directory.listFiles()) {
+ if (f.isDirectory()) {
+ ret.addAll(getTMXFiles(f));
+ } else if (isTMX(f)) {
+ ret.add(f);
+ }
+ }
+
+ return ret;
+ }
+
+ public static PrintWriter getWriter(File f) {
+ try {
+ f.createNewFile();
+ return new PrintWriter(f);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static String getName(File folder, File file) {
+ String path = folder.getAbsolutePath();
+ String name = file.getAbsolutePath();
+ if (name.startsWith(path)) name = name.substring(path.length() + 1);
+ if (name.endsWith(".gz")) name = name.substring(0, name.length() - 3);
+ if (name.endsWith(".tmx")) name = name.substring(0, name.length() - 4);
+ return name;
+ }
+
+ public static void run(String[] args, int unused) {
+ reader = new XMLMapTransformer();
+
+ File folder = new File("server-data/data/");
+ Process.prepWLK(folder);
+
+ folder = new File("tmwdata/maps/");
+
+ Collection<File> tmxs = getTMXFiles(folder);
+ String name;
+ for (File f : tmxs) {
+ name = getName(folder, f);
+ System.out.printf("== %s ==\n", name);
+ Process.processMap(name, loadMap(f));
+ }
+ }
+
+ public static void main(String[] args) {
+ run(args, 0);
+ }
+}