diff --git a/.idea/artifacts/ATContentStudio_jar.xml b/.idea/artifacts/ATContentStudio_jar.xml
index 32836f9..5bd7869 100644
--- a/.idea/artifacts/ATContentStudio_jar.xml
+++ b/.idea/artifacts/ATContentStudio_jar.xml
@@ -10,7 +10,6 @@
-
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..0e36d52
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 4944549..1e030a1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/createProject.bat b/createProject.bat
index 056eb42..966b619 100644
--- a/createProject.bat
+++ b/createProject.bat
@@ -61,6 +61,8 @@ if not exist %2\%1\.gitignore (
echo .workspace > .gitignore
echo .project >> .gitignore
+ echo .workspace.json >> .gitignore
+ echo .project.json >> .gitignore
echo altered/drawable >> .gitignore
echo altered/drawable/* >> .gitignore
echo created/drawable >> .gitignore
diff --git a/hacked-libtiled/tiled/core/MapObject.java b/hacked-libtiled/tiled/core/MapObject.java
index 111b825..8e75282 100644
--- a/hacked-libtiled/tiled/core/MapObject.java
+++ b/hacked-libtiled/tiled/core/MapObject.java
@@ -43,7 +43,7 @@ public class MapObject implements Cloneable
{
private Properties properties = new Properties();
private ObjectGroup objectGroup;
- private Rectangle bounds = new Rectangle();
+ private Rectangle bounds;
private String name = "Object";
private String type = "";
private String imageSource = "";
diff --git a/hacked-libtiled/tiled/core/Sprite.java b/hacked-libtiled/tiled/core/Sprite.java
index 670bc4c..266c6ec 100644
--- a/hacked-libtiled/tiled/core/Sprite.java
+++ b/hacked-libtiled/tiled/core/Sprite.java
@@ -57,7 +57,7 @@ public class Sprite
private String name = null;
private int id = -1;
- private int flags = KEY_LOOP;
+ private int flags;
private float frameRate = 1.0f; //one fps
private Tile[] frames;
diff --git a/hacked-libtiled/tiled/io/TMXMapWriter.java b/hacked-libtiled/tiled/io/TMXMapWriter.java
index 9004af8..600a409 100644
--- a/hacked-libtiled/tiled/io/TMXMapWriter.java
+++ b/hacked-libtiled/tiled/io/TMXMapWriter.java
@@ -588,7 +588,7 @@ public class TMXMapWriter
}
// Iterate while parents are the same
- int shared = 0;
+ int shared;
int maxShared = Math.min(fromParents.size(), toParents.size());
for (shared = 0; shared < maxShared; shared++) {
String fromParent = fromParents.get(shared);
diff --git a/lib/AndorsTrainer_v0.1.5.jar b/lib/AndorsTrainer_v0.1.5.jar
deleted file mode 100644
index 9fec8a5..0000000
Binary files a/lib/AndorsTrainer_v0.1.5.jar and /dev/null differ
diff --git a/packaging/package.sh b/packaging/package.sh
index 0ff0145..96d4091 100755
--- a/packaging/package.sh
+++ b/packaging/package.sh
@@ -31,7 +31,6 @@ EXTRA_SOURCE_DIRS=(
# --- Libraries to include ---
LIBRARIES=(
- "AndorsTrainer_v0.1.5.jar"
"bsh-2.0b4.jar"
"jide-oss.jar"
"json_simple-1.1.jar"
diff --git a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java
index 9223f38..87be333 100644
--- a/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java
+++ b/src/com/gpl/rpg/atcontentstudio/ATContentStudio.java
@@ -1,10 +1,16 @@
package com.gpl.rpg.atcontentstudio;
-import java.awt.Color;
-import java.awt.Desktop;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Toolkit;
+import com.gpl.rpg.atcontentstudio.model.Workspace;
+import com.gpl.rpg.atcontentstudio.ui.StudioFrame;
+import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
+import com.gpl.rpg.atcontentstudio.ui.WorkspaceSelector;
+import prefuse.data.expression.parser.ExpressionParser;
+
+import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.plaf.FontUIResource;
+import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
@@ -14,31 +20,20 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.http.HttpTimeoutException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.JEditorPane;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.UIDefaults;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
-import javax.swing.event.HyperlinkEvent;
-import javax.swing.event.HyperlinkListener;
-import javax.swing.plaf.FontUIResource;
-
-import prefuse.data.expression.parser.ExpressionParser;
-
-import com.gpl.rpg.atcontentstudio.model.Workspace;
-import com.gpl.rpg.atcontentstudio.ui.StudioFrame;
-import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
-import com.gpl.rpg.atcontentstudio.ui.WorkspaceSelector;
-
public class ATContentStudio {
public static final String APP_NAME = "Andor's Trail Content Studio";
public static final String APP_VERSION = readVersionFromFile();
+
public static final String CHECK_UPDATE_URL = "https://andorstrail.com/static/ATCS_latest";
public static final String DOWNLOAD_URL = "https://andorstrail.com/viewtopic.php?f=6&t=4806";
@@ -57,7 +52,7 @@ public class ATContentStudio {
*/
public static void main(String[] args) {
String fontScaling = System.getProperty(FONT_SCALE_ENV_VAR_NAME);
- Float fontScale = null;
+ Float fontScale;
if (fontScaling != null) {
try {
fontScale = Float.parseFloat(fontScaling);
@@ -107,8 +102,6 @@ public class ATContentStudio {
frame.setVisible(true);
frame.setDefaultCloseOperation(StudioFrame.DO_NOTHING_ON_CLOSE);
}
-
- ;
});
for (File f : ConfigCache.getKnownWorkspaces()) {
if (workspaceRoot.equals(f)) {
@@ -207,8 +200,14 @@ public class ATContentStudio {
}
} catch (MalformedURLException e) {
e.printStackTrace();
+ } catch (HttpTimeoutException e) {
+ System.out.println("Could not connect to url to check for updates (timeout): " + CHECK_UPDATE_URL);
} catch (IOException e) {
- e.printStackTrace();
+ if (e.getMessage() != null && e.getMessage().startsWith("Server returned HTTP response code:")) {
+ System.out.println("Could not fetch current version from server to check for updates (non-success-status): " + e.getMessage());
+ } else {
+ System.out.println("Could not check for updates: '" + CHECK_UPDATE_URL + "' - " + e.getMessage());
+ }
} finally {
try {
if (in != null)
diff --git a/src/com/gpl/rpg/atcontentstudio/ConfigCache.java b/src/com/gpl/rpg/atcontentstudio/ConfigCache.java
index 42549d6..58cc3dc 100644
--- a/src/com/gpl/rpg/atcontentstudio/ConfigCache.java
+++ b/src/com/gpl/rpg/atcontentstudio/ConfigCache.java
@@ -1,103 +1,104 @@
package com.gpl.rpg.atcontentstudio;
+import com.gpl.rpg.atcontentstudio.io.SettingsSave;
+
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import com.gpl.rpg.atcontentstudio.io.SettingsSave;
-
public class ConfigCache implements Serializable {
- private static final long serialVersionUID = 4584324644282843961L;
-
- private static final File CONFIG_CACHE_STORAGE;
-
- private static ConfigCache instance = null;
+ private static final long serialVersionUID = 4584324644282843961L;
+
+ private static final File CONFIG_CACHE_STORAGE;
+
+ private static ConfigCache instance = null;
- static {
- if (System.getenv("APPDATA") != null) {
- CONFIG_CACHE_STORAGE = new File(System.getenv("APPDATA")+File.separator+ATContentStudio.APP_NAME+File.separator+"configCache" );
- } else {
- CONFIG_CACHE_STORAGE = new File(System.getenv("HOME")+File.separator+"."+ATContentStudio.APP_NAME+File.separator+"configCache" );
- }
- CONFIG_CACHE_STORAGE.getParentFile().mkdirs();
- if (CONFIG_CACHE_STORAGE.exists()) {
- ConfigCache.instance = (ConfigCache) SettingsSave.loadInstance(CONFIG_CACHE_STORAGE, "Configuration cache");
- if (ConfigCache.instance == null) {
- ConfigCache.instance = new ConfigCache();
- }
- } else {
- ConfigCache.instance = new ConfigCache();
- }
- }
+ static {
+ if (System.getenv("APPDATA") != null) {
+ CONFIG_CACHE_STORAGE = new File(System.getenv("APPDATA") + File.separator + ATContentStudio.APP_NAME + File.separator + "configCache");
+ } else {
+ CONFIG_CACHE_STORAGE = new File(System.getenv("HOME") + File.separator + "." + ATContentStudio.APP_NAME + File.separator + "configCache");
+ }
+ CONFIG_CACHE_STORAGE.getParentFile().mkdirs();
+ if (CONFIG_CACHE_STORAGE.exists()) {
+ ConfigCache.instance = (ConfigCache) SettingsSave.loadInstance(CONFIG_CACHE_STORAGE, "Configuration cache");
+ if (ConfigCache.instance == null) {
+ ConfigCache.instance = new ConfigCache();
+ }
+ } else {
+ ConfigCache.instance = new ConfigCache();
+ }
+ }
- private void save() {
- SettingsSave.saveInstance(instance, ConfigCache.CONFIG_CACHE_STORAGE, "Configuration cache");
- }
+ private void save() {
+ SettingsSave.saveInstance(instance, ConfigCache.CONFIG_CACHE_STORAGE, "Configuration cache");
+ }
- private List knownWorkspaces = new ArrayList();
- private File latestWorkspace = null;
- private String favoriteLaFClassName = null;
- private boolean[] notifConfig = new boolean[]{true, true, true, true};
+ private List knownWorkspaces = new ArrayList();
+ private File latestWorkspace = null;
+ private String favoriteLaFClassName = null;
+ private boolean[] notifConfig = new boolean[]{true, true, true, true};
-
- public static List getKnownWorkspaces() {
- return instance.knownWorkspaces;
- }
-
- public static void addWorkspace(File w) {
- instance.knownWorkspaces.add(w);
- instance.save();
- }
-
- public static void removeWorkspace(File w) {
- instance.knownWorkspaces.remove(w);
- instance.save();
- }
-
- public static File getLatestWorkspace() {
- return instance.latestWorkspace;
- }
- public static void setLatestWorkspace(File latestWorkspace) {
- instance.latestWorkspace = latestWorkspace;
- instance.save();
- }
+ public static List getKnownWorkspaces() {
+ return instance.knownWorkspaces;
+ }
- public static String getFavoriteLaFClassName() {
- return instance.favoriteLaFClassName;
- }
-
- public static void setFavoriteLaFClassName(String favoriteLaFClassName) {
- instance.favoriteLaFClassName = favoriteLaFClassName;
- instance.save();
- }
+ public static void addWorkspace(File w) {
+ instance.knownWorkspaces.add(w);
+ instance.save();
+ }
- public static void putNotifViewConfig(boolean[] view) {
- for (int i=instance.notifConfig.length; i<0; --i) {
- instance.notifConfig[i] = view[i];
- }
- instance.save();
- }
+ public static void removeWorkspace(File w) {
+ instance.knownWorkspaces.remove(w);
+ instance.save();
+ }
- public static boolean[] getNotifViewConfig() {
- if (instance == null || instance.notifConfig == null) {
- //Not yet initialized. All flags on to help corner out init issues.
- return new boolean[]{true, true, true, true};
- }
- return instance.notifConfig;
- }
+ public static File getLatestWorkspace() {
+ return instance.latestWorkspace;
+ }
- public static void init() {}
+ public static void setLatestWorkspace(File latestWorkspace) {
+ instance.latestWorkspace = latestWorkspace;
+ instance.save();
+ }
- public static void clear() {
- instance.knownWorkspaces.clear();
- setFavoriteLaFClassName(null);
- instance.notifConfig = new boolean[]{true, true, true, true};
- instance.save();
- }
+ public static String getFavoriteLaFClassName() {
+ return instance.favoriteLaFClassName;
+ }
+
+ public static void setFavoriteLaFClassName(String favoriteLaFClassName) {
+ instance.favoriteLaFClassName = favoriteLaFClassName;
+ instance.save();
+ }
+
+ public static void putNotifViewConfig(boolean[] view) {
+ for (int i = instance.notifConfig.length; i < 0; --i) {
+ instance.notifConfig[i] = view[i];
+ }
+ instance.save();
+ }
+
+ public static boolean[] getNotifViewConfig() {
+ if (instance == null || instance.notifConfig == null) {
+ //Not yet initialized. All flags on to help corner out init issues.
+ return new boolean[]{true, true, true, true};
+ }
+ return instance.notifConfig;
+ }
+
+ public static void init() {
+ }
+
+ public static void clear() {
+ instance.knownWorkspaces.clear();
+ setFavoriteLaFClassName(null);
+ instance.notifConfig = new boolean[]{true, true, true, true};
+ instance.save();
+ }
}
diff --git a/src/com/gpl/rpg/atcontentstudio/Notification.java b/src/com/gpl/rpg/atcontentstudio/Notification.java
index fa25ebc..d3d6e33 100644
--- a/src/com/gpl/rpg/atcontentstudio/Notification.java
+++ b/src/com/gpl/rpg/atcontentstudio/Notification.java
@@ -6,87 +6,87 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class Notification {
- public static List notifs = new ArrayList();
- private static List listeners = new CopyOnWriteArrayList();
- public static boolean showS = true, showI = true, showW = true, showE = true;
-
- static {
- boolean[] config = ConfigCache.getNotifViewConfig();
- showS = config[0];
- showI = config[1];
- showW = config[2];
- showE = config[3];
- }
-
- public static enum Type {
- SUCCESS,
- INFO,
- WARN,
- ERROR
- }
-
- public Type type;
- public String text;
-
- public Notification(Type type, String text) {
- this.type = type;
- this.text = text;
- }
-
- public String toString() {
- return "["+type.toString()+"] "+text;
- }
-
- public static void clear() {
- int i = notifs.size();
- notifs.clear();
- for (NotificationListener l : listeners) {
- l.onListCleared(i);
- }
- }
+ public static List notifs = new ArrayList();
+ private static List listeners = new CopyOnWriteArrayList();
+ public static boolean showS, showI, showW, showE;
+
+ static {
+ boolean[] config = ConfigCache.getNotifViewConfig();
+ showS = config[0];
+ showI = config[1];
+ showW = config[2];
+ showE = config[3];
+ }
+
+ public static enum Type {
+ SUCCESS,
+ INFO,
+ WARN,
+ ERROR
+ }
+
+ public Type type;
+ public String text;
+
+ public Notification(Type type, String text) {
+ this.type = type;
+ this.text = text;
+ }
+
+ public String toString() {
+ return "[" + type.toString() + "] " + text;
+ }
+
+ public static void clear() {
+ int i = notifs.size();
+ notifs.clear();
+ for (NotificationListener l : listeners) {
+ l.onListCleared(i);
+ }
+ }
+
+ public static void addSuccess(String text) {
+ if (!showS) return;
+ Notification n = new Notification(Notification.Type.SUCCESS, text);
+ notifs.add(n);
+ for (NotificationListener l : listeners) {
+ l.onNewNotification(n);
+ }
+ }
+
+ public static void addInfo(String text) {
+ if (!showI) return;
+ Notification n = new Notification(Notification.Type.INFO, text);
+ notifs.add(n);
+ for (NotificationListener l : listeners) {
+ l.onNewNotification(n);
+ }
+ }
+
+ public static void addWarn(String text) {
+ if (!showW) return;
+ Notification n = new Notification(Notification.Type.WARN, text);
+ notifs.add(n);
+ for (NotificationListener l : listeners) {
+ l.onNewNotification(n);
+ }
+ }
+
+ public static void addError(String text) {
+ if (!showE) return;
+ Notification n = new Notification(Notification.Type.ERROR, text);
+ notifs.add(n);
+ for (NotificationListener l : listeners) {
+ l.onNewNotification(n);
+ }
+ }
+
+ public static void addNotificationListener(NotificationListener l) {
+ listeners.add(l);
+ }
+
+ public static void removeNotificationListener(NotificationListener l) {
+ listeners.remove(l);
+ }
- public static void addSuccess(String text) {
- if (!showS) return;
- Notification n = new Notification(Notification.Type.SUCCESS, text);
- notifs.add(n);
- for (NotificationListener l : listeners) {
- l.onNewNotification(n);
- }
- }
-
- public static void addInfo(String text) {
- if (!showI) return;
- Notification n = new Notification(Notification.Type.INFO, text);
- notifs.add(n);
- for (NotificationListener l : listeners) {
- l.onNewNotification(n);
- }
- }
-
- public static void addWarn(String text) {
- if (!showW) return;
- Notification n = new Notification(Notification.Type.WARN, text);
- notifs.add(n);
- for (NotificationListener l : listeners) {
- l.onNewNotification(n);
- }
- }
-
- public static void addError(String text) {
- if (!showE) return;
- Notification n = new Notification(Notification.Type.ERROR, text);
- notifs.add(n);
- for (NotificationListener l : listeners) {
- l.onNewNotification(n);
- }
- }
-
- public static void addNotificationListener(NotificationListener l) {
- listeners.add(l);
- }
-
- public static void removeNotificationListener(NotificationListener l) {
- listeners.remove(l);
- }
-
}
\ No newline at end of file
diff --git a/src/com/gpl/rpg/atcontentstudio/NotificationListener.java b/src/com/gpl/rpg/atcontentstudio/NotificationListener.java
index f5b265f..b015e68 100644
--- a/src/com/gpl/rpg/atcontentstudio/NotificationListener.java
+++ b/src/com/gpl/rpg/atcontentstudio/NotificationListener.java
@@ -2,7 +2,8 @@ package com.gpl.rpg.atcontentstudio;
public interface NotificationListener {
- public void onNewNotification(Notification n);
- public void onListCleared(int i);
-
+ public void onNewNotification(Notification n);
+
+ public void onListCleared(int i);
+
}
\ No newline at end of file
diff --git a/src/com/gpl/rpg/atcontentstudio/io/JsonPrettyWriter.java b/src/com/gpl/rpg/atcontentstudio/io/JsonPrettyWriter.java
index f3e5a80..65f47a2 100644
--- a/src/com/gpl/rpg/atcontentstudio/io/JsonPrettyWriter.java
+++ b/src/com/gpl/rpg/atcontentstudio/io/JsonPrettyWriter.java
@@ -4,50 +4,50 @@ import java.io.StringWriter;
public class JsonPrettyWriter extends StringWriter {
- private int indentLevel = 0;
- private String indentText = " ";
-
- public JsonPrettyWriter() {
- super();
- }
-
- public JsonPrettyWriter(String indent) {
- super();
- this.indentText = indent;
- }
+ private int indentLevel = 0;
+ private String indentText = " ";
- @Override
- public void write(int c) {
- if (((char) c) == '[' || ((char) c) == '{') {
- super.write(c);
- super.write('\n');
- indentLevel++;
- writeIndentation();
- } else if (((char) c) == ',') {
- super.write(c);
- super.write('\n');
- writeIndentation();
- } else if (((char) c) == ']' || ((char) c) == '}') {
- super.write('\n');
- indentLevel--;
- writeIndentation();
- super.write(c);
- } else {
- super.write(c);
- }
+ public JsonPrettyWriter() {
+ super();
+ }
- }
-
- //Horrible hack to remove the horrible escaping of slashes in json-simple....
- @Override
- public void write(String str) {
- super.write(str.replaceAll("\\\\/", "/"));
- }
+ public JsonPrettyWriter(String indent) {
+ super();
+ this.indentText = indent;
+ }
- private void writeIndentation() {
- for (int i = 0; i < indentLevel; i++) {
- super.write(indentText);
- }
- }
+ @Override
+ public void write(int c) {
+ if (((char) c) == '[' || ((char) c) == '{') {
+ super.write(c);
+ super.write('\n');
+ indentLevel++;
+ writeIndentation();
+ } else if (((char) c) == ',') {
+ super.write(c);
+ super.write('\n');
+ writeIndentation();
+ } else if (((char) c) == ']' || ((char) c) == '}') {
+ super.write('\n');
+ indentLevel--;
+ writeIndentation();
+ super.write(c);
+ } else {
+ super.write(c);
+ }
+
+ }
+
+ //Horrible hack to remove the horrible escaping of slashes in json-simple....
+ @Override
+ public void write(String str) {
+ super.write(str.replaceAll("\\\\/", "/"));
+ }
+
+ private void writeIndentation() {
+ for (int i = 0; i < indentLevel; i++) {
+ super.write(indentText);
+ }
+ }
}
diff --git a/src/com/gpl/rpg/atcontentstudio/io/JsonSerializable.java b/src/com/gpl/rpg/atcontentstudio/io/JsonSerializable.java
new file mode 100644
index 0000000..cd251a0
--- /dev/null
+++ b/src/com/gpl/rpg/atcontentstudio/io/JsonSerializable.java
@@ -0,0 +1,8 @@
+package com.gpl.rpg.atcontentstudio.io;
+
+import java.util.Map;
+
+public interface JsonSerializable {
+ Map toMap();
+ void fromMap(Map map);
+}
diff --git a/src/com/gpl/rpg/atcontentstudio/io/SettingsSave.java b/src/com/gpl/rpg/atcontentstudio/io/SettingsSave.java
index 21bc3bc..c5eccb8 100644
--- a/src/com/gpl/rpg/atcontentstudio/io/SettingsSave.java
+++ b/src/com/gpl/rpg/atcontentstudio/io/SettingsSave.java
@@ -1,76 +1,70 @@
package com.gpl.rpg.atcontentstudio.io;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
import com.gpl.rpg.atcontentstudio.Notification;
+import java.io.*;
+
public class SettingsSave {
- public static void saveInstance(Object obj, File f, String type) {
- try {
- FileOutputStream fos = new FileOutputStream(f);
- try {
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(obj);
- oos.flush();
- oos.close();
- Notification.addSuccess(type+" successfully saved.");
- } catch (IOException e) {
- e.printStackTrace();
- Notification.addError(type+" saving error: "+e.getMessage());
- } finally {
- try {
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- Notification.addError(type+" saving error: "+e.getMessage());
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- Notification.addError(type+" saving error: "+e.getMessage());
- }
- }
-
- public static Object loadInstance(File f, String type) {
- FileInputStream fis;
- Object result = null;
- try {
- fis = new FileInputStream(f);
- ObjectInputStream ois;
- try {
- ois = new ObjectInputStream(fis);
- try {
- result = ois.readObject();
- Notification.addSuccess(type+" successfully loaded.");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- Notification.addError(type+" loading error: "+e.getMessage());
- } finally {
- ois.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- Notification.addError(type+" loading error: "+e.getMessage());
- } finally {
- try {
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- Notification.addError(type+" loading error: "+e.getMessage());
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- Notification.addError(type+" loading error: "+e.getMessage());
- }
- return result;
- }
-
+ public static void saveInstance(Object obj, File f, String type) {
+ try {
+ FileOutputStream fos = new FileOutputStream(f);
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(obj);
+ oos.flush();
+ oos.close();
+ Notification.addSuccess(type + " successfully saved.");
+ } catch (IOException e) {
+ e.printStackTrace();
+ Notification.addError(type + " saving error: " + e.getMessage());
+ } finally {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ Notification.addError(type + " saving error: " + e.getMessage());
+ }
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ Notification.addError(type + " saving error: " + e.getMessage());
+ }
+ }
+
+ public static Object loadInstance(File f, String type) {
+ FileInputStream fis;
+ Object result = null;
+ try {
+ fis = new FileInputStream(f);
+ ObjectInputStream ois;
+ try {
+ ois = new ObjectInputStream(fis);
+ try {
+ result = ois.readObject();
+ Notification.addSuccess(type + " successfully loaded.");
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ Notification.addError(type + " loading error: " + e.getMessage());
+ } finally {
+ ois.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ Notification.addError(type + " loading error: " + e.getMessage());
+ } finally {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ Notification.addError(type + " loading error: " + e.getMessage());
+ }
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ Notification.addError(type + " loading error: " + e.getMessage());
+ }
+ return result;
+ }
+
}
diff --git a/src/com/gpl/rpg/atcontentstudio/model/ClosedProject.java b/src/com/gpl/rpg/atcontentstudio/model/ClosedProject.java
index db92f88..0ce838b 100644
--- a/src/com/gpl/rpg/atcontentstudio/model/ClosedProject.java
+++ b/src/com/gpl/rpg/atcontentstudio/model/ClosedProject.java
@@ -1,124 +1,135 @@
package com.gpl.rpg.atcontentstudio.model;
-import java.awt.Image;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.swing.tree.TreeNode;
-
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
+import javax.swing.tree.TreeNode;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
public class ClosedProject implements ProjectTreeNode {
- String name;
- Workspace parent;
-
- public ClosedProject(Workspace w, String name) {
- this.parent = w;
- this.name = name;
- }
+ String name;
+ Workspace parent;
- @Override
- public TreeNode getChildAt(int childIndex) {
- return null;
- }
- @Override
- public int getChildCount() {
- return 0;
- }
- @Override
- public TreeNode getParent() {
- return parent;
- }
- @Override
- public int getIndex(TreeNode node) {
- return 0;
- }
- @Override
- public boolean getAllowsChildren() {
- return false;
- }
- @Override
- public boolean isLeaf() {
- return true;
- }
- @Override
- public Enumeration children() {
- return null;
- }
-
- @Override
- public void childrenAdded(List path) {
- path.add(0,this);
- parent.childrenAdded(path);
- }
- @Override
- public void childrenChanged(List path) {
- path.add(0,this);
- parent.childrenChanged(path);
- }
- @Override
- public void childrenRemoved(List path) {
- path.add(0,this);
- parent.childrenRemoved(path);
- }
- @Override
- public void notifyCreated() {
- childrenAdded(new ArrayList());
- }
+ public ClosedProject(Workspace w, String name) {
+ this.parent = w;
+ this.name = name;
+ }
- @Override
- public String getDesc() {
- return name+" [closed]";
- }
-
- @Override
- public Project getProject() {
- return null;
- }
+ @Override
+ public TreeNode getChildAt(int childIndex) {
+ return null;
+ }
+
+ @Override
+ public int getChildCount() {
+ return 0;
+ }
+
+ @Override
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ @Override
+ public int getIndex(TreeNode node) {
+ return 0;
+ }
+
+ @Override
+ public boolean getAllowsChildren() {
+ return false;
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return true;
+ }
+
+ @Override
+ public Enumeration children() {
+ return null;
+ }
+
+ @Override
+ public void childrenAdded(List path) {
+ path.add(0, this);
+ parent.childrenAdded(path);
+ }
+
+ @Override
+ public void childrenChanged(List path) {
+ path.add(0, this);
+ parent.childrenChanged(path);
+ }
+
+ @Override
+ public void childrenRemoved(List path) {
+ path.add(0, this);
+ parent.childrenRemoved(path);
+ }
+
+ @Override
+ public void notifyCreated() {
+ childrenAdded(new ArrayList());
+ }
+
+ @Override
+ public String getDesc() {
+ return name + " [closed]";
+ }
+
+ @Override
+ public Project getProject() {
+ return null;
+ }
- @Override
- public Image getIcon() {
- return getOpenIcon();
- }
- @Override
- public Image getClosedIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdClosedIcon();
- }
- @Override
- public Image getLeafIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdClosedIcon();
- }
- @Override
- public Image getOpenIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdOpenIcon();
- }
-
- @Override
- public GameDataSet getDataSet() {
- return null;
- }
+ @Override
+ public Image getIcon() {
+ return getOpenIcon();
+ }
+
+ @Override
+ public Image getClosedIcon() {
+ //TODO Create a cool Project icon.
+ return DefaultIcons.getStdClosedIcon();
+ }
+
+ @Override
+ public Image getLeafIcon() {
+ //TODO Create a cool Project icon.
+ return DefaultIcons.getStdClosedIcon();
+ }
+
+ @Override
+ public Image getOpenIcon() {
+ //TODO Create a cool Project icon.
+ return DefaultIcons.getStdOpenIcon();
+ }
+
+ @Override
+ public GameDataSet getDataSet() {
+ return null;
+ }
+
+ @Override
+ public Type getDataType() {
+ return null;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
+
+ @Override
+ public boolean needsSaving() {
+ return false;
+ }
- @Override
- public Type getDataType() {
- return null;
- }
-
- @Override
- public boolean isEmpty() {
- return true;
- }
-
- @Override
- public boolean needsSaving() {
- return false;
- }
-
}
diff --git a/src/com/gpl/rpg/atcontentstudio/model/GameDataElement.java b/src/com/gpl/rpg/atcontentstudio/model/GameDataElement.java
index 5643f57..584ee1e 100644
--- a/src/com/gpl/rpg/atcontentstudio/model/GameDataElement.java
+++ b/src/com/gpl/rpg/atcontentstudio/model/GameDataElement.java
@@ -1,193 +1,237 @@
package com.gpl.rpg.atcontentstudio.model;
-import java.awt.Image;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.swing.tree.TreeNode;
-
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
+import javax.swing.tree.TreeNode;
+import java.awt.*;
+import java.io.Serializable;
+import java.util.List;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
public abstract class GameDataElement implements ProjectTreeNode, Serializable {
- private static final long serialVersionUID = 2028934451226743389L;
-
- public static enum State {
- init, // We know the object exists, and have its key/ID.
- parsed, // We know the object's properties, but related objects are referenced by ID only.
- linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least.
- created, // This is an object we are creating
- modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON.
- saved // Whether altered or created, this item has been saved since last modification.
- }
-
- public State state = State.init;
-
- //Available from state init.
- public ProjectTreeNode parent;
-
- public boolean writable = false;
-
- public BookmarkEntry bookmark = null;
-
- //List of objects whose transition to "linked" state made them point to this instance.
- private Map backlinks = new ConcurrentHashMap();
+ private static final long serialVersionUID = 2028934451226743389L;
- public String id = null;
-
- @Override
- public Enumeration children() {
- return null;
- }
- @Override
- public boolean getAllowsChildren() {
- return false;
- }
- @Override
- public TreeNode getChildAt(int arg0) {
- return null;
- }
- @Override
- public int getChildCount() {
- return 0;
- }
- @Override
- public int getIndex(TreeNode arg0) {
- return 0;
- }
- @Override
- public TreeNode getParent() {
- return parent;
- }
- @Override
- public boolean isLeaf() {
- return true;
- }
- @Override
- public void childrenAdded(List path) {
- path.add(0,this);
- parent.childrenAdded(path);
- }
+ public static enum State {
+ init, // We know the object exists, and have its key/ID.
+ parsed, // We know the object's properties, but related objects are referenced by ID only.
+ linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least.
+ created, // This is an object we are creating
+ modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON.
+ saved // Whether altered or created, this item has been saved since last modification.
+ }
- @Override
- public void childrenChanged(List path) {
- path.add(0,this);
- parent.childrenChanged(path);
- }
+ public State state = State.init;
- @Override
- public void childrenRemoved(List path) {
- path.add(0,this);
- parent.childrenRemoved(path);
- }
- @Override
- public void notifyCreated() {
- childrenAdded(new ArrayList());
- }
- @Override
- public abstract String getDesc();
-
- public static String getStaticDesc() {
- return "GameDataElements";
- }
-
- public abstract void parse();
- public abstract void link();
-
-
-
- @Override
- public Project getProject() {
- return parent == null ? null : parent.getProject();
- }
-
-
- public Image getIcon() {
- return null;
- }
- @Override
- public Image getClosedIcon() {return null;}
- @Override
- public Image getOpenIcon() {return null;}
- @Override
- public Image getLeafIcon() {
- return getIcon();
- }
-
-
- public abstract GameDataElement clone();
-
- public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
+ //Available from state init.
+ public ProjectTreeNode parent;
-
- @Override
- public GameSource.Type getDataType() {
- if (parent == null) {
- System.out.println("blerf.");
- }
- return parent.getDataType();
- }
-
-
- public List backlinkListeners = new ArrayList();
-
- public void addBacklinkListener(BacklinksListener l) {
- backlinkListeners.add(l);
- }
+ public boolean writable = false;
- public void removeBacklinkListener(BacklinksListener l) {
- backlinkListeners.remove(l);
- }
-
- public void addBacklink(GameDataElement gde) {
- if (!backlinks.containsKey(gde)) {
- backlinks.put(gde, 1);
- for (BacklinksListener l : backlinkListeners) {
- l.backlinkAdded(gde);
- }
- } else {
- backlinks.put(gde, backlinks.get(gde) + 1);
- }
- }
+ public BookmarkEntry bookmark = null;
- public void removeBacklink(GameDataElement gde) {
- if (backlinks.get(gde) == null) return;
- backlinks.put(gde, backlinks.get(gde) - 1);
- if (backlinks.get(gde) == 0) {
- backlinks.remove(gde);
- for (BacklinksListener l : backlinkListeners) {
- l.backlinkRemoved(gde);
- }
- }
- }
+ //List of objects whose transition to "linked" state made them point to this instance.
+ private Map backlinks = new ConcurrentHashMap();
- public Set getBacklinks() {
- return backlinks.keySet();
- }
-
- public static interface BacklinksListener {
- public void backlinkAdded(GameDataElement gde);
- public void backlinkRemoved(GameDataElement gde);
- }
-
- @Override
- public boolean isEmpty() {
- return false;
- }
-
- public boolean needsSaving() {
- return this.state == State.modified || this.state == State.created;
- }
-
- public abstract String getProjectFilename();
-
- public abstract void save();
-
- public abstract List attemptSave();
-
+ public String id = null;
+
+ @Override
+ public Enumeration children() {
+ return null;
+ }
+
+ @Override
+ public boolean getAllowsChildren() {
+ return false;
+ }
+
+ @Override
+ public TreeNode getChildAt(int arg0) {
+ return null;
+ }
+
+ @Override
+ public int getChildCount() {
+ return 0;
+ }
+
+ @Override
+ public int getIndex(TreeNode arg0) {
+ return 0;
+ }
+
+ @Override
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return true;
+ }
+
+ @Override
+ public void childrenAdded(List path) {
+ path.add(0, this);
+ parent.childrenAdded(path);
+ }
+
+ @Override
+ public void childrenChanged(List path) {
+ path.add(0, this);
+ parent.childrenChanged(path);
+ }
+
+ @Override
+ public void childrenRemoved(List path) {
+ path.add(0, this);
+ parent.childrenRemoved(path);
+ }
+
+ @Override
+ public void notifyCreated() {
+ childrenAdded(new ArrayList());
+ }
+
+ @Override
+ public abstract String getDesc();
+
+ public static String getStaticDesc() {
+ return "GameDataElements";
+ }
+
+ public abstract void parse();
+
+ public abstract void link();
+
+
+ @Override
+ public Project getProject() {
+ return parent == null ? null : parent.getProject();
+ }
+
+
+ public Image getIcon() {
+ return null;
+ }
+
+ @Override
+ public Image getClosedIcon() {
+ return null;
+ }
+
+ @Override
+ public Image getOpenIcon() {
+ return null;
+ }
+
+ @Override
+ public Image getLeafIcon() {
+ return getIcon();
+ }
+
+
+ public abstract GameDataElement clone();
+
+ public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
+
+
+ @Override
+ public GameSource.Type getDataType() {
+ if (parent == null) {
+ System.out.println("blerf.");
+ }
+ return parent.getDataType();
+ }
+
+
+ public List backlinkListeners = new ArrayList();
+
+ public void addBacklinkListener(BacklinksListener l) {
+ backlinkListeners.add(l);
+ }
+
+ public void removeBacklinkListener(BacklinksListener l) {
+ backlinkListeners.remove(l);
+ }
+
+ public void addBacklink(GameDataElement gde) {
+ if (!backlinks.containsKey(gde)) {
+ backlinks.put(gde, 1);
+ for (BacklinksListener l : backlinkListeners) {
+ l.backlinkAdded(gde);
+ }
+ } else {
+ backlinks.put(gde, backlinks.get(gde) + 1);
+ }
+ }
+
+ public void removeBacklink(GameDataElement gde) {
+ if (backlinks.get(gde) == null) return;
+ backlinks.put(gde, backlinks.get(gde) - 1);
+ if (backlinks.get(gde) == 0) {
+ backlinks.remove(gde);
+ for (BacklinksListener l : backlinkListeners) {
+ l.backlinkRemoved(gde);
+ }
+ }
+ }
+
+ public Set getBacklinks() {
+ return backlinks.keySet();
+ }
+
+ public static interface BacklinksListener {
+ public void backlinkAdded(GameDataElement gde);
+
+ public void backlinkRemoved(GameDataElement gde);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ public boolean needsSaving() {
+ return this.state == State.modified || this.state == State.created;
+ }
+
+ public abstract String getProjectFilename();
+
+ public abstract void save();
+
+ public abstract List attemptSave();
+
+ /**
+ * Checks if the current state indicates that parsing/linking should be skipped.
+ *
+ * @return true if the operation should be skipped, false otherwise
+ */
+ protected boolean shouldSkipParseOrLink() {
+ if (shouldSkipParse()) return true;
+ if (this.state == State.linked) {
+ //Already linked.
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean shouldSkipParse() {
+ if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
+ //This type of state is unrelated to parsing/linking.
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Ensures the element is parsed if needed based on its current state.
+ */
+ protected void ensureParseIfNeeded() {
+ if (this.state == State.init) {
+ //Not parsed yet.
+ this.parse();
+ }
+ }
}
diff --git a/src/com/gpl/rpg/atcontentstudio/model/GameSource.java b/src/com/gpl/rpg/atcontentstudio/model/GameSource.java
index f94751e..3e280e1 100644
--- a/src/com/gpl/rpg/atcontentstudio/model/GameSource.java
+++ b/src/com/gpl/rpg/atcontentstudio/model/GameSource.java
@@ -1,28 +1,6 @@
package com.gpl.rpg.atcontentstudio.model;
-import java.awt.Image;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.tree.TreeNode;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
+import com.gpl.rpg.atcontentstudio.io.JsonSerializable;
import com.gpl.rpg.atcontentstudio.model.Project.ResourceSet;
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
@@ -32,263 +10,317 @@ import com.gpl.rpg.atcontentstudio.model.sprites.SpriteSheetSet;
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeDataSet;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
-public class GameSource implements ProjectTreeNode, Serializable {
+import javax.swing.tree.TreeNode;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.awt.*;
+import java.io.*;
+import java.util.List;
+import java.util.*;
- private static final long serialVersionUID = -1512979360971918158L;
-
- public static final String DEFAULT_REL_PATH_FOR_GAME_RESOURCE = "res"+File.separator+"values"+File.separator+"loadresources.xml";
- public static final String DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE = "res"+File.separator+"values"+File.separator+"loadresources_debug.xml";
-
- public transient GameDataSet gameData;
- public transient TMXMapSet gameMaps;
- public transient SpriteSheetSet gameSprites;
- public transient Worldmap worldmap;
- public transient WriterModeDataSet writerModeDataSet;
- private transient SavedSlotCollection v;
-
- public static enum Type {
- source,
- referenced,
- altered,
- created
- }
-
- public File baseFolder;
- public Type type;
-
- public transient Project parent = null;
-
- public transient Map> referencedSourceFiles = null;
-
- public GameSource(File folder, Project parent) {
- this.parent = parent;
- this.baseFolder = folder;
- this.type = Type.source;
- initData();
- }
-
- public GameSource(Project parent, Type type) {
- this.parent = parent;
- this.baseFolder = new File(parent.baseFolder, type.toString());
- this.type = type;
- initData();
- }
-
- public void refreshTransients(Project p) {
- parent = p;
- initData();
- }
+public class GameSource implements ProjectTreeNode, Serializable, JsonSerializable {
- public void initData() {
- if (type == Type.source) {
- if (parent.sourceSetToUse == ResourceSet.gameData || parent.sourceSetToUse == ResourceSet.debugData) {
- referencedSourceFiles = new LinkedHashMap>();
- readResourceList();
- }
- }
- if (type == Type.created) {
- this.writerModeDataSet = new WriterModeDataSet(this);
- }
- this.gameData = new GameDataSet(this);
- this.gameMaps = new TMXMapSet(this);
- this.gameSprites = new SpriteSheetSet(this);
- this.worldmap = new Worldmap(this);
- v = new SavedSlotCollection();
- v.add(gameData);
- v.add(gameMaps);
- v.add(gameSprites);
- v.add(worldmap);
- if (type == Type.created) {
- v.add(writerModeDataSet);
- }
- }
-
- public void readResourceList() {
- File xmlFile = null;
- if (parent.sourceSetToUse == ResourceSet.gameData) {
- xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_GAME_RESOURCE);
- } else if (parent.sourceSetToUse == ResourceSet.debugData) {
- xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE);
- } else {
- return;
- }
-
- if (!xmlFile.exists()) return;
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- Document doc;
- try {
- factory.setIgnoringComments(true);
- factory.setIgnoringElementContentWhitespace(true);
- factory.setExpandEntityReferences(false);
- DocumentBuilder builder = factory.newDocumentBuilder();
- InputSource insrc = new InputSource(new FileInputStream(xmlFile));
+ private static final long serialVersionUID = -1512979360971918158L;
+
+ public static final String DEFAULT_REL_PATH_FOR_GAME_RESOURCE = "res" + File.separator + "values" + File.separator + "loadresources.xml";
+ public static final String DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE = "res" + File.separator + "values" + File.separator + "loadresources_debug.xml";
+
+ public transient GameDataSet gameData;
+ public transient TMXMapSet gameMaps;
+ public transient SpriteSheetSet gameSprites;
+ public transient Worldmap worldmap;
+ public transient WriterModeDataSet writerModeDataSet;
+ private transient SavedSlotCollection v;
+
+
+ @Override
+ public Map toMap() {
+ Map map = new HashMap();
+ map.put("type", type.toString());
+ map.put("baseFolder", baseFolder.getPath());
+ return map;
+ }
+
+ @Override
+ public void fromMap(Map map) {
+ if(map==null)return;
+ type = Enum.valueOf(Type.class, (String)map.get("type"));
+ baseFolder = new File((String) map.get("baseFolder"));
+ }
+
+ public static enum Type {
+ source,
+ referenced,
+ altered,
+ created
+ }
+
+ public File baseFolder;
+ public Type type;
+
+ public transient Project parent;
+
+ public transient Map> referencedSourceFiles = null;
+
+ public GameSource(Map json, Project parent) {
+ fromMap(json);
+ refreshTransients(parent);
+ }
+ public GameSource(File folder, Project parent) {
+ this.parent = parent;
+ this.baseFolder = folder;
+ this.type = Type.source;
+ initData();
+ }
+
+ public GameSource(Project parent, Type type) {
+ this.parent = parent;
+ this.baseFolder = new File(parent.baseFolder, type.toString());
+ this.type = type;
+ initData();
+ }
+
+ public void refreshTransients(Project p) {
+ parent = p;
+ initData();
+ }
+
+ public void initData() {
+ if (type == Type.source) {
+ if (parent.sourceSetToUse == ResourceSet.gameData || parent.sourceSetToUse == ResourceSet.debugData) {
+ referencedSourceFiles = new LinkedHashMap>();
+ readResourceList();
+ }
+ }
+ if (type == Type.created) {
+ this.writerModeDataSet = new WriterModeDataSet(this);
+ }
+ this.gameData = new GameDataSet(this);
+ this.gameMaps = new TMXMapSet(this);
+ this.gameSprites = new SpriteSheetSet(this);
+ this.worldmap = new Worldmap(this);
+ v = new SavedSlotCollection();
+ v.add(gameData);
+ v.add(gameMaps);
+ v.add(gameSprites);
+ v.add(worldmap);
+ if (type == Type.created) {
+ v.add(writerModeDataSet);
+ }
+ }
+
+ public void readResourceList() {
+ File xmlFile;
+ if (parent.sourceSetToUse == ResourceSet.gameData) {
+ xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_GAME_RESOURCE);
+ } else if (parent.sourceSetToUse == ResourceSet.debugData) {
+ xmlFile = new File(baseFolder, DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE);
+ } else {
+ return;
+ }
+
+ if (!xmlFile.exists()) return;
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document doc;
+ try {
+ factory.setIgnoringComments(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ factory.setExpandEntityReferences(false);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputSource insrc = new InputSource(new FileInputStream(xmlFile));
// insrc.setSystemId("http://worldmap/");
- insrc.setEncoding("UTF-8");
- doc = builder.parse(insrc);
-
- Element root = (Element) doc.getElementsByTagName("resources").item(0);
- if (root != null) {
- NodeList arraysList = root.getElementsByTagName("array");
- if (arraysList != null) {
- for (int i = 0; i < arraysList.getLength(); i++) {
- Element arrayNode = (Element) arraysList.item(i);
- String name = arrayNode.getAttribute("name");
- List arrayContents = new ArrayList();
- NodeList arrayItems = arrayNode.getElementsByTagName("item");
- if (arrayItems != null) {
- for (int j = 0; j < arrayItems.getLength(); j++) {
- arrayContents.add(((Element)arrayItems.item(j)).getTextContent());
- }
- referencedSourceFiles.put(name, arrayContents);
- }
- }
- }
- }
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public Enumeration children() {
- return v.getNonEmptyElements();
- }
- @Override
- public boolean getAllowsChildren() {
- return true;
- }
- @Override
- public TreeNode getChildAt(int arg0) {
- return v.getNonEmptyElementAt(arg0);
- }
- @Override
- public int getChildCount() {
- return v.getNonEmptySize();
- }
- @Override
- public int getIndex(TreeNode arg0) {
- return v.getNonEmptyIndexOf((ProjectTreeNode) arg0);
- }
- @Override
- public TreeNode getParent() {
- return parent;
- }
- @Override
- public boolean isLeaf() {
- return false;
- }
- @Override
- public void childrenAdded(List path) {
- path.add(0, this);
- parent.childrenAdded(path);
- }
- @Override
- public void childrenChanged(List path) {
- path.add(0, this);
- parent.childrenChanged(path);
- }
- @Override
- public void childrenRemoved(List path) {
- if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
- childrenRemoved(new ArrayList());
- } else {
- path.add(0, this);
- parent.childrenRemoved(path);
- }
- }
- @Override
- public void notifyCreated() {
- childrenAdded(new ArrayList());
- for (ProjectTreeNode node : v.getNonEmptyIterable()) {
- node.notifyCreated();
- }
- }
- @Override
- public String getDesc() {
- switch(type) {
- case altered: return (needsSaving() ? "*" : "")+"Altered data";
- case created: return (needsSaving() ? "*" : "")+"Created data";
- case referenced: return (needsSaving() ? "*" : "")+"Referenced data";
- case source: return (needsSaving() ? "*" : "")+"AT Source"; //The fact that it is from "source" is already mentionned by its parent.
- default: return (needsSaving() ? "*" : "")+"Game data";
- }
- }
-
-
- @Override
- public Project getProject() {
- return parent == null ? null : parent.getProject();
- }
+ insrc.setEncoding("UTF-8");
+ doc = builder.parse(insrc);
- public Image getIcon(String iconId) {
- String[] data = iconId.split(":");
- for (Spritesheet sheet : gameSprites.spritesheets) {
- if (sheet.id.equals(data[0])) {
- return sheet.getIcon(Integer.parseInt(data[1]));
- }
- }
- return null;
- }
-
- public Image getImage(String iconId) {
- String[] data = iconId.split(":");
- for (Spritesheet sheet : gameSprites.spritesheets) {
- if (sheet.id.equals(data[0])) {
- return sheet.getImage(Integer.parseInt(data[1]));
- }
- }
- return null;
- }
-
+ Element root = (Element) doc.getElementsByTagName("resources").item(0);
+ if (root != null) {
+ NodeList arraysList = root.getElementsByTagName("array");
+ if (arraysList != null) {
+ for (int i = 0; i < arraysList.getLength(); i++) {
+ Element arrayNode = (Element) arraysList.item(i);
+ String name = arrayNode.getAttribute("name");
+ List arrayContents = new ArrayList();
+ NodeList arrayItems = arrayNode.getElementsByTagName("item");
+ if (arrayItems != null) {
+ for (int j = 0; j < arrayItems.getLength(); j++) {
+ arrayContents.add(((Element) arrayItems.item(j)).getTextContent());
+ }
+ referencedSourceFiles.put(name, arrayContents);
+ }
+ }
+ }
+ }
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
- @Override
- public Image getIcon() {
- return getOpenIcon();
- }
- @Override
- public Image getClosedIcon() {
- return DefaultIcons.getATClosedIcon();
- }
- @Override
- public Image getLeafIcon() {
- return DefaultIcons.getATClosedIcon();
- }
- @Override
- public Image getOpenIcon() {
- return DefaultIcons.getATOpenIcon();
- }
- @Override
- public GameDataSet getDataSet() {
- return null;
- }
-
+ @Override
+ public Enumeration children() {
+ return v.getNonEmptyElements();
+ }
- @Override
- public Type getDataType() {
- return type;
- }
-
- @Override
- public boolean isEmpty() {
- return v.isEmpty();
- }
+ @Override
+ public boolean getAllowsChildren() {
+ return true;
+ }
- public WorldmapSegment getWorldmapSegment(String id) {
- return worldmap.getWorldmapSegment(id);
- }
-
- @Override
- public boolean needsSaving() {
- for (ProjectTreeNode node : v.getNonEmptyIterable()) {
- if (node.needsSaving()) return true;
- }
- return false;
- }
+ @Override
+ public TreeNode getChildAt(int arg0) {
+ return v.getNonEmptyElementAt(arg0);
+ }
+
+ @Override
+ public int getChildCount() {
+ return v.getNonEmptySize();
+ }
+
+ @Override
+ public int getIndex(TreeNode arg0) {
+ return v.getNonEmptyIndexOf((ProjectTreeNode) arg0);
+ }
+
+ @Override
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return false;
+ }
+
+ @Override
+ public void childrenAdded(List path) {
+ path.add(0, this);
+ parent.childrenAdded(path);
+ }
+
+ @Override
+ public void childrenChanged(List path) {
+ path.add(0, this);
+ parent.childrenChanged(path);
+ }
+
+ @Override
+ public void childrenRemoved(List path) {
+ if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
+ childrenRemoved(new ArrayList());
+ } else {
+ path.add(0, this);
+ parent.childrenRemoved(path);
+ }
+ }
+
+ @Override
+ public void notifyCreated() {
+ childrenAdded(new ArrayList());
+ for (ProjectTreeNode node : v.getNonEmptyIterable()) {
+ node.notifyCreated();
+ }
+ }
+
+ @Override
+ public String getDesc() {
+ switch (type) {
+ case altered:
+ return (needsSaving() ? "*" : "") + "Altered data";
+ case created:
+ return (needsSaving() ? "*" : "") + "Created data";
+ case referenced:
+ return (needsSaving() ? "*" : "") + "Referenced data";
+ case source:
+ return (needsSaving() ? "*" : "") + "AT Source"; //The fact that it is from "source" is already mentionned by its parent.
+ default:
+ return (needsSaving() ? "*" : "") + "Game data";
+ }
+ }
+
+
+ @Override
+ public Project getProject() {
+ return parent == null ? null : parent.getProject();
+ }
+
+ public Image getIcon(String iconId) {
+ String[] data = iconId.split(":");
+ for (Spritesheet sheet : gameSprites.spritesheets) {
+ if (sheet.id.equals(data[0])) {
+ return sheet.getIcon(Integer.parseInt(data[1]));
+ }
+ }
+ return null;
+ }
+
+ public Image getImage(String iconId) {
+ String[] data = iconId.split(":");
+ for (Spritesheet sheet : gameSprites.spritesheets) {
+ if (sheet.id.equals(data[0])) {
+ return sheet.getImage(Integer.parseInt(data[1]));
+ }
+ }
+ return null;
+ }
+
+
+ @Override
+ public Image getIcon() {
+ return getOpenIcon();
+ }
+
+ @Override
+ public Image getClosedIcon() {
+ return DefaultIcons.getATClosedIcon();
+ }
+
+ @Override
+ public Image getLeafIcon() {
+ return DefaultIcons.getATClosedIcon();
+ }
+
+ @Override
+ public Image getOpenIcon() {
+ return DefaultIcons.getATOpenIcon();
+ }
+
+ @Override
+ public GameDataSet getDataSet() {
+ return null;
+ }
+
+
+ @Override
+ public Type getDataType() {
+ return type;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return v.isEmpty();
+ }
+
+ public WorldmapSegment getWorldmapSegment(String id) {
+ return worldmap.getWorldmapSegment(id);
+ }
+
+ @Override
+ public boolean needsSaving() {
+ for (ProjectTreeNode node : v.getNonEmptyIterable()) {
+ if (node.needsSaving()) return true;
+ }
+ return false;
+ }
}
diff --git a/src/com/gpl/rpg/atcontentstudio/model/Preferences.java b/src/com/gpl/rpg/atcontentstudio/model/Preferences.java
index 36fa399..e8ca1e6 100644
--- a/src/com/gpl/rpg/atcontentstudio/model/Preferences.java
+++ b/src/com/gpl/rpg/atcontentstudio/model/Preferences.java
@@ -1,19 +1,53 @@
package com.gpl.rpg.atcontentstudio.model;
-import java.awt.Dimension;
+import com.gpl.rpg.atcontentstudio.io.JsonSerializable;
+
+import java.awt.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
-public class Preferences implements Serializable {
+public class Preferences implements Serializable, JsonSerializable {
- private static final long serialVersionUID = 2455802658424031276L;
-
- public Dimension windowSize = null;
- public Map splittersPositions = new HashMap();
-
- public Preferences() {
+ private static final long serialVersionUID = 2455802658424031276L;
- }
-
+ public Dimension windowSize = null;
+ public Map splittersPositions = new HashMap<>();
+
+ public Preferences() {
+
+ }
+
+ @Override
+ public Map toMap() {
+ Map map = new HashMap();
+
+ if(windowSize!= null){
+ Map windowSizeMap = new HashMap<>();
+ windowSizeMap.put("width", windowSize.width);
+ windowSizeMap.put("height", windowSize.height);
+ map.put("windowSize", windowSizeMap);
+ }
+
+ map.put("splittersPositions", splittersPositions);
+ return map;
+ }
+
+ @Override
+ public void fromMap(Map map) {
+ if(map == null) return;
+
+ Map windowSize1 = (Map) map.get("windowSize");
+ if(windowSize1 != null){
+ windowSize = new Dimension(((Number) windowSize1.get("width")).intValue(), ((Number) windowSize1.get("height")).intValue());
+ }
+
+ Map splitters = (Map) map.get("splittersPositions");
+ Map splittersInt = new HashMap<>(splitters.size());
+ for (Map.Entry entry : splitters. entrySet()){
+ splittersInt.put(entry.getKey(), entry.getValue().intValue());
+ }
+ splittersPositions = splittersInt;
+
+ }
}
diff --git a/src/com/gpl/rpg/atcontentstudio/model/Project.java b/src/com/gpl/rpg/atcontentstudio/model/Project.java
index a6dab19..32cf9fc 100644
--- a/src/com/gpl/rpg/atcontentstudio/model/Project.java
+++ b/src/com/gpl/rpg/atcontentstudio/model/Project.java
@@ -1,1406 +1,1383 @@
-package com.gpl.rpg.atcontentstudio.model;
-
-import java.awt.Image;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.swing.tree.TreeNode;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.json.simple.JSONArray;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import com.gpl.rpg.atcontentstudio.ATContentStudio;
-import com.gpl.rpg.atcontentstudio.Notification;
-import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
-import com.gpl.rpg.atcontentstudio.io.SettingsSave;
-import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
-import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarksRoot;
-import com.gpl.rpg.atcontentstudio.model.gamedata.ActorCondition;
-import com.gpl.rpg.atcontentstudio.model.gamedata.Dialogue;
-import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
-import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataCategory;
-import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
-import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
-import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
-import com.gpl.rpg.atcontentstudio.model.gamedata.JSONElement;
-import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
-import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
-import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
-import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
-import com.gpl.rpg.atcontentstudio.model.maps.TMXMapSet;
-import com.gpl.rpg.atcontentstudio.model.maps.Worldmap;
-import com.gpl.rpg.atcontentstudio.model.maps.WorldmapSegment;
-import com.gpl.rpg.atcontentstudio.model.saves.SavedGamesSet;
-import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
-import com.gpl.rpg.atcontentstudio.model.tools.writermode.WriterModeData;
-import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
-import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
-import com.gpl.rpg.atcontentstudio.utils.FileUtils;
-
-public class Project implements ProjectTreeNode, Serializable {
-
- private static final long serialVersionUID = 4807454973303366758L;
- private static final String drawablePath = TMXMapSet.DEFAULT_REL_PATH_TO_DRAWABLE.replace("\\", "/");
-
-
- //Every instance field that is not transient will be saved in this file.
- public static final String SETTINGS_FILE = ".project";
-
- public String name;
-
- public File baseFolder;
- public boolean open;
-
- public GameSource baseContent; //A.k.a library
-
- public GameSource referencedContent; //Pointers to base content
- public transient GameSource alteredContent; //Copied from base content (does not overwrite yet)
- public transient GameSource createdContent; //Stand-alone.
- public transient BookmarksRoot bookmarks;
-
-
- public SavedGamesSet saves; //For simulations.
-
- public transient SavedSlotCollection v;
-
- public transient Workspace parent;
-
- public Properties knownSpritesheetsProperties = null;
-
- public static enum ResourceSet {
- gameData,
- debugData,
- allFiles
- }
-
- public ResourceSet sourceSetToUse = ResourceSet.allFiles;
-
- public Project(Workspace w, String name, File source, ResourceSet sourceSet) {
- this.parent = w;
- this.name = name;
- this.sourceSetToUse = sourceSet;
-
- //CREATE PROJECT
- baseFolder = new File(w.baseFolder, name+File.separator);
- try {
- baseFolder.mkdir();
- } catch (SecurityException e) {
- Notification.addError("Eror creating project root folder: "+e.getMessage());
- e.printStackTrace();
- }
- open = true;
- v = new SavedSlotCollection();
-
- knownSpritesheetsProperties = new Properties();
- try {
- knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
- } catch (IOException e) {
- Notification.addWarn("Unable to load default spritesheets properties.");
- e.printStackTrace();
- }
-
-
- baseContent = new GameSource(source, this);
-
-// referencedContent = new GameSource(this, GameSource.Type.referenced);
-
- alteredContent = new GameSource(this, GameSource.Type.altered);
- createdContent = new GameSource(this, GameSource.Type.created);
- bookmarks = new BookmarksRoot(this);
-
- saves = new SavedGamesSet(this);
-
- v.add(createdContent);
- v.add(alteredContent);
-// v.add(referencedContent);
- v.add(baseContent);
- v.add(saves);
- v.add(bookmarks);
-
- linkAll();
-
- save();
- }
-
-
- @Override
- public TreeNode getChildAt(int childIndex) {
- return v.getNonEmptyElementAt(childIndex);
- }
-
- @Override
- public int getChildCount() {
- return v.getNonEmptySize();
- }
-
- @Override
- public TreeNode getParent() {
- return parent;
- }
-
- @Override
- public int getIndex(TreeNode node) {
- return v.getNonEmptyIndexOf((ProjectTreeNode) node);
- }
-
- @Override
- public boolean getAllowsChildren() {
- return open;
- }
-
- @Override
- public boolean isLeaf() {
- return !open;
- }
-
- @Override
- public Enumeration children() {
- return v.getNonEmptyElements();
- }
-
- @Override
- public void childrenAdded(List path) {
- path.add(0,this);
- parent.childrenAdded(path);
- }
-
- @Override
- public void childrenChanged(List path) {
- path.add(0,this);
- parent.childrenChanged(path);
- }
-
- @Override
- public void childrenRemoved(List path) {
- path.add(0,this);
- parent.childrenRemoved(path);
- }
- @Override
- public void notifyCreated() {
- childrenAdded(new ArrayList());
- for (ProjectTreeNode node : v.getNonEmptyIterable()) {
- node.notifyCreated();
- }
- }
- @Override
- public String getDesc() {
- return (needsSaving() ? "*" : "")+name;
- }
-
-
- public void close() {
- this.open = false;
- childrenRemoved(new ArrayList());
- }
-
- public void open() {
- open = true;
- }
-
-
- public static Project fromFolder(Workspace w, File projRoot) {
- Project p = null;
- File f = new File(projRoot, Project.SETTINGS_FILE);
- if (!f.exists()) {
- Notification.addError("Unable to find "+SETTINGS_FILE+" for project "+projRoot.getName());
- return null;
- } else {
- p = (Project) SettingsSave.loadInstance(f, "Project");
- }
- p.refreshTransients(w);
- return p;
- }
-
- public void refreshTransients(Workspace w) {
- this.parent = w;
-
- projectElementListeners = new HashMap, List>();
-
- try {
- knownSpritesheetsProperties = new Properties();
- knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
- } catch (IOException e) {
- Notification.addWarn("Unable to load default spritesheets properties.");
- e.printStackTrace();
- }
-
- if (sourceSetToUse == null) {
- sourceSetToUse = ResourceSet.allFiles;
- }
-
-// long l = new Date().getTime();
- baseContent.refreshTransients(this);
-// l = new Date().getTime() - l;
-// System.out.println("All initialized in "+l+"ms.");
-// referencedContent.refreshTransients(this);
- alteredContent = new GameSource(this, GameSource.Type.altered);
- createdContent = new GameSource(this, GameSource.Type.created);
- bookmarks = new BookmarksRoot(this);
-
- saves.refreshTransients();
-
- v = new SavedSlotCollection();
- v.add(createdContent);
- v.add(alteredContent);
-// v.add(referencedContent);
- v.add(baseContent);
- v.add(saves);
- v.add(bookmarks);
-
-
- linkAll();
-
- }
-
- public void linkAll() {
- for (ProjectTreeNode node : baseContent.gameData.v.getNonEmptyIterable()) {
- if (node instanceof GameDataCategory>) {
- for (GameDataElement e : ((GameDataCategory>) node)) {
- e.link();
- }
- }
- }
- for (ProjectTreeNode node : baseContent.gameMaps.tmxMaps) {
- ((TMXMap)node).link();
- }
- for (ProjectTreeNode node : alteredContent.gameData.v.getNonEmptyIterable()) {
- if (node instanceof GameDataCategory>) {
- for (GameDataElement e : ((GameDataCategory>) node)) {
- e.link();
- }
- }
- }
- for (ProjectTreeNode node : alteredContent.gameMaps.tmxMaps) {
- ((TMXMap)node).link();
- }
- for (ProjectTreeNode node : createdContent.gameData.v.getNonEmptyIterable()) {
- if (node instanceof GameDataCategory>) {
- for (GameDataElement e : ((GameDataCategory>) node)) {
- e.link();
- }
- }
- }
- for (ProjectTreeNode node : createdContent.gameMaps.tmxMaps) {
- ((TMXMap)node).link();
- }
-
- for (WorldmapSegment node : createdContent.worldmap) {
- node.link();
- }
- for (WorldmapSegment node : alteredContent.worldmap) {
- node.link();
- }
- for (WorldmapSegment node : baseContent.worldmap) {
- node.link();
- }
- }
-
- public void save() {
- SettingsSave.saveInstance(this, new File(baseFolder, Project.SETTINGS_FILE), "Project "+this.name);
- }
-
-
- public JSONElement getGameDataElement(Class extends JSONElement> gdeClass, String id) {
- if (gdeClass == ActorCondition.class) {
- return getActorCondition(id);
- }
- if (gdeClass == Dialogue.class) {
- return getDialogue(id);
- }
- if (gdeClass == Droplist.class) {
- return getDroplist(id);
- }
- if (gdeClass == ItemCategory.class) {
- return getItemCategory(id);
- }
- if (gdeClass == Item.class) {
- return getItem(id);
- }
- if (gdeClass == NPC.class) {
- return getNPC(id);
- }
- if (gdeClass == Quest.class) {
- return getQuest(id);
- }
- return null;
- }
-
- public int getNodeCount(Class extends GameDataElement> gdeClass) {
- if (gdeClass == ActorCondition.class) {
- return getActorConditionCount();
- }
- if (gdeClass == Dialogue.class) {
- return getDialogueCount();
- }
- if (gdeClass == Droplist.class) {
- return getDroplistCount();
- }
- if (gdeClass == ItemCategory.class) {
- return getItemCategoryCount();
- }
- if (gdeClass == Item.class) {
- return getItemCount();
- }
- if (gdeClass == NPC.class) {
- return getNPCCount();
- }
- if (gdeClass == Quest.class) {
- return getQuestCount();
- }
- return 0;
- }
-
- public int getNodeIndex(GameDataElement node) {
- Class extends GameDataElement> gdeClass = node.getClass();
- if (gdeClass == ActorCondition.class) {
- return getActorConditionIndex((ActorCondition) node);
- }
- if (gdeClass == Dialogue.class) {
- return getDialogueIndex((Dialogue) node);
- }
- if (gdeClass == Droplist.class) {
- return getDroplistIndex((Droplist) node);
- }
- if (gdeClass == ItemCategory.class) {
- return getItemCategoryIndex((ItemCategory) node);
- }
- if (gdeClass == Item.class) {
- return getItemIndex((Item) node);
- }
- if (gdeClass == NPC.class) {
- return getNPCIndex((NPC) node);
- }
- if (gdeClass == Quest.class) {
- return getQuestIndex((Quest) node);
- }
- return 0;
- }
-
- public ActorCondition getActorCondition(String id) {
- ActorCondition gde = createdContent.gameData.getActorCondition(id);
- if (gde == null) gde = alteredContent.gameData.getActorCondition(id);
- if (gde == null) gde = baseContent.gameData.getActorCondition(id);
- return gde;
- }
-
- public int getActorConditionCount() {
- return createdContent.gameData.actorConditions.size() + baseContent.gameData.actorConditions.size();
- }
-
- public ActorCondition getActorCondition(int index) {
- if (index < createdContent.gameData.actorConditions.size()) {
- return createdContent.gameData.actorConditions.get(index);
- } else if (index < getActorConditionCount()){
- return getActorCondition(baseContent.gameData.actorConditions.get(index - createdContent.gameData.actorConditions.size()).id);
- }
- return null;
- }
-
- public int getActorConditionIndex(ActorCondition ac) {
- if (ac.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.actorConditions.getIndex(ac);
- } else {
- return createdContent.gameData.actorConditions.size() + baseContent.gameData.actorConditions.indexOf(baseContent.gameData.getActorCondition(ac.id));
- }
- }
-
-
- public Dialogue getDialogue(String id) {
- Dialogue gde = createdContent.gameData.getDialogue(id);
- if (gde == null) gde = alteredContent.gameData.getDialogue(id);
- if (gde == null) gde = baseContent.gameData.getDialogue(id);
- return gde;
- }
-
- public int getDialogueCount() {
- return createdContent.gameData.dialogues.size() + baseContent.gameData.dialogues.size();
- }
-
- public Dialogue getDialogue(int index) {
- if (index < createdContent.gameData.dialogues.size()) {
- return createdContent.gameData.dialogues.get(index);
- } else if (index < getDialogueCount()){
- return getDialogue(baseContent.gameData.dialogues.get(index - createdContent.gameData.dialogues.size()).id);
- }
- return null;
- }
-
- public int getDialogueIndex(Dialogue dialogue) {
- if (dialogue.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.dialogues.getIndex(dialogue);
- } else {
- return createdContent.gameData.dialogues.size() + baseContent.gameData.dialogues.indexOf(baseContent.gameData.getDialogue(dialogue.id));
- }
- }
-
-
- public Droplist getDroplist(String id) {
- Droplist gde = createdContent.gameData.getDroplist(id);
- if (gde == null) gde = alteredContent.gameData.getDroplist(id);
- if (gde == null) gde = baseContent.gameData.getDroplist(id);
- return gde;
- }
-
- public int getDroplistCount() {
- return createdContent.gameData.droplists.size() + baseContent.gameData.droplists.size();
- }
-
- public Droplist getDroplist(int index) {
- if (index < createdContent.gameData.droplists.size()) {
- return createdContent.gameData.droplists.get(index);
- } else if (index < getDroplistCount()){
- return getDroplist(baseContent.gameData.droplists.get(index - createdContent.gameData.droplists.size()).id);
- }
- return null;
- }
-
- public int getDroplistIndex(Droplist droplist) {
- if (droplist.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.droplists.getIndex(droplist);
- } else {
- return createdContent.gameData.droplists.size() + baseContent.gameData.droplists.indexOf(baseContent.gameData.getDroplist(droplist.id));
- }
- }
-
-
- public Item getItem(String id) {
- Item gde = createdContent.gameData.getItem(id);
- if (gde == null) gde = alteredContent.gameData.getItem(id);
- if (gde == null) gde = baseContent.gameData.getItem(id);
- return gde;
- }
-
- public int getItemCount() {
- return createdContent.gameData.items.size() + baseContent.gameData.items.size();
- }
-
- public Item getItem(int index) {
- if (index < createdContent.gameData.items.size()) {
- return createdContent.gameData.items.get(index);
- } else if (index < getItemCount()){
- return getItem(baseContent.gameData.items.get(index - createdContent.gameData.items.size()).id);
- }
- return null;
- }
-
- public int getItemCountIncludingAltered() {
- return createdContent.gameData.items.size() + alteredContent.gameData.items.size() + baseContent.gameData.items.size();
- }
-
- public Item getItemIncludingAltered(int index) {
- if (index < createdContent.gameData.items.size()) {
- return createdContent.gameData.items.get(index);
- } else if (index < createdContent.gameData.items.size() + alteredContent.gameData.items.size()){
- return alteredContent.gameData.items.get(index - createdContent.gameData.items.size());
- } else if (index < getItemCountIncludingAltered()) {
- return baseContent.gameData.items.get(index - (createdContent.gameData.items.size() + alteredContent.gameData.items.size()));
- }
- return null;
- }
-
- public int getItemIndex(Item item) {
- if (item.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.items.getIndex(item);
- } else {
- return createdContent.gameData.items.size() + baseContent.gameData.items.indexOf(baseContent.gameData.getItem(item.id));
- }
- }
-
-
- public ItemCategory getItemCategory(String id) {
- ItemCategory gde = createdContent.gameData.getItemCategory(id);
- if (gde == null) gde = alteredContent.gameData.getItemCategory(id);
- if (gde == null) gde = baseContent.gameData.getItemCategory(id);
- return gde;
- }
-
- public int getItemCategoryCount() {
- return createdContent.gameData.itemCategories.size() + baseContent.gameData.itemCategories.size();
- }
-
- public ItemCategory getItemCategory(int index) {
- if (index < createdContent.gameData.itemCategories.size()) {
- return createdContent.gameData.itemCategories.get(index);
- } else if (index < getItemCategoryCount()){
- return getItemCategory(baseContent.gameData.itemCategories.get(index - createdContent.gameData.itemCategories.size()).id);
- }
- return null;
- }
-
- public int getItemCategoryIndex(ItemCategory iCat) {
- if (iCat.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.itemCategories.getIndex(iCat);
- } else {
- return createdContent.gameData.itemCategories.size() + baseContent.gameData.itemCategories.indexOf(baseContent.gameData.getItemCategory(iCat.id));
- }
- }
-
-
- public NPC getNPC(String id) {
- NPC gde = createdContent.gameData.getNPC(id);
- if (gde == null) gde = alteredContent.gameData.getNPC(id);
- if (gde == null) gde = baseContent.gameData.getNPC(id);
- return gde;
- }
-
- public NPC getNPCIgnoreCase(String id) {
- NPC gde = createdContent.gameData.getNPCIgnoreCase(id);
- if (gde == null) gde = alteredContent.gameData.getNPCIgnoreCase(id);
- if (gde == null) gde = baseContent.gameData.getNPCIgnoreCase(id);
- return gde;
- }
-
- public int getNPCCount() {
- return createdContent.gameData.npcs.size() + baseContent.gameData.npcs.size();
- }
-
- public NPC getNPC(int index) {
- if (index < createdContent.gameData.npcs.size()) {
- return createdContent.gameData.npcs.get(index);
- } else if (index < getNPCCount()){
- return getNPC(baseContent.gameData.npcs.get(index - createdContent.gameData.npcs.size()).id);
- }
- return null;
- }
-
- public int getNPCCountIncludingAltered() {
- return createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size() + baseContent.gameData.npcs.size();
- }
-
- public NPC getNPCIncludingAltered(int index) {
- if (index < createdContent.gameData.npcs.size()) {
- return createdContent.gameData.npcs.get(index);
- } else if (index < createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size()){
- return alteredContent.gameData.npcs.get(index - createdContent.gameData.npcs.size());
- } else if (index < getNPCCountIncludingAltered()) {
- return baseContent.gameData.npcs.get(index - (createdContent.gameData.npcs.size() + alteredContent.gameData.npcs.size()));
- }
- return null;
- }
-
- public int getNPCIndex(NPC npc) {
- if (npc.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.npcs.getIndex(npc);
- } else {
- return createdContent.gameData.npcs.size() + baseContent.gameData.npcs.indexOf(baseContent.gameData.getNPC(npc.id));
- }
- }
-
-
- public Quest getQuest(String id) {
- Quest gde = createdContent.gameData.getQuest(id);
- if (gde == null) gde = alteredContent.gameData.getQuest(id);
- if (gde == null) gde = baseContent.gameData.getQuest(id);
- return gde;
- }
-
- public int getQuestCount() {
- return createdContent.gameData.quests.size() + baseContent.gameData.quests.size();
- }
-
- public Quest getQuest(int index) {
- if (index < createdContent.gameData.quests.size()) {
- return createdContent.gameData.quests.get(index);
- } else if (index < getQuestCount()){
- return getQuest(baseContent.gameData.quests.get(index - createdContent.gameData.quests.size()).id);
- }
- return null;
- }
-
- public int getQuestIndex(Quest quest) {
- if (quest.getDataType() == GameSource.Type.created) {
- return createdContent.gameData.quests.getIndex(quest);
- } else {
- return createdContent.gameData.quests.size() + baseContent.gameData.quests.indexOf(baseContent.gameData.getQuest(quest.id));
- }
- }
-
- public WorldmapSegment getWorldmapSegment(String id) {
- WorldmapSegment gde = createdContent.getWorldmapSegment(id);
- if (gde == null) gde = alteredContent.getWorldmapSegment(id);
- if (gde == null) gde = baseContent.getWorldmapSegment(id);
- return gde;
- }
-
- public int getWorldmapSegmentCount() {
- return createdContent.worldmap.size() + baseContent.worldmap.size();
- }
-
- public WorldmapSegment getWorldmapSegment(int index) {
- if (index < createdContent.worldmap.size()) {
- return createdContent.worldmap.get(index);
- } else if (index < getWorldmapSegmentCount()){
- return getWorldmapSegment(baseContent.worldmap.get(index - createdContent.worldmap.size()).id);
- }
- return null;
- }
-
- public int getWorldmapSegmentIndex(WorldmapSegment segment) {
- if (segment.getDataType() == GameSource.Type.created) {
- return createdContent.worldmap.getIndex(segment);
- } else {
- return createdContent.worldmap.size() + baseContent.worldmap.indexOf(baseContent.getWorldmapSegment(segment.id));
- }
- }
-
- public Image getIcon(String iconId) {
- return baseContent.getIcon(iconId);
- }
-
- public Image getImage(String iconId) {
- return baseContent.getImage(iconId);
- }
-
- public Spritesheet getSpritesheet(String id) {
- Spritesheet sheet = createdContent.gameSprites.getSpritesheet(id);
- if (sheet == null) sheet = alteredContent.gameSprites.getSpritesheet(id);
- if (sheet == null) sheet = baseContent.gameSprites.getSpritesheet(id);
- return sheet;
- }
-
- public int getSpritesheetCount() {
- return createdContent.gameSprites.spritesheets.size() + baseContent.gameSprites.spritesheets.size();
- }
-
- public Spritesheet getSpritesheet(int index) {
- if (index < createdContent.gameSprites.spritesheets.size()) {
- return createdContent.gameSprites.spritesheets.get(index);
- } else if (index < getSpritesheetCount()){
- return getSpritesheet(baseContent.gameSprites.spritesheets.get(index - createdContent.gameSprites.spritesheets.size()).id);
- }
- return null;
- }
-
- public int getSpritesheetIndex(Spritesheet spritesheet) {
- if (spritesheet.getDataType() == GameSource.Type.created) {
- return createdContent.gameSprites.spritesheets.indexOf(spritesheet);
- } else {
- return createdContent.gameSprites.spritesheets.size() + baseContent.gameSprites.spritesheets.indexOf(baseContent.gameSprites.getSpritesheet(spritesheet.id));
- }
- }
-
- public TMXMap getMap(String id) {
- TMXMap map = createdContent.gameMaps.getMap(id);
- if (map == null) map = alteredContent.gameMaps.getMap(id);
- if (map == null) map = baseContent.gameMaps.getMap(id);
- return map;
- }
-
- public int getMapCount() {
- return createdContent.gameMaps.getChildCount() + baseContent.gameMaps.getChildCount();
- }
-
- public TMXMap getMap(int index) {
- if (index < createdContent.gameMaps.getChildCount()) {
- return createdContent.gameMaps.get(index);
- } else if (index < getMapCount()){
- return getMap(baseContent.gameMaps.get(index - createdContent.gameMaps.getChildCount()).id);
- }
- return null;
- }
-
- public int getMapIndex(TMXMap map) {
- if (map.getDataType() == GameSource.Type.created) {
- return createdContent.gameMaps.tmxMaps.indexOf(map);
- } else {
- return createdContent.gameMaps.tmxMaps.size() + baseContent.gameMaps.tmxMaps.indexOf(baseContent.gameMaps.getMap(map.id));
- }
- }
-
- public int getWriterSketchCount() {
- return createdContent.writerModeDataSet.getChildCount();
- }
-
- public WriterModeData getWriterSketch(String id) {
- return createdContent.writerModeDataSet.getWriterSketch(id);
- }
-
- public WriterModeData getWriterSketch(int index) {
- if (index < createdContent.writerModeDataSet.getChildCount()) {
- return createdContent.writerModeDataSet.get(index);
- }
- return null;
- }
-
- @Override
- public Project getProject() {
- return this;
- }
-
- @Override
- public Image getIcon() {
- return getOpenIcon();
- }
- @Override
- public Image getClosedIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdClosedIcon();
- }
- @Override
- public Image getLeafIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdClosedIcon();
- }
- @Override
- public Image getOpenIcon() {
- //TODO Create a cool Project icon.
- return DefaultIcons.getStdOpenIcon();
- }
-
- public void makeWritable(JSONElement node) {
- GameSource.Type type = node.getDataType();
- if (type == null) {
- Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
- } else {
- if (type == GameSource.Type.source) {
- JSONElement clone = (JSONElement) node.clone();
- if (node instanceof Quest) {
- for (QuestStage oldStage : ((Quest) node).stages) {
- QuestStage newStage = ((Quest) clone).getStage(oldStage.progress);
- for (GameDataElement backlink : oldStage.getBacklinks()) {
- backlink.elementChanged(oldStage, newStage);
- }
- oldStage.getBacklinks().clear();
- }
- }
- for (GameDataElement backlink : node.getBacklinks()) {
- backlink.elementChanged(node, clone);
- }
- node.getBacklinks().clear();
- clone.writable = true;
- clone.state = GameDataElement.State.created;
- alteredContent.gameData.addElement(clone);
- } else {
- Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
- }
- }
- }
-
-
-
- public void makeWritable(TMXMap node) {
- GameSource.Type type = node.getDataType();
- if (type == null) {
- Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
- } else {
- if (type == GameSource.Type.source) {
- TMXMap clone = node.clone();
- for (GameDataElement backlink : node.getBacklinks()) {
- backlink.elementChanged(node, clone);
- }
- node.getBacklinks().clear();
- clone.writable = true;
- clone.state = GameDataElement.State.created;
- alteredContent.gameMaps.addMap(clone);
- } else {
- Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
- }
- }
- }
-
- public void makeWritable(WorldmapSegment node) {
- GameSource.Type type = node.getDataType();
- if (type == null) {
- Notification.addError("Unable to make "+node.getDesc()+" writable. No owning GameDataSet found.");
- } else {
- if (type == GameSource.Type.source) {
- WorldmapSegment clone = node.clone();
- for (GameDataElement backlink : node.getBacklinks()) {
- backlink.elementChanged(node, clone);
- }
- clone.state = GameDataElement.State.init;
- clone.parse();
- node.getBacklinks().clear();
- clone.writable = true;
- clone.state = GameDataElement.State.created;
- alteredContent.worldmap.addSegment(clone);
- } else {
- Notification.addError("Unable to make "+node.getDesc()+" writable. It does not originate from game source material.");
- }
- }
- }
-
- /**
- *
- * @param node. Before calling this method, make sure that no other node with the same class and id exist in either created or altered.
- */
- public void createElement(JSONElement node) {
- node.writable = true;
- if (getGameDataElement(node.getClass(), node.id) != null) {
- GameDataElement existingNode = getGameDataElement(node.getClass(), node.id);
- for (GameDataElement backlink : existingNode.getBacklinks()) {
- backlink.elementChanged(existingNode, node);
- }
- existingNode.getBacklinks().clear();
- node.writable = true;
- alteredContent.gameData.addElement(node);
- node.link();
- node.state = GameDataElement.State.created;
- } else {
- createdContent.gameData.addElement(node);
- node.link();
- node.state = GameDataElement.State.created;
- }
- fireElementAdded(node, getNodeIndex(node));
- }
-
- /**
- *
- * @param node. Before calling this method, make sure that no other node with the same class and id exist in either created or altered.
- */
- public void createElements(List extends JSONElement> nodes) {
- for (JSONElement node : nodes) {
- //Already added.
- if (node.getProject() != null) continue;
- node.writable = true;
- if (getGameDataElement(node.getClass(), node.id) != null) {
- GameDataElement existingNode = getGameDataElement(node.getClass(), node.id);
- for (GameDataElement backlink : existingNode.getBacklinks()) {
- backlink.elementChanged(existingNode, node);
- }
- existingNode.getBacklinks().clear();
- node.writable = true;
- alteredContent.gameData.addElement(node);
- } else {
- createdContent.gameData.addElement(node);
- }
- }
- for (JSONElement node : nodes) {
- node.link();
- node.state = GameDataElement.State.created;
- fireElementAdded(node, getNodeIndex(node));
- }
- }
-
- /**
- *
- * @param node. Before calling this method, make sure that no other map with the same id exist in either created or altered.
- */
- public void createElement(TMXMap node) {
- node.writable = true;
- if (getMap(node.id) != null) {
- GameDataElement existingNode = getMap(node.id);
- for (GameDataElement backlink : existingNode.getBacklinks()) {
- backlink.elementChanged(existingNode, node);
- }
- existingNode.getBacklinks().clear();
- node.writable = true;
- node.tmxFile = new File(alteredContent.baseFolder, node.tmxFile.getName());
- node.parent = alteredContent.gameMaps;
- alteredContent.gameMaps.addMap(node);
- node.link();
- node.state = GameDataElement.State.created;
- } else {
- node.tmxFile = new File(createdContent.baseFolder, node.tmxFile.getName());
- node.parent = createdContent.gameMaps;
- createdContent.gameMaps.addMap(node);
- node.link();
- node.state = GameDataElement.State.created;
- }
- fireElementAdded(node, getNodeIndex(node));
- }
-
-
- public void moveToCreated(JSONElement target) {
- target.childrenRemoved(new ArrayList());
- ((GameDataCategory>)target.getParent()).remove(target);
- target.state = GameDataElement.State.created;
- createdContent.gameData.addElement(target);
- }
-
- public void moveToAltered(JSONElement target) {
- target.childrenRemoved(new ArrayList());
- ((GameDataCategory>)target.getParent()).remove(target);
- target.state = GameDataElement.State.created;
- ((JSONElement) target).jsonFile = new File(baseContent.gameData.getGameDataElement(((JSONElement)target).getClass(), target.id).jsonFile.getAbsolutePath());
- alteredContent.gameData.addElement((JSONElement) target);
- }
-
- public void createWorldmapSegment(WorldmapSegment node) {
- node.writable = true;
- if (getWorldmapSegment(node.id) != null) {
- WorldmapSegment existingNode = getWorldmapSegment(node.id);
- for (GameDataElement backlink : existingNode.getBacklinks()) {
- backlink.elementChanged(existingNode, node);
- }
- existingNode.getBacklinks().clear();
- node.writable = true;
- node.state = GameDataElement.State.created;
- alteredContent.worldmap.addSegment(node);
- node.link();
- } else {
- createdContent.worldmap.addSegment(node);
- node.state = GameDataElement.State.created;
- node.link();
- }
- fireElementAdded(node, getNodeIndex(node));
- }
-
-
-
- public void createWriterSketch(WriterModeData node) {
- node.writable = true;
- createdContent.writerModeDataSet.add(node);
- node.link();
- fireElementAdded(node, getNodeIndex(node));
- }
-
- public void bookmark(GameDataElement gde) {
- bookmarks.addBookmark(gde);
- }
-
-
- @Override
- public GameDataSet getDataSet() {
- return null;
- }
-
- @Override
- public Type getDataType() {
- return null;
- }
-
-
- public String getSpritesheetsProperty(String string) {
- return knownSpritesheetsProperties.getProperty(string);
- }
-
- public void setSpritesheetsProperty(String key, String value) {
- knownSpritesheetsProperties.setProperty(key, value);
- }
-
-
- @Override
- public boolean isEmpty() {
- return v.isEmpty();
- }
-
-
- public void addSave(File selectedFile) {
- saves.addSave(selectedFile);
- }
-
-
- public List getSpawnGroup(String spawngroup_id) {
- List result = new ArrayList();
- int i = getNPCCount();
- boolean alreadyAdded = false;
- int index = -1;
- while (--i >= 0) {
- NPC npc = getNPC(i);
- if (spawngroup_id.equalsIgnoreCase(npc.spawngroup_id)) {
- for (NPC present : result) {
- if (present.id.equals(npc.id)) {
- alreadyAdded = true;
- index = result.indexOf(present);
- break;
- }
- }
- if (alreadyAdded) {
- result.set(index, npc);
- } else {
- result.add(npc);
- }
- }
- alreadyAdded = false;
- }
- if (result.isEmpty()) {
- //Fallback case. A single NPC does not declare a spawn group, but is referred by its ID in maps' spawn areas.
- NPC npc = getNPCIgnoreCase(spawngroup_id);
- if (npc != null) result.add(npc);
- }
- return result;
- }
-
- transient Map, List> projectElementListeners = new HashMap, List>();
-
- public void addElementListener(Class extends GameDataElement> interestingType, ProjectElementListener listener) {
- if (projectElementListeners.get(interestingType) == null) {
- projectElementListeners.put(interestingType, new ArrayList());
- }
- projectElementListeners.get(interestingType).add(listener);
- }
-
- public void removeElementListener(Class extends GameDataElement> interestingType, ProjectElementListener listener) {
- if (projectElementListeners.get(interestingType) != null) projectElementListeners.get(interestingType).remove(listener);
- }
-
- public void fireElementAdded(GameDataElement element, int index) {
- if (projectElementListeners.get(element.getClass()) != null) {
- for (ProjectElementListener l : projectElementListeners.get(element.getClass())) {
- l.elementAdded(element, index);
- }
- }
- }
-
- public void fireElementRemoved(GameDataElement element, int index) {
- if (projectElementListeners.get(element.getClass()) != null) {
- for (ProjectElementListener l : projectElementListeners.get(element.getClass())) {
- l.elementRemoved(element, index);
- }
- }
- }
-
- public void exportProjectAsZipPackage(final File target) {
- WorkerDialog.showTaskMessage("Exporting project "+name+"...", ATContentStudio.frame, true, new Runnable() {
- @Override
- public void run() {
- Notification.addInfo("Exporting project \""+name+"\" as "+target.getAbsolutePath());
-
- File tmpDir;
- try {
- tmpDir = exportProjectToTmpDir();
- FileUtils.writeToZip(tmpDir, target);
- FileUtils.deleteDir(tmpDir);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- Notification.addSuccess("Project \""+name+"\" exported as "+target.getAbsolutePath());
- }
-
-
- });
- }
-
- public void exportProjectOverGameSource(final File target) {
- WorkerDialog.showTaskMessage("Exporting project "+name+"...", ATContentStudio.frame, true, new Runnable() {
- @Override
- public void run() {
- Notification.addInfo("Exporting project \""+name+"\" into "+target.getAbsolutePath());
-
- File tmpDir;
- try {
- tmpDir = exportProjectToTmpDir();
- FileUtils.copyOver(tmpDir, target);
- FileUtils.deleteDir(tmpDir);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- Notification.addSuccess("Project \""+name+"\" exported into "+target.getAbsolutePath());
- }
-
-
- });
- }
-
- public File exportProjectToTmpDir() throws IOException {
- File tmpDir = new File(baseFolder, "tmp");
- FileUtils.deleteDir(tmpDir);
- tmpDir.mkdir();
- File tmpJsonDataDir = new File(tmpDir, GameDataSet.DEFAULT_REL_PATH_IN_SOURCE);
- tmpJsonDataDir.mkdirs();
-
-// for (File createdJsonFile : createdContent.gameData.baseFolder.listFiles()) {
-// FileUtils.copyFile(createdJsonFile, new File(tmpJsonDataDir, createdJsonFile.getName()));
-// }
- Map, List> writtenFilesPerDataType = new LinkedHashMap, List>();
- List writtenFiles;
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.actorConditions, alteredContent.gameData.actorConditions, baseContent.gameData.actorConditions, ActorCondition.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(ActorCondition.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.dialogues, alteredContent.gameData.dialogues, baseContent.gameData.dialogues, Dialogue.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(Dialogue.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.droplists, alteredContent.gameData.droplists, baseContent.gameData.droplists, Droplist.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(Droplist.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.itemCategories, alteredContent.gameData.itemCategories, baseContent.gameData.itemCategories, ItemCategory.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(ItemCategory.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.items, alteredContent.gameData.items, baseContent.gameData.items, Item.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(Item.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.npcs, alteredContent.gameData.npcs, baseContent.gameData.npcs, NPC.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(NPC.class, writtenFiles);
- writtenFiles = writeDataDeltaForDataType(createdContent.gameData.quests, alteredContent.gameData.quests, baseContent.gameData.quests, Quest.class, tmpJsonDataDir);
- writtenFilesPerDataType.put(Quest.class, writtenFiles);
-
- File tmpMapDir = new File(tmpDir, TMXMapSet.DEFAULT_REL_PATH_IN_SOURCE);
- tmpMapDir.mkdirs();
- writtenFiles = new LinkedList();
- for (File createdMapFile : createdContent.gameMaps.mapFolder.listFiles()) {
- if (createdMapFile.getName().equalsIgnoreCase("worldmap.xml")) continue;
- copyTmxConverted(createdMapFile.toPath(), Paths.get(tmpMapDir.getAbsolutePath(), createdMapFile.getName()));
- writtenFiles.add(createdMapFile.getName());
- }
- for (File alteredMapFile : alteredContent.gameMaps.mapFolder.listFiles()) {
- if (alteredMapFile.getName().equalsIgnoreCase("worldmap.xml")) continue;
- copyTmxConverted(alteredMapFile.toPath(), Paths.get(tmpMapDir.getAbsolutePath(), alteredMapFile.getName()));
- writtenFiles.add(alteredMapFile.getName());
- }
- writtenFilesPerDataType.put(TMXMap.class, writtenFiles);
-
- if (sourceSetToUse == ResourceSet.gameData) {
- writeResourceListXml(writtenFilesPerDataType, GameSource.DEFAULT_REL_PATH_FOR_GAME_RESOURCE, baseContent.baseFolder, tmpDir);
- } else if (sourceSetToUse == ResourceSet.debugData) {
- writeResourceListXml(writtenFilesPerDataType, GameSource.DEFAULT_REL_PATH_FOR_DEBUG_RESOURCE, baseContent.baseFolder, tmpDir);
- }
-
-
- if (!createdContent.worldmap.isEmpty() || !alteredContent.worldmap.isEmpty()) {
- try {
- Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- doc.setXmlVersion("1.0");
- Element root = doc.createElement("worldmap");
- doc.appendChild(root);
-
- for (int i = 0; i < getWorldmapSegmentCount(); i++) {
- root.appendChild(getWorldmapSegment(i).toXmlElement(doc));
- }
-
- Worldmap.saveDocToFile(doc, new File(tmpMapDir, "worldmap.xml"));
- } catch (ParserConfigurationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- return tmpDir;
- }
-
- private void copyTmxConverted(Path from, Path to) throws IOException {
- String xml = new String(Files.readAllBytes(from), StandardCharsets.UTF_8);
- xml = xml.replace("../../altered/spritesheets/", drawablePath);
- xml = xml.replace("../../created/spritesheets/", drawablePath);
- xml = xml.replace("../spritesheets/", drawablePath);
- xml = xml.replace("../spritesheets/", drawablePath);
- Files.write(to, xml.getBytes(StandardCharsets.UTF_8));
- }
-
-
- @SuppressWarnings("rawtypes")
- public List writeDataDeltaForDataType(GameDataCategory extends JSONElement> created, GameDataCategory extends JSONElement> altered, GameDataCategory extends JSONElement> source, Class extends JSONElement> gdeClass, File targetFolder) {
- List filenamesToWrite = new LinkedList();
- Map> dataToWritePerFilename = new LinkedHashMap>();
- for (JSONElement gde : altered) {
- if (!filenamesToWrite.contains(gde.jsonFile.getName())) {
- filenamesToWrite.add(gde.jsonFile.getName());
- }
- }
- for (JSONElement gde : created) {
- if (!filenamesToWrite.contains(gde.jsonFile.getName())) {
- filenamesToWrite.add(gde.jsonFile.getName());
- }
- }
- for (String fName : filenamesToWrite) {
- for (JSONElement gde : source) {
- if (gde.jsonFile.getName().equals(fName)) {
- if (dataToWritePerFilename.get(fName) == null) {
- dataToWritePerFilename.put(fName, new ArrayList