diff options
Diffstat (limited to 'outdated/tmwcon')
-rw-r--r-- | outdated/tmwcon/.gitignore | 6 | ||||
-rw-r--r-- | outdated/tmwcon/Converter.class | bin | 0 -> 1985 bytes | |||
-rw-r--r-- | outdated/tmwcon/MANIFEST.MF | 1 | ||||
-rw-r--r-- | outdated/tmwcon/README | 27 | ||||
-rwxr-xr-x | outdated/tmwcon/build.xml | 31 | ||||
-rw-r--r-- | outdated/tmwcon/src/Converter.java | 54 | ||||
-rw-r--r-- | outdated/tmwcon/src/converter/Main.java | 110 | ||||
-rw-r--r-- | outdated/tmwcon/src/converter/Process.java | 246 | ||||
-rw-r--r-- | outdated/tmwcon/src/converter/WLKInterface.java | 29 | ||||
-rw-r--r-- | outdated/tmwcon/tiled-core.jar | bin | 0 -> 52337 bytes | |||
-rw-r--r-- | outdated/tmwcon/tmw.jar | bin | 0 -> 2767 bytes |
11 files changed, 504 insertions, 0 deletions
diff --git a/outdated/tmwcon/.gitignore b/outdated/tmwcon/.gitignore new file mode 100644 index 0000000..7123179 --- /dev/null +++ b/outdated/tmwcon/.gitignore @@ -0,0 +1,6 @@ +# java converter +converter.jar +server-data/ +summary.txt +tmwdata +build diff --git a/outdated/tmwcon/Converter.class b/outdated/tmwcon/Converter.class Binary files differnew file mode 100644 index 0000000..f96b708 --- /dev/null +++ b/outdated/tmwcon/Converter.class diff --git a/outdated/tmwcon/MANIFEST.MF b/outdated/tmwcon/MANIFEST.MF new file mode 100644 index 0000000..954575d --- /dev/null +++ b/outdated/tmwcon/MANIFEST.MF @@ -0,0 +1 @@ +Main-Class: converter.Main diff --git a/outdated/tmwcon/README b/outdated/tmwcon/README new file mode 100644 index 0000000..a48fc83 --- /dev/null +++ b/outdated/tmwcon/README @@ -0,0 +1,27 @@ +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) + +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 diff --git a/outdated/tmwcon/build.xml b/outdated/tmwcon/build.xml new file mode 100755 index 0000000..b2937e6 --- /dev/null +++ b/outdated/tmwcon/build.xml @@ -0,0 +1,31 @@ +<project name="TMWServ to eAthena Converter" default="dist"> + <description> + A tool to convert map data from TMWServ format to eAthena format + </description> + <!-- set global properties for this build --> + + <target name="init"> + <!-- Create the time stamp --> + <tstamp/> + <!-- Create the build directory structure used by compile --> + <mkdir dir="build"/> + </target> + + <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="."/> + </target> + + <target name="dist" depends="compile" description="Generate the distribution"> + <jar + jarfile="converter.jar" + manifest="MANIFEST.MF" + basedir="build" + /> + </target> + + <target name="clean" description="Clean up the build directory" > + <delete dir="build"/> + </target> +</project> diff --git a/outdated/tmwcon/src/Converter.java b/outdated/tmwcon/src/Converter.java new file mode 100644 index 0000000..0f245aa --- /dev/null +++ b/outdated/tmwcon/src/Converter.java @@ -0,0 +1,54 @@ +/* + * 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/outdated/tmwcon/src/converter/Main.java b/outdated/tmwcon/src/converter/Main.java new file mode 100644 index 0000000..80dfe30 --- /dev/null +++ b/outdated/tmwcon/src/converter/Main.java @@ -0,0 +1,110 @@ +/* + * TMWServ to eAthena Converter (c) 2008 Jared Adams + * License: GPL, v2 or later + */ + +package converter; + +import java.io.*; +import java.util.*; + +import tiled.io.xml.*; + +public class Main { + 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(); + + PrintWriter summary = null; + + 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(); + } + + File folder = new File("server-data/data/"); + folder.mkdirs(); + Process.prepWLK(folder); + + folder = new File("tmwdata/maps/"); + + Collection<File> tmxs = getTMXFiles(folder); + Vector<String> folders = new Vector<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])); + } + + public static void main(String[] args) { + run(args, 0); + } +} diff --git a/outdated/tmwcon/src/converter/Process.java b/outdated/tmwcon/src/converter/Process.java new file mode 100644 index 0000000..2e7103e --- /dev/null +++ b/outdated/tmwcon/src/converter/Process.java @@ -0,0 +1,246 @@ +/* + * TMWServ to eAthena Converter (c) 2008 Jared Adams + * License: GPL, v2 or later + */ + +package converter; + +import java.awt.*; +import java.io.*; +import java.util.Iterator; +import java.util.Properties; +import java.util.TreeSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; + +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 wlkFolder; + + private static WLKInterface wlk = null; + + public static void prepWLK(File folder) { + wlkFolder = folder; + try { + wlk = new WLKInterface(); + } catch (NoClassDefFoundError ncdfe) {} + } + + private static String getProp(Properties props, String name, String def) { + if (name == null) return def; + for (java.util.Map.Entry<Object, Object> entry : props.entrySet()) { + if (name.equalsIgnoreCase(entry.getKey().toString())) { + return entry.getValue().toString(); + } + } + return def; + } + + private static int getProp(Properties props, String name, int def) { + if (name == null) return def; + try { + return Integer.parseInt(getProp(props, name, "?")); + } catch (Exception e) {} + return def; + } + + private static int[] resolveBounds(Rectangle in, boolean warp) { + int x = Math.round((float)in.x / (float)32); + int y = Math.round((float)in.y / (float)32); + int width = Math.round((float)in.width / (float)32); + int height = Math.round((float)in.height / (float)32); + if (!warp) { + if (width > 1) --width; + if (height > 1) --height; + } + x += width / 2; + y += height / 2; + if (warp) { + width -= 2; + height -= 2; + } + return new int[]{x, y, width, height}; + } + + private static void handleWarp(PrintWriter out, String map, String name, Rectangle bounds, Properties props) { + if (out == null) return; + String dest = getProp(props, "dest_map", null); + if (dest == null) return; + int x = getProp(props, "dest_tile_x", -1); + if (x < 0) + { + x = getProp(props, "dest_x", -1); + if (x < 0) return; + x = Math.round((float)x / (float)32); + } + int y = getProp(props, "dest_tile_y", -1); + if (y < 0) + { + y = getProp(props, "dest_y", -1); + if (y < 0) return; + y = Math.round((float)y / (float)32); + } + 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, y); + } + + private static int handleMob(PrintWriter out, String map, String name, Rectangle bounds, Properties props) { + if (out == null) return -1; + int mob = getProp(props, "monster_id", -1); + if (mob < 0) return -1; + mob += 1002; + int max = getProp(props, "max_beings", 1); + int time1 = getProp(props, "eA_spawn", 0); + 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); + return mob; + } + + private static void processObject(MapObject mo, String map, PrintWriter warpOut, PrintWriter mobOut, TreeSet<Integer> mobs) { + if (mo == null) return; + String name = mo.getName(); + String type = mo.getType(); + Rectangle bounds = new Rectangle(mo.getBounds()); + Properties props = mo.getProperties(); + + if (type.equalsIgnoreCase("warp")) { + handleWarp(warpOut, map, name, bounds, props); + } else if (type.equalsIgnoreCase("spawn")) { + mobs.add(handleMob(mobOut, map, name, bounds, props)); + } + } + + private static void processObjects(Iterator<MapObject> objs, String map, PrintWriter warpOut, PrintWriter mobOut, TreeSet<Integer> mobs) { + MapObject mo; + while (objs.hasNext()) { + mo = objs.next(); + if (mo == null) continue; + processObject(mo, map, warpOut, mobOut, mobs); + } + } + + private static void processFiles(File folder, List<String> out) { + for (File f : folder.listFiles()) { + if (f.isDirectory()) { + processFiles(folder, out); + } else if (!f.getName().equals(importFile)) { + out.add("npc: " + f.getPath().substring(_baseFolder.getPath().length() + 1)); + } + } + } + + private static void makeInclude(String name, File folder) { + File _import = new File(folder, importFile); + List<String> output_elements = new ArrayList<String>(); + processFiles(folder, output_elements); + PrintWriter importOut = Main.getWriter(_import); + importOut.printf("map: %s.gat\n", name); + Collections.sort(output_elements); + for (String s : output_elements) + importOut.println(s); + importOut.flush(); + importOut.close(); + } + + public static String processMap(String name, Map map, File mapFile, PrintWriter summary) { + if (name == null) return null; + if (map == null) return null; + + Properties props = map.getProperties(); + String title = getProp(props, "name", ""); + + String folderName = scriptDirectory + name; + if (title.length() > 0) { + folderName += "_" + title.replaceAll("\\s", "_").replaceAll("[^A-Za-z0-9\\-_]", ""); + title = name + " " + title; + } else { + title = name; + } + + File folder = new File(baseFolder + folderName); + folder.mkdirs(); + + System.out.println(title); + + File wlkFile = new File(wlkFolder, name + ".wlk"); + + if (wlkFile.exists() && mapFile.lastModified() < wlkFile.lastModified()) { + System.out.println("Up to date, skipping"); + makeInclude(name, folder); + return folderName; + } + + if (summary != null) { + summary.printf("\tName: '%s'\n", title); + summary.printf("\tMusic: '%s'\n", getProp(props, "music", "")); + summary.printf("\tMinimap: '%s'\n", getProp(props, "minimap", "")); + } + + if (wlk != null) wlk.write(name, map, wlkFile); + + PrintWriter warpOut = Main.getWriter(new File(folder, warpFile)); + PrintWriter mobOut = Main.getWriter(new File(folder, mobFile)); + + warpOut.printf("// %s warps\n\n", title); + mobOut.printf("// %s mobs\n\n", title); + + TreeSet<Integer> mobs = new TreeSet<Integer>(); + processObjects(map.getObjects(), name, warpOut, mobOut, mobs); + for (MapLayer layer : map) { + if (layer instanceof ObjectGroup) { + processObjects(((ObjectGroup) layer).getObjects(), name, warpOut, mobOut, mobs); + } + } + + warpOut.flush(); + warpOut.close(); + + System.out.println("Starting mob points"); + mobOut.printf("\n\n%s.gat,0,0,0\tscript\tMob%1$s\t-1,{\n", name); + for (int mob : mobs) { + if (mob == -1) continue; + mobOut.printf("On%d:\n\tset @mobID, %d;\n\tcallfunc \"MobPoints\";\n\tbreak;\n\n", mob, mob); + } + mobOut.printf("\tend;\n}\n"); + System.out.println("Finished mob points"); + + mobOut.flush(); + mobOut.close(); + + makeInclude(name, folder); + + return folderName; + } + + public static void writeMasterImport(String[] folders) { + File master = new File(baseFolder + scriptDirectory + "_import.txt"); + PrintWriter out = Main.getWriter(master); + if (out == null) return; + + List<String> output_elements = new ArrayList<String>(); + + for (String folder : folders) { + if (folder == null) continue; + output_elements.add("import: " + folder + "/_import.txt"); + } + + Collections.sort(output_elements); + for (String s : output_elements) + out.println(s); + + out.flush(); + out.close(); + } +} diff --git a/outdated/tmwcon/src/converter/WLKInterface.java b/outdated/tmwcon/src/converter/WLKInterface.java new file mode 100644 index 0000000..b9e0cb2 --- /dev/null +++ b/outdated/tmwcon/src/converter/WLKInterface.java @@ -0,0 +1,29 @@ +/* + * TMWServ to eAthena Converter (c) 2008 Jared Adams + * License: GPL, v2 or later + */ + +package converter; + +import java.io.*; + +import tiled.core.*; +import tiled.plugins.tmw.*; + +public class WLKInterface { + public WLKInterface() { + // See if the writer is available + WLKWriter.class.getName(); + } + + public void write(String name, Map map, File wlk) { + try { + wlk.createNewFile(); + WLKWriter.writeMap(map, new FileOutputStream(wlk)); + System.out.println("WLK written"); + } catch (Exception e) { + System.out.println("Prolem writing WLK file:"); + e.printStackTrace(); + } + } +} diff --git a/outdated/tmwcon/tiled-core.jar b/outdated/tmwcon/tiled-core.jar Binary files differnew file mode 100644 index 0000000..78d44bc --- /dev/null +++ b/outdated/tmwcon/tiled-core.jar diff --git a/outdated/tmwcon/tmw.jar b/outdated/tmwcon/tmw.jar Binary files differnew file mode 100644 index 0000000..3dfd070 --- /dev/null +++ b/outdated/tmwcon/tmw.jar |