Initial commit
85
src/com/gpl/rpg/atcontentstudio/ATContentStudio.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.gpl.rpg.atcontentstudio;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
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 = "v0.3.3";
|
||||
|
||||
public static boolean STARTED = false;
|
||||
public static StudioFrame frame = null;
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
ConfigCache.init();
|
||||
|
||||
try {
|
||||
String laf = ConfigCache.getFavoriteLaFClassName();
|
||||
if (laf == null) laf = UIManager.getSystemLookAndFeelClassName();
|
||||
UIManager.setLookAndFeel(laf);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
final WorkspaceSelector wsSelect = new WorkspaceSelector();
|
||||
wsSelect.pack();
|
||||
Dimension sdim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
Dimension wdim = wsSelect.getSize();
|
||||
wsSelect.setLocation((sdim.width - wdim.width)/2, (sdim.height - wdim.height)/2);
|
||||
wsSelect.setVisible(true);
|
||||
|
||||
wsSelect.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public synchronized void windowClosed(WindowEvent e) {
|
||||
if (wsSelect.selected != null && !STARTED) {
|
||||
ATContentStudio.STARTED = true;
|
||||
final File workspaceRoot = new File(wsSelect.selected);
|
||||
WorkerDialog.showTaskMessage("Loading your workspace...", null, new Runnable(){
|
||||
public void run() {
|
||||
Workspace.setActive(workspaceRoot);
|
||||
frame = new StudioFrame(APP_NAME+" "+APP_VERSION);
|
||||
frame.setVisible(true);
|
||||
frame.setDefaultCloseOperation(StudioFrame.EXIT_ON_CLOSE);
|
||||
};
|
||||
});
|
||||
for (File f : ConfigCache.getKnownWorkspaces()) {
|
||||
if (workspaceRoot.equals(f)) {
|
||||
if (!workspaceRoot.equals(ConfigCache.getLatestWorkspace())) {
|
||||
ConfigCache.setLatestWorkspace(f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
ConfigCache.addWorkspace(workspaceRoot);
|
||||
ConfigCache.setLatestWorkspace(workspaceRoot);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
103
src/com/gpl/rpg/atcontentstudio/ConfigCache.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package com.gpl.rpg.atcontentstudio;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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 List<File> knownWorkspaces = new ArrayList<File>();
|
||||
private File latestWorkspace = null;
|
||||
private String favoriteLaFClassName = null;
|
||||
private boolean[] notifConfig = new boolean[]{true, true, true, true};
|
||||
|
||||
|
||||
public static List<File> 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 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();
|
||||
}
|
||||
|
||||
}
|
||||
91
src/com/gpl/rpg/atcontentstudio/Notification.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package com.gpl.rpg.atcontentstudio;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Notification {
|
||||
|
||||
public static List<Notification> notifs = new ArrayList<Notification>();
|
||||
private static List<NotificationListener> listeners = new ArrayList<NotificationListener>();
|
||||
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 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.gpl.rpg.atcontentstudio;
|
||||
|
||||
public interface NotificationListener {
|
||||
|
||||
public void onNewNotification(Notification n);
|
||||
public void onListCleared(int i);
|
||||
|
||||
}
|
||||
BIN
src/com/gpl/rpg/atcontentstudio/img/ATCS.ico
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/Thumbs.db
Normal file
BIN
src/com/gpl/rpg/atcontentstudio/img/actor_condition.png
Normal file
|
After Width: | Height: | Size: 514 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/andorstrainer.png
Normal file
|
After Width: | Height: | Size: 5.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/arrow_down.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/arrow_left.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/arrow_right.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/arrow_up.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/atcs_border_banner.png
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/atcs_logo_banner.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/char_hero.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/container.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_container.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_key.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_object_group.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_replace.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_rest.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_script.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_sign.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_spawnarea.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_tile_layer.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/create_tiled.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/dialogue.png
Normal file
|
After Width: | Height: | Size: 975 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_body.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_feet.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_hand.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_head.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_neck.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_ring.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_shield.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_square.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/equip_weapon.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/error.png
Normal file
|
After Width: | Height: | Size: 566 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/file_create.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_at_closed.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_at_open.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_json_closed.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_json_open.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_map_closed.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_map_open.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_sav_closed.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_sav_open.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_sprite_closed.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_sprite_open.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_std_closed.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_std_open.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_tmx_closed.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/folder_tmx_open.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/info.png
Normal file
|
After Width: | Height: | Size: 278 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/item.png
Normal file
|
After Width: | Height: | Size: 806 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/key.png
Normal file
|
After Width: | Height: | Size: 1021 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/mapchange.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/npc.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/npc_close.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/nsisBorderBanner.bmp
Normal file
|
After Width: | Height: | Size: 151 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/nsisHeader.bmp
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/nullify.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/object_layer.png
Normal file
|
After Width: | Height: | Size: 406 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/replace.png
Normal file
|
After Width: | Height: | Size: 908 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/rest.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/script.png
Normal file
|
After Width: | Height: | Size: 941 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/sign.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/success.png
Normal file
|
After Width: | Height: | Size: 224 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/tile_layer.png
Normal file
|
After Width: | Height: | Size: 333 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/tiled-icon.png
Normal file
|
After Width: | Height: | Size: 423 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/ui_icon_coins.png
Normal file
|
After Width: | Height: | Size: 334 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/ui_icon_combat.png
Normal file
|
After Width: | Height: | Size: 653 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/ui_icon_equipment.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/com/gpl/rpg/atcontentstudio/img/ui_icon_map.png
Normal file
|
After Width: | Height: | Size: 365 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/ui_icon_quest.png
Normal file
|
After Width: | Height: | Size: 310 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/warn.png
Normal file
|
After Width: | Height: | Size: 481 B |
BIN
src/com/gpl/rpg/atcontentstudio/img/zoom.png
Normal file
|
After Width: | Height: | Size: 663 B |
53
src/com/gpl/rpg/atcontentstudio/io/JsonPrettyWriter.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.gpl.rpg.atcontentstudio.io;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
76
src/com/gpl/rpg/atcontentstudio/io/SettingsSave.java
Normal file
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
119
src/com/gpl/rpg/atcontentstudio/model/ClosedProject.java
Normal file
@@ -0,0 +1,119 @@
|
||||
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;
|
||||
|
||||
public class ClosedProject implements ProjectTreeNode {
|
||||
|
||||
String name;
|
||||
Workspace parent;
|
||||
|
||||
public ClosedProject(Workspace w, String name) {
|
||||
this.parent = w;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@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<ProjectTreeNode> children() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenAdded(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
}
|
||||
|
||||
@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 Type getDataType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
185
src/com/gpl/rpg/atcontentstudio/model/GameDataElement.java
Normal file
@@ -0,0 +1,185 @@
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
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;
|
||||
|
||||
//List of objects whose transition to "linked" state made them point to this instance.
|
||||
private Map<GameDataElement, Integer> backlinks = new HashMap<GameDataElement, Integer>();
|
||||
|
||||
public String id = null;
|
||||
|
||||
@Override
|
||||
public Enumeration<ProjectTreeNode> 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<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
}
|
||||
@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.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<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>();
|
||||
|
||||
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<GameDataElement> 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 abstract String getProjectFilename();
|
||||
|
||||
public abstract void save();
|
||||
|
||||
public abstract List<SaveEvent> attemptSave();
|
||||
|
||||
}
|
||||
200
src/com/gpl/rpg/atcontentstudio/model/GameSource.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
||||
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.sprites.SpriteSheetSet;
|
||||
import com.gpl.rpg.atcontentstudio.model.sprites.Spritesheet;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
public class GameSource implements ProjectTreeNode, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1512979360971918158L;
|
||||
|
||||
public transient GameDataSet gameData;
|
||||
public transient TMXMapSet gameMaps;
|
||||
public transient SpriteSheetSet gameSprites;
|
||||
public transient Worldmap worldmap;
|
||||
private transient SavedSlotCollection v;
|
||||
|
||||
public static enum Type {
|
||||
source,
|
||||
referenced,
|
||||
altered,
|
||||
created
|
||||
}
|
||||
|
||||
public File baseFolder;
|
||||
public Type type;
|
||||
|
||||
public transient Project parent = 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 void initData() {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<ProjectTreeNode> 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<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
|
||||
childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
} else {
|
||||
path.add(0, this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (ProjectTreeNode node : v.getNonEmptyIterable()) {
|
||||
node.notifyCreated();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
switch(type) {
|
||||
case altered: return "Altered data";
|
||||
case created: return "Created data";
|
||||
case referenced: return "Referenced data";
|
||||
case source: return "AT Source"; //The fact that it is from "source" is already mentionned by its parent.
|
||||
default: return "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);
|
||||
}
|
||||
}
|
||||
19
src/com/gpl/rpg/atcontentstudio/model/Preferences.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Preferences implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2455802658424031276L;
|
||||
|
||||
public Dimension windowSize = null;
|
||||
public Map<String, Integer> splittersPositions = new HashMap<String, Integer>();
|
||||
|
||||
public Preferences() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
964
src/com/gpl/rpg/atcontentstudio/model/Project.java
Normal file
@@ -0,0 +1,964 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
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.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.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.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;
|
||||
|
||||
//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 SavedGamesSet saves; //For simulations.
|
||||
|
||||
public transient SavedSlotCollection v;
|
||||
|
||||
public transient Workspace parent;
|
||||
|
||||
public Properties knownSpritesheetsProperties = null;
|
||||
|
||||
public Project(Workspace w, String name, File source) {
|
||||
this.parent = w;
|
||||
this.name = name;
|
||||
|
||||
//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);
|
||||
|
||||
saves = new SavedGamesSet(this);
|
||||
|
||||
v.add(createdContent);
|
||||
v.add(alteredContent);
|
||||
// v.add(referencedContent);
|
||||
v.add(baseContent);
|
||||
v.add(saves);
|
||||
|
||||
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<ProjectTreeNode> children() {
|
||||
return v.getNonEmptyElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenAdded(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
path.add(0,this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (ProjectTreeNode node : v.getNonEmptyIterable()) {
|
||||
node.notifyCreated();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
this.open = false;
|
||||
childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (knownSpritesheetsProperties == null) {
|
||||
try {
|
||||
knownSpritesheetsProperties = new Properties();
|
||||
knownSpritesheetsProperties.load(Project.class.getResourceAsStream("/spritesheets.properties"));
|
||||
} catch (IOException e) {
|
||||
Notification.addWarn("Unable to load default spritesheets properties.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
saves.refreshTransients();
|
||||
|
||||
v = new SavedSlotCollection();
|
||||
v.add(createdContent);
|
||||
v.add(alteredContent);
|
||||
// v.add(referencedContent);
|
||||
v.add(baseContent);
|
||||
v.add(saves);
|
||||
|
||||
|
||||
linkAll();
|
||||
|
||||
projectElementListeners = new HashMap<Class<? extends GameDataElement>, List<ProjectElementListener>>();
|
||||
}
|
||||
|
||||
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).parse();
|
||||
}
|
||||
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).parse();
|
||||
}
|
||||
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).parse();
|
||||
}
|
||||
for (ProjectTreeNode node : baseContent.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 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 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 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 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
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 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;
|
||||
node.state = GameDataElement.State.created;
|
||||
alteredContent.gameData.addElement(node);
|
||||
node.link();
|
||||
} else {
|
||||
createdContent.gameData.addElement(node);
|
||||
node.state = GameDataElement.State.created;
|
||||
node.link();
|
||||
}
|
||||
fireElementAdded(node, getNodeIndex(node));
|
||||
}
|
||||
|
||||
|
||||
public void moveToCreated(JSONElement target) {
|
||||
target.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
((GameDataCategory<?>)target.getParent()).remove(target);
|
||||
target.state = GameDataElement.State.created;
|
||||
createdContent.gameData.addElement(target);
|
||||
}
|
||||
|
||||
public void moveToAltered(JSONElement target) {
|
||||
target.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
((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);
|
||||
}
|
||||
|
||||
|
||||
@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<NPC> getSpawnGroup(String spawngroup_id) {
|
||||
List<NPC> result = new ArrayList<NPC>();
|
||||
int i = getNPCCount();
|
||||
boolean alreadyAdded = false;
|
||||
int index = -1;
|
||||
while (--i >= 0) {
|
||||
NPC npc = getNPC(i);
|
||||
if (spawngroup_id.equals(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;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
transient Map<Class<? extends GameDataElement>, List<ProjectElementListener>> projectElementListeners = new HashMap<Class<? extends GameDataElement>, List<ProjectElementListener>>();
|
||||
|
||||
public void addElementListener(Class<? extends GameDataElement> interestingType, ProjectElementListener listener) {
|
||||
if (projectElementListeners.get(interestingType) == null) {
|
||||
projectElementListeners.put(interestingType, new ArrayList<ProjectElementListener>());
|
||||
}
|
||||
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 generateExportPackage(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 = 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()));
|
||||
}
|
||||
writeAltered(alteredContent.gameData.actorConditions, baseContent.gameData.actorConditions, ActorCondition.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.dialogues, baseContent.gameData.dialogues, Dialogue.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.droplists, baseContent.gameData.droplists, Droplist.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.itemCategories, baseContent.gameData.itemCategories, ItemCategory.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.items, baseContent.gameData.items, Item.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.npcs, baseContent.gameData.npcs, NPC.class, tmpJsonDataDir);
|
||||
writeAltered(alteredContent.gameData.quests, baseContent.gameData.quests, Quest.class, tmpJsonDataDir);
|
||||
|
||||
File tmpMapDir = new File(tmpDir, TMXMapSet.DEFAULT_REL_PATH_IN_SOURCE);
|
||||
tmpMapDir.mkdirs();
|
||||
for (File createdMapFile : createdContent.gameMaps.mapFolder.listFiles()) {
|
||||
FileUtils.copyFile(createdMapFile, new File(tmpMapDir, createdMapFile.getName()));
|
||||
}
|
||||
for (File alteredMapFile : alteredContent.gameMaps.mapFolder.listFiles()) {
|
||||
FileUtils.copyFile(alteredMapFile, new File(tmpMapDir, alteredMapFile.getName()));
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
FileUtils.writeToZip(tmpDir, target);
|
||||
FileUtils.deleteDir(tmpDir);
|
||||
Notification.addSuccess("Project \""+name+"\" exported as "+target.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void writeAltered(GameDataCategory<? extends JSONElement> altered, GameDataCategory<? extends JSONElement> source, Class<? extends JSONElement> gdeClass, File targetFolder) {
|
||||
Set<String> alteredFileNames = new HashSet<String>();
|
||||
Map<String, List<Map>> toWrite = new HashMap<String, List<Map>>();
|
||||
for (JSONElement gde : altered) {
|
||||
alteredFileNames.add(gde.jsonFile.getName());
|
||||
}
|
||||
for (String fName : alteredFileNames) {
|
||||
for (JSONElement gde : source) {
|
||||
if (gde.jsonFile.getName().equals(fName)) {
|
||||
if (toWrite.get(fName) == null) {
|
||||
toWrite.put(fName, new ArrayList<Map>());
|
||||
}
|
||||
toWrite.get(fName).add(getGameDataElement(gdeClass, gde.id).toJson());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String fName : toWrite.keySet()) {
|
||||
File jsonFile = new File(targetFolder, fName);
|
||||
StringWriter writer = new JsonPrettyWriter();
|
||||
try {
|
||||
JSONArray.writeJSONString(toWrite.get(fName), writer);
|
||||
} catch (IOException e) {
|
||||
//Impossible with a StringWriter
|
||||
}
|
||||
String textToWrite = writer.toString();
|
||||
try {
|
||||
FileWriter w = new FileWriter(jsonFile);
|
||||
w.write(textToWrite);
|
||||
w.close();
|
||||
// Notification.addSuccess("Json file "+jsonFile.getAbsolutePath()+" saved.");
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while writing json file "+jsonFile.getAbsolutePath()+" : "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
public interface ProjectElementListener {
|
||||
|
||||
public void elementAdded(GameDataElement added, int index);
|
||||
|
||||
public void elementRemoved(GameDataElement removed, int index);
|
||||
|
||||
public Class<? extends GameDataElement> getDataType();
|
||||
|
||||
}
|
||||
57
src/com/gpl/rpg/atcontentstudio/model/ProjectTreeNode.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
||||
|
||||
public interface ProjectTreeNode extends TreeNode {
|
||||
|
||||
public void childrenAdded(List<ProjectTreeNode> path);
|
||||
public void childrenChanged(List<ProjectTreeNode> path);
|
||||
public void childrenRemoved(List<ProjectTreeNode> path);
|
||||
public void notifyCreated();
|
||||
|
||||
public String getDesc();
|
||||
|
||||
/**
|
||||
* Unnecessary for anything not below a Project. Can return null.
|
||||
* @return the parent Project or null.
|
||||
*/
|
||||
public Project getProject();
|
||||
|
||||
|
||||
/**
|
||||
* Unnecessary for anything not below a GameDataSet. Can return null.
|
||||
* @return the parent GameDataSet or null.
|
||||
*/
|
||||
public GameDataSet getDataSet();
|
||||
|
||||
public Image getIcon();
|
||||
/**
|
||||
*
|
||||
* @return The icon depicting this node when it is an open folder. Can be null for leaves.
|
||||
*/
|
||||
public Image getOpenIcon();
|
||||
/**
|
||||
*
|
||||
* @return The icon depicting this node when it is a closed folder. Can be null for leaves.
|
||||
*/
|
||||
public Image getClosedIcon();
|
||||
/**
|
||||
*
|
||||
* @return The icon depicting this node when it is a leaf. Should return the closed one for empty folders.
|
||||
*/
|
||||
public Image getLeafIcon();
|
||||
|
||||
/**
|
||||
* Unnecessary for anything not below a GameSource. Can return null.
|
||||
* @return the parent GameSource or null.
|
||||
*/
|
||||
public GameSource.Type getDataType();
|
||||
|
||||
public boolean isEmpty();
|
||||
|
||||
}
|
||||
35
src/com/gpl/rpg/atcontentstudio/model/SaveEvent.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
public class SaveEvent {
|
||||
|
||||
public enum Type {
|
||||
moveToAltered,
|
||||
moveToCreated,
|
||||
alsoSave
|
||||
}
|
||||
|
||||
public Type type;
|
||||
public GameDataElement target;
|
||||
|
||||
public boolean error = false;
|
||||
public String errorText;
|
||||
|
||||
public SaveEvent(SaveEvent.Type type, GameDataElement target) {
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public SaveEvent(SaveEvent.Type type, GameDataElement target, boolean error, String errorText) {
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
this.error = error;
|
||||
this.errorText = errorText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SaveEvent)) return false;
|
||||
else return (((SaveEvent)obj).type == this.type) && (((SaveEvent)obj).target == this.target);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
public class SavedSlotCollection {
|
||||
|
||||
Vector<ProjectTreeNode> contents = new Vector<ProjectTreeNode>();
|
||||
|
||||
public void add(ProjectTreeNode node) {
|
||||
contents.add(node);
|
||||
}
|
||||
|
||||
public int getNonEmptySize() {
|
||||
// return contents.size();
|
||||
int size = 0;
|
||||
for (ProjectTreeNode node : contents) {
|
||||
if (!node.isEmpty()) size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public Enumeration<ProjectTreeNode> getNonEmptyElements() {
|
||||
// return contents.elements();
|
||||
Vector<ProjectTreeNode> v = new Vector<ProjectTreeNode>();
|
||||
for (ProjectTreeNode node : contents) {
|
||||
if (!node.isEmpty()) v.add(node);
|
||||
}
|
||||
return v.elements();
|
||||
}
|
||||
|
||||
public ProjectTreeNode getNonEmptyElementAt(int index) {
|
||||
// return contents.get(index);
|
||||
int i = 0;
|
||||
while (i < contents.size()) {
|
||||
if (!contents.get(i).isEmpty()) index--;
|
||||
if (index == -1) return contents.get(i);
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public int getNonEmptyIndexOf(ProjectTreeNode node) {
|
||||
// return contents.indexOf(node);
|
||||
int index = contents.indexOf(node);
|
||||
int trueIndex = index;
|
||||
for (int i = 0; i < trueIndex; i++) {
|
||||
if (contents.get(i).isEmpty()) index--;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
public Vector<ProjectTreeNode> getNonEmptyIterable() {
|
||||
// return contents;
|
||||
Vector<ProjectTreeNode> v = new Vector<ProjectTreeNode>();
|
||||
for (ProjectTreeNode node : contents) {
|
||||
if (!node.isEmpty()) v.add(node);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
// return contents.isEmpty();
|
||||
for (ProjectTreeNode node : contents) {
|
||||
if (!node.isEmpty()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
300
src/com/gpl/rpg/atcontentstudio/model/Workspace.java
Normal file
@@ -0,0 +1,300 @@
|
||||
package com.gpl.rpg.atcontentstudio.model;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.ATContentStudio;
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.io.SettingsSave;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.GameDataSet;
|
||||
import com.gpl.rpg.atcontentstudio.ui.WorkerDialog;
|
||||
import com.gpl.rpg.atcontentstudio.ui.ProjectsTree.ProjectsTreeModel;
|
||||
|
||||
public class Workspace implements ProjectTreeNode, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7938633033601384956L;
|
||||
|
||||
public static final String WS_SETTINGS_FILE = ".workspace";
|
||||
|
||||
public static Workspace activeWorkspace;
|
||||
|
||||
public Preferences preferences = new Preferences();
|
||||
public File baseFolder;
|
||||
public File settingsFile;
|
||||
public transient List<ProjectTreeNode> projects = new ArrayList<ProjectTreeNode>();
|
||||
public Set<String> projectsName = new HashSet<String>();
|
||||
public Map<String, Boolean> projectsOpenByName = new HashMap<String, Boolean>();
|
||||
public Set<File> knownMapSourcesFolders = new HashSet<File>();
|
||||
|
||||
public transient ProjectsTreeModel projectsTreeModel = null;
|
||||
|
||||
public Workspace(File workspaceRoot) {
|
||||
baseFolder = workspaceRoot;
|
||||
if (!workspaceRoot.exists()) {
|
||||
try {
|
||||
workspaceRoot.mkdir();
|
||||
} catch (SecurityException e) {
|
||||
Notification.addError("Error creating workspace directory: "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
settingsFile = new File(workspaceRoot, WS_SETTINGS_FILE);
|
||||
if (!settingsFile.exists()) {
|
||||
try {
|
||||
settingsFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error creating workspace datafile: "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Notification.addSuccess("New workspace created: "+workspaceRoot.getAbsolutePath());
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
public static void setActive(File workspaceRoot) {
|
||||
Workspace w = null;
|
||||
File f = new File(workspaceRoot, WS_SETTINGS_FILE);
|
||||
if (!workspaceRoot.exists() || !f.exists()) {
|
||||
w = new Workspace(workspaceRoot);
|
||||
} else {
|
||||
w = (Workspace) SettingsSave.loadInstance(f, "Workspace");
|
||||
if (w == null) {
|
||||
w = new Workspace(workspaceRoot);
|
||||
} else {
|
||||
w.refreshTransients();
|
||||
}
|
||||
}
|
||||
activeWorkspace = w;
|
||||
}
|
||||
|
||||
public static void saveActive() {
|
||||
activeWorkspace.save();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
SettingsSave.saveInstance(this, settingsFile, "Workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<ProjectTreeNode> children() {
|
||||
return Collections.enumeration(projects);
|
||||
}
|
||||
@Override
|
||||
public boolean getAllowsChildren() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public TreeNode getChildAt(int arg0) {
|
||||
return projects.get(arg0);
|
||||
}
|
||||
@Override
|
||||
public int getChildCount() {
|
||||
return projects.size();
|
||||
}
|
||||
@Override
|
||||
public int getIndex(TreeNode arg0) {
|
||||
return projects.indexOf(arg0);
|
||||
}
|
||||
@Override
|
||||
public TreeNode getParent() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void childrenAdded(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.insertNode(new TreePath(path.toArray()));
|
||||
}
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.changeNode(new TreePath(path.toArray()));
|
||||
}
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
if (projectsTreeModel != null) projectsTreeModel.removeNode(new TreePath(path.toArray()));
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (ProjectTreeNode node : projects) {
|
||||
if (node != null) node.notifyCreated();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return "Workspace: "+baseFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
public static void createProject(final String projectName, final File gameSourceFolder) {
|
||||
WorkerDialog.showTaskMessage("Creating project "+projectName+"...", ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (activeWorkspace.projectsName.contains(projectName)) {
|
||||
Notification.addError("A project named "+projectName+" already exists in this workspace.");
|
||||
return;
|
||||
}
|
||||
Project p = new Project(activeWorkspace, projectName, gameSourceFolder);
|
||||
activeWorkspace.projects.add(p);
|
||||
activeWorkspace.projectsName.add(projectName);
|
||||
activeWorkspace.projectsOpenByName.put(projectName, p.open);
|
||||
activeWorkspace.knownMapSourcesFolders.add(gameSourceFolder);
|
||||
p.notifyCreated();
|
||||
Notification.addSuccess("Project "+projectName+" successfully created");
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void closeProject(Project p) {
|
||||
int index = activeWorkspace.projects.indexOf(p);
|
||||
if (index < 0) {
|
||||
Notification.addError("Cannot close unknown project "+p.name);
|
||||
return;
|
||||
}
|
||||
p.close();
|
||||
ClosedProject cp = new ClosedProject(activeWorkspace, p.name);
|
||||
activeWorkspace.projects.set(index, cp);
|
||||
activeWorkspace.projectsOpenByName.put(p.name, false);
|
||||
cp.notifyCreated();
|
||||
saveActive();
|
||||
}
|
||||
|
||||
public static void openProject(final ClosedProject cp) {
|
||||
WorkerDialog.showTaskMessage("Opening project "+cp.name+"...", ATContentStudio.frame, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = activeWorkspace.projects.indexOf(cp);
|
||||
if (index < 0) {
|
||||
Notification.addError("Cannot open unknown project "+cp.name);
|
||||
return;
|
||||
}
|
||||
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
Project p = Project.fromFolder(activeWorkspace, new File(activeWorkspace.baseFolder, cp.name));
|
||||
p.open();
|
||||
activeWorkspace.projects.set(index, p);
|
||||
activeWorkspace.projectsOpenByName.put(p.name, true);
|
||||
p.notifyCreated();
|
||||
saveActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void refreshTransients() {
|
||||
this.projects = new ArrayList<ProjectTreeNode>();
|
||||
Set<String> projectsFailed = new HashSet<String>();
|
||||
for (String projectName : projectsName) {
|
||||
if (projectsOpenByName.get(projectName)) {
|
||||
File projRoot = new File(this.baseFolder, projectName);
|
||||
if (projRoot.exists()) {
|
||||
Project p = Project.fromFolder(this, projRoot);
|
||||
if (p != null) {
|
||||
projects.add(p);
|
||||
} else {
|
||||
Notification.addError("Failed to open project "+projectName+". Removing it from workspace (not from filesystem though).");
|
||||
projectsFailed.add(projectName);
|
||||
}
|
||||
} else {
|
||||
Notification.addError("Unable to find project "+projectName+"'s root folder. Removing it from workspace");
|
||||
projectsFailed.add(projectName);
|
||||
}
|
||||
} else {
|
||||
projects.add(new ClosedProject(this, projectName));
|
||||
}
|
||||
}
|
||||
for (String projectName : projectsFailed) {
|
||||
projectsName.remove(projectName);
|
||||
projectsOpenByName.remove(projectName);
|
||||
}
|
||||
notifyCreated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {return null;}
|
||||
@Override
|
||||
public Image getClosedIcon() {return null;}
|
||||
@Override
|
||||
public Image getLeafIcon() {return null;}
|
||||
@Override
|
||||
public Image getOpenIcon() {return null;}
|
||||
|
||||
|
||||
public static void deleteProject(ClosedProject cp) {
|
||||
cp.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
activeWorkspace.projects.remove(cp);
|
||||
activeWorkspace.projectsOpenByName.remove(cp.name);
|
||||
activeWorkspace.projectsName.remove(cp.name);
|
||||
if (delete(new File(activeWorkspace.baseFolder, cp.name))) {
|
||||
Notification.addSuccess("Closed project "+cp.name+" successfully deleted.");
|
||||
} else {
|
||||
Notification.addError("Error while deleting closed project "+cp.name+". Files may remain in the workspace.");
|
||||
}
|
||||
cp = null;
|
||||
saveActive();
|
||||
}
|
||||
|
||||
public static void deleteProject(Project p) {
|
||||
p.childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
activeWorkspace.projects.remove(p);
|
||||
activeWorkspace.projectsOpenByName.remove(p.name);
|
||||
activeWorkspace.projectsName.remove(p.name);
|
||||
if (delete(p.baseFolder)) {
|
||||
Notification.addSuccess("Project "+p.name+" successfully deleted.");
|
||||
} else {
|
||||
Notification.addError("Error while deleting project "+p.name+". Files may remain in the workspace.");
|
||||
}
|
||||
p = null;
|
||||
saveActive();
|
||||
}
|
||||
|
||||
private static boolean delete(File f) {
|
||||
boolean b = true;
|
||||
if (f.isDirectory()) {
|
||||
for (File c : f.listFiles())
|
||||
b &= delete(c);
|
||||
}
|
||||
return b&= f.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataSet getDataSet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return projects.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
|
||||
|
||||
public class ActorCondition extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = -3969824899972048507L;
|
||||
|
||||
// Available from init state
|
||||
//public String id; inherited.
|
||||
public String icon_id;
|
||||
public String display_name;
|
||||
|
||||
// Available from parsed state
|
||||
public ACCategory category = null;
|
||||
public Integer positive = null;
|
||||
public Integer stacking = null;
|
||||
public RoundEffect round_effect = null;
|
||||
public RoundEffect full_round_effect = null;
|
||||
public AbilityEffect constant_ability_effect = null;
|
||||
|
||||
public enum ACCategory {
|
||||
spiritual,
|
||||
mental,
|
||||
physical,
|
||||
blood
|
||||
}
|
||||
|
||||
public static class RoundEffect implements Cloneable {
|
||||
// Available from parsed state
|
||||
public String visual_effect = null;
|
||||
public Integer hp_boost_min = null;
|
||||
public Integer hp_boost_max = null;
|
||||
public Integer ap_boost_min = null;
|
||||
public Integer ap_boost_max = null;
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AbilityEffect implements Cloneable {
|
||||
// Available from parsed state
|
||||
public Integer max_hp_boost = null;
|
||||
public Integer max_ap_boost = null;
|
||||
public Integer increase_move_cost = null;
|
||||
public Integer increase_use_cost = null;
|
||||
public Integer increase_reequip_cost = null;
|
||||
public Integer increase_attack_cost = null;
|
||||
public Integer increase_attack_chance = null;
|
||||
public Integer increase_damage_min = null;
|
||||
public Integer increase_damage_max = null;
|
||||
public Integer increase_critical_skill = null;
|
||||
public Integer increase_block_chance = null;
|
||||
public Integer increase_damage_resistance = null;
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+display_name+" ("+id+")";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<ActorCondition> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List actorConditions = (List) parser.parse(reader);
|
||||
for (Object obj : actorConditions) {
|
||||
Map aCondJson = (Map)obj;
|
||||
ActorCondition aCond = fromJson(aCondJson);
|
||||
aCond.jsonFile = jsonFile;
|
||||
aCond.parent = category;
|
||||
if (aCond.getDataType() == GameSource.Type.created || aCond.getDataType() == GameSource.Type.altered) {
|
||||
aCond.writable = true;
|
||||
}
|
||||
category.add(aCond);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ActorCondition fromJson(String jsonString) throws ParseException {
|
||||
Map aCondJson = (Map) new JSONParser().parse(jsonString);
|
||||
ActorCondition aCond = fromJson(aCondJson);
|
||||
aCond.parse(aCondJson);
|
||||
return aCond;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ActorCondition fromJson(Map aCondJson) {
|
||||
ActorCondition aCond = new ActorCondition();
|
||||
aCond.icon_id = (String) aCondJson.get("iconID");
|
||||
aCond.id = (String) aCondJson.get("id");
|
||||
aCond.display_name = (String) aCondJson.get("name");
|
||||
return aCond;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map aCondJson) {
|
||||
|
||||
if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category"));
|
||||
this.positive = JSONElement.getInteger((Number) aCondJson.get("positive"));
|
||||
Map abilityEffect = (Map) aCondJson.get("abilityEffect");
|
||||
if (abilityEffect != null) {
|
||||
this.constant_ability_effect = new AbilityEffect();
|
||||
this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance"));
|
||||
if (abilityEffect.get("increaseAttackDamage") != null) {
|
||||
this.constant_ability_effect.increase_damage_min = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("min")));
|
||||
this.constant_ability_effect.increase_damage_max = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("max")));
|
||||
}
|
||||
this.constant_ability_effect.max_hp_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxHP"));
|
||||
this.constant_ability_effect.max_ap_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxAP"));
|
||||
this.constant_ability_effect.increase_move_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseMoveCost"));
|
||||
this.constant_ability_effect.increase_use_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseUseItemCost"));
|
||||
this.constant_ability_effect.increase_reequip_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseReequipCost"));
|
||||
this.constant_ability_effect.increase_attack_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackCost"));
|
||||
this.constant_ability_effect.increase_critical_skill = JSONElement.getInteger((Number) abilityEffect.get("increaseCriticalSkill"));
|
||||
this.constant_ability_effect.increase_block_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseBlockChance"));
|
||||
this.constant_ability_effect.increase_damage_resistance = JSONElement.getInteger((Number) abilityEffect.get("increaseDamageResistance"));
|
||||
}
|
||||
this.stacking = JSONElement.getInteger((Number) aCondJson.get("isStacking"));
|
||||
Map roundEffect = (Map) aCondJson.get("roundEffect");
|
||||
if (roundEffect != null) {
|
||||
this.round_effect = new RoundEffect();
|
||||
if (roundEffect.get("increaseCurrentHP") != null) {
|
||||
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min")));
|
||||
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max")));
|
||||
}
|
||||
if (roundEffect.get("increaseCurrentAP") != null) {
|
||||
this.round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min")));
|
||||
this.round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("max")));
|
||||
}
|
||||
this.round_effect.visual_effect = (String) roundEffect.get("visualEffectID");
|
||||
}
|
||||
Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect");
|
||||
if (fullRoundEffect != null) {
|
||||
this.full_round_effect = new RoundEffect();
|
||||
if (fullRoundEffect.get("increaseCurrentHP") != null) {
|
||||
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min")));
|
||||
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max")));
|
||||
}
|
||||
if (fullRoundEffect.get("increaseCurrentAP") != null) {
|
||||
this.full_round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min")));
|
||||
this.full_round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("max")));
|
||||
}
|
||||
this.full_round_effect.visual_effect = (String) fullRoundEffect.get("visualEffectID");
|
||||
}
|
||||
this.state = State.parsed;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
if (this.icon_id != null) {
|
||||
String spritesheetId = this.icon_id.split(":")[0];
|
||||
getProject().getSpritesheet(spritesheetId).addBacklink(this);
|
||||
}
|
||||
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Actor Conditions";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getProject().getIcon(icon_id);
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return getProject().getImage(icon_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONElement clone() {
|
||||
ActorCondition clone = new ActorCondition();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.display_name = this.display_name;
|
||||
clone.icon_id = this.icon_id;
|
||||
clone.category = this.category;
|
||||
clone.positive = this.positive;
|
||||
clone.stacking = this.stacking;
|
||||
if (this.round_effect != null) {
|
||||
clone.round_effect = (RoundEffect) this.round_effect.clone();
|
||||
}
|
||||
if (this.constant_ability_effect != null) {
|
||||
clone.constant_ability_effect = (AbilityEffect) constant_ability_effect.clone();
|
||||
}
|
||||
if (this.full_round_effect != null) {
|
||||
clone.full_round_effect = (RoundEffect) this.full_round_effect.clone();
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
//Nothing to link to.
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map jsonAC = new HashMap();
|
||||
jsonAC.put("id", this.id);
|
||||
if (this.icon_id != null) jsonAC.put("iconID", this.icon_id);
|
||||
if (this.display_name != null) jsonAC.put("name", this.display_name);
|
||||
if (this.category != null) jsonAC.put("category", this.category.toString());
|
||||
if (this.positive != null && this.positive == 1) jsonAC.put("positive", this.positive);
|
||||
if (this.stacking != null && this.stacking == 1) jsonAC.put("stacking", this.stacking);
|
||||
if (this.round_effect != null) {
|
||||
Map jsonRound = new HashMap();
|
||||
if (this.round_effect.visual_effect != null) jsonRound.put("visualEffectID", this.round_effect.visual_effect);
|
||||
if (this.round_effect.hp_boost_min != null || this.round_effect.hp_boost_max != null) {
|
||||
Map jsonHP = new HashMap();
|
||||
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
|
||||
else jsonHP.put("min", 0);
|
||||
if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max);
|
||||
else jsonHP.put("max", 0);
|
||||
jsonRound.put("increaseCurrentHP", jsonHP);
|
||||
}
|
||||
if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) {
|
||||
Map jsonAP = new HashMap();
|
||||
if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min);
|
||||
else jsonAP.put("min", 0);
|
||||
if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max);
|
||||
else jsonAP.put("max", 0);
|
||||
jsonRound.put("increaseCurrentAP", jsonAP);
|
||||
}
|
||||
jsonAC.put("roundEffect", jsonRound);
|
||||
}
|
||||
if (this.full_round_effect != null) {
|
||||
Map jsonFullRound = new HashMap();
|
||||
if (this.full_round_effect.visual_effect != null) jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect);
|
||||
if (this.full_round_effect.hp_boost_min != null || this.full_round_effect.hp_boost_max != null) {
|
||||
Map jsonHP = new HashMap();
|
||||
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
|
||||
else jsonHP.put("min", 0);
|
||||
if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max);
|
||||
else jsonHP.put("max", 0);
|
||||
jsonFullRound.put("increaseCurrentHP", jsonHP);
|
||||
}
|
||||
if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) {
|
||||
Map jsonAP = new HashMap();
|
||||
if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min);
|
||||
else jsonAP.put("min", 0);
|
||||
if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max);
|
||||
else jsonAP.put("max", 0);
|
||||
jsonFullRound.put("increaseCurrentAP", jsonAP);
|
||||
}
|
||||
jsonAC.put("fullRoundEffect", jsonFullRound);
|
||||
}
|
||||
if (this.constant_ability_effect != null) {
|
||||
Map jsonAbility = new HashMap();
|
||||
if (this.constant_ability_effect.increase_attack_chance != null) jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance);
|
||||
if (this.constant_ability_effect.increase_damage_min != null || this.constant_ability_effect.increase_damage_max != null) {
|
||||
Map jsonAD = new HashMap();
|
||||
if (this.constant_ability_effect.increase_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
|
||||
else jsonAD.put("min", 0);
|
||||
if (this.constant_ability_effect.increase_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
|
||||
else jsonAD.put("max", 0);
|
||||
jsonAbility.put("increaseCurrentAP", jsonAD);
|
||||
}
|
||||
if (this.constant_ability_effect.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
|
||||
if (this.constant_ability_effect.max_ap_boost != null) jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
|
||||
if (this.constant_ability_effect.increase_move_cost != null) jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost);
|
||||
if (this.constant_ability_effect.increase_use_cost != null) jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_use_cost);
|
||||
if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_reequip_cost);
|
||||
if (this.constant_ability_effect.increase_attack_cost != null) jsonAbility.put("increaseReequipCost", this.constant_ability_effect.increase_attack_cost);
|
||||
if (this.constant_ability_effect.increase_critical_skill != null) jsonAbility.put("increaseCriticalSkill", this.constant_ability_effect.increase_critical_skill);
|
||||
if (this.constant_ability_effect.increase_block_chance != null) jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
|
||||
if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
|
||||
jsonAC.put("abilityEffect", jsonAbility);
|
||||
}
|
||||
return jsonAC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "actorconditions_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
}
|
||||
446
src/com/gpl/rpg/atcontentstudio/model/gamedata/Dialogue.java
Normal file
@@ -0,0 +1,446 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement.RequirementType;
|
||||
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
|
||||
public class Dialogue extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = -6872164604703134683L;
|
||||
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
public String message = null;
|
||||
|
||||
//Available from parsed state;
|
||||
public List<Reward> rewards = null;
|
||||
public List<Reply> replies = null;
|
||||
public String switch_to_npc_id = null;
|
||||
|
||||
//Available from linked state;
|
||||
public NPC switch_to_npc = null;
|
||||
|
||||
public static class Reward {
|
||||
|
||||
//Available from parsed state
|
||||
public RewardType type = null;
|
||||
public String reward_obj_id = null;
|
||||
public Integer reward_value = null;
|
||||
public String map_name = null;
|
||||
|
||||
//Available from linked state
|
||||
public GameDataElement reward_obj = null;
|
||||
public TMXMap map = null;
|
||||
|
||||
public enum RewardType {
|
||||
questProgress,
|
||||
dropList,
|
||||
skillIncrease,
|
||||
actorCondition,
|
||||
alignmentChange,
|
||||
giveItem,
|
||||
createTimer,
|
||||
spawnAll,
|
||||
removeSpawnArea,
|
||||
deactivateSpawnArea,
|
||||
activateMapChangeArea,
|
||||
deactivateMapChangeArea
|
||||
}
|
||||
}
|
||||
|
||||
public static class Reply {
|
||||
|
||||
public static final String GO_NEXT_TEXT = "N";
|
||||
public static final String SHOP_PHRASE_ID = "S";
|
||||
public static final String FIGHT_PHRASE_ID = "F";
|
||||
public static final String EXIT_PHRASE_ID = "X";
|
||||
public static final String REMOVE_PHRASE_ID = "R";
|
||||
|
||||
public static final List<String> KEY_PHRASE_ID = Arrays.asList(new String[]{SHOP_PHRASE_ID, FIGHT_PHRASE_ID, EXIT_PHRASE_ID, REMOVE_PHRASE_ID});
|
||||
|
||||
//Available from parsed state
|
||||
public String text = null;
|
||||
public String next_phrase_id = null;
|
||||
public List<Requirement> requirements = null;
|
||||
|
||||
//Available from linked state
|
||||
public Dialogue next_phrase = null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+id;
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Dialogues";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<Dialogue> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List dialogues = (List) parser.parse(reader);
|
||||
for (Object obj : dialogues) {
|
||||
Map dialogueJson = (Map)obj;
|
||||
Dialogue dialogue = fromJson(dialogueJson);
|
||||
dialogue.jsonFile = jsonFile;
|
||||
dialogue.parent = category;
|
||||
if (dialogue.getDataType() == GameSource.Type.created || dialogue.getDataType() == GameSource.Type.altered) {
|
||||
dialogue.writable = true;
|
||||
}
|
||||
category.add(dialogue);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Dialogue fromJson(String jsonString) throws ParseException {
|
||||
Map dialogueJson = (Map) new JSONParser().parse(jsonString);
|
||||
Dialogue dialogue = fromJson(dialogueJson);
|
||||
dialogue.parse(dialogueJson);
|
||||
return dialogue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Dialogue fromJson(Map dialogueJson) {
|
||||
Dialogue dialogue = new Dialogue();
|
||||
dialogue.id = (String) dialogueJson.get("id");
|
||||
dialogue.message = (String) dialogueJson.get("message");
|
||||
return dialogue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map dialogueJson) {
|
||||
this.switch_to_npc_id = (String) dialogueJson.get("switchToNPC");
|
||||
List repliesJson = (List) dialogueJson.get("replies");
|
||||
if (repliesJson != null && !repliesJson.isEmpty()) {
|
||||
this.replies = new ArrayList<Dialogue.Reply>();
|
||||
for (Object replyJsonObj : repliesJson) {
|
||||
Map replyJson = (Map)replyJsonObj;
|
||||
Reply reply = new Reply();
|
||||
reply.text = (String) replyJson.get("text");
|
||||
reply.next_phrase_id = (String) replyJson.get("nextPhraseID");
|
||||
List requirementsJson = (List) replyJson.get("requires");
|
||||
if (requirementsJson != null && !requirementsJson.isEmpty()) {
|
||||
reply.requirements = new ArrayList<Requirement>();
|
||||
for (Object requirementJsonObj : requirementsJson) {
|
||||
Map requirementJson = (Map) requirementJsonObj;
|
||||
Requirement requirement = new Requirement();
|
||||
requirement.jsonFile = this.jsonFile;
|
||||
requirement.parent = this;
|
||||
if (requirementJson.get("requireType") != null) requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType"));
|
||||
requirement.required_obj_id = (String) requirementJson.get("requireID");
|
||||
requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString()));
|
||||
if (requirementJson.get("negate") != null) requirement.negated = (Boolean) requirementJson.get("negate");
|
||||
requirement.state = State.parsed;
|
||||
reply.requirements.add(requirement);
|
||||
}
|
||||
}
|
||||
this.replies.add(reply);
|
||||
}
|
||||
}
|
||||
List rewardsJson = (List) dialogueJson.get("rewards");
|
||||
if (rewardsJson != null && !rewardsJson.isEmpty()) {
|
||||
this.rewards = new ArrayList<Dialogue.Reward>();
|
||||
for (Object rewardJsonObj : rewardsJson) {
|
||||
Map rewardJson = (Map)rewardJsonObj;
|
||||
Reward reward = new Reward();
|
||||
if (rewardJson.get("rewardType") != null) reward.type = Reward.RewardType.valueOf((String) rewardJson.get("rewardType"));
|
||||
if (rewardJson.get("rewardID") != null) reward.reward_obj_id = (String) rewardJson.get("rewardID");
|
||||
if (rewardJson.get("value") != null) reward.reward_value = JSONElement.getInteger((Number) rewardJson.get("value"));
|
||||
if (rewardJson.get("mapName") != null) reward.map_name = (String) rewardJson.get("mapName");
|
||||
this.rewards.add(reward);
|
||||
}
|
||||
}
|
||||
this.state = State.parsed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
Project proj = getProject();
|
||||
if (proj == null) {
|
||||
Notification.addError("Error linking dialogue "+id+". No parent project found.");
|
||||
return;
|
||||
}
|
||||
if (this.switch_to_npc_id != null) this.switch_to_npc = proj.getNPC(this.switch_to_npc_id);
|
||||
if (this.switch_to_npc != null) this.switch_to_npc.addBacklink(this);
|
||||
|
||||
if (replies != null) {
|
||||
for (Reply reply : replies) {
|
||||
if (reply.next_phrase_id != null) {
|
||||
if (!reply.next_phrase_id.equals(Reply.EXIT_PHRASE_ID)
|
||||
&& !reply.next_phrase_id.equals(Reply.FIGHT_PHRASE_ID)
|
||||
&& !reply.next_phrase_id.equals(Reply.SHOP_PHRASE_ID)
|
||||
&& !reply.next_phrase_id.equals(Reply.REMOVE_PHRASE_ID)) {
|
||||
reply.next_phrase = proj.getDialogue(reply.next_phrase_id);
|
||||
}
|
||||
}
|
||||
if (reply.next_phrase != null) reply.next_phrase.addBacklink(this);
|
||||
if (reply.requirements != null) {
|
||||
for (Requirement requirement : reply.requirements) {
|
||||
requirement.link();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rewards != null) {
|
||||
for (Reward reward : rewards) {
|
||||
if (reward.reward_obj_id != null) {
|
||||
switch (reward.type) {
|
||||
case activateMapChangeArea:
|
||||
case deactivateMapChangeArea:
|
||||
case spawnAll:
|
||||
case removeSpawnArea:
|
||||
case deactivateSpawnArea:
|
||||
reward.map = proj.getMap(reward.map_name);
|
||||
break;
|
||||
case actorCondition:
|
||||
reward.reward_obj = proj.getActorCondition(reward.reward_obj_id);
|
||||
break;
|
||||
case alignmentChange:
|
||||
//Nothing to do (yet ?).
|
||||
break;
|
||||
case createTimer:
|
||||
//Nothing to do.
|
||||
break;
|
||||
case dropList:
|
||||
reward.reward_obj = proj.getDroplist(reward.reward_obj_id);
|
||||
break;
|
||||
case giveItem:
|
||||
reward.reward_obj = proj.getItem(reward.reward_obj_id);
|
||||
break;
|
||||
case questProgress:
|
||||
reward.reward_obj = proj.getQuest(reward.reward_obj_id);
|
||||
break;
|
||||
case skillIncrease:
|
||||
//Nothing to do (yet ?).
|
||||
break;
|
||||
}
|
||||
if (reward.reward_obj != null) reward.reward_obj.addBacklink(this);
|
||||
if (reward.map != null) reward.map.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return DefaultIcons.getDialogueIcon();
|
||||
}
|
||||
|
||||
|
||||
public Image getImage() {
|
||||
return DefaultIcons.getDialogueImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
Dialogue clone = new Dialogue();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.message = this.message;
|
||||
clone.switch_to_npc_id = this.switch_to_npc_id;
|
||||
clone.switch_to_npc = this.switch_to_npc;
|
||||
if (clone.switch_to_npc != null) {
|
||||
clone.switch_to_npc.addBacklink(clone);
|
||||
}
|
||||
if (this.rewards != null) {
|
||||
clone.rewards = new ArrayList<Dialogue.Reward>();
|
||||
for (Reward r : this.rewards) {
|
||||
Reward rclone = new Reward();
|
||||
rclone.type = r.type;
|
||||
rclone.reward_obj_id = r.reward_obj_id;
|
||||
rclone.reward_value = r.reward_value;
|
||||
rclone.reward_obj = r.reward_obj;
|
||||
if (rclone.reward_obj != null) {
|
||||
rclone.reward_obj.addBacklink(clone);
|
||||
}
|
||||
clone.rewards.add(rclone);
|
||||
}
|
||||
}
|
||||
if (this.replies != null) {
|
||||
clone.replies = new ArrayList<Dialogue.Reply>();
|
||||
for (Reply r : this.replies) {
|
||||
Reply rclone = new Reply();
|
||||
rclone.text = r.text;
|
||||
rclone.next_phrase_id = r.next_phrase_id;
|
||||
rclone.next_phrase = r.next_phrase;
|
||||
if (rclone.next_phrase != null) {
|
||||
rclone.next_phrase.addBacklink(clone);
|
||||
}
|
||||
if (r.requirements != null) {
|
||||
rclone.requirements = new ArrayList<Requirement>();
|
||||
for (Requirement req : r.requirements) {
|
||||
//Special clone method, as Requirement is a special GDE, hidden from the project tree.
|
||||
rclone.requirements.add((Requirement) req.clone(clone));
|
||||
}
|
||||
}
|
||||
clone.replies.add(rclone);
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (switch_to_npc == oldOne) {
|
||||
switch_to_npc = (NPC) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
} else {
|
||||
if (replies != null) {
|
||||
for (Reply r : replies) {
|
||||
if (r.next_phrase == oldOne) {
|
||||
r.next_phrase = (Dialogue) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
if (r.requirements != null) {
|
||||
for (Requirement req : r.requirements) {
|
||||
if (req.required_obj == oldOne) {
|
||||
req.required_obj = newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rewards != null) {
|
||||
for (Reward r : rewards) {
|
||||
if (r.reward_obj == oldOne) {
|
||||
r.reward_obj = newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map dialogueJson = new HashMap();
|
||||
dialogueJson.put("id", this.id);
|
||||
if (this.message != null) dialogueJson.put("message", this.message);
|
||||
if (this.switch_to_npc != null) {
|
||||
dialogueJson.put("switchToNPC", this.switch_to_npc.id);
|
||||
} else if (this.switch_to_npc_id != null) {
|
||||
dialogueJson.put("switchToNPC", this.switch_to_npc_id);
|
||||
}
|
||||
if (this.replies != null) {
|
||||
List repliesJson = new ArrayList();
|
||||
dialogueJson.put("replies", repliesJson);
|
||||
for (Reply reply : this.replies){
|
||||
Map replyJson = new HashMap();
|
||||
repliesJson.add(replyJson);
|
||||
if (reply.text != null) replyJson.put("text", reply.text);
|
||||
if (reply.next_phrase != null) {
|
||||
replyJson.put("nextPhraseID", reply.next_phrase.id);
|
||||
} else if (reply.next_phrase_id != null) {
|
||||
replyJson.put("nextPhraseID", reply.next_phrase_id);
|
||||
}
|
||||
if (reply.requirements != null) {
|
||||
List requirementsJson = new ArrayList();
|
||||
replyJson.put("requires", requirementsJson);
|
||||
for (Requirement requirement : reply.requirements) {
|
||||
Map requirementJson = new HashMap();
|
||||
requirementsJson.add(requirementJson);
|
||||
if (requirement.type != null) requirementJson.put("requireType", requirement.type.toString());
|
||||
if (requirement.required_obj != null) {
|
||||
requirementJson.put("requireID", requirement.required_obj.id);
|
||||
} else if (requirement.required_obj_id != null) {
|
||||
requirementJson.put("requireID", requirement.required_obj_id);
|
||||
}
|
||||
if (requirement.required_value != null) {
|
||||
requirementJson.put("value", requirement.required_value);
|
||||
}
|
||||
if (requirement.negated != null) requirementJson.put("negate", requirement.negated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.rewards != null) {
|
||||
List rewardsJson = new ArrayList();
|
||||
dialogueJson.put("rewards", rewardsJson);
|
||||
for (Reward reward : this.rewards) {
|
||||
Map rewardJson = new HashMap();
|
||||
rewardsJson.add(rewardJson);
|
||||
if (reward.type != null) rewardJson.put("rewardType", reward.type.toString());
|
||||
if (reward.reward_obj != null) {
|
||||
rewardJson.put("rewardID", reward.reward_obj.id);
|
||||
} else if (reward.reward_obj_id != null) {
|
||||
rewardJson.put("rewardID", reward.reward_obj_id);
|
||||
}
|
||||
if (reward.reward_value != null) rewardJson.put("value", reward.reward_value);
|
||||
if (reward.map != null) {
|
||||
rewardJson.put("mapName", reward.map.id);
|
||||
} else if (reward.map_name != null) rewardJson.put("mapName", reward.map_name);
|
||||
}
|
||||
}
|
||||
return dialogueJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "conversationlist_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
}
|
||||
239
src/com/gpl/rpg/atcontentstudio/model/gamedata/Droplist.java
Normal file
@@ -0,0 +1,239 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
|
||||
public class Droplist extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = -2903944916807382571L;
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
|
||||
//Available from parsed state;
|
||||
public List<DroppedItem> dropped_items = null;
|
||||
|
||||
//Available from linked state;
|
||||
//None
|
||||
|
||||
public static class DroppedItem {
|
||||
//Available from parsed state;
|
||||
public String item_id = null;
|
||||
public Double chance = null;
|
||||
public Integer quantity_min = null;
|
||||
public Integer quantity_max = null;
|
||||
|
||||
//Available from linked state;
|
||||
public Item item = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+id;
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Droplists";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<Droplist> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List droplists = (List) parser.parse(reader);
|
||||
for (Object obj : droplists) {
|
||||
Map droplistJson = (Map)obj;
|
||||
Droplist droplist = fromJson(droplistJson);
|
||||
droplist.jsonFile = jsonFile;
|
||||
droplist.parent = category;
|
||||
if (droplist.getDataType() == GameSource.Type.created || droplist.getDataType() == GameSource.Type.altered) {
|
||||
droplist.writable = true;
|
||||
}
|
||||
category.add(droplist);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Droplist fromJson(String jsonString) throws ParseException {
|
||||
Map droplistJson = (Map) new JSONParser().parse(jsonString);
|
||||
Droplist droplist = fromJson(droplistJson);
|
||||
droplist.parse(droplistJson);
|
||||
return droplist;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Droplist fromJson(Map droplistJson) {
|
||||
Droplist droplist = new Droplist();
|
||||
droplist.id = (String) droplistJson.get("id");
|
||||
return droplist;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map droplistJson) {
|
||||
List droppedItemsJson = (List) droplistJson.get("items");
|
||||
if (droppedItemsJson != null && !droppedItemsJson.isEmpty()) {
|
||||
this.dropped_items = new ArrayList<DroppedItem>();
|
||||
for (Object droppedItemJsonObj : droppedItemsJson) {
|
||||
Map droppedItemJson = (Map)droppedItemJsonObj;
|
||||
DroppedItem droppedItem = new DroppedItem();
|
||||
droppedItem.item_id = (String) droppedItemJson.get("itemID");
|
||||
if (droppedItemJson.get("chance") != null) droppedItem.chance = JSONElement.parseChance(droppedItemJson.get("chance").toString());
|
||||
Map droppedItemQtyJson = (Map) droppedItemJson.get("quantity");
|
||||
if (droppedItemQtyJson != null) {
|
||||
droppedItem.quantity_min = JSONElement.getInteger((Number) droppedItemQtyJson.get("min"));
|
||||
droppedItem.quantity_max = JSONElement.getInteger((Number) droppedItemQtyJson.get("max"));
|
||||
}
|
||||
this.dropped_items.add(droppedItem);
|
||||
}
|
||||
}
|
||||
this.state = State.parsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
Project proj = getProject();
|
||||
if (proj == null) {
|
||||
Notification.addError("Error linking droplist "+id+". No parent project found.");
|
||||
return;
|
||||
}
|
||||
if (dropped_items != null) {
|
||||
for (DroppedItem droppedItem : dropped_items) {
|
||||
if (droppedItem.item_id != null) droppedItem.item = proj.getItem(droppedItem.item_id);
|
||||
if (droppedItem.item != null) droppedItem.item.addBacklink(this);
|
||||
}
|
||||
}
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Image getImage() {
|
||||
return DefaultIcons.getDroplistImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return DefaultIcons.getDroplistIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
Droplist clone = new Droplist();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
if (this.dropped_items != null) {
|
||||
clone.dropped_items = new ArrayList<Droplist.DroppedItem>();
|
||||
for (DroppedItem di : this.dropped_items) {
|
||||
DroppedItem diclone = new DroppedItem();
|
||||
diclone.chance = di.chance;
|
||||
diclone.item_id = di.item_id;
|
||||
diclone.quantity_min = di.quantity_min;
|
||||
diclone.quantity_max = di.quantity_max;
|
||||
diclone.item = di.item;
|
||||
if (diclone.item != null) {
|
||||
diclone.item.addBacklink(clone);
|
||||
}
|
||||
clone.dropped_items.add(diclone);
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (dropped_items != null) {
|
||||
for (DroppedItem di : dropped_items) {
|
||||
if (di.item == oldOne) {
|
||||
di.item = (Item) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map droplistJson = new HashMap();
|
||||
droplistJson.put("id", this.id);
|
||||
if (this.dropped_items != null) {
|
||||
List droppedItemsJson = new ArrayList();
|
||||
droplistJson.put("items", droppedItemsJson);
|
||||
for (DroppedItem droppedItem : this.dropped_items) {
|
||||
Map droppedItemJson = new HashMap();
|
||||
droppedItemsJson.add(droppedItemJson);
|
||||
if (droppedItem.item != null) {
|
||||
droppedItemJson.put("itemID", droppedItem.item.id);
|
||||
} else if (droppedItem.item_id != null) {
|
||||
droppedItemJson.put("itemID", droppedItem.item_id);
|
||||
}
|
||||
if (droppedItem.chance != null) droppedItemJson.put("chance", JSONElement.printJsonChance(droppedItem.chance));
|
||||
if (droppedItem.quantity_min != null || droppedItem.quantity_max != null) {
|
||||
Map quantityJson = new HashMap();
|
||||
droppedItemJson.put("quantity", quantityJson);
|
||||
if (droppedItem.quantity_min != null) quantityJson.put("min", droppedItem.quantity_min);
|
||||
else quantityJson.put("min", 0);
|
||||
if (droppedItem.quantity_max != null) quantityJson.put("max", droppedItem.quantity_max);
|
||||
else quantityJson.put("max", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return droplistJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "droplists_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
|
||||
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
public class GameDataCategory<E extends JSONElement> extends ArrayList<E> implements ProjectTreeNode, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5486008219704443733L;
|
||||
|
||||
public GameDataSet parent;
|
||||
public String name;
|
||||
|
||||
public GameDataCategory(GameDataSet parent, String name) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getChildAt(int childIndex) {
|
||||
return get(childIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount() {
|
||||
return size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex(TreeNode node) {
|
||||
return indexOf(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowsChildren() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<E> children() {
|
||||
return Collections.enumeration(this);
|
||||
}
|
||||
@Override
|
||||
public void childrenAdded(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
if (path.size() == 1 && this.getChildCount() == 1) {
|
||||
childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
} else {
|
||||
path.add(0, this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (E node : this) {
|
||||
node.notifyCreated();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return (o == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return parent.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getOpenIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getClosedIcon() {
|
||||
return DefaultIcons.getJsonClosedIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getLeafIcon() {
|
||||
return DefaultIcons.getJsonClosedIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getOpenIcon() {
|
||||
return DefaultIcons.getJsonOpenIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataSet getDataSet() {
|
||||
return parent.getDataSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
return parent.getDataType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void save(File jsonFile) {
|
||||
if (getDataType() != GameSource.Type.created && getDataType() != GameSource.Type.altered) {
|
||||
Notification.addError("Error while trying to write json file "+jsonFile.getAbsolutePath()+" : Game Source type "+getDataType().toString()+" should not be saved.");
|
||||
return;
|
||||
}
|
||||
List<Map> dataToSave = new ArrayList<Map>();
|
||||
for (E element : this) {
|
||||
if (element.jsonFile.equals(jsonFile)) {
|
||||
dataToSave.add(element.toJson());
|
||||
}
|
||||
}
|
||||
if (dataToSave.isEmpty()) {
|
||||
if (jsonFile.delete()) {
|
||||
Notification.addSuccess("File "+jsonFile.getAbsolutePath()+" deleted.");
|
||||
} else {
|
||||
Notification.addError("Error deleting file "+jsonFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
StringWriter writer = new JsonPrettyWriter();
|
||||
try {
|
||||
JSONArray.writeJSONString(dataToSave, writer);
|
||||
} catch (IOException e) {
|
||||
//Impossible with a StringWriter
|
||||
}
|
||||
String toWrite = writer.toString();
|
||||
try {
|
||||
FileWriter w = new FileWriter(jsonFile);
|
||||
w.write(toWrite);
|
||||
w.close();
|
||||
for (E element : this) {
|
||||
element.state = GameDataElement.State.saved;
|
||||
}
|
||||
Notification.addSuccess("Json file "+jsonFile.getAbsolutePath()+" saved.");
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while writing json file "+jsonFile.getAbsolutePath()+" : "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<SaveEvent> attemptSave(boolean checkImpactedCategory, String fileName) {
|
||||
List<SaveEvent> events = new ArrayList<SaveEvent>();
|
||||
GameDataCategory<? extends JSONElement> impactedCategory = null;
|
||||
String impactedFileName = fileName;
|
||||
Map<String, Integer> containedIds = new HashMap<String, Integer>();
|
||||
for (JSONElement node : this) {
|
||||
if (node.getDataType() == GameSource.Type.created && getProject().baseContent.gameData.getGameDataElement(node.getClass(), node.id) != null) {
|
||||
if (getProject().alteredContent.gameData.getGameDataElement(node.getClass(), node.id) != null) {
|
||||
events.add(new SaveEvent(SaveEvent.Type.moveToAltered, node, true, "Element ID matches one already present in the altered game content. Change this ID before saving."));
|
||||
} else {
|
||||
events.add(new SaveEvent(SaveEvent.Type.moveToAltered, node));
|
||||
impactedFileName = getProject().baseContent.gameData.getGameDataElement(node.getClass(), node.id).jsonFile.getName();
|
||||
impactedCategory = getProject().alteredContent.gameData.getCategory(node.getClass());
|
||||
}
|
||||
} else if (this.getDataType() == GameSource.Type.altered && getProject().baseContent.gameData.getGameDataElement(node.getClass(), node.id) == null) {
|
||||
if (getProject().createdContent.gameData.getGameDataElement(node.getClass(), node.id) != null) {
|
||||
events.add(new SaveEvent(SaveEvent.Type.moveToCreated, node, true, "Element ID matches one already present in the created game content. Change this ID before saving."));
|
||||
} else {
|
||||
events.add(new SaveEvent(SaveEvent.Type.moveToCreated, node));
|
||||
impactedCategory = getProject().createdContent.gameData.getCategory(node.getClass());
|
||||
impactedFileName = node.getProjectFilename();
|
||||
}
|
||||
} else if (node.state == GameDataElement.State.modified) {
|
||||
events.add(new SaveEvent(SaveEvent.Type.alsoSave, node));
|
||||
}
|
||||
if (containedIds.containsKey(node.id)) {
|
||||
containedIds.put(node.id, containedIds.get(node.id) + 1);
|
||||
} else {
|
||||
containedIds.put(node.id, 1);
|
||||
}
|
||||
}
|
||||
for (String key : containedIds.keySet()) {
|
||||
if (containedIds.get(key) > 1) {
|
||||
E node = null;
|
||||
for (E n : this) {
|
||||
if (key.equals(n.id)) {
|
||||
node = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
events.add(new SaveEvent(SaveEvent.Type.alsoSave, node, true, "There are "+containedIds.get(node.id)+" elements with this ID in this category. Change the conflicting IDs before saving."));
|
||||
}
|
||||
}
|
||||
if (checkImpactedCategory && impactedCategory != null) {
|
||||
events.addAll(impactedCategory.attemptSave(false, impactedFileName));
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public boolean remove(E o) {
|
||||
int index = getProject().getNodeIndex(o);
|
||||
boolean result = super.remove(o);
|
||||
getProject().fireElementRemoved(o, index);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
364
src/com/gpl/rpg/atcontentstudio/model/gamedata/GameDataSet.java
Normal file
@@ -0,0 +1,364 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource.Type;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
|
||||
import com.gpl.rpg.atcontentstudio.model.SavedSlotCollection;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
|
||||
public class GameDataSet implements ProjectTreeNode, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8558067213826970968L;
|
||||
|
||||
public static final String DEFAULT_REL_PATH_IN_SOURCE = "res"+File.separator+"raw"+File.separator;
|
||||
public static final String DEFAULT_REL_PATH_IN_PROJECT = "json"+File.separator;
|
||||
|
||||
public File baseFolder;
|
||||
|
||||
public GameDataCategory<ActorCondition> actorConditions;
|
||||
public GameDataCategory<Dialogue> dialogues;
|
||||
public GameDataCategory<Droplist> droplists;
|
||||
public GameDataCategory<Item> items;
|
||||
public GameDataCategory<ItemCategory> itemCategories;
|
||||
public GameDataCategory<NPC> npcs;
|
||||
public GameDataCategory<Quest> quests;
|
||||
|
||||
public GameSource parent;
|
||||
public SavedSlotCollection v;
|
||||
|
||||
public GameDataSet(GameSource source) {
|
||||
|
||||
this.parent = source;
|
||||
v = new SavedSlotCollection();
|
||||
|
||||
if (parent.type.equals(GameSource.Type.altered) || parent.type.equals(GameSource.Type.created)) {
|
||||
this.baseFolder = new File(parent.baseFolder, GameDataSet.DEFAULT_REL_PATH_IN_PROJECT);
|
||||
if (!baseFolder.exists()) this.baseFolder.mkdirs();
|
||||
} else if (parent.type.equals(GameSource.Type.source)) {
|
||||
this.baseFolder = new File(source.baseFolder, DEFAULT_REL_PATH_IN_SOURCE);
|
||||
}
|
||||
|
||||
actorConditions = new GameDataCategory<ActorCondition>(this, ActorCondition.getStaticDesc());
|
||||
dialogues = new GameDataCategory<Dialogue>(this, Dialogue.getStaticDesc());
|
||||
droplists = new GameDataCategory<Droplist>(this, Droplist.getStaticDesc());
|
||||
items = new GameDataCategory<Item>(this, Item.getStaticDesc());
|
||||
itemCategories = new GameDataCategory<ItemCategory>(this, ItemCategory.getStaticDesc());
|
||||
npcs = new GameDataCategory<NPC>(this, NPC.getStaticDesc());
|
||||
quests = new GameDataCategory<Quest>(this, Quest.getStaticDesc());
|
||||
|
||||
v.add(actorConditions);
|
||||
v.add(dialogues);
|
||||
v.add(droplists);
|
||||
v.add(items);
|
||||
v.add(itemCategories);
|
||||
v.add(npcs);
|
||||
v.add(quests);
|
||||
|
||||
//Start parsing to populate categories' content.
|
||||
if (parent.type != GameSource.Type.referenced) {
|
||||
for (File f : baseFolder.listFiles()) {
|
||||
if (f.getName().startsWith("actorconditions_")) {
|
||||
ActorCondition.fromJson(f, actorConditions);
|
||||
} else if (f.getName().startsWith("conversationlist_")) {
|
||||
Dialogue.fromJson(f, dialogues);
|
||||
} else if (f.getName().startsWith("droplists_")) {
|
||||
Droplist.fromJson(f, droplists);
|
||||
} else if (f.getName().startsWith("itemlist_")) {
|
||||
Item.fromJson(f, items);
|
||||
} else if (f.getName().startsWith("itemcategories_")) {
|
||||
ItemCategory.fromJson(f, itemCategories);
|
||||
} else if (f.getName().startsWith("monsterlist_")) {
|
||||
NPC.fromJson(f, npcs);
|
||||
} else if (f.getName().startsWith("questlist")) {
|
||||
Quest.fromJson(f, quests);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<ProjectTreeNode> 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<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenAdded(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenChanged(List<ProjectTreeNode> path) {
|
||||
path.add(0, this);
|
||||
parent.childrenChanged(path);
|
||||
}
|
||||
@Override
|
||||
public void childrenRemoved(List<ProjectTreeNode> path) {
|
||||
if (path.size() == 1 && this.v.getNonEmptySize() == 1) {
|
||||
childrenRemoved(new ArrayList<ProjectTreeNode>());
|
||||
} else {
|
||||
path.add(0, this);
|
||||
parent.childrenRemoved(path);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void notifyCreated() {
|
||||
childrenAdded(new ArrayList<ProjectTreeNode>());
|
||||
for (ProjectTreeNode node : v.getNonEmptyIterable()) {
|
||||
node.notifyCreated();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return "JSON data";
|
||||
}
|
||||
|
||||
|
||||
public void refreshTransients() {
|
||||
|
||||
}
|
||||
|
||||
public ActorCondition getActorCondition(String id) {
|
||||
if (actorConditions == null) return null;
|
||||
for (ActorCondition gde : actorConditions) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dialogue getDialogue(String id) {
|
||||
if (dialogues == null) return null;
|
||||
for (Dialogue gde : dialogues) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Droplist getDroplist(String id) {
|
||||
if (droplists == null) return null;
|
||||
for (Droplist gde : droplists) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Item getItem(String id) {
|
||||
if (items == null) return null;
|
||||
for (Item gde : items) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemCategory getItemCategory(String id) {
|
||||
if (itemCategories == null) return null;
|
||||
for (ItemCategory gde : itemCategories) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NPC getNPC(String id) {
|
||||
if (npcs == null) return null;
|
||||
for (NPC gde : npcs) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Quest getQuest(String id) {
|
||||
if (quests == null) return null;
|
||||
for (Quest gde : quests) {
|
||||
if (id.equals(gde.id)){
|
||||
return gde;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return parent.getProject();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getOpenIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getClosedIcon() {
|
||||
return DefaultIcons.getJsonClosedIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getLeafIcon() {
|
||||
return DefaultIcons.getJsonClosedIcon();
|
||||
}
|
||||
@Override
|
||||
public Image getOpenIcon() {
|
||||
return DefaultIcons.getJsonOpenIcon();
|
||||
}
|
||||
|
||||
public void addElement(JSONElement node) {
|
||||
ProjectTreeNode higherEmptyParent = this;
|
||||
while (higherEmptyParent != null) {
|
||||
if (higherEmptyParent.getParent() != null && ((ProjectTreeNode)higherEmptyParent.getParent()).isEmpty()) higherEmptyParent = (ProjectTreeNode)higherEmptyParent.getParent();
|
||||
else break;
|
||||
}
|
||||
if (higherEmptyParent == this && !this.isEmpty()) higherEmptyParent = null;
|
||||
if (node instanceof ActorCondition) {
|
||||
if (actorConditions.isEmpty() && higherEmptyParent == null) higherEmptyParent = actorConditions;
|
||||
actorConditions.add((ActorCondition) node);
|
||||
node.parent = actorConditions;
|
||||
} else if (node instanceof Dialogue) {
|
||||
if (dialogues.isEmpty() && higherEmptyParent == null) higherEmptyParent = dialogues;
|
||||
dialogues.add((Dialogue) node);
|
||||
node.parent = dialogues;
|
||||
} else if (node instanceof Droplist) {
|
||||
if (droplists.isEmpty() && higherEmptyParent == null) higherEmptyParent = droplists;
|
||||
droplists.add((Droplist) node);
|
||||
node.parent = droplists;
|
||||
} else if (node instanceof Item) {
|
||||
if (items.isEmpty() && higherEmptyParent == null) higherEmptyParent = items;
|
||||
items.add((Item) node);
|
||||
node.parent = items;
|
||||
} else if (node instanceof ItemCategory) {
|
||||
if (itemCategories.isEmpty() && higherEmptyParent == null) higherEmptyParent = itemCategories;
|
||||
itemCategories.add((ItemCategory) node);
|
||||
node.parent = itemCategories;
|
||||
} else if (node instanceof NPC) {
|
||||
if (npcs.isEmpty() && higherEmptyParent == null) higherEmptyParent = npcs;
|
||||
npcs.add((NPC) node);
|
||||
node.parent = npcs;
|
||||
} else if (node instanceof Quest) {
|
||||
if (quests.isEmpty() && higherEmptyParent == null) higherEmptyParent = quests;
|
||||
quests.add((Quest) node);
|
||||
node.parent = quests;
|
||||
} else {
|
||||
Notification.addError("Cannot add "+node.getDesc()+". Unknown data type.");
|
||||
return;
|
||||
}
|
||||
if (node.jsonFile != null && parent.type == GameSource.Type.altered) {
|
||||
//Altered node.
|
||||
node.jsonFile = new File(this.baseFolder, node.jsonFile.getName());
|
||||
} else {
|
||||
//Created node.
|
||||
node.jsonFile = new File(this.baseFolder, node.getProjectFilename());
|
||||
}
|
||||
if (higherEmptyParent != null) higherEmptyParent.notifyCreated();
|
||||
else node.notifyCreated();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameDataSet getDataSet() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getDataType() {
|
||||
return parent.getDataType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return v.isEmpty();
|
||||
}
|
||||
|
||||
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 GameDataCategory<? extends JSONElement> getCategory(Class<? extends JSONElement> gdeClass) {
|
||||
if (gdeClass == ActorCondition.class) {
|
||||
return actorConditions;
|
||||
}
|
||||
if (gdeClass == Dialogue.class) {
|
||||
return dialogues;
|
||||
}
|
||||
if (gdeClass == Droplist.class) {
|
||||
return droplists;
|
||||
}
|
||||
if (gdeClass == ItemCategory.class) {
|
||||
return itemCategories;
|
||||
}
|
||||
if (gdeClass == Item.class) {
|
||||
return items;
|
||||
}
|
||||
if (gdeClass == NPC.class) {
|
||||
return npcs;
|
||||
}
|
||||
if (gdeClass == Quest.class) {
|
||||
return quests;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
723
src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java
Normal file
@@ -0,0 +1,723 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
|
||||
public class Item extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = -516874303672548638L;
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
public String name = null;
|
||||
public DisplayType display_type = null;
|
||||
public String icon_id = null;
|
||||
|
||||
//Available from parsed state
|
||||
public Integer has_manual_price = null;
|
||||
public Integer base_market_cost = null;
|
||||
public String category_id = null;
|
||||
public String description = null;
|
||||
public HitEffect hit_effect = null;
|
||||
public KillEffect kill_effect = null;
|
||||
public EquipEffect equip_effect = null;
|
||||
|
||||
//Available from linked state
|
||||
public ItemCategory category = null;
|
||||
|
||||
|
||||
|
||||
public static class KillEffect {
|
||||
//Available from parsed state
|
||||
public Integer hp_boost_min = null;
|
||||
public Integer hp_boost_max = null;
|
||||
public Integer ap_boost_min = null;
|
||||
public Integer ap_boost_max = null;
|
||||
public List<TimedConditionEffect> conditions_source = null;
|
||||
|
||||
}
|
||||
|
||||
//Inheritance for code compactness, not semantically correct.
|
||||
public static class HitEffect extends KillEffect {
|
||||
//Available from parsed state
|
||||
public List<TimedConditionEffect> conditions_target = null;
|
||||
}
|
||||
|
||||
public static class EquipEffect {
|
||||
//Available from parsed state
|
||||
public Integer damage_boost_min = null;
|
||||
public Integer damage_boost_max = null;
|
||||
public Integer max_hp_boost = null;
|
||||
public Integer max_ap_boost = null;
|
||||
public List<ConditionEffect> conditions = null;
|
||||
public Integer increase_move_cost = null;
|
||||
public Integer increase_use_item_cost = null;
|
||||
public Integer increase_reequip_cost = null;
|
||||
public Integer increase_attack_cost = null;
|
||||
public Integer increase_attack_chance = null;
|
||||
public Integer increase_critical_skill = null;
|
||||
public Integer increase_block_chance = null;
|
||||
public Integer increase_damage_resistance = null;
|
||||
public Double critical_multiplier = null;
|
||||
}
|
||||
|
||||
public static class ConditionEffect {
|
||||
//Available from parsed state
|
||||
public Integer magnitude = null;
|
||||
public String condition_id = null;
|
||||
|
||||
//Available from linked state
|
||||
public ActorCondition condition = null;
|
||||
}
|
||||
|
||||
public static class TimedConditionEffect extends ConditionEffect {
|
||||
//Available from parsed state
|
||||
public Integer duration = null;
|
||||
public Double chance = null;
|
||||
}
|
||||
|
||||
public static enum DisplayType {
|
||||
ordinary,
|
||||
quest,
|
||||
extraordinary,
|
||||
legendary,
|
||||
rare
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Items";
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<Item> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List items = (List) parser.parse(reader);
|
||||
for (Object obj : items) {
|
||||
Map itemJson = (Map)obj;
|
||||
Item item = fromJson(itemJson);
|
||||
item.jsonFile = jsonFile;
|
||||
item.parent = category;
|
||||
if (item.getDataType() == GameSource.Type.created || item.getDataType() == GameSource.Type.altered) {
|
||||
item.writable = true;
|
||||
}
|
||||
category.add(item);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Item fromJson(String jsonString) throws ParseException {
|
||||
Map itemJson = (Map) new JSONParser().parse(jsonString);
|
||||
Item item = fromJson(itemJson);
|
||||
item.parse(itemJson);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Item fromJson(Map itemJson) {
|
||||
Item item = new Item();
|
||||
item.icon_id = (String) itemJson.get("iconID");
|
||||
item.id = (String) itemJson.get("id");
|
||||
item.name = (String) itemJson.get("name");
|
||||
if (itemJson.get("displaytype") != null) item.display_type = DisplayType.valueOf((String) itemJson.get("displaytype"));
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map itemJson) {
|
||||
|
||||
this.has_manual_price = JSONElement.getInteger((Number) itemJson.get("hasManualPrice"));
|
||||
this.base_market_cost = JSONElement.getInteger((Number) itemJson.get("baseMarketCost"));
|
||||
//TODO change the debug json data....
|
||||
// this.category_id = (String) itemJson.get("category");
|
||||
if (itemJson.get("category") != null) this.category_id = (String) itemJson.get("category").toString();
|
||||
this.description = (String) itemJson.get("description");
|
||||
|
||||
Map equipEffect = (Map) itemJson.get("equipEffect");
|
||||
if (equipEffect != null) {
|
||||
this.equip_effect = new EquipEffect();
|
||||
if (equipEffect.get("increaseAttackDamage") != null) {
|
||||
this.equip_effect.damage_boost_min = JSONElement.getInteger((Number) (((Map)equipEffect.get("increaseAttackDamage")).get("min")));
|
||||
this.equip_effect.damage_boost_max = JSONElement.getInteger((Number) (((Map)equipEffect.get("increaseAttackDamage")).get("max")));
|
||||
}
|
||||
this.equip_effect.max_hp_boost = JSONElement.getInteger((Number) equipEffect.get("increaseMaxHP"));
|
||||
this.equip_effect.max_ap_boost = JSONElement.getInteger((Number) equipEffect.get("increaseMaxAP"));
|
||||
this.equip_effect.increase_move_cost = JSONElement.getInteger((Number) equipEffect.get("increaseMoveCost"));
|
||||
this.equip_effect.increase_use_item_cost = JSONElement.getInteger((Number) equipEffect.get("increaseUseItemCost"));
|
||||
this.equip_effect.increase_reequip_cost = JSONElement.getInteger((Number) equipEffect.get("increaseReequipCost"));
|
||||
this.equip_effect.increase_attack_cost = JSONElement.getInteger((Number) equipEffect.get("increaseAttackCost"));
|
||||
this.equip_effect.increase_attack_chance = JSONElement.getInteger((Number) equipEffect.get("increaseAttackChance"));
|
||||
this.equip_effect.increase_critical_skill = JSONElement.getInteger((Number) equipEffect.get("increaseCriticalSkill"));
|
||||
this.equip_effect.increase_block_chance = JSONElement.getInteger((Number) equipEffect.get("increaseBlockChance"));
|
||||
this.equip_effect.increase_damage_resistance = JSONElement.getInteger((Number) equipEffect.get("increaseDamageResistance"));
|
||||
//TODO correct game data, to unify format.
|
||||
// this.equip_effect.critical_multiplier = JSONElement.getDouble((Number) equipEffect.get("setCriticalMultiplier"));
|
||||
if (equipEffect.get("setCriticalMultiplier") != null) this.equip_effect.critical_multiplier = JSONElement.getDouble(Double.parseDouble(equipEffect.get("setCriticalMultiplier").toString()));
|
||||
|
||||
List conditionsJson = (List) equipEffect.get("addedConditions");
|
||||
if (conditionsJson != null && !conditionsJson.isEmpty()) {
|
||||
this.equip_effect.conditions = new ArrayList<Item.ConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
ConditionEffect condition = new ConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
this.equip_effect.conditions.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map hitEffect = (Map) itemJson.get("hitEffect");
|
||||
if (hitEffect != null) {
|
||||
this.hit_effect = new HitEffect();
|
||||
if (hitEffect.get("increaseCurrentHP") != null) {
|
||||
this.hit_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("min")));
|
||||
this.hit_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("max")));
|
||||
}
|
||||
if (hitEffect.get("increaseCurrentAP") != null) {
|
||||
this.hit_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("min")));
|
||||
this.hit_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("max")));
|
||||
}
|
||||
List conditionsSourceJson = (List) hitEffect.get("conditionsSource");
|
||||
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
|
||||
this.hit_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsSourceJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
TimedConditionEffect condition = new TimedConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
|
||||
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
|
||||
this.hit_effect.conditions_source.add(condition);
|
||||
}
|
||||
}
|
||||
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
|
||||
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
|
||||
this.hit_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsTargetJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
TimedConditionEffect condition = new TimedConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
|
||||
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
|
||||
this.hit_effect.conditions_target.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map killEffect = (Map) itemJson.get("killEffect");
|
||||
if (killEffect == null) {
|
||||
killEffect = (Map) itemJson.get("useEffect");
|
||||
}
|
||||
if (killEffect != null) {
|
||||
this.kill_effect = new KillEffect();
|
||||
if (killEffect.get("increaseCurrentHP") != null) {
|
||||
this.kill_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentHP")).get("min")));
|
||||
this.kill_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentHP")).get("max")));
|
||||
}
|
||||
if (killEffect.get("increaseCurrentAP") != null) {
|
||||
this.kill_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentAP")).get("min")));
|
||||
this.kill_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)killEffect.get("increaseCurrentAP")).get("max")));
|
||||
}
|
||||
List conditionsSourceJson = (List) killEffect.get("conditionsSource");
|
||||
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
|
||||
this.kill_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsSourceJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
TimedConditionEffect condition = new TimedConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
|
||||
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
|
||||
this.kill_effect.conditions_source.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.state = State.parsed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
Project proj = getProject();
|
||||
if (proj == null) {
|
||||
Notification.addError("Error linking item "+id+". No parent project found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.icon_id != null) {
|
||||
String spritesheetId = this.icon_id.split(":")[0];
|
||||
proj.getSpritesheet(spritesheetId).addBacklink(this);
|
||||
}
|
||||
if (this.category_id != null) this.category = proj.getItemCategory(this.category_id);
|
||||
if (this.category != null) this.category.addBacklink(this);
|
||||
if (this.equip_effect != null && this.equip_effect.conditions != null) {
|
||||
for (ConditionEffect ce : this.equip_effect.conditions) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect ce : this.hit_effect.conditions_source) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
|
||||
for (TimedConditionEffect ce : this.hit_effect.conditions_target) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
if (this.kill_effect != null && this.kill_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect ce : this.kill_effect.conditions_source) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getProject().getIcon(icon_id);
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return getProject().getImage(icon_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
Item clone = new Item();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.name = this.name;
|
||||
clone.icon_id = this.icon_id;
|
||||
clone.base_market_cost = this.base_market_cost;
|
||||
clone.category = this.category;
|
||||
if (clone.category != null) {
|
||||
clone.category.addBacklink(clone);
|
||||
}
|
||||
clone.category_id = this.category_id;
|
||||
clone.description = this.description;
|
||||
clone.display_type = this.display_type;
|
||||
clone.has_manual_price = this.has_manual_price;
|
||||
if (this.equip_effect != null) {
|
||||
clone.equip_effect = new EquipEffect();
|
||||
clone.equip_effect.critical_multiplier = this.equip_effect.critical_multiplier;
|
||||
clone.equip_effect.damage_boost_max = this.equip_effect.damage_boost_max;
|
||||
clone.equip_effect.damage_boost_min = this.equip_effect.damage_boost_min;
|
||||
clone.equip_effect.increase_attack_chance = this.equip_effect.increase_attack_chance;
|
||||
clone.equip_effect.increase_attack_cost = this.equip_effect.increase_attack_cost;
|
||||
clone.equip_effect.increase_block_chance = this.equip_effect.increase_block_chance;
|
||||
clone.equip_effect.increase_critical_skill = this.equip_effect.increase_critical_skill;
|
||||
clone.equip_effect.increase_damage_resistance = this.equip_effect.increase_damage_resistance;
|
||||
clone.equip_effect.increase_move_cost = this.equip_effect.increase_move_cost;
|
||||
clone.equip_effect.increase_reequip_cost = this.equip_effect.increase_reequip_cost;
|
||||
clone.equip_effect.increase_use_item_cost = this.equip_effect.increase_use_item_cost;
|
||||
clone.equip_effect.max_ap_boost = this.equip_effect.max_ap_boost;
|
||||
clone.equip_effect.max_hp_boost = this.equip_effect.max_hp_boost;
|
||||
if (this.equip_effect.conditions != null) {
|
||||
clone.equip_effect.conditions = new ArrayList<Item.ConditionEffect>();
|
||||
for (ConditionEffect c : this.equip_effect.conditions) {
|
||||
ConditionEffect cclone = new ConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.equip_effect.conditions.add(cclone);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null) {
|
||||
clone.hit_effect = new HitEffect();
|
||||
clone.hit_effect.ap_boost_max = this.hit_effect.ap_boost_max;
|
||||
clone.hit_effect.ap_boost_min = this.hit_effect.ap_boost_min;
|
||||
clone.hit_effect.hp_boost_max = this.hit_effect.hp_boost_max;
|
||||
clone.hit_effect.hp_boost_min = this.hit_effect.hp_boost_min;
|
||||
if (this.hit_effect.conditions_source != null) {
|
||||
clone.hit_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
|
||||
TimedConditionEffect cclone = new TimedConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
cclone.chance = c.chance;
|
||||
cclone.duration = c.duration;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.hit_effect.conditions_source.add(cclone);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect.conditions_target != null) {
|
||||
clone.hit_effect.conditions_target = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
|
||||
TimedConditionEffect cclone = new TimedConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
cclone.chance = c.chance;
|
||||
cclone.duration = c.duration;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.hit_effect.conditions_target.add(cclone);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.kill_effect != null) {
|
||||
clone.kill_effect = new KillEffect();
|
||||
clone.kill_effect.ap_boost_max = this.kill_effect.ap_boost_max;
|
||||
clone.kill_effect.ap_boost_min = this.kill_effect.ap_boost_min;
|
||||
clone.kill_effect.hp_boost_max = this.kill_effect.hp_boost_max;
|
||||
clone.kill_effect.hp_boost_min = this.kill_effect.hp_boost_min;
|
||||
if (this.kill_effect.conditions_source != null) {
|
||||
clone.kill_effect.conditions_source = new ArrayList<Item.TimedConditionEffect>();
|
||||
for (TimedConditionEffect c : this.kill_effect.conditions_source) {
|
||||
TimedConditionEffect cclone = new TimedConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
cclone.chance = c.chance;
|
||||
cclone.duration = c.duration;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.kill_effect.conditions_source.add(cclone);
|
||||
}
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (this.category == oldOne) {
|
||||
this.category = (ItemCategory) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
} else {
|
||||
if (this.equip_effect != null && this.equip_effect.conditions != null) {
|
||||
for (ConditionEffect c : this.equip_effect.conditions) {
|
||||
if (c.condition == oldOne) {
|
||||
c.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
|
||||
if (c.condition == oldOne) {
|
||||
c.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
|
||||
if (c.condition == oldOne) {
|
||||
c.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.kill_effect != null && this.kill_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect c : this.kill_effect.conditions_source) {
|
||||
if (c.condition == oldOne) {
|
||||
c.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map itemJson = new HashMap();
|
||||
itemJson.put("id", this.id);
|
||||
if (this.icon_id != null) itemJson.put("iconID", this.icon_id);
|
||||
if (this.name != null) itemJson.put("name", this.name);
|
||||
if (this.has_manual_price != null) itemJson.put("hasManualPrice", this.has_manual_price);
|
||||
if (this.base_market_cost != null) itemJson.put("baseMarketCost", this.base_market_cost);
|
||||
if (this.category != null) {
|
||||
itemJson.put("category", this.category.id);
|
||||
} else if (this.category_id != null) {
|
||||
itemJson.put("category", this.category_id);
|
||||
}
|
||||
if (this.description != null) itemJson.put("description", this.description);
|
||||
if (this.equip_effect != null) {
|
||||
Map equipEffectJson = new HashMap();
|
||||
itemJson.put("equipEffect", equipEffectJson);
|
||||
if (this.equip_effect.damage_boost_min != null || this.equip_effect.damage_boost_max != null) {
|
||||
Map damageJson = new HashMap();
|
||||
equipEffectJson.put("increaseAttackDamage", damageJson);
|
||||
if (this.equip_effect.damage_boost_min != null) damageJson.put("min", this.equip_effect.damage_boost_min);
|
||||
else damageJson.put("min", 0);
|
||||
if (this.equip_effect.damage_boost_max != null) damageJson.put("max", this.equip_effect.damage_boost_max);
|
||||
else damageJson.put("max", 0);
|
||||
}
|
||||
if (this.equip_effect.max_hp_boost != null) equipEffectJson.put("increaseMaxHP", this.equip_effect.max_hp_boost);
|
||||
if (this.equip_effect.max_ap_boost != null) equipEffectJson.put("increaseMaxAP", this.equip_effect.max_ap_boost);
|
||||
if (this.equip_effect.increase_move_cost != null) equipEffectJson.put("increaseMoveCost", this.equip_effect.increase_move_cost);
|
||||
if (this.equip_effect.increase_use_item_cost != null) equipEffectJson.put("increaseUseItemCost", this.equip_effect.increase_use_item_cost);
|
||||
if (this.equip_effect.increase_reequip_cost != null) equipEffectJson.put("increaseReequipCost", this.equip_effect.increase_reequip_cost);
|
||||
if (this.equip_effect.increase_attack_cost != null) equipEffectJson.put("increaseAttackCost", this.equip_effect.increase_attack_cost);
|
||||
if (this.equip_effect.increase_attack_chance != null) equipEffectJson.put("increaseAttackChance", this.equip_effect.increase_attack_chance);
|
||||
if (this.equip_effect.increase_critical_skill != null) equipEffectJson.put("increaseCriticalSkill", this.equip_effect.increase_critical_skill);
|
||||
if (this.equip_effect.increase_block_chance != null) equipEffectJson.put("increaseBlockChance", this.equip_effect.increase_block_chance);
|
||||
if (this.equip_effect.increase_damage_resistance != null) equipEffectJson.put("increaseDamageResistance", this.equip_effect.increase_damage_resistance);
|
||||
if (this.equip_effect.critical_multiplier != null) equipEffectJson.put("setCriticalMultiplier", this.equip_effect.critical_multiplier);
|
||||
if (this.equip_effect.conditions != null) {
|
||||
List conditionsJson = new ArrayList();
|
||||
equipEffectJson.put("addedConditions", conditionsJson);
|
||||
for (ConditionEffect condition : this.equip_effect.conditions) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null) {
|
||||
Map hitEffectJson = new HashMap();
|
||||
itemJson.put("hitEffect", hitEffectJson);
|
||||
if (this.hit_effect.hp_boost_min != null || this.hit_effect.hp_boost_max != null) {
|
||||
Map hpJson = new HashMap();
|
||||
hitEffectJson.put("increaseCurrentHP", hpJson);
|
||||
if (this.hit_effect.hp_boost_min != null) hpJson.put("min", this.hit_effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.hit_effect.hp_boost_max != null) hpJson.put("max", this.hit_effect.hp_boost_max);
|
||||
else hpJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
|
||||
Map apJson = new HashMap();
|
||||
hitEffectJson.put("increaseCurrentAP", apJson);
|
||||
if (this.hit_effect.ap_boost_min != null) apJson.put("min", this.hit_effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.hit_effect.ap_boost_max != null) apJson.put("max", this.hit_effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_effect.conditions_source != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
hitEffectJson.put("conditionsSource", conditionsSourceJson);
|
||||
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
if (this.hit_effect.conditions_target != null) {
|
||||
List conditionsTargetJson = new ArrayList();
|
||||
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
|
||||
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsTargetJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.kill_effect != null) {
|
||||
Map killEffectJson = new HashMap();
|
||||
if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.equip) {
|
||||
itemJson.put("killEffect", killEffectJson);
|
||||
} else if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.use) {
|
||||
itemJson.put("useEffect", killEffectJson);
|
||||
}
|
||||
if (this.kill_effect.hp_boost_min != null || this.kill_effect.hp_boost_max != null) {
|
||||
Map hpJson = new HashMap();
|
||||
killEffectJson.put("increaseCurrentHP", hpJson);
|
||||
if (this.kill_effect.hp_boost_min != null) hpJson.put("min", this.kill_effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.kill_effect.hp_boost_max != null) hpJson.put("max", this.kill_effect.hp_boost_max);
|
||||
else hpJson.put("min", 0);
|
||||
}
|
||||
if (this.kill_effect.ap_boost_min != null || this.kill_effect.ap_boost_max != null) {
|
||||
Map apJson = new HashMap();
|
||||
killEffectJson.put("increaseCurrentAP", apJson);
|
||||
if (this.kill_effect.ap_boost_min != null) apJson.put("min", this.kill_effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.kill_effect.ap_boost_max != null) apJson.put("max", this.kill_effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.kill_effect.conditions_source != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
killEffectJson.put("conditionsSource", conditionsSourceJson);
|
||||
for (TimedConditionEffect condition : this.kill_effect.conditions_source) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "itemlist_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
public Integer computePrice() {
|
||||
int price = 0;
|
||||
if (category != null && category.action_type != null) {
|
||||
if (category.action_type == ItemCategory.ActionType.use) {
|
||||
price += kill_effect == null ? 0 : calculateUseCost();
|
||||
} else if (category.action_type == ItemCategory.ActionType.equip) {
|
||||
price += equip_effect == null ? 0 : calculateEquipCost(isWeapon());;
|
||||
price += hit_effect == null ? 0 : calculateHitCost();
|
||||
price += kill_effect == null ? 0 : calculateKillCost();
|
||||
}
|
||||
}
|
||||
return Math.max(1, price);
|
||||
}
|
||||
|
||||
public int zeroForNull(Integer val) {
|
||||
return val == null ? 0 : val;
|
||||
}
|
||||
|
||||
public double zeroForNull(Double val) {
|
||||
return val == null ? 0 : val;
|
||||
}
|
||||
|
||||
public boolean isWeapon() {
|
||||
return category != null && category.action_type != null && category.action_type == ItemCategory.ActionType.equip && category.slot != null && category.slot == ItemCategory.InventorySlot.weapon;
|
||||
}
|
||||
|
||||
public int calculateUseCost() {
|
||||
final float averageHPBoost = (zeroForNull(kill_effect.hp_boost_min) + zeroForNull(kill_effect.hp_boost_max)) / 2.0f;
|
||||
if (averageHPBoost == 0) return 0;
|
||||
return (int) (0.1*Math.signum(averageHPBoost)*Math.pow(Math.abs(averageHPBoost), 2) + 3*averageHPBoost);
|
||||
}
|
||||
|
||||
public int calculateEquipCost(boolean isWeapon) {
|
||||
final int costBC = (int) (3*Math.pow(Math.max(0, zeroForNull(equip_effect.increase_block_chance)), 2.5) + 28*zeroForNull(equip_effect.increase_block_chance));
|
||||
final int costAC = (int) (0.4*Math.pow(Math.max(0,zeroForNull(equip_effect.increase_attack_chance)), 2.5) - 6*Math.pow(Math.abs(Math.min(0,zeroForNull(equip_effect.increase_attack_chance))),2.7));
|
||||
final int costAP = isWeapon ?
|
||||
(int) (0.2*Math.pow(10.0f/zeroForNull(equip_effect.increase_attack_cost), 8) - 25*zeroForNull(equip_effect.increase_attack_cost))
|
||||
:-3125 * zeroForNull(equip_effect.increase_attack_cost);
|
||||
final int costDR = 1325 * zeroForNull(equip_effect.increase_damage_resistance);
|
||||
final int costDMG_Min = isWeapon ?
|
||||
(int) (10*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 2.5))
|
||||
:(int) (10*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_min)), 3) + zeroForNull(equip_effect.damage_boost_min)*80);
|
||||
final int costDMG_Max = isWeapon ?
|
||||
(int) (2*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 2.1))
|
||||
:(int) (2*Math.pow(Math.max(0, zeroForNull(equip_effect.damage_boost_max)), 3) + zeroForNull(equip_effect.damage_boost_max)*20);
|
||||
final int costCS = (int) (2.2*Math.pow(zeroForNull(equip_effect.increase_critical_skill), 3));
|
||||
final int costCM = (int) (50*Math.pow(Math.max(0, zeroForNull(equip_effect.critical_multiplier)), 2));
|
||||
|
||||
final int costMaxHP = (int) (30*Math.pow(Math.max(0,zeroForNull(equip_effect.max_hp_boost)), 1.2) + 70*zeroForNull(equip_effect.max_hp_boost));
|
||||
final int costMaxAP = (int) (50*Math.pow(Math.max(0,zeroForNull(equip_effect.max_ap_boost)), 3) + 750*zeroForNull(equip_effect.max_ap_boost));
|
||||
final int costMovement = (int) (510*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_move_cost)), 2.5) - 350*zeroForNull(equip_effect.increase_move_cost));
|
||||
final int costUseItem = (int)(915*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_use_item_cost)), 3) - 430*zeroForNull(equip_effect.increase_use_item_cost));
|
||||
final int costReequip = (int)(450*Math.pow(Math.max(0,-zeroForNull(equip_effect.increase_reequip_cost)), 2) - 250*zeroForNull(equip_effect.increase_reequip_cost));
|
||||
|
||||
return costBC + costAC + costAP + costDR + costDMG_Min + costDMG_Max + costCS + costCM
|
||||
+ costMaxHP + costMaxAP
|
||||
+ costMovement + costUseItem + costReequip;
|
||||
}
|
||||
|
||||
|
||||
public int calculateHitCost() {
|
||||
final float averageHPBoost = (zeroForNull(hit_effect.hp_boost_min) + zeroForNull(hit_effect.hp_boost_max)) / 2.0f;
|
||||
final float averageAPBoost = (zeroForNull(hit_effect.ap_boost_min) + zeroForNull(hit_effect.ap_boost_max)) / 2.0f;
|
||||
if (averageHPBoost == 0 && averageAPBoost == 0) return 0;
|
||||
|
||||
final int costBoostHP = (int)(2770*Math.pow(Math.max(0,averageHPBoost), 2.5) + 450*averageHPBoost);
|
||||
final int costBoostAP = (int)(3100*Math.pow(Math.max(0,averageAPBoost), 2.5) + 300*averageAPBoost);
|
||||
return costBoostHP + costBoostAP;
|
||||
}
|
||||
|
||||
public int calculateKillCost() {
|
||||
final float averageHPBoost = (zeroForNull(kill_effect.hp_boost_min) + zeroForNull(kill_effect.hp_boost_max)) / 2.0f;
|
||||
final float averageAPBoost = (zeroForNull(kill_effect.ap_boost_min) + zeroForNull(kill_effect.ap_boost_max)) / 2.0f;
|
||||
if (averageHPBoost == 0 && averageAPBoost == 0) return 0;
|
||||
|
||||
final int costBoostHP = (int)(923*Math.pow(Math.max(0,averageHPBoost), 2.5) + 450*averageHPBoost);
|
||||
final int costBoostAP = (int)(1033*Math.pow(Math.max(0,averageAPBoost), 2.5) + 300*averageAPBoost);
|
||||
return costBoostHP + costBoostAP;
|
||||
}
|
||||
}
|
||||
329
src/com/gpl/rpg/atcontentstudio/model/gamedata/ItemCategory.java
Normal file
@@ -0,0 +1,329 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
|
||||
public class ItemCategory extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = -348864002519568300L;
|
||||
|
||||
public static final String ICON_NO_SLOT_RES = "/com/gpl/rpg/atcontentstudio/img/equip_square.png";
|
||||
public static final String ICON_BODY_RES = "/com/gpl/rpg/atcontentstudio/img/equip_body.png";
|
||||
public static final String ICON_FEET_RES = "/com/gpl/rpg/atcontentstudio/img/equip_feet.png";
|
||||
public static final String ICON_HAND_RES = "/com/gpl/rpg/atcontentstudio/img/equip_hand.png";
|
||||
public static final String ICON_HEAD_RES = "/com/gpl/rpg/atcontentstudio/img/equip_head.png";
|
||||
public static final String ICON_NECK_RES = "/com/gpl/rpg/atcontentstudio/img/equip_neck.png";
|
||||
public static final String ICON_RING_RES = "/com/gpl/rpg/atcontentstudio/img/equip_ring.png";
|
||||
public static final String ICON_SHIELD_RES = "/com/gpl/rpg/atcontentstudio/img/equip_shield.png";
|
||||
public static final String ICON_WEAPON_RES = "/com/gpl/rpg/atcontentstudio/img/equip_weapon.png";
|
||||
|
||||
public static Image no_slot_image = null;
|
||||
public static Image no_slot_icon = null;
|
||||
|
||||
public static Image body_image = null;
|
||||
public static Image body_icon = null;
|
||||
|
||||
public static Image feet_image = null;
|
||||
public static Image feet_icon = null;
|
||||
|
||||
public static Image hand_image = null;
|
||||
public static Image hand_icon = null;
|
||||
|
||||
public static Image head_image = null;
|
||||
public static Image head_icon = null;
|
||||
|
||||
public static Image neck_image = null;
|
||||
public static Image neck_icon = null;
|
||||
|
||||
public static Image ring_image = null;
|
||||
public static Image ring_icon = null;
|
||||
|
||||
public static Image shield_image = null;
|
||||
public static Image shield_icon = null;
|
||||
|
||||
public static Image weapon_image = null;
|
||||
public static Image weapon_icon = null;
|
||||
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
public String name = null;
|
||||
public InventorySlot slot = null;
|
||||
|
||||
//Available from parsed state
|
||||
public ActionType action_type = null;
|
||||
public Size size = null;
|
||||
|
||||
//Available from linked state
|
||||
//None
|
||||
|
||||
public static enum ActionType {
|
||||
none,
|
||||
use,
|
||||
equip
|
||||
}
|
||||
|
||||
public static enum Size {
|
||||
none,
|
||||
light,
|
||||
std,
|
||||
large
|
||||
}
|
||||
|
||||
public static enum InventorySlot {
|
||||
weapon,
|
||||
shield,
|
||||
head,
|
||||
body,
|
||||
hand,
|
||||
feet,
|
||||
neck,
|
||||
leftring,
|
||||
rightring
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Item categories";
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<ItemCategory> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List itemCategories = (List) parser.parse(reader);
|
||||
for (Object obj : itemCategories) {
|
||||
Map itemCatJson = (Map)obj;
|
||||
ItemCategory itemCat = fromJson(itemCatJson);
|
||||
itemCat.jsonFile = jsonFile;
|
||||
itemCat.parent = category;
|
||||
if (itemCat.getDataType() == GameSource.Type.created || itemCat.getDataType() == GameSource.Type.altered) {
|
||||
itemCat.writable = true;
|
||||
}
|
||||
category.add(itemCat);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ItemCategory fromJson(String jsonString) throws ParseException {
|
||||
Map itemCatJson = (Map) new JSONParser().parse(jsonString);
|
||||
ItemCategory item = fromJson(itemCatJson);
|
||||
item.parse(itemCatJson);
|
||||
return item;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static ItemCategory fromJson(Map itemCatJson) {
|
||||
ItemCategory itemCat = new ItemCategory();
|
||||
itemCat.id = (String) itemCatJson.get("id");
|
||||
itemCat.name = (String) itemCatJson.get("name");
|
||||
if (itemCatJson.get("inventorySlot") != null) itemCat.slot = InventorySlot.valueOf((String) itemCatJson.get("inventorySlot"));
|
||||
return itemCat;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map itemCatJson) {
|
||||
if (itemCatJson.get("actionType") != null) action_type = ActionType.valueOf((String) itemCatJson.get("actionType"));
|
||||
if (itemCatJson.get("size") != null) size = Size.valueOf((String) itemCatJson.get("size"));
|
||||
this.state = State.parsed;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
|
||||
//Nothing to link to :D
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getIcon(this.slot);
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return getImage(this.slot);
|
||||
}
|
||||
|
||||
public static Image getImage(InventorySlot slot) {
|
||||
if (slot == null) {
|
||||
return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image");
|
||||
}
|
||||
switch (slot) {
|
||||
case body:
|
||||
return getImage(ICON_BODY_RES, body_image, "body_image");
|
||||
case feet:
|
||||
return getImage(ICON_FEET_RES, feet_image, "feet_image");
|
||||
case hand:
|
||||
return getImage(ICON_HAND_RES, hand_image, "hand_image");
|
||||
case head:
|
||||
return getImage(ICON_HEAD_RES, head_image, "head_image");
|
||||
case leftring:
|
||||
case rightring:
|
||||
return getImage(ICON_RING_RES, ring_image, "ring_image");
|
||||
case neck:
|
||||
return getImage(ICON_NECK_RES, neck_image, "neck_image");
|
||||
case shield:
|
||||
return getImage(ICON_SHIELD_RES, shield_image, "shield_image");
|
||||
case weapon:
|
||||
return getImage(ICON_WEAPON_RES, weapon_image, "weapon_image");
|
||||
default:
|
||||
return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image");
|
||||
}
|
||||
}
|
||||
|
||||
public static Image getIcon(InventorySlot slot) {
|
||||
if (slot == null) {
|
||||
return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_icon");
|
||||
}
|
||||
switch (slot) {
|
||||
case body:
|
||||
return getIcon(ICON_BODY_RES, body_image, body_icon, "body_image", "body_icon");
|
||||
case feet:
|
||||
return getIcon(ICON_FEET_RES, feet_image, feet_icon, "feet_image", "feet_icon");
|
||||
case hand:
|
||||
return getIcon(ICON_HAND_RES, hand_image, hand_icon, "hand_image", "hand_icon");
|
||||
case head:
|
||||
return getIcon(ICON_HEAD_RES, head_image, head_icon, "head_image", "head_icon");
|
||||
case leftring:
|
||||
case rightring:
|
||||
return getIcon(ICON_RING_RES, ring_image, ring_icon, "ring_image", "ring_icon");
|
||||
case neck:
|
||||
return getIcon(ICON_NECK_RES, neck_image, neck_icon, "neck_image", "neck_icon");
|
||||
case shield:
|
||||
return getIcon(ICON_SHIELD_RES, shield_image, shield_icon, "shield_image", "shield_icon");
|
||||
case weapon:
|
||||
return getIcon(ICON_WEAPON_RES, weapon_image, weapon_icon, "weapon_image", "weapon_icon");
|
||||
default:
|
||||
return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_icon");
|
||||
}
|
||||
}
|
||||
|
||||
public static Image getImage(String res, Image img, String fieldName) {
|
||||
if (img == null) {
|
||||
try {
|
||||
img = ImageIO.read(ItemCategory.class.getResourceAsStream(res));
|
||||
ItemCategory.class.getField(fieldName).set(null, img);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Failed to load item category icon "+res);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public static Image getIcon(String res, Image img, Image icon, String imgFieldName, String iconFieldName) {
|
||||
if (icon == null) {
|
||||
icon = getImage(res, img, imgFieldName).getScaledInstance(16, 16, Image.SCALE_SMOOTH);
|
||||
try {
|
||||
ItemCategory.class.getField(iconFieldName).set(null, icon);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
ItemCategory clone = new ItemCategory();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.name = this.name;
|
||||
clone.size = this.size;
|
||||
clone.slot = this.slot;
|
||||
clone.action_type = this.action_type;
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
// Nothing to link to.
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map itemCatJson = new HashMap();
|
||||
itemCatJson.put("id", this.id);
|
||||
if (this.name != null) itemCatJson.put("name", this.name);
|
||||
if (this.action_type != null) itemCatJson.put("actionType", this.action_type.toString());
|
||||
if (this.size != null) itemCatJson.put("size", this.size.toString());
|
||||
if (this.slot != null) itemCatJson.put("inventorySlot", this.slot.toString());
|
||||
return itemCatJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "itemcategories_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
169
src/com/gpl/rpg/atcontentstudio/model/gamedata/JSONElement.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
|
||||
|
||||
public abstract class JSONElement extends GameDataElement {
|
||||
|
||||
private static final long serialVersionUID = -8015398814080503982L;
|
||||
|
||||
//Available from state init.
|
||||
public File jsonFile;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void parse() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List gameDataElements = (List) parser.parse(reader);
|
||||
for (Object obj : gameDataElements) {
|
||||
Map jsonObj = (Map)obj;
|
||||
String id = (String) jsonObj.get("id");
|
||||
if (id != null && id.equals(this.id )) {
|
||||
this.parse(jsonObj);
|
||||
this.state = State.parsed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract void parse(@SuppressWarnings("rawtypes") Map jsonObj);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract Map toJson();
|
||||
public String toJsonString() {
|
||||
StringWriter writer = new JsonPrettyWriter();
|
||||
try {
|
||||
JSONObject.writeJSONString(this.toJson(), writer);
|
||||
} catch (IOException e) {
|
||||
//Impossible with a StringWriter
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameDataSet getDataSet() {
|
||||
if (parent == null) {
|
||||
System.out.println("blerf.");
|
||||
}
|
||||
return parent.getDataSet();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (this.getParent() instanceof GameDataCategory<?> && writable) {
|
||||
((GameDataCategory<?>)this.getParent()).save(this.jsonFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null if save occurred (no notable events).
|
||||
*/
|
||||
public List<SaveEvent> attemptSave() {
|
||||
List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName());
|
||||
if (events == null || events.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) {
|
||||
save();
|
||||
return null;
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public static Integer getInteger(Number n) {
|
||||
return n == null ? null : n.intValue();
|
||||
}
|
||||
|
||||
public static Double getDouble(Number n) {
|
||||
return n == null ? null : n.doubleValue();
|
||||
}
|
||||
|
||||
public static Double parseChance(String s) {
|
||||
if (s.equals("100")) return 100d;
|
||||
else if (s.equals("70")) return 70d;
|
||||
else if (s.equals("30")) return 30d;
|
||||
else if (s.equals("25")) return 25d;
|
||||
else if (s.equals("20")) return 20d;
|
||||
else if (s.equals("10")) return 10d;
|
||||
else if (s.equals("5")) return 5d;
|
||||
else if (s.equals("1")) return 1d;
|
||||
else if (s.equals("1/1000")) return 0.1;
|
||||
else if (s.equals("1/10000")) return 0.01;
|
||||
else if (s.indexOf('/') >= 0) {
|
||||
int c = s.indexOf('/');
|
||||
double a = 1;
|
||||
try {
|
||||
a = Integer.parseInt(s.substring(0, c));
|
||||
} catch (NumberFormatException nfe) {}
|
||||
double b = 100;
|
||||
try {
|
||||
b = Integer.parseInt(s.substring(c+1));
|
||||
} catch (NumberFormatException nfe) {}
|
||||
return a/b;
|
||||
}
|
||||
else {
|
||||
double a = 10;
|
||||
try {
|
||||
a = Double.parseDouble(s);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public static String printJsonChance(Double chance) {
|
||||
if (chance.equals(100d)) return "100";
|
||||
else if (chance.equals(70d)) return "70";
|
||||
else if (chance.equals(30d)) return "30";
|
||||
else if (chance.equals(25d)) return "25";
|
||||
else if (chance.equals(20d)) return "20";
|
||||
else if (chance.equals(10d)) return "10";
|
||||
else if (chance.equals(5d)) return "5";
|
||||
else if (chance.equals(1d)) return "1";
|
||||
else if (chance.equals(0.1d)) return "1/1000";
|
||||
else if (chance.equals(0.01d)) return "1/10000";
|
||||
else {
|
||||
//TODO Better handling of fractions. Chance description need a complete rehaul in AT.
|
||||
//This part does not output the input content of parseDouble(String s) in the case of fractions.
|
||||
return chance.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
511
src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java
Normal file
@@ -0,0 +1,511 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
|
||||
public class NPC extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = 1093728879485491933L;
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
public String name = null;
|
||||
public String icon_id = null;
|
||||
|
||||
//Available from parsed state
|
||||
public Integer max_hp = null;
|
||||
public Integer max_ap = null;
|
||||
public Integer move_cost = null;
|
||||
public Integer unique = null;
|
||||
public MonsterClass monster_class = null;
|
||||
public MovementType movement_type = null;
|
||||
public Integer attack_damage_max = null;
|
||||
public Integer attack_damage_min = null;
|
||||
public String spawngroup_id = null;
|
||||
public String faction_id = null;
|
||||
public String dialogue_id = null;
|
||||
public String droplist_id = null;
|
||||
public Integer attack_cost = null;
|
||||
public Integer attack_chance = null;
|
||||
public Integer critical_skill = null;
|
||||
public Double critical_multiplier = null;
|
||||
public Integer block_chance = null;
|
||||
public Integer damage_resistance = null;
|
||||
public HitEffect hit_effect = null;
|
||||
|
||||
//Available from linked state
|
||||
public Dialogue dialogue = null;
|
||||
public Droplist droplist = null;
|
||||
|
||||
public enum MonsterClass {
|
||||
humanoid,
|
||||
insect,
|
||||
demon,
|
||||
construct,
|
||||
animal,
|
||||
giant,
|
||||
undead,
|
||||
reptile,
|
||||
ghost
|
||||
}
|
||||
|
||||
public enum MovementType {
|
||||
none,
|
||||
helpOthers,
|
||||
protectSpawn,
|
||||
wholeMap
|
||||
}
|
||||
|
||||
public static class HitEffect {
|
||||
//Available from parsed state
|
||||
public Integer hp_boost_min = null;
|
||||
public Integer hp_boost_max = null;
|
||||
public Integer ap_boost_min = null;
|
||||
public Integer ap_boost_max = null;
|
||||
public List<TimedConditionEffect> conditions_source = null;
|
||||
public List<TimedConditionEffect> conditions_target = null;
|
||||
}
|
||||
|
||||
public static class TimedConditionEffect {
|
||||
//Available from parsed state
|
||||
public Integer magnitude = null;
|
||||
public String condition_id = null;
|
||||
public Integer duration = null;
|
||||
public Double chance = null;
|
||||
|
||||
//Available from linked state
|
||||
public ActorCondition condition = null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "NPCs";
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<NPC> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List npcs = (List) parser.parse(reader);
|
||||
for (Object obj : npcs) {
|
||||
Map npcJson = (Map)obj;
|
||||
NPC npc = fromJson(npcJson);
|
||||
npc.jsonFile = jsonFile;
|
||||
npc.parent = category;
|
||||
if (npc.getDataType() == GameSource.Type.created || npc.getDataType() == GameSource.Type.altered) {
|
||||
npc.writable = true;
|
||||
}
|
||||
category.add(npc);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static NPC fromJson(String jsonString) throws ParseException {
|
||||
Map npcJson = (Map) new JSONParser().parse(jsonString);
|
||||
NPC npc = fromJson(npcJson);
|
||||
npc.parse(npcJson);
|
||||
return npc;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static NPC fromJson(Map npcJson) {
|
||||
NPC npc = new NPC();
|
||||
npc.icon_id = (String) npcJson.get("iconID");
|
||||
npc.id = (String) npcJson.get("id");
|
||||
npc.name = (String) npcJson.get("name");
|
||||
return npc;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map npcJson) {
|
||||
|
||||
this.max_hp = JSONElement.getInteger((Number) npcJson.get("maxHP"));
|
||||
this.max_ap = JSONElement.getInteger((Number) npcJson.get("maxAP"));
|
||||
this.move_cost = JSONElement.getInteger((Number) npcJson.get("moveCost"));
|
||||
this.unique = JSONElement.getInteger((Number) npcJson.get("unique"));
|
||||
if (npcJson.get("monsterClass") != null) this.monster_class = MonsterClass.valueOf((String) npcJson.get("monsterClass"));
|
||||
if (npcJson.get("movementAggressionType") != null) this.movement_type = MovementType.valueOf((String) npcJson.get("movementAggressionType"));
|
||||
if (npcJson.get("attackDamage") != null) {
|
||||
this.attack_damage_min = JSONElement.getInteger((Number) (((Map)npcJson.get("attackDamage")).get("min")));
|
||||
this.attack_damage_max = JSONElement.getInteger((Number) (((Map)npcJson.get("attackDamage")).get("max")));
|
||||
}
|
||||
this.spawngroup_id = (String) npcJson.get("spawnGroup");
|
||||
this.faction_id = (String) npcJson.get("faction");
|
||||
this.dialogue_id = (String) npcJson.get("phraseID");
|
||||
this.droplist_id = (String) npcJson.get("droplistID");
|
||||
this.attack_cost = JSONElement.getInteger((Number) npcJson.get("attackCost"));
|
||||
this.attack_chance = JSONElement.getInteger((Number) npcJson.get("attackChance"));
|
||||
this.critical_skill = JSONElement.getInteger((Number) npcJson.get("criticalSkill"));
|
||||
//TODO correct game data, to unify format.
|
||||
// this.critical_multiplier = JSONElement.getDouble((Number) npcJson.get("criticalMultiplier"));
|
||||
if (npcJson.get("criticalMultiplier") != null) this.critical_multiplier = JSONElement.getDouble(Double.parseDouble(npcJson.get("criticalMultiplier").toString()));
|
||||
|
||||
this.block_chance = JSONElement.getInteger((Number) npcJson.get("blockChance"));
|
||||
this.damage_resistance = JSONElement.getInteger((Number) npcJson.get("damageResistance"));
|
||||
|
||||
Map hitEffect = (Map) npcJson.get("hitEffect");
|
||||
if (hitEffect != null) {
|
||||
this.hit_effect = new HitEffect();
|
||||
if (hitEffect.get("increaseCurrentHP") != null) {
|
||||
this.hit_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("min")));
|
||||
this.hit_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentHP")).get("max")));
|
||||
}
|
||||
if (hitEffect.get("increaseCurrentAP") != null) {
|
||||
this.hit_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("min")));
|
||||
this.hit_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)hitEffect.get("increaseCurrentAP")).get("max")));
|
||||
}
|
||||
List conditionsSourceJson = (List) hitEffect.get("conditionsSource");
|
||||
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
|
||||
this.hit_effect.conditions_source = new ArrayList<NPC.TimedConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsSourceJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
TimedConditionEffect condition = new TimedConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
|
||||
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
|
||||
this.hit_effect.conditions_source.add(condition);
|
||||
}
|
||||
}
|
||||
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
|
||||
if (conditionsTargetJson != null && !conditionsTargetJson.isEmpty()) {
|
||||
this.hit_effect.conditions_target = new ArrayList<NPC.TimedConditionEffect>();
|
||||
for (Object conditionJsonObj : conditionsTargetJson) {
|
||||
Map conditionJson = (Map)conditionJsonObj;
|
||||
TimedConditionEffect condition = new TimedConditionEffect();
|
||||
condition.condition_id = (String) conditionJson.get("condition");
|
||||
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
|
||||
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
|
||||
if (conditionJson.get("chance") != null) condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
|
||||
this.hit_effect.conditions_target.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
Project proj = getProject();
|
||||
if (proj == null) {
|
||||
Notification.addError("Error linking item "+id+". No parent project found.");
|
||||
return;
|
||||
}
|
||||
if (this.icon_id != null) {
|
||||
String spritesheetId = this.icon_id.split(":")[0];
|
||||
proj.getSpritesheet(spritesheetId).addBacklink(this);
|
||||
}
|
||||
|
||||
if (this.dialogue_id != null) this.dialogue = proj.getDialogue(this.dialogue_id);
|
||||
if (this.dialogue != null) this.dialogue.addBacklink(this);
|
||||
|
||||
if (this.droplist_id != null) this.droplist = proj.getDroplist(this.droplist_id);
|
||||
if (this.droplist != null) this.droplist.addBacklink(this);
|
||||
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect ce : this.hit_effect.conditions_source) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
|
||||
for (TimedConditionEffect ce : this.hit_effect.conditions_target) {
|
||||
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
|
||||
if (ce.condition != null) ce.condition.addBacklink(this);
|
||||
}
|
||||
}
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return getProject().getIcon(icon_id);
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return getProject().getImage(icon_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
NPC clone = new NPC();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.name = this.name;
|
||||
clone.icon_id = this.icon_id;
|
||||
clone.attack_chance = this.attack_chance;
|
||||
clone.attack_cost = this.attack_cost;
|
||||
clone.attack_damage_min = this.attack_damage_min;
|
||||
clone.attack_damage_max = this.attack_damage_max;
|
||||
clone.block_chance = this.block_chance;
|
||||
clone.critical_multiplier = this.critical_multiplier;
|
||||
clone.critical_skill = this.critical_skill;
|
||||
clone.damage_resistance = this.damage_resistance;
|
||||
clone.dialogue = this.dialogue;
|
||||
if (clone.dialogue != null) {
|
||||
clone.dialogue.addBacklink(clone);
|
||||
}
|
||||
clone.dialogue_id = this.dialogue_id;
|
||||
clone.droplist = this.droplist;
|
||||
if (clone.droplist != null) {
|
||||
clone.droplist.addBacklink(clone);
|
||||
}
|
||||
clone.droplist_id = this.droplist_id;
|
||||
clone.faction_id = this.faction_id;
|
||||
if (this.hit_effect != null) {
|
||||
clone.hit_effect = new HitEffect();
|
||||
clone.hit_effect.ap_boost_max = this.hit_effect.ap_boost_max;
|
||||
clone.hit_effect.ap_boost_min = this.hit_effect.ap_boost_min;
|
||||
clone.hit_effect.hp_boost_max = this.hit_effect.hp_boost_max;
|
||||
clone.hit_effect.hp_boost_min = this.hit_effect.hp_boost_min;
|
||||
if (this.hit_effect.conditions_source != null) {
|
||||
clone.hit_effect.conditions_source = new ArrayList<TimedConditionEffect>();
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_source) {
|
||||
TimedConditionEffect cclone = new TimedConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
cclone.chance = c.chance;
|
||||
cclone.duration = c.duration;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.hit_effect.conditions_source.add(cclone);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect.conditions_target != null) {
|
||||
clone.hit_effect.conditions_target = new ArrayList<TimedConditionEffect>();
|
||||
for (TimedConditionEffect c : this.hit_effect.conditions_target) {
|
||||
TimedConditionEffect cclone = new TimedConditionEffect();
|
||||
cclone.magnitude = c.magnitude;
|
||||
cclone.condition_id = c.condition_id;
|
||||
cclone.condition = c.condition;
|
||||
cclone.chance = c.chance;
|
||||
cclone.duration = c.duration;
|
||||
if (cclone.condition != null) {
|
||||
cclone.condition.addBacklink(clone);
|
||||
}
|
||||
clone.hit_effect.conditions_target.add(cclone);
|
||||
}
|
||||
}
|
||||
}
|
||||
clone.max_ap = this.max_ap;
|
||||
clone.max_hp = this.max_hp;
|
||||
clone.monster_class = this.monster_class;
|
||||
clone.move_cost = this.move_cost;
|
||||
clone.movement_type = this.movement_type;
|
||||
clone.spawngroup_id = this.spawngroup_id;
|
||||
clone.unique = this.unique;
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (dialogue == oldOne) {
|
||||
this.dialogue = (Dialogue) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
} else {
|
||||
if (this.droplist == oldOne) {
|
||||
this.droplist = (Droplist) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
} else {
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
|
||||
for (TimedConditionEffect tce : this.hit_effect.conditions_source) {
|
||||
if (tce.condition == oldOne) {
|
||||
tce.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
|
||||
for (TimedConditionEffect tce : this.hit_effect.conditions_target) {
|
||||
if (tce.condition == oldOne) {
|
||||
tce.condition = (ActorCondition) newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map npcJson = new HashMap();
|
||||
npcJson.put("id", this.id);
|
||||
if (this.name != null) npcJson.put("name", this.name);
|
||||
if (this.icon_id != null) npcJson.put("iconID", this.icon_id);
|
||||
if (this.max_hp != null) npcJson.put("maxHP", this.max_hp);
|
||||
if (this.max_ap != null) npcJson.put("maxAP", this.max_ap);
|
||||
if (this.move_cost != null) npcJson.put("moveCost", this.move_cost);
|
||||
if (this.unique != null) npcJson.put("unique", this.unique);
|
||||
if (this.monster_class != null) npcJson.put("monsterClass", this.monster_class.toString());
|
||||
if (this.movement_type != null) npcJson.put("movementAggressionType", this.movement_type.toString());
|
||||
if (this.attack_damage_min != null || this.attack_damage_max != null) {
|
||||
Map adJson = new HashMap();
|
||||
npcJson.put("attackDamage", adJson);
|
||||
if (this.attack_damage_min != null) adJson.put("min", this.attack_damage_min);
|
||||
else adJson.put("min", 0);
|
||||
if (this.attack_damage_max != null) adJson.put("max", this.attack_damage_max);
|
||||
else adJson.put("max", 0);
|
||||
}
|
||||
if (this.spawngroup_id != null) npcJson.put("spawnGroup", this.spawngroup_id);
|
||||
if (this.faction_id != null) npcJson.put("faction", this.faction_id);
|
||||
if (this.dialogue != null) {
|
||||
npcJson.put("phraseID", this.dialogue.id);
|
||||
} else if (this.dialogue_id != null) {
|
||||
npcJson.put("phraseID", this.dialogue_id);
|
||||
}
|
||||
if (this.droplist != null) {
|
||||
npcJson.put("droplistID", this.droplist.id);
|
||||
} else if (this.droplist_id != null) {
|
||||
npcJson.put("droplistID", this.droplist_id);
|
||||
}
|
||||
if (this.attack_cost != null) npcJson.put("attackCost", this.attack_cost);
|
||||
if (this.attack_chance != null) npcJson.put("attackChance", this.attack_chance);
|
||||
if (this.critical_skill != null) npcJson.put("criticalSkill", this.critical_skill);
|
||||
if (this.critical_multiplier != null) npcJson.put("criticalMultiplier", this.critical_multiplier);
|
||||
if (this.block_chance != null) npcJson.put("blockChance", this.block_chance);
|
||||
if (this.damage_resistance != null) npcJson.put("damageResistance", this.damage_resistance);
|
||||
if (this.hit_effect != null) {
|
||||
Map hitEffectJson = new HashMap();
|
||||
npcJson.put("hitEffect", hitEffectJson);
|
||||
if (this.hit_effect.hp_boost_min != null || this.hit_effect.hp_boost_max != null) {
|
||||
Map hpJson = new HashMap();
|
||||
hitEffectJson.put("increaseCurrentHP", hpJson);
|
||||
if (this.hit_effect.hp_boost_min != null) hpJson.put("min", this.hit_effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.hit_effect.hp_boost_max != null) hpJson.put("max", this.hit_effect.hp_boost_max);
|
||||
else hpJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_effect.ap_boost_min != null || this.hit_effect.ap_boost_max != null) {
|
||||
Map apJson = new HashMap();
|
||||
hitEffectJson.put("increaseCurrentAP", apJson);
|
||||
if (this.hit_effect.ap_boost_min != null) apJson.put("min", this.hit_effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.hit_effect.ap_boost_max != null) apJson.put("max", this.hit_effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_effect.conditions_source != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
hitEffectJson.put("conditionsSource", conditionsSourceJson);
|
||||
for (TimedConditionEffect condition : this.hit_effect.conditions_source) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
if (this.hit_effect.conditions_target != null) {
|
||||
List conditionsTargetJson = new ArrayList();
|
||||
hitEffectJson.put("conditionsTarget", conditionsTargetJson);
|
||||
for (TimedConditionEffect condition : this.hit_effect.conditions_target) {
|
||||
Map conditionJson = new HashMap();
|
||||
conditionsTargetJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null) conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
}
|
||||
return npcJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "monsterlist_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
public int getMonsterExperience() {
|
||||
double EXP_FACTOR_DAMAGERESISTANCE = 9;
|
||||
double EXP_FACTOR_SCALING = 0.7;
|
||||
|
||||
double attacksPerTurn = Math.floor((double)(max_ap != null ? max_ap : 10.0) / (double)(attack_cost != null ? attack_cost : 10.0));
|
||||
double avgDamagePotential = 0;
|
||||
if (attack_damage_min != null || attack_damage_max != null) {
|
||||
avgDamagePotential = ((double)(attack_damage_min != null ? attack_damage_min : 0) + (double)(attack_damage_max != null ? attack_damage_max : 0)) / 2.0;
|
||||
}
|
||||
double avgCrit = 0;
|
||||
if (critical_skill != null && critical_multiplier != null) {
|
||||
avgCrit = (double)(critical_skill / 100.0) * critical_multiplier;
|
||||
}
|
||||
double avgAttackHP = attacksPerTurn * ((double)(attack_chance != null ? attack_chance : 0) / 100.0) * avgDamagePotential * (1 + avgCrit);
|
||||
double avgDefenseHP = ((max_hp != null ? max_hp : 1) * (1 + ((double)(block_chance != null ? block_chance : 0) / 100.0))) + ( EXP_FACTOR_DAMAGERESISTANCE * (damage_resistance != null ? damage_resistance : 0));
|
||||
double attackConditionBonus = 0;
|
||||
if (hit_effect != null && hit_effect.conditions_target != null && hit_effect.conditions_target.size() > 0) {
|
||||
attackConditionBonus = 50;
|
||||
}
|
||||
double experience = (((avgAttackHP * 3) + avgDefenseHP) * EXP_FACTOR_SCALING) + attackConditionBonus;
|
||||
|
||||
return new Double(Math.ceil(experience)).intValue();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
208
src/com/gpl/rpg/atcontentstudio/model/gamedata/Quest.java
Normal file
@@ -0,0 +1,208 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameSource;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
public class Quest extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = 2004839647483250099L;
|
||||
|
||||
//Available from init state
|
||||
//public String id = null; inherited.
|
||||
public String name = null;
|
||||
|
||||
//Available in parsed state
|
||||
public Integer visible_in_log = null;
|
||||
public List<QuestStage> stages = null;
|
||||
|
||||
public static class QuestStage implements Cloneable {
|
||||
public Integer progress = null;
|
||||
public String log_text = null;
|
||||
public Integer exp_reward = null;
|
||||
public Integer finishes_quest = null;
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return (this.state == State.modified ? "*" : "")+name+" ("+id+")";
|
||||
}
|
||||
|
||||
public static String getStaticDesc() {
|
||||
return "Quests";
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void fromJson(File jsonFile, GameDataCategory<Quest> category) {
|
||||
JSONParser parser = new JSONParser();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(jsonFile);
|
||||
List quests = (List) parser.parse(reader);
|
||||
for (Object obj : quests) {
|
||||
Map questJson = (Map)obj;
|
||||
Quest quest = fromJson(questJson);
|
||||
quest.jsonFile = jsonFile;
|
||||
quest.parent = category;
|
||||
if (quest.getDataType() == GameSource.Type.created || quest.getDataType() == GameSource.Type.altered) {
|
||||
quest.writable = true;
|
||||
}
|
||||
category.add(quest);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (reader != null)
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Quest fromJson(String jsonString) throws ParseException {
|
||||
Map questJson = (Map) new JSONParser().parse(jsonString);
|
||||
Quest quest = fromJson(questJson);
|
||||
quest.parse(questJson);
|
||||
return quest;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Quest fromJson(Map questJson) {
|
||||
Quest quest = new Quest();
|
||||
quest.id = (String) questJson.get("id");
|
||||
quest.name = (String) questJson.get("name");
|
||||
return quest;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map questJson) {
|
||||
this.visible_in_log = JSONElement.getInteger((Number) questJson.get("showInLog"));
|
||||
List questStagesJson = (List) questJson.get("stages");
|
||||
if (questStagesJson != null && !questStagesJson.isEmpty()) {
|
||||
this.stages = new ArrayList<QuestStage>();
|
||||
for (Object questStageJsonObj : questStagesJson) {
|
||||
Map questStageJson = (Map)questStageJsonObj;
|
||||
QuestStage questStage = new QuestStage();
|
||||
questStage.progress = JSONElement.getInteger((Number) questStageJson.get("progress"));
|
||||
questStage.log_text = (String) questStageJson.get("logText");
|
||||
questStage.exp_reward = JSONElement.getInteger((Number) questStageJson.get("rewardExperience"));
|
||||
questStage.finishes_quest = JSONElement.getInteger((Number) questStageJson.get("finishesQuest"));
|
||||
this.stages.add(questStage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
|
||||
//Nothing to link to :D
|
||||
this.state = State.linked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
return DefaultIcons.getQuestIcon();
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return DefaultIcons.getQuestImage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
Quest clone = new Quest();
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.id = this.id;
|
||||
clone.name = this.name;
|
||||
clone.visible_in_log = this.visible_in_log;
|
||||
if (this.stages != null) {
|
||||
clone.stages = new ArrayList<Quest.QuestStage>();
|
||||
for (QuestStage stage : this.stages){
|
||||
clone.stages.add((QuestStage) stage.clone());
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
//Nothing to link to.
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Map toJson() {
|
||||
Map questJson = new HashMap();
|
||||
questJson.put("id", this.id);
|
||||
if (this.name != null) questJson.put("name", this.name);
|
||||
if (this.visible_in_log != null) questJson.put("showInLog", this.visible_in_log);
|
||||
if (this.stages != null) {
|
||||
List stagesJson = new ArrayList();
|
||||
questJson.put("stages", stagesJson);
|
||||
for (QuestStage stage : this.stages) {
|
||||
Map stageJson = new HashMap();
|
||||
stagesJson.add(stageJson);
|
||||
if (stage.progress != null) stageJson.put("progress", stage.progress);
|
||||
if (stage.log_text != null) stageJson.put("logText", stage.log_text);
|
||||
if (stage.exp_reward != null) stageJson.put("rewardExperience", stage.exp_reward);
|
||||
if (stage.finishes_quest != null) stageJson.put("finishesQuest", stage.finishes_quest);
|
||||
}
|
||||
}
|
||||
return questJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "questlist_"+getProject().name+".json";
|
||||
}
|
||||
|
||||
}
|
||||
166
src/com/gpl/rpg/atcontentstudio/model/gamedata/Requirement.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.gamedata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.Notification;
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
|
||||
public class Requirement extends JSONElement {
|
||||
|
||||
private static final long serialVersionUID = 7295593297142310955L;
|
||||
|
||||
private static Map<RequirementType, List<RequirementType>> COMPATIBLE_TYPES = new HashMap<RequirementType, List<RequirementType>>();
|
||||
|
||||
static {
|
||||
List<RequirementType> questTypes = new ArrayList<RequirementType>();
|
||||
questTypes.add(RequirementType.questProgress);
|
||||
questTypes.add(RequirementType.questLatestProgress);
|
||||
COMPATIBLE_TYPES.put(RequirementType.questProgress, questTypes);
|
||||
COMPATIBLE_TYPES.put(RequirementType.questLatestProgress, questTypes);
|
||||
|
||||
List<RequirementType> countedItemTypes = new ArrayList<RequirementType>();
|
||||
countedItemTypes.add(RequirementType.inventoryRemove);
|
||||
countedItemTypes.add(RequirementType.inventoryKeep);
|
||||
countedItemTypes.add(RequirementType.usedItem);
|
||||
COMPATIBLE_TYPES.put(RequirementType.inventoryRemove, countedItemTypes);
|
||||
COMPATIBLE_TYPES.put(RequirementType.inventoryKeep, countedItemTypes);
|
||||
COMPATIBLE_TYPES.put(RequirementType.usedItem, countedItemTypes);
|
||||
|
||||
}
|
||||
|
||||
//Available from parsed state
|
||||
public RequirementType type = null;
|
||||
public String required_obj_id = null;
|
||||
public Integer required_value = null;
|
||||
public Boolean negated = null;
|
||||
|
||||
//Available from linked state
|
||||
public GameDataElement required_obj = null;
|
||||
|
||||
public enum RequirementType {
|
||||
questProgress,
|
||||
questLatestProgress,
|
||||
inventoryRemove,
|
||||
inventoryKeep,
|
||||
wear,
|
||||
skillLevel,
|
||||
killedMonster,
|
||||
timerElapsed,
|
||||
usedItem,
|
||||
spentGold,
|
||||
consumedBonemeals,
|
||||
hasActorCondition
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return ((negated != null && negated) ? "NOT " : "")+required_obj_id+(required_value == null ? "" : ":"+required_value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse() {
|
||||
throw new Error("Thou shalt not reach this method.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Map toJson() {
|
||||
throw new Error("Thou shalt not reach this method.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void parse(Map jsonObj) {
|
||||
throw new Error("Thou shalt not reach this method.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
|
||||
//This type of state is unrelated to parsing/linking.
|
||||
return;
|
||||
}
|
||||
if (this.state == State.init) {
|
||||
//Not parsed yet.
|
||||
this.parse();
|
||||
} else if (this.state == State.linked) {
|
||||
//Already linked.
|
||||
return;
|
||||
}
|
||||
Project proj = getProject();
|
||||
if (proj == null) {
|
||||
Notification.addError("Error linking requirement "+getDesc()+". No parent project found.");
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case hasActorCondition:
|
||||
this.required_obj = proj.getActorCondition(required_obj_id);
|
||||
break;
|
||||
case inventoryKeep:
|
||||
case inventoryRemove:
|
||||
case usedItem:
|
||||
case wear:
|
||||
this.required_obj = proj.getItem(required_obj_id);
|
||||
break;
|
||||
case killedMonster:
|
||||
this.required_obj = proj.getNPC(required_obj_id);
|
||||
break;
|
||||
case questLatestProgress:
|
||||
case questProgress:
|
||||
this.required_obj = proj.getQuest(required_obj_id);
|
||||
break;
|
||||
case consumedBonemeals:
|
||||
case skillLevel:
|
||||
case spentGold:
|
||||
case timerElapsed:
|
||||
break;
|
||||
}
|
||||
if (this.required_obj != null) this.required_obj.addBacklink((GameDataElement) this.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameDataElement clone() {
|
||||
return clone(null);
|
||||
}
|
||||
|
||||
public GameDataElement clone(GameDataElement parent) {
|
||||
Requirement clone = new Requirement();
|
||||
clone.parent = parent;
|
||||
clone.jsonFile = this.jsonFile;
|
||||
clone.state = this.state;
|
||||
clone.required_obj_id = this.required_obj_id;
|
||||
clone.required_value = this.required_value;
|
||||
clone.required_obj = this.required_obj;
|
||||
clone.type = this.type;
|
||||
if (clone.required_obj != null && parent != null) {
|
||||
clone.required_obj.addBacklink(parent);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (this.required_obj == oldOne) {
|
||||
this.required_obj = newOne;
|
||||
if (newOne != null) newOne.addBacklink(this);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
throw new Error("Thou shalt not reach this method.");
|
||||
}
|
||||
|
||||
public void changeType(RequirementType destType) {
|
||||
if (COMPATIBLE_TYPES.get(type) == null || !COMPATIBLE_TYPES.get(type).contains(destType)) {
|
||||
required_obj = null;
|
||||
required_obj_id = null;
|
||||
required_value = null;
|
||||
}
|
||||
type = destType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.gpl.rpg.atcontentstudio.model.maps;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
|
||||
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
|
||||
|
||||
public class ContainerArea extends MapObject {
|
||||
|
||||
public Droplist droplist = null;
|
||||
|
||||
public ContainerArea(tiled.core.MapObject obj) {}
|
||||
|
||||
@Override
|
||||
public void link() {
|
||||
droplist = parentMap.getProject().getDroplist(name);
|
||||
if (droplist != null) {
|
||||
droplist.addBacklink(parentMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getIcon() {
|
||||
if (droplist != null) return DefaultIcons.getContainerIcon();
|
||||
else return DefaultIcons.getNullifyIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
|
||||
if (oldOne == droplist) {
|
||||
droplist = (Droplist) newOne;
|
||||
newOne.addBacklink(parentMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePropertiesInTmxObject(tiled.core.MapObject tmxObject) {
|
||||
if (droplist != null) {
|
||||
tmxObject.setName(droplist.id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||