From a185fab9ff741a8f1da3eb8cc2aef6860338e986 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 19 Jun 2011 14:08:55 -0700 Subject: Make converter nicer --- tools/tmwcon/src/converter/Main.java | 42 +++++++++++----------------- tools/tmwcon/src/converter/Process.java | 37 ++++++++++++------------ tools/tmwcon/src/converter/WLKInterface.java | 2 +- 3 files changed, 36 insertions(+), 45 deletions(-) (limited to 'tools/tmwcon/src/converter') 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 tmxs = getTMXFiles(folder); - Vector folders = new Vector(); + ArrayList folders = new ArrayList(); 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 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(); } } -- cgit v1.2.3-70-g09d2