summaryrefslogtreecommitdiff
path: root/tools/tmwcon/src
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-06-19 14:08:55 -0700
committerBen Longbons <b.r.longbons@gmail.com>2011-06-19 14:19:55 -0700
commita185fab9ff741a8f1da3eb8cc2aef6860338e986 (patch)
tree9b2eefa5785696de2435c8afb60a2ba8a5bad22b /tools/tmwcon/src
parentee0ef0d8ce591a0c364f4f53130eb9581118d4cc (diff)
downloadserverdata-a185fab9ff741a8f1da3eb8cc2aef6860338e986.tar.gz
serverdata-a185fab9ff741a8f1da3eb8cc2aef6860338e986.tar.bz2
serverdata-a185fab9ff741a8f1da3eb8cc2aef6860338e986.tar.xz
serverdata-a185fab9ff741a8f1da3eb8cc2aef6860338e986.zip
Make converter nicer
Diffstat (limited to 'tools/tmwcon/src')
-rw-r--r--tools/tmwcon/src/Converter.java54
-rw-r--r--tools/tmwcon/src/converter/Main.java42
-rw-r--r--tools/tmwcon/src/converter/Process.java37
-rw-r--r--tools/tmwcon/src/converter/WLKInterface.java2
4 files changed, 36 insertions, 99 deletions
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();
}
}