Compare commits

..

1 Commits

28 changed files with 8374 additions and 7094 deletions

1
.gitignore vendored
View File

@@ -11,4 +11,3 @@ ATCS.jar
/packaging/common/ATCS.env.bat /packaging/common/ATCS.env.bat
/packaging/common/ATCS.env /packaging/common/ATCS.env
/packaging/common/ATCS_v*.zip /packaging/common/ATCS_v*.zip
/.output.txt

View File

@@ -153,8 +153,7 @@ public class ATContentStudio {
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
lastLine = inputLine; lastLine = inputLine;
} }
if (lastLine != null && !lastLine.equals(APP_VERSION)) { if (lastLine != null && compareVersions(lastLine) < 0) {
// for copying style // for copying style
JLabel label = new JLabel(); JLabel label = new JLabel();
Font font = label.getFont(); Font font = label.getFont();
@@ -231,4 +230,19 @@ public class ATContentStudio {
} }
} }
} }
/// returns The difference between the the latest version and the current one (CURRENT - LATEST)
private static int compareVersions(String latest) {
String[] levels1 = ATContentStudio.APP_VERSION.substring(1).split("\\.");
String[] levels2 = latest.substring(1).split("\\.");
int length = Math.max(levels1.length, levels2.length);
for (int i = 0; i < length; i++) {
int v1 = i < levels1.length ? Integer.parseInt(levels1[i]) : 0;
int v2 = i < levels2.length ? Integer.parseInt(levels2[i]) : 0;
if (v1 != v2) {
return v1 - v2;
}
}
return 0;
}
} }

View File

@@ -1,219 +1,193 @@
package com.gpl.rpg.atcontentstudio.model; package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image; import java.awt.Image;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry; import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
public abstract class GameDataElement implements ProjectTreeNode, Serializable { public abstract class GameDataElement implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 2028934451226743389L; private static final long serialVersionUID = 2028934451226743389L;
public static enum State { public static enum State {
init, // We know the object exists, and have its key/ID. 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. 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. 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 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. 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. saved // Whether altered or created, this item has been saved since last modification.
} }
public State state = State.init; public State state = State.init;
//Available from state init. //Available from state init.
public ProjectTreeNode parent; public ProjectTreeNode parent;
public boolean writable = false; public boolean writable = false;
public BookmarkEntry bookmark = null; public BookmarkEntry bookmark = null;
//List of objects whose transition to "linked" state made them point to this instance. //List of objects whose transition to "linked" state made them point to this instance.
private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>(); private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>();
public String id = null; public String id = null;
@Override @Override
public Enumeration<ProjectTreeNode> children() { public Enumeration<ProjectTreeNode> children() {
return null; return null;
} }
@Override @Override
public boolean getAllowsChildren() { public boolean getAllowsChildren() {
return false; return false;
} }
@Override @Override
public TreeNode getChildAt(int arg0) { public TreeNode getChildAt(int arg0) {
return null; return null;
} }
@Override @Override
public int getChildCount() { public int getChildCount() {
return 0; return 0;
} }
@Override @Override
public int getIndex(TreeNode arg0) { public int getIndex(TreeNode arg0) {
return 0; return 0;
} }
@Override @Override
public TreeNode getParent() { public TreeNode getParent() {
return parent; return parent;
} }
@Override @Override
public boolean isLeaf() { public boolean isLeaf() {
return true; return true;
} }
@Override @Override
public void childrenAdded(List<ProjectTreeNode> path) { public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenAdded(path); parent.childrenAdded(path);
} }
@Override @Override
public void childrenChanged(List<ProjectTreeNode> path) { public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenChanged(path); parent.childrenChanged(path);
} }
@Override @Override
public void childrenRemoved(List<ProjectTreeNode> path) { public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenRemoved(path); parent.childrenRemoved(path);
} }
@Override @Override
public void notifyCreated() { public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>()); childrenAdded(new ArrayList<ProjectTreeNode>());
} }
@Override @Override
public abstract String getDesc(); public abstract String getDesc();
public static String getStaticDesc() { public static String getStaticDesc() {
return "GameDataElements"; return "GameDataElements";
} }
public abstract void parse(); public abstract void parse();
public abstract void link(); public abstract void link();
@Override @Override
public Project getProject() { public Project getProject() {
return parent == null ? null : parent.getProject(); return parent == null ? null : parent.getProject();
} }
public Image getIcon() { public Image getIcon() {
return null; return null;
} }
@Override @Override
public Image getClosedIcon() {return null;} public Image getClosedIcon() {return null;}
@Override @Override
public Image getOpenIcon() {return null;} public Image getOpenIcon() {return null;}
@Override @Override
public Image getLeafIcon() { public Image getLeafIcon() {
return getIcon(); return getIcon();
} }
public abstract GameDataElement clone(); public abstract GameDataElement clone();
public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne); public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
@Override @Override
public GameSource.Type getDataType() { public GameSource.Type getDataType() {
if (parent == null) { if (parent == null) {
System.out.println("blerf."); System.out.println("blerf.");
} }
return parent.getDataType(); return parent.getDataType();
} }
public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>(); public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>();
public void addBacklinkListener(BacklinksListener l) { public void addBacklinkListener(BacklinksListener l) {
backlinkListeners.add(l); backlinkListeners.add(l);
} }
public void removeBacklinkListener(BacklinksListener l) { public void removeBacklinkListener(BacklinksListener l) {
backlinkListeners.remove(l); backlinkListeners.remove(l);
} }
public void addBacklink(GameDataElement gde) { public void addBacklink(GameDataElement gde) {
if (!backlinks.containsKey(gde)) { if (!backlinks.containsKey(gde)) {
backlinks.put(gde, 1); backlinks.put(gde, 1);
for (BacklinksListener l : backlinkListeners) { for (BacklinksListener l : backlinkListeners) {
l.backlinkAdded(gde); l.backlinkAdded(gde);
} }
} else { } else {
backlinks.put(gde, backlinks.get(gde) + 1); backlinks.put(gde, backlinks.get(gde) + 1);
} }
} }
public void removeBacklink(GameDataElement gde) { public void removeBacklink(GameDataElement gde) {
if (backlinks.get(gde) == null) return; if (backlinks.get(gde) == null) return;
backlinks.put(gde, backlinks.get(gde) - 1); backlinks.put(gde, backlinks.get(gde) - 1);
if (backlinks.get(gde) == 0) { if (backlinks.get(gde) == 0) {
backlinks.remove(gde); backlinks.remove(gde);
for (BacklinksListener l : backlinkListeners) { for (BacklinksListener l : backlinkListeners) {
l.backlinkRemoved(gde); l.backlinkRemoved(gde);
} }
} }
} }
public Set<GameDataElement> getBacklinks() { public Set<GameDataElement> getBacklinks() {
return backlinks.keySet(); return backlinks.keySet();
} }
public static interface BacklinksListener { public static interface BacklinksListener {
public void backlinkAdded(GameDataElement gde); public void backlinkAdded(GameDataElement gde);
public void backlinkRemoved(GameDataElement gde); public void backlinkRemoved(GameDataElement gde);
} }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return false; return false;
} }
public boolean needsSaving() { public boolean needsSaving() {
return this.state == State.modified || this.state == State.created; return this.state == State.modified || this.state == State.created;
} }
public abstract String getProjectFilename(); public abstract String getProjectFilename();
public abstract void save(); public abstract void save();
public abstract List<SaveEvent> attemptSave(); public abstract List<SaveEvent> attemptSave();
/** }
* Checks if the current state indicates that parsing/linking should be skipped.
* @return true if the operation should be skipped, false otherwise
*/
protected boolean shouldSkipParseOrLink() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return true;
}
if (this.state == State.linked) {
//Already linked.
return true;
}
return false;
}
/**
* Ensures the element is parsed if needed based on its current state.
*/
protected void ensureParseIfNeeded() {
if (this.state == State.init) {
//Not parsed yet.
this.parse();
}
}
}

View File

@@ -1,374 +1,381 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ActorCondition extends JSONElement { public class ActorCondition extends JSONElement {
private static final long serialVersionUID = -3969824899972048507L; private static final long serialVersionUID = -3969824899972048507L;
public static final Integer MAGNITUDE_CLEAR = -99; public static final Integer MAGNITUDE_CLEAR = -99;
public static final Integer DURATION_FOREVER = 999;; public static final Integer DURATION_FOREVER = 999;;
public static final Integer DURATION_NONE = 0; public static final Integer DURATION_NONE = 0;
// Available from init state // Available from init state
//public String id; inherited. //public String id; inherited.
public String icon_id; public String icon_id;
public String display_name; public String display_name;
public String description; public String description;
// Available from parsed state // Available from parsed state
public ACCategory category = null; public ACCategory category = null;
public Integer positive = null; public Integer positive = null;
public Integer stacking = null; public Integer stacking = null;
public RoundEffect round_effect = null; public RoundEffect round_effect = null;
public RoundEffect full_round_effect = null; public RoundEffect full_round_effect = null;
public AbilityEffect constant_ability_effect = null; public AbilityEffect constant_ability_effect = null;
public enum ACCategory { public enum ACCategory {
spiritual, spiritual,
mental, mental,
physical, physical,
blood blood
} }
public static enum VisualEffectID { public static enum VisualEffectID {
redSplash redSplash
,blueSwirl ,blueSwirl
,greenSplash ,greenSplash
,miss ,miss
} }
public static class RoundEffect implements Cloneable { public static class RoundEffect implements Cloneable {
// Available from parsed state // Available from parsed state
public VisualEffectID visual_effect = null; public VisualEffectID visual_effect = null;
public Integer hp_boost_min = null; public Integer hp_boost_min = null;
public Integer hp_boost_max = null; public Integer hp_boost_max = null;
public Integer ap_boost_min = null; public Integer ap_boost_min = null;
public Integer ap_boost_max = null; public Integer ap_boost_max = null;
public Object clone() { public Object clone() {
try { try {
return super.clone(); return super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
} }
public static class AbilityEffect implements Cloneable { public static class AbilityEffect implements Cloneable {
// Available from parsed state // Available from parsed state
public Integer max_hp_boost = null; public Integer max_hp_boost = null;
public Integer max_ap_boost = null; public Integer max_ap_boost = null;
public Integer increase_move_cost = null; public Integer increase_move_cost = null;
public Integer increase_use_cost = null; public Integer increase_use_cost = null;
public Integer increase_reequip_cost = null; public Integer increase_reequip_cost = null;
public Integer increase_attack_cost = null; public Integer increase_attack_cost = null;
public Integer increase_attack_chance = null; public Integer increase_attack_chance = null;
public Integer increase_damage_min = null; public Integer increase_damage_min = null;
public Integer increase_damage_max = null; public Integer increase_damage_max = null;
public Integer increase_critical_skill = null; public Integer increase_critical_skill = null;
public Integer increase_block_chance = null; public Integer increase_block_chance = null;
public Integer increase_damage_resistance = null; public Integer increase_damage_resistance = null;
public Object clone() { public Object clone() {
try { try {
return super.clone(); return super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
} }
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+display_name+" ("+id+")"; return (needsSaving() ? "*" : "")+display_name+" ("+id+")";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<ActorCondition> category) { public static void fromJson(File jsonFile, GameDataCategory<ActorCondition> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
FileReader reader = null; FileReader reader = null;
try { try {
reader = new FileReader(jsonFile); reader = new FileReader(jsonFile);
List actorConditions = (List) parser.parse(reader); List actorConditions = (List) parser.parse(reader);
for (Object obj : actorConditions) { for (Object obj : actorConditions) {
Map aCondJson = (Map)obj; Map aCondJson = (Map)obj;
ActorCondition aCond = fromJson(aCondJson); ActorCondition aCond = fromJson(aCondJson);
aCond.jsonFile = jsonFile; aCond.jsonFile = jsonFile;
aCond.parent = category; aCond.parent = category;
if (aCond.getDataType() == GameSource.Type.created || aCond.getDataType() == GameSource.Type.altered) { if (aCond.getDataType() == GameSource.Type.created || aCond.getDataType() == GameSource.Type.altered) {
aCond.writable = true; aCond.writable = true;
} }
category.add(aCond); category.add(aCond);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (reader != null) if (reader != null)
try { try {
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static ActorCondition fromJson(String jsonString) throws ParseException { public static ActorCondition fromJson(String jsonString) throws ParseException {
Map aCondJson = (Map) new JSONParser().parse(jsonString); Map aCondJson = (Map) new JSONParser().parse(jsonString);
ActorCondition aCond = fromJson(aCondJson); ActorCondition aCond = fromJson(aCondJson);
aCond.parse(aCondJson); aCond.parse(aCondJson);
return aCond; return aCond;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static ActorCondition fromJson(Map aCondJson) { public static ActorCondition fromJson(Map aCondJson) {
ActorCondition aCond = new ActorCondition(); ActorCondition aCond = new ActorCondition();
aCond.icon_id = (String) aCondJson.get("iconID"); aCond.icon_id = (String) aCondJson.get("iconID");
aCond.id = (String) aCondJson.get("id"); aCond.id = (String) aCondJson.get("id");
aCond.display_name = (String) aCondJson.get("name"); aCond.display_name = (String) aCondJson.get("name");
return aCond; return aCond;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map aCondJson) { public void parse(Map aCondJson) {
if (aCondJson.get("description") != null) this.description = (String) aCondJson.get("description"); if (aCondJson.get("description") != null) this.description = (String) aCondJson.get("description");
if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category")); if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category"));
this.positive = JSONElement.getInteger((Number) aCondJson.get("isPositive")); this.positive = JSONElement.getInteger((Number) aCondJson.get("isPositive"));
Map abilityEffect = (Map) aCondJson.get("abilityEffect"); Map abilityEffect = (Map) aCondJson.get("abilityEffect");
if (abilityEffect != null) { if (abilityEffect != null) {
this.constant_ability_effect = new AbilityEffect(); this.constant_ability_effect = new AbilityEffect();
this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance")); this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance"));
if (abilityEffect.get("increaseAttackDamage") != null) { 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_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.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_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.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_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_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_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_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_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_block_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseBlockChance"));
this.constant_ability_effect.increase_damage_resistance = JSONElement.getInteger((Number) abilityEffect.get("increaseDamageResistance")); this.constant_ability_effect.increase_damage_resistance = JSONElement.getInteger((Number) abilityEffect.get("increaseDamageResistance"));
} }
this.stacking = JSONElement.getInteger((Number) aCondJson.get("isStacking")); this.stacking = JSONElement.getInteger((Number) aCondJson.get("isStacking"));
Map roundEffect = (Map) aCondJson.get("roundEffect"); Map roundEffect = (Map) aCondJson.get("roundEffect");
if (roundEffect != null) { if (roundEffect != null) {
this.round_effect = new RoundEffect(); this.round_effect = new RoundEffect();
if (roundEffect.get("increaseCurrentHP") != null) { if (roundEffect.get("increaseCurrentHP") != null) {
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max"))); this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max")));
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min"))); this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min")));
} }
if (roundEffect.get("increaseCurrentAP") != null) { if (roundEffect.get("increaseCurrentAP") != null) {
this.round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("max"))); this.round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("max")));
this.round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min"))); this.round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min")));
} }
String vfx = (String) roundEffect.get("visualEffectID"); String vfx = (String) roundEffect.get("visualEffectID");
this.round_effect.visual_effect = null; this.round_effect.visual_effect = null;
if (vfx != null) { if (vfx != null) {
try { try {
this.round_effect.visual_effect = VisualEffectID.valueOf(vfx); this.round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {} } catch(IllegalArgumentException e) {}
} }
} }
Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect"); Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect");
if (fullRoundEffect != null) { if (fullRoundEffect != null) {
this.full_round_effect = new RoundEffect(); this.full_round_effect = new RoundEffect();
if (fullRoundEffect.get("increaseCurrentHP") != null) { if (fullRoundEffect.get("increaseCurrentHP") != null) {
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max"))); this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max")));
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min"))); this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min")));
} }
if (fullRoundEffect.get("increaseCurrentAP") != null) { if (fullRoundEffect.get("increaseCurrentAP") != null) {
this.full_round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("max"))); this.full_round_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("max")));
this.full_round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min"))); this.full_round_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min")));
} }
String vfx = (String) fullRoundEffect.get("visualEffectID"); String vfx = (String) fullRoundEffect.get("visualEffectID");
this.full_round_effect.visual_effect = null; this.full_round_effect.visual_effect = null;
if (vfx != null) { if (vfx != null) {
try { try {
this.full_round_effect.visual_effect = VisualEffectID.valueOf(vfx); this.full_round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {} } catch(IllegalArgumentException e) {}
} }
} }
this.state = State.parsed; this.state = State.parsed;
} }
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
ensureParseIfNeeded(); }
if (this.icon_id != null) { if (this.state == State.init) {
String spritesheetId = this.icon_id.split(":")[0]; //Not parsed yet.
if (getProject().getSpritesheet(spritesheetId) == null) { this.parse();
System.out.println("Actor Condition"); } else if (this.state == State.linked) {
System.out.println(this.id); //Already linked.
System.out.println("failed to load spritesheet:"); return;
System.out.println(spritesheetId); }
System.out.println("while creating backlink for icon_id:"); if (this.icon_id != null) {
System.out.println(this.icon_id); String spritesheetId = this.icon_id.split(":")[0];
} if (getProject().getSpritesheet(spritesheetId) == null) {
getProject().getSpritesheet(spritesheetId).addBacklink(this); System.out.println("Actor Condition");
} System.out.println(this.id);
System.out.println("failed to load spritesheet:");
this.state = State.linked; System.out.println(spritesheetId);
} System.out.println("while creating backlink for icon_id:");
System.out.println(this.icon_id);
}
public static String getStaticDesc() { getProject().getSpritesheet(spritesheetId).addBacklink(this);
return "Actor Conditions"; }
}
this.state = State.linked;
}
@Override
public Image getIcon() {
return getProject().getIcon(icon_id); public static String getStaticDesc() {
} return "Actor Conditions";
}
public Image getImage() {
return getProject().getImage(icon_id);
} @Override
public Image getIcon() {
@Override return getProject().getIcon(icon_id);
public JSONElement clone() { }
ActorCondition clone = new ActorCondition();
clone.jsonFile = this.jsonFile; public Image getImage() {
clone.state = this.state; return getProject().getImage(icon_id);
clone.id = this.id; }
clone.display_name = this.display_name;
clone.description = this.description; @Override
clone.icon_id = this.icon_id; public JSONElement clone() {
clone.category = this.category; ActorCondition clone = new ActorCondition();
clone.positive = this.positive; clone.jsonFile = this.jsonFile;
clone.stacking = this.stacking; clone.state = this.state;
if (this.round_effect != null) { clone.id = this.id;
clone.round_effect = (RoundEffect) this.round_effect.clone(); clone.display_name = this.display_name;
} clone.description = this.description;
if (this.constant_ability_effect != null) { clone.icon_id = this.icon_id;
clone.constant_ability_effect = (AbilityEffect) constant_ability_effect.clone(); clone.category = this.category;
} clone.positive = this.positive;
if (this.full_round_effect != null) { clone.stacking = this.stacking;
clone.full_round_effect = (RoundEffect) this.full_round_effect.clone(); if (this.round_effect != null) {
} clone.round_effect = (RoundEffect) this.round_effect.clone();
return clone; }
} if (this.constant_ability_effect != null) {
clone.constant_ability_effect = (AbilityEffect) constant_ability_effect.clone();
@Override }
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { if (this.full_round_effect != null) {
//Nothing to link to. clone.full_round_effect = (RoundEffect) this.full_round_effect.clone();
} }
return clone;
@SuppressWarnings({ "rawtypes", "unchecked" }) }
@Override
public Map toJson() { @Override
Map jsonAC = new LinkedHashMap(); public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
jsonAC.put("id", this.id); //Nothing to link to.
if (this.icon_id != null) jsonAC.put("iconID", this.icon_id); }
if (this.display_name != null) jsonAC.put("name", this.display_name);
if (this.description != null) jsonAC.put("description", this.description); @SuppressWarnings({ "rawtypes", "unchecked" })
if (this.category != null) jsonAC.put("category", this.category.toString()); @Override
if (this.positive != null && this.positive == 1) jsonAC.put("isPositive", this.positive); public Map toJson() {
if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking); Map jsonAC = new LinkedHashMap();
if (this.round_effect != null) { jsonAC.put("id", this.id);
Map jsonRound = new LinkedHashMap(); if (this.icon_id != null) jsonAC.put("iconID", this.icon_id);
if (this.round_effect.visual_effect != null) jsonRound.put("visualEffectID", this.round_effect.visual_effect.toString()); if (this.display_name != null) jsonAC.put("name", this.display_name);
if (this.round_effect.hp_boost_min != null || this.round_effect.hp_boost_max != null) { if (this.description != null) jsonAC.put("description", this.description);
Map jsonHP = new LinkedHashMap(); if (this.category != null) jsonAC.put("category", this.category.toString());
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min); if (this.positive != null && this.positive == 1) jsonAC.put("isPositive", this.positive);
else jsonHP.put("min", 0); if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking);
if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max); if (this.round_effect != null) {
else jsonHP.put("max", 0); Map jsonRound = new LinkedHashMap();
jsonRound.put("increaseCurrentHP", jsonHP); if (this.round_effect.visual_effect != null) jsonRound.put("visualEffectID", this.round_effect.visual_effect.toString());
} if (this.round_effect.hp_boost_min != null || this.round_effect.hp_boost_max != null) {
if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) { Map jsonHP = new LinkedHashMap();
Map jsonAP = new LinkedHashMap(); if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min); else jsonHP.put("min", 0);
else jsonAP.put("min", 0); if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max);
if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max); else jsonHP.put("max", 0);
else jsonAP.put("max", 0); jsonRound.put("increaseCurrentHP", jsonHP);
jsonRound.put("increaseCurrentAP", jsonAP); }
} if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) {
jsonAC.put("roundEffect", jsonRound); Map jsonAP = new LinkedHashMap();
} if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min);
if (this.full_round_effect != null) { else jsonAP.put("min", 0);
Map jsonFullRound = new LinkedHashMap(); if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max);
if (this.full_round_effect.visual_effect != null) jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect.toString()); else jsonAP.put("max", 0);
if (this.full_round_effect.hp_boost_min != null || this.full_round_effect.hp_boost_max != null) { jsonRound.put("increaseCurrentAP", jsonAP);
Map jsonHP = new LinkedHashMap(); }
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min); jsonAC.put("roundEffect", jsonRound);
else jsonHP.put("min", 0); }
if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max); if (this.full_round_effect != null) {
else jsonHP.put("max", 0); Map jsonFullRound = new LinkedHashMap();
jsonFullRound.put("increaseCurrentHP", jsonHP); if (this.full_round_effect.visual_effect != null) jsonFullRound.put("visualEffectID", this.full_round_effect.visual_effect.toString());
} if (this.full_round_effect.hp_boost_min != null || this.full_round_effect.hp_boost_max != null) {
if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) { Map jsonHP = new LinkedHashMap();
Map jsonAP = new LinkedHashMap(); if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min); else jsonHP.put("min", 0);
else jsonAP.put("min", 0); if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max);
if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max); else jsonHP.put("max", 0);
else jsonAP.put("max", 0); jsonFullRound.put("increaseCurrentHP", jsonHP);
jsonFullRound.put("increaseCurrentAP", jsonAP); }
} if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) {
jsonAC.put("fullRoundEffect", jsonFullRound); Map jsonAP = new LinkedHashMap();
} if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min);
if (this.constant_ability_effect != null) { else jsonAP.put("min", 0);
Map jsonAbility = new LinkedHashMap(); if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max);
if (this.constant_ability_effect.increase_attack_chance != null) jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance); else jsonAP.put("max", 0);
if (this.constant_ability_effect.increase_damage_min != null || this.constant_ability_effect.increase_damage_max != null) { jsonFullRound.put("increaseCurrentAP", jsonAP);
Map jsonAD = new LinkedHashMap(); }
if (this.constant_ability_effect.increase_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min); jsonAC.put("fullRoundEffect", jsonFullRound);
else jsonAD.put("min", 0); }
if (this.constant_ability_effect.increase_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max); if (this.constant_ability_effect != null) {
else jsonAD.put("max", 0); Map jsonAbility = new LinkedHashMap();
jsonAbility.put("increaseAttackDamage", jsonAD); 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) {
if (this.constant_ability_effect.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost); Map jsonAD = new LinkedHashMap();
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_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
if (this.constant_ability_effect.increase_move_cost != null) jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost); else jsonAD.put("min", 0);
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_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("increaseReequipCost", this.constant_ability_effect.increase_reequip_cost); else jsonAD.put("max", 0);
if (this.constant_ability_effect.increase_attack_cost != null) jsonAbility.put("increaseAttackCost", this.constant_ability_effect.increase_attack_cost); jsonAbility.put("increaseAttackDamage", jsonAD);
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.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance); if (this.constant_ability_effect.max_ap_boost != null) jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
jsonAC.put("abilityEffect", jsonAbility); 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);
return jsonAC; if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("increaseReequipCost", this.constant_ability_effect.increase_reequip_cost);
} if (this.constant_ability_effect.increase_attack_cost != null) jsonAbility.put("increaseAttackCost", 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);
@Override if (this.constant_ability_effect.increase_block_chance != null) jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
public String getProjectFilename() { if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
return "actorconditions_"+getProject().name+".json"; jsonAC.put("abilityEffect", jsonAbility);
} }
return jsonAC;
} }
@Override
public String getProjectFilename() {
return "actorconditions_"+getProject().name+".json";
}
}

View File

@@ -1,184 +0,0 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public final class Common {
public static void linkConditions(List<?extends ConditionEffect> conditions, Project proj, GameDataElement backlink) {
if (conditions != null) {
for (ConditionEffect ce : conditions) {
if (ce.condition_id != null) ce.condition = proj.getActorCondition(ce.condition_id);
if (ce.condition != null) ce.condition.addBacklink(backlink);
}
}
}
public static class TimedConditionEffect extends ConditionEffect {
//Available from parsed state
public Integer duration = null;
public Double chance = null;
public TimedConditionEffect createClone() {
TimedConditionEffect cclone = new TimedConditionEffect();
cclone.magnitude = this.magnitude;
cclone.condition_id = this.condition_id;
cclone.condition = this.condition;
cclone.chance = this.chance;
cclone.duration = this.duration;
return cclone;
}
}
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;
}
@SuppressWarnings("rawtypes")
public static ArrayList<TimedConditionEffect> parseTimedConditionEffects(List conditionsSourceJson) {
ArrayList<TimedConditionEffect> conditions_source;
if (conditionsSourceJson != null && !conditionsSourceJson.isEmpty()) {
conditions_source = new ArrayList<>();
for (Object conditionJsonObj : conditionsSourceJson) {
Map conditionJson = (Map) conditionJsonObj;
TimedConditionEffect condition = new TimedConditionEffect();
readConditionEffect(condition, conditionJson);
condition.duration = JSONElement.getInteger((Number) conditionJson.get("duration"));
if (conditionJson.get("chance") != null)
condition.chance = JSONElement.parseChance(conditionJson.get("chance").toString());
conditions_source.add(condition);
}
} else {
conditions_source = null;
}
return conditions_source;
}
@SuppressWarnings("rawtypes")
private static void readConditionEffect(ConditionEffect condition, Map conditionJson) {
condition.condition_id = (String) conditionJson.get("condition");
condition.magnitude = JSONElement.getInteger((Number) conditionJson.get("magnitude"));
}
@SuppressWarnings("rawtypes")
public static Common.DeathEffect parseDeathEffect(Map killEffect) {
Common.DeathEffect kill_effect = new Common.DeathEffect();
readDeathEffect(killEffect, kill_effect);
return kill_effect;
}
@SuppressWarnings("rawtypes")
public static HitEffect parseHitEffect(Map hitEffect) {
Common.HitEffect hit_effect = new Common.HitEffect();
readHitEffect(hitEffect, hit_effect);
return hit_effect;
}
@SuppressWarnings("rawtypes")
public static HitReceivedEffect parseHitReceivedEffect(Map hitReceivedEffect) {
HitReceivedEffect hit_received_effect = new Common.HitReceivedEffect();
readHitEffect(hitReceivedEffect, hit_received_effect);
if (hitReceivedEffect.get("increaseAttackerCurrentHP") != null) {
hit_received_effect.hp_boost_max_target = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentHP")).get("max")));
hit_received_effect.hp_boost_min_target = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentHP")).get("min")));
}
if (hitReceivedEffect.get("increaseAttackerCurrentAP") != null) {
hit_received_effect.ap_boost_max_target = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentAP")).get("max")));
hit_received_effect.ap_boost_min_target = JSONElement.getInteger((Number) (((Map) hitReceivedEffect.get("increaseAttackerCurrentAP")).get("min")));
}
return hit_received_effect;
}
@SuppressWarnings("rawtypes")
private static void readDeathEffect(Map killEffect, DeathEffect kill_effect) {
if (killEffect.get("increaseCurrentHP") != null) {
kill_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentHP")).get("min")));
kill_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentHP")).get("max")));
}
if (killEffect.get("increaseCurrentAP") != null) {
kill_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentAP")).get("min")));
kill_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) killEffect.get("increaseCurrentAP")).get("max")));
}
List conditionsSourceJson = (List) killEffect.get("conditionsSource");
kill_effect.conditions_source = parseTimedConditionEffects(conditionsSourceJson);
}
@SuppressWarnings("rawtypes")
private static void readHitEffect(Map hitEffect, HitEffect hit_effect) {
readDeathEffect(hitEffect, hit_effect);
List conditionsTargetJson = (List) hitEffect.get("conditionsTarget");
hit_effect.conditions_target = parseTimedConditionEffects(conditionsTargetJson);
}
public static class DeathEffect {
//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 static class HitEffect extends DeathEffect {
//Available from parsed state
public List<TimedConditionEffect> conditions_target = null;
}
public static class HitReceivedEffect extends Common.HitEffect {
//Available from parsed state
public Integer hp_boost_min_target = null;
public Integer hp_boost_max_target = null;
public Integer ap_boost_min_target = null;
public Integer ap_boost_max_target = null;
}
public static void copyDeathEffectValues(Common.DeathEffect target, Common.DeathEffect source, GameDataElement backlink) {
target.ap_boost_max = source.ap_boost_max;
target.ap_boost_min = source.ap_boost_min;
target.hp_boost_max = source.hp_boost_max;
target.hp_boost_min = source.hp_boost_min;
if (source.conditions_source != null) {
target.conditions_source = new ArrayList<>();
for (Common.TimedConditionEffect c : source.conditions_source) {
Common.TimedConditionEffect cclone = c.createClone();
if (cclone.condition != null) {
cclone.condition.addBacklink(backlink);
}
target.conditions_source.add(cclone);
}
}
}
public static void copyHitEffectValues(Common.HitEffect target, Common.HitEffect source, GameDataElement backlink) {
copyDeathEffectValues(target, source, backlink);
if (source.conditions_target != null) {
target.conditions_target = new ArrayList<>();
for (Common.TimedConditionEffect c : source.conditions_target) {
Common.TimedConditionEffect cclone = c.createClone();
if (cclone.condition != null) {
cclone.condition.addBacklink(backlink);
}
target.conditions_target.add(cclone);
}
}
}
public static void copyHitReceivedEffectValues(Common.HitReceivedEffect target, Common.HitReceivedEffect source, GameDataElement backlink) {
copyHitEffectValues(target, source, backlink);
target.ap_boost_max_target = source.ap_boost_max_target;
target.ap_boost_min_target = source.ap_boost_min_target;
target.hp_boost_max_target = source.hp_boost_max_target;
target.hp_boost_min_target = source.hp_boost_min_target;
}
}

View File

@@ -1,463 +1,470 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project; import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement.RequirementType; import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement.RequirementType;
import com.gpl.rpg.atcontentstudio.model.maps.TMXMap; import com.gpl.rpg.atcontentstudio.model.maps.TMXMap;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Dialogue extends JSONElement { public class Dialogue extends JSONElement {
private static final long serialVersionUID = -6872164604703134683L; private static final long serialVersionUID = -6872164604703134683L;
//Available from init state //Available from init state
//public String id = null; inherited. //public String id = null; inherited.
public String message = null; public String message = null;
//Available from parsed state; //Available from parsed state;
public List<Reward> rewards = null; public List<Reward> rewards = null;
public List<Reply> replies = null; public List<Reply> replies = null;
public String switch_to_npc_id = null; public String switch_to_npc_id = null;
//Available from linked state; //Available from linked state;
public NPC switch_to_npc = null; public NPC switch_to_npc = null;
public static class Reward { public static class Reward {
//Available from parsed state //Available from parsed state
public RewardType type = null; public RewardType type = null;
public String reward_obj_id = null; public String reward_obj_id = null;
public Integer reward_value = null; public Integer reward_value = null;
public String map_name = null; public String map_name = null;
//Available from linked state //Available from linked state
public GameDataElement reward_obj = null; public GameDataElement reward_obj = null;
public TMXMap map = null; public TMXMap map = null;
public enum RewardType { public enum RewardType {
questProgress, questProgress,
removeQuestProgress, removeQuestProgress,
dropList, dropList,
skillIncrease, skillIncrease,
actorCondition, actorCondition,
actorConditionImmunity, actorConditionImmunity,
alignmentChange, alignmentChange,
alignmentSet, alignmentSet,
giveItem, giveItem,
createTimer, createTimer,
spawnAll, spawnAll,
removeSpawnArea, removeSpawnArea,
deactivateSpawnArea, deactivateSpawnArea,
activateMapObjectGroup, activateMapObjectGroup,
deactivateMapObjectGroup, deactivateMapObjectGroup,
changeMapFilter, changeMapFilter,
mapchange mapchange
} }
} }
public static class Reply { public static class Reply {
public static final String GO_NEXT_TEXT = "N"; public static final String GO_NEXT_TEXT = "N";
public static final String SHOP_PHRASE_ID = "S"; public static final String SHOP_PHRASE_ID = "S";
public static final String FIGHT_PHRASE_ID = "F"; public static final String FIGHT_PHRASE_ID = "F";
public static final String EXIT_PHRASE_ID = "X"; public static final String EXIT_PHRASE_ID = "X";
public static final String REMOVE_PHRASE_ID = "R"; 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}); 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 //Available from parsed state
public String text = null; public String text = null;
public String next_phrase_id = null; public String next_phrase_id = null;
public List<Requirement> requirements = null; public List<Requirement> requirements = null;
//Available from linked state //Available from linked state
public Dialogue next_phrase = null; public Dialogue next_phrase = null;
} }
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+id; return (needsSaving() ? "*" : "")+id;
} }
public static String getStaticDesc() { public static String getStaticDesc() {
return "Dialogues"; return "Dialogues";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Dialogue> category) { public static void fromJson(File jsonFile, GameDataCategory<Dialogue> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
FileReader reader = null; FileReader reader = null;
try { try {
reader = new FileReader(jsonFile); reader = new FileReader(jsonFile);
List dialogues = (List) parser.parse(reader); List dialogues = (List) parser.parse(reader);
for (Object obj : dialogues) { for (Object obj : dialogues) {
Map dialogueJson = (Map)obj; Map dialogueJson = (Map)obj;
Dialogue dialogue = fromJson(dialogueJson); Dialogue dialogue = fromJson(dialogueJson);
dialogue.jsonFile = jsonFile; dialogue.jsonFile = jsonFile;
dialogue.parent = category; dialogue.parent = category;
if (dialogue.getDataType() == GameSource.Type.created || dialogue.getDataType() == GameSource.Type.altered) { if (dialogue.getDataType() == GameSource.Type.created || dialogue.getDataType() == GameSource.Type.altered) {
dialogue.writable = true; dialogue.writable = true;
} }
category.add(dialogue); category.add(dialogue);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (reader != null) if (reader != null)
try { try {
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Dialogue fromJson(String jsonString) throws ParseException { public static Dialogue fromJson(String jsonString) throws ParseException {
Map dialogueJson = (Map) new JSONParser().parse(jsonString); Map dialogueJson = (Map) new JSONParser().parse(jsonString);
Dialogue dialogue = fromJson(dialogueJson); Dialogue dialogue = fromJson(dialogueJson);
dialogue.parse(dialogueJson); dialogue.parse(dialogueJson);
return dialogue; return dialogue;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Dialogue fromJson(Map dialogueJson) { public static Dialogue fromJson(Map dialogueJson) {
Dialogue dialogue = new Dialogue(); Dialogue dialogue = new Dialogue();
dialogue.id = (String) dialogueJson.get("id"); dialogue.id = (String) dialogueJson.get("id");
dialogue.message = (String) dialogueJson.get("message"); dialogue.message = (String) dialogueJson.get("message");
return dialogue; return dialogue;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map dialogueJson) { public void parse(Map dialogueJson) {
this.switch_to_npc_id = (String) dialogueJson.get("switchToNPC"); this.switch_to_npc_id = (String) dialogueJson.get("switchToNPC");
List repliesJson = (List) dialogueJson.get("replies"); List repliesJson = (List) dialogueJson.get("replies");
if (repliesJson != null && !repliesJson.isEmpty()) { if (repliesJson != null && !repliesJson.isEmpty()) {
this.replies = new ArrayList<Dialogue.Reply>(); this.replies = new ArrayList<Dialogue.Reply>();
for (Object replyJsonObj : repliesJson) { for (Object replyJsonObj : repliesJson) {
Map replyJson = (Map)replyJsonObj; Map replyJson = (Map)replyJsonObj;
Reply reply = new Reply(); Reply reply = new Reply();
reply.text = (String) replyJson.get("text"); reply.text = (String) replyJson.get("text");
reply.next_phrase_id = (String) replyJson.get("nextPhraseID"); reply.next_phrase_id = (String) replyJson.get("nextPhraseID");
List requirementsJson = (List) replyJson.get("requires"); List requirementsJson = (List) replyJson.get("requires");
if (requirementsJson != null && !requirementsJson.isEmpty()) { if (requirementsJson != null && !requirementsJson.isEmpty()) {
reply.requirements = new ArrayList<Requirement>(); reply.requirements = new ArrayList<Requirement>();
for (Object requirementJsonObj : requirementsJson) { for (Object requirementJsonObj : requirementsJson) {
Map requirementJson = (Map) requirementJsonObj; Map requirementJson = (Map) requirementJsonObj;
Requirement requirement = new Requirement(); Requirement requirement = new Requirement();
requirement.jsonFile = this.jsonFile; requirement.jsonFile = this.jsonFile;
requirement.parent = this; requirement.parent = this;
if (requirementJson.get("requireType") != null) requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType")); if (requirementJson.get("requireType") != null) requirement.type = RequirementType.valueOf((String) requirementJson.get("requireType"));
requirement.required_obj_id = (String) requirementJson.get("requireID"); requirement.required_obj_id = (String) requirementJson.get("requireID");
if (requirementJson.get("value") != null) requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString())); if (requirementJson.get("value") != null) requirement.required_value = JSONElement.getInteger(Integer.parseInt(requirementJson.get("value").toString()));
if (requirementJson.get("negate") != null) requirement.negated = (Boolean) requirementJson.get("negate"); if (requirementJson.get("negate") != null) requirement.negated = (Boolean) requirementJson.get("negate");
requirement.state = State.parsed; requirement.state = State.parsed;
reply.requirements.add(requirement); reply.requirements.add(requirement);
} }
} }
this.replies.add(reply); this.replies.add(reply);
} }
} }
List rewardsJson = (List) dialogueJson.get("rewards"); List rewardsJson = (List) dialogueJson.get("rewards");
if (rewardsJson != null && !rewardsJson.isEmpty()) { if (rewardsJson != null && !rewardsJson.isEmpty()) {
this.rewards = new ArrayList<Dialogue.Reward>(); this.rewards = new ArrayList<Dialogue.Reward>();
for (Object rewardJsonObj : rewardsJson) { for (Object rewardJsonObj : rewardsJson) {
Map rewardJson = (Map)rewardJsonObj; Map rewardJson = (Map)rewardJsonObj;
Reward reward = new Reward(); Reward reward = new Reward();
if (rewardJson.get("rewardType") != null) reward.type = Reward.RewardType.valueOf((String) rewardJson.get("rewardType")); 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("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("value") != null) reward.reward_value = JSONElement.getInteger((Number) rewardJson.get("value"));
if (rewardJson.get("mapName") != null) reward.map_name = (String) rewardJson.get("mapName"); if (rewardJson.get("mapName") != null) reward.map_name = (String) rewardJson.get("mapName");
this.rewards.add(reward); this.rewards.add(reward);
} }
} }
this.state = State.parsed; this.state = State.parsed;
} }
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
ensureParseIfNeeded(); }
Project proj = getProject(); if (this.state == State.init) {
if (proj == null) { //Not parsed yet.
Notification.addError("Error linking dialogue "+id+". No parent project found."); this.parse();
return; } else if (this.state == State.linked) {
} //Already linked.
if (this.switch_to_npc_id != null) this.switch_to_npc = proj.getNPC(this.switch_to_npc_id); return;
if (this.switch_to_npc != null) this.switch_to_npc.addBacklink(this); }
Project proj = getProject();
if (replies != null) { if (proj == null) {
for (Reply reply : replies) { Notification.addError("Error linking dialogue "+id+". No parent project found.");
if (reply.next_phrase_id != null) { return;
if (!Reply.KEY_PHRASE_ID.contains(reply.next_phrase_id)) { }
reply.next_phrase = proj.getDialogue(reply.next_phrase_id); 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 (reply.next_phrase != null) reply.next_phrase.addBacklink(this); if (replies != null) {
if (reply.requirements != null) { for (Reply reply : replies) {
for (Requirement requirement : reply.requirements) { if (reply.next_phrase_id != null) {
requirement.link(); if (!Reply.KEY_PHRASE_ID.contains(reply.next_phrase_id)) {
} reply.next_phrase = proj.getDialogue(reply.next_phrase_id);
} }
} }
} if (reply.next_phrase != null) reply.next_phrase.addBacklink(this);
if (rewards != null) { if (reply.requirements != null) {
for (Reward reward : rewards) { for (Requirement requirement : reply.requirements) {
if (reward.reward_obj_id != null) { requirement.link();
switch (reward.type) { }
case activateMapObjectGroup: }
case deactivateMapObjectGroup: }
case spawnAll: }
case removeSpawnArea: if (rewards != null) {
case deactivateSpawnArea: for (Reward reward : rewards) {
case changeMapFilter: if (reward.reward_obj_id != null) {
case mapchange: switch (reward.type) {
reward.map = reward.map_name != null ? proj.getMap(reward.map_name) : null; case activateMapObjectGroup:
break; case deactivateMapObjectGroup:
case actorCondition: case spawnAll:
case actorConditionImmunity: case removeSpawnArea:
reward.reward_obj = proj.getActorCondition(reward.reward_obj_id); case deactivateSpawnArea:
break; case changeMapFilter:
case alignmentChange: case mapchange:
case alignmentSet: reward.map = reward.map_name != null ? proj.getMap(reward.map_name) : null;
//Nothing to do (yet ?). break;
break; case actorCondition:
case createTimer: case actorConditionImmunity:
//Nothing to do. reward.reward_obj = proj.getActorCondition(reward.reward_obj_id);
break; break;
case dropList: case alignmentChange:
reward.reward_obj = proj.getDroplist(reward.reward_obj_id); case alignmentSet:
break; //Nothing to do (yet ?).
case giveItem: break;
reward.reward_obj = proj.getItem(reward.reward_obj_id); case createTimer:
break; //Nothing to do.
case questProgress: break;
case removeQuestProgress: case dropList:
reward.reward_obj = proj.getQuest(reward.reward_obj_id); reward.reward_obj = proj.getDroplist(reward.reward_obj_id);
if (reward.reward_obj != null && reward.reward_value != null) { break;
QuestStage stage = ((Quest)reward.reward_obj).getStage(reward.reward_value); case giveItem:
if (stage != null) { reward.reward_obj = proj.getItem(reward.reward_obj_id);
stage.addBacklink(this); break;
} case questProgress:
} case removeQuestProgress:
break; reward.reward_obj = proj.getQuest(reward.reward_obj_id);
case skillIncrease: if (reward.reward_obj != null && reward.reward_value != null) {
//Nothing to do (yet ?). QuestStage stage = ((Quest)reward.reward_obj).getStage(reward.reward_value);
break; if (stage != null) {
} stage.addBacklink(this);
if (reward.reward_obj != null) reward.reward_obj.addBacklink(this); }
if (reward.map != null) reward.map.addBacklink(this); }
} break;
} case skillIncrease:
} //Nothing to do (yet ?).
break;
this.state = State.linked; }
} if (reward.reward_obj != null) reward.reward_obj.addBacklink(this);
if (reward.map != null) reward.map.addBacklink(this);
}
}
@Override }
public Image getIcon() {
return DefaultIcons.getDialogueIcon(); this.state = State.linked;
} }
public Image getImage() {
return DefaultIcons.getDialogueImage(); @Override
} public Image getIcon() {
return DefaultIcons.getDialogueIcon();
@Override }
public GameDataElement clone() {
Dialogue clone = new Dialogue();
clone.jsonFile = this.jsonFile; public Image getImage() {
clone.state = this.state; return DefaultIcons.getDialogueImage();
clone.id = this.id; }
clone.message = this.message;
clone.switch_to_npc_id = this.switch_to_npc_id; @Override
clone.switch_to_npc = this.switch_to_npc; public GameDataElement clone() {
if (clone.switch_to_npc != null) { Dialogue clone = new Dialogue();
clone.switch_to_npc.addBacklink(clone); clone.jsonFile = this.jsonFile;
} clone.state = this.state;
if (this.rewards != null) { clone.id = this.id;
clone.rewards = new ArrayList<Dialogue.Reward>(); clone.message = this.message;
for (Reward r : this.rewards) { clone.switch_to_npc_id = this.switch_to_npc_id;
Reward rclone = new Reward(); clone.switch_to_npc = this.switch_to_npc;
rclone.type = r.type; if (clone.switch_to_npc != null) {
rclone.reward_obj_id = r.reward_obj_id; clone.switch_to_npc.addBacklink(clone);
rclone.reward_value = r.reward_value; }
rclone.reward_obj = r.reward_obj; if (this.rewards != null) {
if (rclone.reward_obj != null) { clone.rewards = new ArrayList<Dialogue.Reward>();
rclone.reward_obj.addBacklink(clone); for (Reward r : this.rewards) {
} Reward rclone = new Reward();
rclone.map = r.map; rclone.type = r.type;
rclone.map_name = r.map_name; rclone.reward_obj_id = r.reward_obj_id;
if (rclone.map != null) { rclone.reward_value = r.reward_value;
rclone.map.addBacklink(clone); rclone.reward_obj = r.reward_obj;
} if (rclone.reward_obj != null) {
clone.rewards.add(rclone); rclone.reward_obj.addBacklink(clone);
} }
} rclone.map = r.map;
if (this.replies != null) { rclone.map_name = r.map_name;
clone.replies = new ArrayList<Dialogue.Reply>(); if (rclone.map != null) {
for (Reply r : this.replies) { rclone.map.addBacklink(clone);
Reply rclone = new Reply(); }
rclone.text = r.text; clone.rewards.add(rclone);
rclone.next_phrase_id = r.next_phrase_id; }
rclone.next_phrase = r.next_phrase; }
if (rclone.next_phrase != null) { if (this.replies != null) {
rclone.next_phrase.addBacklink(clone); clone.replies = new ArrayList<Dialogue.Reply>();
} for (Reply r : this.replies) {
if (r.requirements != null) { Reply rclone = new Reply();
rclone.requirements = new ArrayList<Requirement>(); rclone.text = r.text;
for (Requirement req : r.requirements) { rclone.next_phrase_id = r.next_phrase_id;
//Special clone method, as Requirement is a special GDE, hidden from the project tree. rclone.next_phrase = r.next_phrase;
rclone.requirements.add((Requirement) req.clone(clone)); if (rclone.next_phrase != null) {
} rclone.next_phrase.addBacklink(clone);
} }
clone.replies.add(rclone); if (r.requirements != null) {
} rclone.requirements = new ArrayList<Requirement>();
} for (Requirement req : r.requirements) {
return clone; //Special clone method, as Requirement is a special GDE, hidden from the project tree.
} rclone.requirements.add((Requirement) req.clone(clone));
}
@Override }
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { clone.replies.add(rclone);
if (switch_to_npc == oldOne) { }
oldOne.removeBacklink(this); }
switch_to_npc = (NPC) newOne; return clone;
if (newOne != null) newOne.addBacklink(this); }
} else {
if (replies != null) { @Override
for (Reply r : replies) { public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (r.next_phrase == oldOne) { if (switch_to_npc == oldOne) {
oldOne.removeBacklink(this); oldOne.removeBacklink(this);
r.next_phrase = (Dialogue) newOne; switch_to_npc = (NPC) newOne;
if (newOne != null) newOne.addBacklink(this); if (newOne != null) newOne.addBacklink(this);
} } else {
if (r.requirements != null) { if (replies != null) {
for (Requirement req : r.requirements) { for (Reply r : replies) {
req.elementChanged(oldOne, newOne); if (r.next_phrase == oldOne) {
} oldOne.removeBacklink(this);
} r.next_phrase = (Dialogue) newOne;
} if (newOne != null) newOne.addBacklink(this);
} }
if (rewards != null) { if (r.requirements != null) {
for (Reward r : rewards) { for (Requirement req : r.requirements) {
if (r.reward_obj == oldOne) { req.elementChanged(oldOne, newOne);
oldOne.removeBacklink(this); }
r.reward_obj = newOne; }
if (newOne != null) newOne.addBacklink(this); }
} }
if (oldOne instanceof QuestStage) { if (rewards != null) {
if (r.reward_obj != null && r.reward_obj.equals(oldOne.parent) && r.reward_value != null && r.reward_value.equals(((QuestStage) oldOne).progress)) { for (Reward r : rewards) {
oldOne.removeBacklink((GameDataElement) this); if (r.reward_obj == oldOne) {
if (newOne != null) newOne.addBacklink((GameDataElement) this); oldOne.removeBacklink(this);
} r.reward_obj = newOne;
} if (newOne != null) newOne.addBacklink(this);
} }
} if (oldOne instanceof QuestStage) {
} if (r.reward_obj != null && r.reward_obj.equals(oldOne.parent) && r.reward_value != null && r.reward_value.equals(((QuestStage) oldOne).progress)) {
} oldOne.removeBacklink((GameDataElement) this);
if (newOne != null) newOne.addBacklink((GameDataElement) this);
@SuppressWarnings({ "rawtypes", "unchecked" }) }
@Override }
public Map toJson() { }
Map dialogueJson = new LinkedHashMap(); }
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); @SuppressWarnings({ "rawtypes", "unchecked" })
} else if (this.switch_to_npc_id != null) { @Override
dialogueJson.put("switchToNPC", this.switch_to_npc_id); public Map toJson() {
} Map dialogueJson = new LinkedHashMap();
if (this.replies != null) { dialogueJson.put("id", this.id);
List repliesJson = new ArrayList(); if (this.message != null) dialogueJson.put("message", this.message);
dialogueJson.put("replies", repliesJson); if (this.switch_to_npc != null) {
for (Reply reply : this.replies){ dialogueJson.put("switchToNPC", this.switch_to_npc.id);
Map replyJson = new LinkedHashMap(); } else if (this.switch_to_npc_id != null) {
repliesJson.add(replyJson); dialogueJson.put("switchToNPC", this.switch_to_npc_id);
if (reply.text != null) replyJson.put("text", reply.text); }
if (reply.next_phrase != null) { if (this.replies != null) {
replyJson.put("nextPhraseID", reply.next_phrase.id); List repliesJson = new ArrayList();
} else if (reply.next_phrase_id != null) { dialogueJson.put("replies", repliesJson);
replyJson.put("nextPhraseID", reply.next_phrase_id); for (Reply reply : this.replies){
} Map replyJson = new LinkedHashMap();
if (reply.requirements != null) { repliesJson.add(replyJson);
List requirementsJson = new ArrayList(); if (reply.text != null) replyJson.put("text", reply.text);
replyJson.put("requires", requirementsJson); if (reply.next_phrase != null) {
for (Requirement requirement : reply.requirements) { replyJson.put("nextPhraseID", reply.next_phrase.id);
Map requirementJson = new LinkedHashMap(); } else if (reply.next_phrase_id != null) {
requirementsJson.add(requirementJson); replyJson.put("nextPhraseID", reply.next_phrase_id);
if (requirement.type != null) requirementJson.put("requireType", requirement.type.toString()); }
if (requirement.required_obj != null) { if (reply.requirements != null) {
requirementJson.put("requireID", requirement.required_obj.id); List requirementsJson = new ArrayList();
} else if (requirement.required_obj_id != null) { replyJson.put("requires", requirementsJson);
requirementJson.put("requireID", requirement.required_obj_id); for (Requirement requirement : reply.requirements) {
} Map requirementJson = new LinkedHashMap();
if (requirement.required_value != null) { requirementsJson.add(requirementJson);
requirementJson.put("value", requirement.required_value); if (requirement.type != null) requirementJson.put("requireType", requirement.type.toString());
} if (requirement.required_obj != null) {
if (requirement.negated != null) requirementJson.put("negate", requirement.negated); 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) {
if (this.rewards != null) { requirementJson.put("value", requirement.required_value);
List rewardsJson = new ArrayList(); }
dialogueJson.put("rewards", rewardsJson); if (requirement.negated != null) requirementJson.put("negate", requirement.negated);
for (Reward reward : this.rewards) { }
Map rewardJson = new LinkedHashMap(); }
rewardsJson.add(rewardJson); }
if (reward.type != null) rewardJson.put("rewardType", reward.type.toString()); }
if (reward.reward_obj != null) { if (this.rewards != null) {
rewardJson.put("rewardID", reward.reward_obj.id); List rewardsJson = new ArrayList();
} else if (reward.reward_obj_id != null) { dialogueJson.put("rewards", rewardsJson);
rewardJson.put("rewardID", reward.reward_obj_id); for (Reward reward : this.rewards) {
} Map rewardJson = new LinkedHashMap();
if (reward.reward_value != null) rewardJson.put("value", reward.reward_value); rewardsJson.add(rewardJson);
if (reward.map != null) { if (reward.type != null) rewardJson.put("rewardType", reward.type.toString());
rewardJson.put("mapName", reward.map.id); if (reward.reward_obj != null) {
} else if (reward.map_name != null) rewardJson.put("mapName", reward.map_name); rewardJson.put("rewardID", reward.reward_obj.id);
} } else if (reward.reward_obj_id != null) {
} rewardJson.put("rewardID", reward.reward_obj_id);
return dialogueJson; }
} if (reward.reward_value != null) rewardJson.put("value", reward.reward_value);
if (reward.map != null) {
@Override rewardJson.put("mapName", reward.map.id);
public String getProjectFilename() { } else if (reward.map_name != null) rewardJson.put("mapName", reward.map_name);
return "conversationlist_"+getProject().name+".json"; }
} }
return dialogueJson;
} }
@Override
public String getProjectFilename() {
return "conversationlist_"+getProject().name+".json";
}
}

View File

@@ -1,235 +1,242 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.Project; import com.gpl.rpg.atcontentstudio.model.Project;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Droplist extends JSONElement { public class Droplist extends JSONElement {
private static final long serialVersionUID = -2903944916807382571L; private static final long serialVersionUID = -2903944916807382571L;
//Available from init state //Available from init state
//public String id = null; inherited. //public String id = null; inherited.
//Available from parsed state; //Available from parsed state;
public List<DroppedItem> dropped_items = null; public List<DroppedItem> dropped_items = null;
//Available from linked state; //Available from linked state;
//None //None
public static class DroppedItem { public static class DroppedItem {
//Available from parsed state; //Available from parsed state;
public String item_id = null; public String item_id = null;
public String chance = null; public String chance = null;
public Integer quantity_min = null; public Integer quantity_min = null;
public Integer quantity_max = null; public Integer quantity_max = null;
//Available from linked state; //Available from linked state;
public Item item = null; public Item item = null;
} }
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+id; return (needsSaving() ? "*" : "")+id;
} }
public static String getStaticDesc() { public static String getStaticDesc() {
return "Droplists"; return "Droplists";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Droplist> category) { public static void fromJson(File jsonFile, GameDataCategory<Droplist> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
FileReader reader = null; FileReader reader = null;
try { try {
reader = new FileReader(jsonFile); reader = new FileReader(jsonFile);
List droplists = (List) parser.parse(reader); List droplists = (List) parser.parse(reader);
for (Object obj : droplists) { for (Object obj : droplists) {
Map droplistJson = (Map)obj; Map droplistJson = (Map)obj;
Droplist droplist = fromJson(droplistJson); Droplist droplist = fromJson(droplistJson);
droplist.jsonFile = jsonFile; droplist.jsonFile = jsonFile;
droplist.parent = category; droplist.parent = category;
if (droplist.getDataType() == GameSource.Type.created || droplist.getDataType() == GameSource.Type.altered) { if (droplist.getDataType() == GameSource.Type.created || droplist.getDataType() == GameSource.Type.altered) {
droplist.writable = true; droplist.writable = true;
} }
category.add(droplist); category.add(droplist);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (reader != null) if (reader != null)
try { try {
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Droplist fromJson(String jsonString) throws ParseException { public static Droplist fromJson(String jsonString) throws ParseException {
Map droplistJson = (Map) new JSONParser().parse(jsonString); Map droplistJson = (Map) new JSONParser().parse(jsonString);
Droplist droplist = fromJson(droplistJson); Droplist droplist = fromJson(droplistJson);
droplist.parse(droplistJson); droplist.parse(droplistJson);
return droplist; return droplist;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Droplist fromJson(Map droplistJson) { public static Droplist fromJson(Map droplistJson) {
Droplist droplist = new Droplist(); Droplist droplist = new Droplist();
droplist.id = (String) droplistJson.get("id"); droplist.id = (String) droplistJson.get("id");
return droplist; return droplist;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map droplistJson) { public void parse(Map droplistJson) {
List droppedItemsJson = (List) droplistJson.get("items"); List droppedItemsJson = (List) droplistJson.get("items");
if (droppedItemsJson != null && !droppedItemsJson.isEmpty()) { if (droppedItemsJson != null && !droppedItemsJson.isEmpty()) {
this.dropped_items = new ArrayList<DroppedItem>(); this.dropped_items = new ArrayList<DroppedItem>();
for (Object droppedItemJsonObj : droppedItemsJson) { for (Object droppedItemJsonObj : droppedItemsJson) {
Map droppedItemJson = (Map)droppedItemJsonObj; Map droppedItemJson = (Map)droppedItemJsonObj;
DroppedItem droppedItem = new DroppedItem(); DroppedItem droppedItem = new DroppedItem();
droppedItem.item_id = (String) droppedItemJson.get("itemID"); droppedItem.item_id = (String) droppedItemJson.get("itemID");
//if (droppedItemJson.get("chance") != null) droppedItem.chance = JSONElement.parseChance(droppedItemJson.get("chance").toString()); //if (droppedItemJson.get("chance") != null) droppedItem.chance = JSONElement.parseChance(droppedItemJson.get("chance").toString());
droppedItem.chance = (String) droppedItemJson.get("chance"); droppedItem.chance = (String) droppedItemJson.get("chance");
Map droppedItemQtyJson = (Map) droppedItemJson.get("quantity"); Map droppedItemQtyJson = (Map) droppedItemJson.get("quantity");
if (droppedItemQtyJson != null) { if (droppedItemQtyJson != null) {
droppedItem.quantity_min = JSONElement.getInteger((Number) droppedItemQtyJson.get("min")); droppedItem.quantity_min = JSONElement.getInteger((Number) droppedItemQtyJson.get("min"));
droppedItem.quantity_max = JSONElement.getInteger((Number) droppedItemQtyJson.get("max")); droppedItem.quantity_max = JSONElement.getInteger((Number) droppedItemQtyJson.get("max"));
} }
this.dropped_items.add(droppedItem); this.dropped_items.add(droppedItem);
} }
} }
this.state = State.parsed; this.state = State.parsed;
} }
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
ensureParseIfNeeded(); }
Project proj = getProject(); if (this.state == State.init) {
if (proj == null) { //Not parsed yet.
Notification.addError("Error linking droplist "+id+". No parent project found."); this.parse();
return; } else if (this.state == State.linked) {
} //Already linked.
if (dropped_items != null) { return;
for (DroppedItem droppedItem : dropped_items) { }
if (droppedItem.item_id != null) droppedItem.item = proj.getItem(droppedItem.item_id); Project proj = getProject();
if (droppedItem.item != null) droppedItem.item.addBacklink(this); if (proj == null) {
} Notification.addError("Error linking droplist "+id+". No parent project found.");
} return;
this.state = State.linked; }
} 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);
public static Image getImage() { }
return DefaultIcons.getDroplistImage(); }
} this.state = State.linked;
}
@Override
public Image getIcon() {
return DefaultIcons.getDroplistIcon();
} public static Image getImage() {
return DefaultIcons.getDroplistImage();
@Override }
public GameDataElement clone() {
Droplist clone = new Droplist(); @Override
clone.jsonFile = this.jsonFile; public Image getIcon() {
clone.state = this.state; return DefaultIcons.getDroplistIcon();
clone.id = this.id; }
if (this.dropped_items != null) {
clone.dropped_items = new ArrayList<Droplist.DroppedItem>(); @Override
for (DroppedItem di : this.dropped_items) { public GameDataElement clone() {
DroppedItem diclone = new DroppedItem(); Droplist clone = new Droplist();
diclone.chance = di.chance; clone.jsonFile = this.jsonFile;
diclone.item_id = di.item_id; clone.state = this.state;
diclone.quantity_min = di.quantity_min; clone.id = this.id;
diclone.quantity_max = di.quantity_max; if (this.dropped_items != null) {
diclone.item = di.item; clone.dropped_items = new ArrayList<Droplist.DroppedItem>();
if (diclone.item != null) { for (DroppedItem di : this.dropped_items) {
diclone.item.addBacklink(clone); DroppedItem diclone = new DroppedItem();
} diclone.chance = di.chance;
clone.dropped_items.add(diclone); diclone.item_id = di.item_id;
} diclone.quantity_min = di.quantity_min;
} diclone.quantity_max = di.quantity_max;
return clone; diclone.item = di.item;
} if (diclone.item != null) {
diclone.item.addBacklink(clone);
@Override }
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { clone.dropped_items.add(diclone);
if (dropped_items != null) { }
for (DroppedItem di : dropped_items) { }
if (di.item == oldOne) { return clone;
oldOne.removeBacklink(this); }
di.item = (Item) newOne;
if (newOne != null) newOne.addBacklink(this); @Override
} public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
} if (dropped_items != null) {
} for (DroppedItem di : dropped_items) {
} if (di.item == oldOne) {
oldOne.removeBacklink(this);
@SuppressWarnings({ "rawtypes", "unchecked" }) di.item = (Item) newOne;
@Override if (newOne != null) newOne.addBacklink(this);
public Map toJson() { }
Map droplistJson = new LinkedHashMap(); }
droplistJson.put("id", this.id); }
if (this.dropped_items != null) { }
List droppedItemsJson = new ArrayList();
droplistJson.put("items", droppedItemsJson); @SuppressWarnings({ "rawtypes", "unchecked" })
for (DroppedItem droppedItem : this.dropped_items) { @Override
Map droppedItemJson = new LinkedHashMap(); public Map toJson() {
droppedItemsJson.add(droppedItemJson); Map droplistJson = new LinkedHashMap();
if (droppedItem.item != null) { droplistJson.put("id", this.id);
droppedItemJson.put("itemID", droppedItem.item.id); if (this.dropped_items != null) {
} else if (droppedItem.item_id != null) { List droppedItemsJson = new ArrayList();
droppedItemJson.put("itemID", droppedItem.item_id); droplistJson.put("items", droppedItemsJson);
} for (DroppedItem droppedItem : this.dropped_items) {
//if (droppedItem.chance != null) droppedItemJson.put("chance", JSONElement.printJsonChance(droppedItem.chance)); Map droppedItemJson = new LinkedHashMap();
if (droppedItem.chance != null) droppedItemJson.put("chance", droppedItem.chance); droppedItemsJson.add(droppedItemJson);
if (droppedItem.quantity_min != null || droppedItem.quantity_max != null) { if (droppedItem.item != null) {
Map quantityJson = new LinkedHashMap(); droppedItemJson.put("itemID", droppedItem.item.id);
droppedItemJson.put("quantity", quantityJson); } else if (droppedItem.item_id != null) {
if (droppedItem.quantity_min != null) quantityJson.put("min", droppedItem.quantity_min); droppedItemJson.put("itemID", droppedItem.item_id);
else quantityJson.put("min", 0); }
if (droppedItem.quantity_max != null) quantityJson.put("max", droppedItem.quantity_max); //if (droppedItem.chance != null) droppedItemJson.put("chance", JSONElement.printJsonChance(droppedItem.chance));
else quantityJson.put("max", 0); if (droppedItem.chance != null) droppedItemJson.put("chance", droppedItem.chance);
} if (droppedItem.quantity_min != null || droppedItem.quantity_max != null) {
} Map quantityJson = new LinkedHashMap();
} droppedItemJson.put("quantity", quantityJson);
return droplistJson; 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);
@Override }
public String getProjectFilename() { }
return "droplists_"+getProject().name+".json"; }
} return droplistJson;
}
}
@Override
public String getProjectFilename() {
return "droplists_"+getProject().name+".json";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,322 +1,329 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ItemCategory extends JSONElement { public class ItemCategory extends JSONElement {
private static final long serialVersionUID = -348864002519568300L; 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_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_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_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_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_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_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_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_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 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_image = null;
public static Image no_slot_icon = null; public static Image no_slot_icon = null;
public static Image body_image = null; public static Image body_image = null;
public static Image body_icon = null; public static Image body_icon = null;
public static Image feet_image = null; public static Image feet_image = null;
public static Image feet_icon = null; public static Image feet_icon = null;
public static Image hand_image = null; public static Image hand_image = null;
public static Image hand_icon = null; public static Image hand_icon = null;
public static Image head_image = null; public static Image head_image = null;
public static Image head_icon = null; public static Image head_icon = null;
public static Image neck_image = null; public static Image neck_image = null;
public static Image neck_icon = null; public static Image neck_icon = null;
public static Image ring_image = null; public static Image ring_image = null;
public static Image ring_icon = null; public static Image ring_icon = null;
public static Image shield_image = null; public static Image shield_image = null;
public static Image shield_icon = null; public static Image shield_icon = null;
public static Image weapon_image = null; public static Image weapon_image = null;
public static Image weapon_icon = null; public static Image weapon_icon = null;
//Available from init state //Available from init state
//public String id = null; inherited. //public String id = null; inherited.
public String name = null; public String name = null;
public InventorySlot slot = null; public InventorySlot slot = null;
//Available from parsed state //Available from parsed state
public ActionType action_type = null; public ActionType action_type = null;
public Size size = null; public Size size = null;
//Available from linked state //Available from linked state
//None //None
public static enum ActionType { public static enum ActionType {
none, none,
use, use,
equip equip
} }
public static enum Size { public static enum Size {
none, none,
light, light,
std, std,
large large
} }
public static enum InventorySlot { public static enum InventorySlot {
weapon, weapon,
shield, shield,
head, head,
body, body,
hand, hand,
feet, feet,
neck, neck,
leftring, leftring,
rightring rightring
} }
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")"; return (needsSaving() ? "*" : "")+name+" ("+id+")";
} }
public static String getStaticDesc() { public static String getStaticDesc() {
return "Item categories"; return "Item categories";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<ItemCategory> category) { public static void fromJson(File jsonFile, GameDataCategory<ItemCategory> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
FileReader reader = null; FileReader reader = null;
try { try {
reader = new FileReader(jsonFile); reader = new FileReader(jsonFile);
List itemCategories = (List) parser.parse(reader); List itemCategories = (List) parser.parse(reader);
for (Object obj : itemCategories) { for (Object obj : itemCategories) {
Map itemCatJson = (Map)obj; Map itemCatJson = (Map)obj;
ItemCategory itemCat = fromJson(itemCatJson); ItemCategory itemCat = fromJson(itemCatJson);
itemCat.jsonFile = jsonFile; itemCat.jsonFile = jsonFile;
itemCat.parent = category; itemCat.parent = category;
if (itemCat.getDataType() == GameSource.Type.created || itemCat.getDataType() == GameSource.Type.altered) { if (itemCat.getDataType() == GameSource.Type.created || itemCat.getDataType() == GameSource.Type.altered) {
itemCat.writable = true; itemCat.writable = true;
} }
category.add(itemCat); category.add(itemCat);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (reader != null) if (reader != null)
try { try {
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static ItemCategory fromJson(String jsonString) throws ParseException { public static ItemCategory fromJson(String jsonString) throws ParseException {
Map itemCatJson = (Map) new JSONParser().parse(jsonString); Map itemCatJson = (Map) new JSONParser().parse(jsonString);
ItemCategory item = fromJson(itemCatJson); ItemCategory item = fromJson(itemCatJson);
item.parse(itemCatJson); item.parse(itemCatJson);
return item; return item;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static ItemCategory fromJson(Map itemCatJson) { public static ItemCategory fromJson(Map itemCatJson) {
ItemCategory itemCat = new ItemCategory(); ItemCategory itemCat = new ItemCategory();
itemCat.id = (String) itemCatJson.get("id"); itemCat.id = (String) itemCatJson.get("id");
itemCat.name = (String) itemCatJson.get("name"); itemCat.name = (String) itemCatJson.get("name");
if (itemCatJson.get("inventorySlot") != null) itemCat.slot = InventorySlot.valueOf((String) itemCatJson.get("inventorySlot")); if (itemCatJson.get("inventorySlot") != null) itemCat.slot = InventorySlot.valueOf((String) itemCatJson.get("inventorySlot"));
return itemCat; return itemCat;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map itemCatJson) { public void parse(Map itemCatJson) {
if (itemCatJson.get("actionType") != null) action_type = ActionType.valueOf((String) itemCatJson.get("actionType")); 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")); if (itemCatJson.get("size") != null) size = Size.valueOf((String) itemCatJson.get("size"));
this.state = State.parsed; this.state = State.parsed;
} }
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
ensureParseIfNeeded(); }
if (this.state == State.init) {
//Nothing to link to :D //Not parsed yet.
this.state = State.linked; this.parse();
} } else if (this.state == State.linked) {
//Already linked.
@Override return;
public Image getIcon() { }
return getIcon(this.slot);
} //Nothing to link to :D
this.state = State.linked;
public Image getImage() { }
return getImage(this.slot);
} @Override
public Image getIcon() {
public static Image getImage(InventorySlot slot) { return getIcon(this.slot);
if (slot == null) { }
return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image");
} public Image getImage() {
switch (slot) { return getImage(this.slot);
case body: }
return getImage(ICON_BODY_RES, body_image, "body_image");
case feet: public static Image getImage(InventorySlot slot) {
return getImage(ICON_FEET_RES, feet_image, "feet_image"); if (slot == null) {
case hand: return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image");
return getImage(ICON_HAND_RES, hand_image, "hand_image"); }
case head: switch (slot) {
return getImage(ICON_HEAD_RES, head_image, "head_image"); case body:
case leftring: return getImage(ICON_BODY_RES, body_image, "body_image");
case rightring: case feet:
return getImage(ICON_RING_RES, ring_image, "ring_image"); return getImage(ICON_FEET_RES, feet_image, "feet_image");
case neck: case hand:
return getImage(ICON_NECK_RES, neck_image, "neck_image"); return getImage(ICON_HAND_RES, hand_image, "hand_image");
case shield: case head:
return getImage(ICON_SHIELD_RES, shield_image, "shield_image"); return getImage(ICON_HEAD_RES, head_image, "head_image");
case weapon: case leftring:
return getImage(ICON_WEAPON_RES, weapon_image, "weapon_image"); case rightring:
default: return getImage(ICON_RING_RES, ring_image, "ring_image");
return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image"); case neck:
} return getImage(ICON_NECK_RES, neck_image, "neck_image");
} case shield:
return getImage(ICON_SHIELD_RES, shield_image, "shield_image");
public static Image getIcon(InventorySlot slot) { case weapon:
if (slot == null) { return getImage(ICON_WEAPON_RES, weapon_image, "weapon_image");
return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_icon"); default:
} return getImage(ICON_NO_SLOT_RES, no_slot_image, "no_slot_image");
switch (slot) { }
case body: }
return getIcon(ICON_BODY_RES, body_image, body_icon, "body_image", "body_icon");
case feet: public static Image getIcon(InventorySlot slot) {
return getIcon(ICON_FEET_RES, feet_image, feet_icon, "feet_image", "feet_icon"); if (slot == null) {
case hand: return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_icon");
return getIcon(ICON_HAND_RES, hand_image, hand_icon, "hand_image", "hand_icon"); }
case head: switch (slot) {
return getIcon(ICON_HEAD_RES, head_image, head_icon, "head_image", "head_icon"); case body:
case leftring: return getIcon(ICON_BODY_RES, body_image, body_icon, "body_image", "body_icon");
case rightring: case feet:
return getIcon(ICON_RING_RES, ring_image, ring_icon, "ring_image", "ring_icon"); return getIcon(ICON_FEET_RES, feet_image, feet_icon, "feet_image", "feet_icon");
case neck: case hand:
return getIcon(ICON_NECK_RES, neck_image, neck_icon, "neck_image", "neck_icon"); return getIcon(ICON_HAND_RES, hand_image, hand_icon, "hand_image", "hand_icon");
case shield: case head:
return getIcon(ICON_SHIELD_RES, shield_image, shield_icon, "shield_image", "shield_icon"); return getIcon(ICON_HEAD_RES, head_image, head_icon, "head_image", "head_icon");
case weapon: case leftring:
return getIcon(ICON_WEAPON_RES, weapon_image, weapon_icon, "weapon_image", "weapon_icon"); case rightring:
default: return getIcon(ICON_RING_RES, ring_image, ring_icon, "ring_image", "ring_icon");
return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_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");
public static Image getImage(String res, Image img, String fieldName) { case weapon:
if (img == null) { return getIcon(ICON_WEAPON_RES, weapon_image, weapon_icon, "weapon_image", "weapon_icon");
try { default:
img = ImageIO.read(ItemCategory.class.getResourceAsStream(res)); return getIcon(ICON_NO_SLOT_RES, no_slot_image, no_slot_icon, "no_slot_image", "no_slot_icon");
ItemCategory.class.getField(fieldName).set(null, img); }
} catch (IllegalArgumentException e) { }
e.printStackTrace();
} catch (SecurityException e) { public static Image getImage(String res, Image img, String fieldName) {
e.printStackTrace(); if (img == null) {
} catch (IllegalAccessException e) { try {
e.printStackTrace(); img = ImageIO.read(ItemCategory.class.getResourceAsStream(res));
} catch (NoSuchFieldException e) { ItemCategory.class.getField(fieldName).set(null, img);
e.printStackTrace(); } catch (IllegalArgumentException e) {
} catch (IOException e) { e.printStackTrace();
Notification.addError("Failed to load item category icon "+res); } catch (SecurityException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (IllegalAccessException e) {
} e.printStackTrace();
return img; } catch (NoSuchFieldException e) {
} e.printStackTrace();
} catch (IOException e) {
public static Image getIcon(String res, Image img, Image icon, String imgFieldName, String iconFieldName) { Notification.addError("Failed to load item category icon "+res);
if (icon == null) { e.printStackTrace();
icon = getImage(res, img, imgFieldName).getScaledInstance(16, 16, Image.SCALE_SMOOTH); }
try { }
ItemCategory.class.getField(iconFieldName).set(null, icon); return img;
} catch (IllegalArgumentException e) { }
e.printStackTrace();
} catch (SecurityException e) { public static Image getIcon(String res, Image img, Image icon, String imgFieldName, String iconFieldName) {
e.printStackTrace(); if (icon == null) {
} catch (IllegalAccessException e) { icon = getImage(res, img, imgFieldName).getScaledInstance(16, 16, Image.SCALE_SMOOTH);
e.printStackTrace(); try {
} catch (NoSuchFieldException e) { ItemCategory.class.getField(iconFieldName).set(null, icon);
e.printStackTrace(); } catch (IllegalArgumentException e) {
} e.printStackTrace();
} } catch (SecurityException e) {
return icon; e.printStackTrace();
} } catch (IllegalAccessException e) {
e.printStackTrace();
@Override } catch (NoSuchFieldException e) {
public GameDataElement clone() { e.printStackTrace();
ItemCategory clone = new ItemCategory(); }
clone.jsonFile = this.jsonFile; }
clone.state = this.state; return icon;
clone.id = this.id; }
clone.name = this.name;
clone.size = this.size; @Override
clone.slot = this.slot; public GameDataElement clone() {
clone.action_type = this.action_type; ItemCategory clone = new ItemCategory();
return clone; clone.jsonFile = this.jsonFile;
} clone.state = this.state;
clone.id = this.id;
@Override clone.name = this.name;
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { clone.size = this.size;
// Nothing to link to. clone.slot = this.slot;
} clone.action_type = this.action_type;
return clone;
@SuppressWarnings({ "rawtypes", "unchecked" }) }
@Override
public Map toJson() { @Override
Map itemCatJson = new LinkedHashMap(); public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
itemCatJson.put("id", this.id); // Nothing to link to.
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()); @SuppressWarnings({ "rawtypes", "unchecked" })
if (this.slot != null) itemCatJson.put("inventorySlot", this.slot.toString()); @Override
return itemCatJson; public Map toJson() {
} Map itemCatJson = new LinkedHashMap();
itemCatJson.put("id", this.id);
if (this.name != null) itemCatJson.put("name", this.name);
@Override if (this.action_type != null) itemCatJson.put("actionType", this.action_type.toString());
public String getProjectFilename() { if (this.size != null) itemCatJson.put("size", this.size.toString());
return "itemcategories_"+getProject().name+".json"; if (this.slot != null) itemCatJson.put("inventorySlot", this.slot.toString());
} return itemCatJson;
}
}
@Override
public String getProjectFilename() {
return "itemcategories_"+getProject().name+".json";
}
}

View File

@@ -1,179 +1,180 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter; import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent; import com.gpl.rpg.atcontentstudio.model.SaveEvent;
public abstract class JSONElement extends GameDataElement { public abstract class JSONElement extends GameDataElement {
private static final long serialVersionUID = -8015398814080503982L; private static final long serialVersionUID = -8015398814080503982L;
//Available from state init. //Available from state init.
public File jsonFile; public File jsonFile;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void parse() { public void parse() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
JSONParser parser = new JSONParser(); }
FileReader reader = null; JSONParser parser = new JSONParser();
try { FileReader reader = null;
reader = new FileReader(jsonFile); try {
List gameDataElements = (List) parser.parse(reader); reader = new FileReader(jsonFile);
for (Object obj : gameDataElements) { List gameDataElements = (List) parser.parse(reader);
Map jsonObj = (Map)obj; for (Object obj : gameDataElements) {
String id = (String) jsonObj.get("id"); Map jsonObj = (Map)obj;
try { String id = (String) jsonObj.get("id");
if (id != null && id.equals(this.id )) { try {
this.parse(jsonObj); if (id != null && id.equals(this.id )) {
this.state = State.parsed; this.parse(jsonObj);
break; this.state = State.parsed;
} break;
} }
catch(Exception e){ }
System.out.println("Error in ID: " + id); catch(Exception e){
System.out.println(e.getMessage()); System.out.println("Error in ID: " + id);
} System.out.println(e.getMessage());
} }
} catch (FileNotFoundException e) { }
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); } catch (FileNotFoundException e) {
e.printStackTrace(); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
} catch (IOException e) { e.printStackTrace();
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); } catch (IOException e) {
e.printStackTrace(); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
} catch (ParseException e) { e.printStackTrace();
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); } catch (ParseException e) {
e.printStackTrace(); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
} catch (IllegalArgumentException e) { e.printStackTrace();
System.out.println(id); } catch (IllegalArgumentException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); System.out.println(id);
e.printStackTrace(); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
} finally { e.printStackTrace();
if (reader != null) } finally {
try { if (reader != null)
reader.close(); try {
} catch (IOException e) { reader.close();
e.printStackTrace(); } catch (IOException e) {
} e.printStackTrace();
} }
}
}
}
public abstract void parse(@SuppressWarnings("rawtypes") Map jsonObj);
public abstract void parse(@SuppressWarnings("rawtypes") Map jsonObj);
@SuppressWarnings("rawtypes")
public abstract Map toJson(); @SuppressWarnings("rawtypes")
public String toJsonString() { public abstract Map toJson();
StringWriter writer = new JsonPrettyWriter(); public String toJsonString() {
try { StringWriter writer = new JsonPrettyWriter();
JSONObject.writeJSONString(this.toJson(), writer); try {
} catch (IOException e) { JSONObject.writeJSONString(this.toJson(), writer);
//Impossible with a StringWriter } catch (IOException e) {
} //Impossible with a StringWriter
return writer.toString(); }
} return writer.toString();
}
@Override
public GameDataSet getDataSet() { @Override
if (parent == null) { public GameDataSet getDataSet() {
System.out.println("blerf."); if (parent == null) {
} System.out.println("blerf.");
return parent.getDataSet(); }
} return parent.getDataSet();
}
public void save() {
if (this.getParent() instanceof GameDataCategory<?> && writable) { public void save() {
((GameDataCategory<?>)this.getParent()).save(this.jsonFile); if (this.getParent() instanceof GameDataCategory<?> && writable) {
} ((GameDataCategory<?>)this.getParent()).save(this.jsonFile);
} }
}
/**
* Returns null if save occurred (no notable events). /**
*/ * Returns null if save occurred (no notable events).
public List<SaveEvent> attemptSave() { */
List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName()); public List<SaveEvent> attemptSave() {
if (events == null || events.isEmpty()) { List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName());
return null; if (events == null || events.isEmpty()) {
} return null;
if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) { }
save(); if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) {
return null; save();
} return null;
return events; }
} return events;
}
public static Integer getInteger(Number n) {
return n == null ? null : n.intValue(); 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 getDouble(Number n) {
} return n == null ? null : n.doubleValue();
}
public static Double parseChance(String s) {
if (s.equals("100")) return 100d; public static Double parseChance(String s) {
else if (s.equals("70")) return 70d; if (s.equals("100")) return 100d;
else if (s.equals("30")) return 30d; else if (s.equals("70")) return 70d;
else if (s.equals("25")) return 25d; else if (s.equals("30")) return 30d;
else if (s.equals("20")) return 20d; else if (s.equals("25")) return 25d;
else if (s.equals("10")) return 10d; else if (s.equals("20")) return 20d;
else if (s.equals("5")) return 5d; else if (s.equals("10")) return 10d;
else if (s.equals("1")) return 1d; else if (s.equals("5")) return 5d;
else if (s.equals("1/1000")) return 0.1; else if (s.equals("1")) return 1d;
else if (s.equals("1/10000")) return 0.01; else if (s.equals("1/1000")) return 0.1;
else if (s.indexOf('/') >= 0) { else if (s.equals("1/10000")) return 0.01;
int c = s.indexOf('/'); else if (s.indexOf('/') >= 0) {
double a = 1; int c = s.indexOf('/');
try { double a = 1;
a = Integer.parseInt(s.substring(0, c)); try {
} catch (NumberFormatException nfe) {} a = Integer.parseInt(s.substring(0, c));
double b = 100; } catch (NumberFormatException nfe) {}
try { double b = 100;
b = Integer.parseInt(s.substring(c+1)); try {
} catch (NumberFormatException nfe) {} b = Integer.parseInt(s.substring(c+1));
return a/b; } catch (NumberFormatException nfe) {}
} return a/b;
else { }
double a = 10; else {
try { double a = 10;
a = Double.parseDouble(s); try {
} catch (NumberFormatException nfe) {} a = Double.parseDouble(s);
return a; } catch (NumberFormatException nfe) {}
} return a;
} }
}
public static String printJsonChance(Double chance) {
if (chance.equals(100d)) return "100"; public static String printJsonChance(Double chance) {
else if (chance.equals(70d)) return "70"; if (chance.equals(100d)) return "100";
else if (chance.equals(30d)) return "30"; else if (chance.equals(70d)) return "70";
else if (chance.equals(25d)) return "25"; else if (chance.equals(30d)) return "30";
else if (chance.equals(20d)) return "20"; else if (chance.equals(25d)) return "25";
else if (chance.equals(10d)) return "10"; else if (chance.equals(20d)) return "20";
else if (chance.equals(5d)) return "5"; else if (chance.equals(10d)) return "10";
else if (chance.equals(1d)) return "1"; else if (chance.equals(5d)) return "5";
else if (chance.equals(0.1d)) return "1/1000"; else if (chance.equals(1d)) return "1";
else if (chance.equals(0.01d)) return "1/10000"; else if (chance.equals(0.1d)) return "1/1000";
else { else if (chance.equals(0.01d)) return "1/10000";
if (chance.intValue() == chance) return Integer.toString(chance.intValue()); else {
//TODO Better handling of fractions. Chance description need a complete overhaul in AT. if (chance.intValue() == chance) return Integer.toString(chance.intValue());
//This part does not output the input content of parseDouble(String s) in the case of fractions. //TODO Better handling of fractions. Chance description need a complete overhaul in AT.
return chance.toString(); //This part does not output the input content of parseDouble(String s) in the case of fractions.
} return chance.toString();
} }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,191 +1,198 @@
package com.gpl.rpg.atcontentstudio.model.gamedata; package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification; import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Quest extends JSONElement { public class Quest extends JSONElement {
private static final long serialVersionUID = 2004839647483250099L; private static final long serialVersionUID = 2004839647483250099L;
//Available from init state //Available from init state
//public String id = null; inherited. //public String id = null; inherited.
public String name = null; public String name = null;
//Available in parsed state //Available in parsed state
public Integer visible_in_log = null; public Integer visible_in_log = null;
public List<QuestStage> stages = null; public List<QuestStage> stages = null;
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")"; return (needsSaving() ? "*" : "")+name+" ("+id+")";
} }
public static String getStaticDesc() { public static String getStaticDesc() {
return "Quests"; return "Quests";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Quest> category) { public static void fromJson(File jsonFile, GameDataCategory<Quest> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
FileReader reader = null; FileReader reader = null;
try { try {
reader = new FileReader(jsonFile); reader = new FileReader(jsonFile);
List quests = (List) parser.parse(reader); List quests = (List) parser.parse(reader);
for (Object obj : quests) { for (Object obj : quests) {
Map questJson = (Map)obj; Map questJson = (Map)obj;
Quest quest = fromJson(questJson); Quest quest = fromJson(questJson);
quest.jsonFile = jsonFile; quest.jsonFile = jsonFile;
quest.parent = category; quest.parent = category;
if (quest.getDataType() == GameSource.Type.created || quest.getDataType() == GameSource.Type.altered) { if (quest.getDataType() == GameSource.Type.created || quest.getDataType() == GameSource.Type.altered) {
quest.writable = true; quest.writable = true;
} }
category.add(quest); category.add(quest);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) { } catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage()); Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (reader != null) if (reader != null)
try { try {
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Quest fromJson(String jsonString) throws ParseException { public static Quest fromJson(String jsonString) throws ParseException {
Map questJson = (Map) new JSONParser().parse(jsonString); Map questJson = (Map) new JSONParser().parse(jsonString);
Quest quest = fromJson(questJson); Quest quest = fromJson(questJson);
quest.parse(questJson); quest.parse(questJson);
return quest; return quest;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Quest fromJson(Map questJson) { public static Quest fromJson(Map questJson) {
Quest quest = new Quest(); Quest quest = new Quest();
quest.id = (String) questJson.get("id"); quest.id = (String) questJson.get("id");
quest.name = (String) questJson.get("name"); quest.name = (String) questJson.get("name");
//Quests have to be parsed to have their stages initialized. //Quests have to be parsed to have their stages initialized.
quest.parse(questJson); quest.parse(questJson);
return quest; return quest;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map questJson) { public void parse(Map questJson) {
this.visible_in_log = JSONElement.getInteger((Number) questJson.get("showInLog")); this.visible_in_log = JSONElement.getInteger((Number) questJson.get("showInLog"));
List questStagesJson = (List) questJson.get("stages"); List questStagesJson = (List) questJson.get("stages");
this.stages = new ArrayList<QuestStage>(); this.stages = new ArrayList<QuestStage>();
if (questStagesJson != null && !questStagesJson.isEmpty()) { if (questStagesJson != null && !questStagesJson.isEmpty()) {
for (Object questStageJsonObj : questStagesJson) { for (Object questStageJsonObj : questStagesJson) {
Map questStageJson = (Map)questStageJsonObj; Map questStageJson = (Map)questStageJsonObj;
QuestStage questStage = new QuestStage(this); QuestStage questStage = new QuestStage(this);
questStage.parse(questStageJson); questStage.parse(questStageJson);
this.stages.add(questStage); this.stages.add(questStage);
} }
} }
this.state = State.parsed; this.state = State.parsed;
} }
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
return; //This type of state is unrelated to parsing/linking.
} return;
ensureParseIfNeeded(); }
if (this.state == State.init) {
for (QuestStage stage : stages) { //Not parsed yet.
stage.link(); this.parse();
} } else if (this.state == State.linked) {
//Nothing to link to :D //Already linked.
this.state = State.linked; return;
} }
@Override for (QuestStage stage : stages) {
public Image getIcon() { stage.link();
return DefaultIcons.getQuestIcon(); }
} //Nothing to link to :D
this.state = State.linked;
public Image getImage() { }
return DefaultIcons.getQuestImage();
} @Override
public Image getIcon() {
@Override return DefaultIcons.getQuestIcon();
public GameDataElement clone() { }
Quest clone = new Quest();
clone.jsonFile = this.jsonFile; public Image getImage() {
clone.state = this.state; return DefaultIcons.getQuestImage();
clone.id = this.id; }
clone.name = this.name;
clone.visible_in_log = this.visible_in_log; @Override
if (this.stages != null) { public GameDataElement clone() {
clone.stages = new ArrayList<QuestStage>(); Quest clone = new Quest();
for (QuestStage stage : this.stages){ clone.jsonFile = this.jsonFile;
clone.stages.add((QuestStage) stage.clone(clone)); clone.state = this.state;
} clone.id = this.id;
} clone.name = this.name;
return clone; clone.visible_in_log = this.visible_in_log;
} if (this.stages != null) {
clone.stages = new ArrayList<QuestStage>();
@Override for (QuestStage stage : this.stages){
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { clone.stages.add((QuestStage) stage.clone(clone));
//Nothing to link to. }
} }
return clone;
@SuppressWarnings({ "rawtypes", "unchecked" }) }
@Override
public Map toJson() { @Override
Map questJson = new LinkedHashMap(); public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
questJson.put("id", this.id); //Nothing to link to.
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) { @SuppressWarnings({ "rawtypes", "unchecked" })
List stagesJson = new ArrayList(); @Override
questJson.put("stages", stagesJson); public Map toJson() {
for (QuestStage stage : this.stages) { Map questJson = new LinkedHashMap();
stagesJson.add(stage.toJson()); 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);
return questJson; if (this.stages != null) {
} List stagesJson = new ArrayList();
questJson.put("stages", stagesJson);
for (QuestStage stage : this.stages) {
@Override stagesJson.add(stage.toJson());
public String getProjectFilename() { }
return "questlist_"+getProject().name+".json"; }
} return questJson;
}
public QuestStage getStage(Integer stageId) {
for (QuestStage stage : stages) {
if (stage.progress.equals(stageId)) { @Override
return stage; public String getProjectFilename() {
} return "questlist_"+getProject().name+".json";
} }
return null;
} public QuestStage getStage(Integer stageId) {
for (QuestStage stage : stages) {
} if (stage.progress.equals(stageId)) {
return stage;
}
}
return null;
}
}

View File

@@ -8,18 +8,18 @@ import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class QuestStage extends JSONElement { public class QuestStage extends JSONElement {
private static final long serialVersionUID = 8313645819951513431L; private static final long serialVersionUID = 8313645819951513431L;
public Integer progress = null; public Integer progress = null;
public String log_text = null; public String log_text = null;
public Integer exp_reward = null; public Integer exp_reward = null;
public Integer finishes_quest = null; public Integer finishes_quest = null;
public QuestStage(Quest parent){ public QuestStage(Quest parent){
this.parent = parent; this.parent = parent;
} }
public QuestStage clone(Quest cloneParent) { public QuestStage clone(Quest cloneParent) {
QuestStage clone = new QuestStage(cloneParent); QuestStage clone = new QuestStage(cloneParent);
clone.progress = progress != null ? new Integer(progress) : null; clone.progress = progress != null ? new Integer(progress) : null;
@@ -59,11 +59,18 @@ public class QuestStage extends JSONElement {
@Override @Override
public void link() { public void link() {
if (shouldSkipParseOrLink()) { if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return; return;
} }
ensureParseIfNeeded(); if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
return;
}
//Nothing to link to :D //Nothing to link to :D
this.state = State.linked; this.state = State.linked;
} }
@@ -82,15 +89,15 @@ public class QuestStage extends JSONElement {
public GameDataElement clone() { public GameDataElement clone() {
return null; return null;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return DefaultIcons.getQuestIcon(); return DefaultIcons.getQuestIcon();
} }
public Image getImage() { public Image getImage() {
return DefaultIcons.getQuestImage(); return DefaultIcons.getQuestImage();
} }
} }

View File

@@ -71,9 +71,6 @@ public class ReplaceArea extends MapObject {
addReplacement(repl); addReplacement(repl);
return repl; return repl;
} }
public ReplaceArea.Replacement createReplacement(String source, String target) {
return new Replacement(source, target);
}
public void addReplacement(ReplaceArea.Replacement repl) { public void addReplacement(ReplaceArea.Replacement repl) {
if (replacements == null) replacements = new ArrayList<ReplaceArea.Replacement>(); if (replacements == null) replacements = new ArrayList<ReplaceArea.Replacement>();

View File

@@ -1,205 +1,299 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors; package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component; import java.awt.Component;
import java.util.ArrayList; import java.awt.event.ActionEvent;
import java.util.List; import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.DefaultListCellRenderer; import java.util.List;
import javax.swing.ImageIcon; import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.DefaultListCellRenderer;
import javax.swing.JList; import javax.swing.ImageIcon;
import javax.swing.JPanel; import javax.swing.JButton;
import javax.swing.JSpinner; import javax.swing.JComponent;
import javax.swing.JTextField; import javax.swing.JLabel;
import javax.swing.JList;
import com.gpl.rpg.atcontentstudio.ATContentStudio; import javax.swing.JPanel;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import javax.swing.JScrollPane;
import com.gpl.rpg.atcontentstudio.model.Project; import javax.swing.JSpinner;
import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode; import javax.swing.JTextField;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist; import javax.swing.ListModel;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist.DroppedItem; import javax.swing.ListSelectionModel;
import com.gpl.rpg.atcontentstudio.model.gamedata.Item; import javax.swing.event.ListDataEvent;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; import javax.swing.event.ListDataListener;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; import javax.swing.event.ListSelectionEvent;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor; import javax.swing.event.ListSelectionListener;
import com.jidesoft.swing.JideBoxLayout;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
public class DroplistEditor extends JSONElementEditor { import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.Project;
private static final long serialVersionUID = 1139455254096811058L; import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist;
private static final String form_view_id = "Form"; import com.gpl.rpg.atcontentstudio.model.gamedata.Droplist.DroppedItem;
private static final String json_view_id = "JSON"; import com.gpl.rpg.atcontentstudio.model.gamedata.Item;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
private Droplist.DroppedItem selectedItem; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
private JTextField idField; import com.jidesoft.swing.JideBoxLayout;
private MyComboBox itemCombo;
private DroppedItemsListModel droppedItemsListModel; public class DroplistEditor extends JSONElementEditor {
private JSpinner qtyMinField;
private JSpinner qtyMaxField; private static final long serialVersionUID = 1139455254096811058L;
private JComponent chanceField;
private static final String form_view_id = "Form";
public DroplistEditor(Droplist droplist) { private static final String json_view_id = "JSON";
super(droplist, droplist.getDesc(), droplist.getIcon());
addEditorTab(form_view_id, getFormView()); private Droplist.DroppedItem selectedItem;
addEditorTab(json_view_id, getJSONView());
} private JTextField idField;
private MyComboBox itemCombo;
@Override private DroppedItemsListModel droppedItemsListModel;
public void insertFormViewDataField(JPanel pane) { private JSpinner qtyMinField;
private JSpinner qtyMaxField;
final Droplist droplist = (Droplist)target; private JComponent chanceField;
final FieldUpdateListener listener = new DroplistFieldUpdater();
public DroplistEditor(Droplist droplist) {
createButtonPane(pane, droplist.getProject(), droplist, Droplist.class, Droplist.getImage(), null, listener); super(droplist, droplist.getDesc(), droplist.getIcon());
addEditorTab(form_view_id, getFormView());
idField = addTextField(pane, "Droplist ID: ", droplist.id, droplist.writable, listener); addEditorTab(json_view_id, getJSONView());
}
String title = "Items in this droplist: ";
DroppedItemsCellRenderer cellRenderer = new DroppedItemsCellRenderer(); @SuppressWarnings({ "rawtypes", "unchecked" })
droppedItemsListModel = new DroppedItemsListModel(droplist); @Override
final boolean moveUpDownEnabled = false; public void insertFormViewDataField(JPanel pane) {
CollapsiblePanel itemsPane = CommonEditor.createListPanel( final Droplist droplist = (Droplist)target;
title, final FieldUpdateListener listener = new DroplistFieldUpdater();
cellRenderer,
droppedItemsListModel, createButtonPane(pane, droplist.getProject(), droplist, Droplist.class, Droplist.getImage(), null, listener);
droplist.writable,
moveUpDownEnabled, idField = addTextField(pane, "Droplist ID: ", droplist.id, droplist.writable, listener);
(e) -> selectedItem = e,
() -> selectedItem, CollapsiblePanel itemsPane = new CollapsiblePanel("Items in this droplist: ");
this::updateDroppedItemsEditorPane, itemsPane.setLayout(new JideBoxLayout(itemsPane, JideBoxLayout.PAGE_AXIS));
listener, droppedItemsListModel = new DroppedItemsListModel(droplist);
Droplist.DroppedItem::new).panel; final JList itemsList = new JList(droppedItemsListModel);
itemsList.setCellRenderer(new DroppedItemsCellRenderer());
if (droplist.dropped_items == null || droplist.dropped_items.isEmpty()) { itemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
itemsPane.collapse(); itemsPane.add(new JScrollPane(itemsList), JideBoxLayout.FIX);
} final JPanel droppedItemsEditorPane = new JPanel();
final JButton createDroppedItem = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
pane.add(itemsPane, JideBoxLayout.FIX); final JButton deleteDroppedItem = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
deleteDroppedItem.setEnabled(false);
} itemsList.addListSelectionListener(new ListSelectionListener() {
@Override
public void updateDroppedItemsEditorPane(JPanel pane, DroppedItem di, FieldUpdateListener listener) { public void valueChanged(ListSelectionEvent e) {
boolean writable = target.writable; selectedItem = (Droplist.DroppedItem) itemsList.getSelectedValue();
Project proj = target.getProject(); if (selectedItem == null) {
pane.removeAll(); deleteDroppedItem.setEnabled(false);
if (itemCombo != null) { } else {
removeElementListener(itemCombo); deleteDroppedItem.setEnabled(true);
} }
if (di != null) { updateDroppedItemsEditorPane(droppedItemsEditorPane, selectedItem, listener);
itemCombo = addItemBox(pane, proj, "Item: ", di.item, writable, listener); }
qtyMinField = addIntegerField(pane, "Quantity min: ", di.quantity_min, false, writable, listener); });
qtyMaxField = addIntegerField(pane, "Quantity max: ", di.quantity_max, false, writable, listener); if (droplist.writable) {
chanceField = addChanceField(pane, "Chance: ", di.chance, "100", writable, listener);//addDoubleField(pane, "Chance: ", di.chance, writable, listener); JPanel listButtonsPane = new JPanel();
} listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
pane.revalidate(); createDroppedItem.addActionListener(new ActionListener() {
pane.repaint(); @Override
} public void actionPerformed(ActionEvent e) {
Droplist.DroppedItem tempItem = new Droplist.DroppedItem();
public static class DroppedItemsListModel extends CommonEditor.AtListModel<Droplist.DroppedItem, Droplist> { droppedItemsListModel.addItem(tempItem);
itemsList.setSelectedValue(tempItem, true);
public DroppedItemsListModel(Droplist droplist) { listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
super(droplist); }
} });
deleteDroppedItem.addActionListener(new ActionListener() {
@Override @Override
protected List<Droplist.DroppedItem> getInner() { public void actionPerformed(ActionEvent e) {
return source.dropped_items; if (selectedItem != null) {
} droppedItemsListModel.removeItem(selectedItem);
selectedItem = null;
@Override itemsList.clearSelection();
protected void setInner(List<Droplist.DroppedItem> value) { listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
source.dropped_items = value; }
} }
} });
public static class DroppedItemsCellRenderer extends DefaultListCellRenderer { listButtonsPane.add(createDroppedItem, JideBoxLayout.FIX);
private static final long serialVersionUID = 7987880146189575234L; listButtonsPane.add(deleteDroppedItem, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
@Override itemsPane.add(listButtonsPane, JideBoxLayout.FIX);
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { }
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); droppedItemsEditorPane.setLayout(new JideBoxLayout(droppedItemsEditorPane, JideBoxLayout.PAGE_AXIS));
if (c instanceof JLabel) { itemsPane.add(droppedItemsEditorPane, JideBoxLayout.FIX);
JLabel label = ((JLabel)c); if (droplist.dropped_items == null || droplist.dropped_items.isEmpty()) {
Droplist.DroppedItem di = (Droplist.DroppedItem)value; itemsPane.collapse();
if (di.item != null) { }
label.setIcon(new ImageIcon(di.item.getIcon()));
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item.getDesc()); pane.add(itemsPane, JideBoxLayout.FIX);
} else if (!isNull(di)) {
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item_id); }
} else {
label.setText("New, undefined, dropped item."); public void updateDroppedItemsEditorPane(JPanel pane, DroppedItem di, FieldUpdateListener listener) {
} boolean writable = ((Droplist)target).writable;
} Project proj = ((Droplist)target).getProject();
return c; pane.removeAll();
} if (itemCombo != null) {
removeElementListener(itemCombo);
public boolean isNull(Droplist.DroppedItem item) { }
return ((item == null) || ( if (di != null) {
item.item == null && itemCombo = addItemBox(pane, proj, "Item: ", di.item, writable, listener);
item.item_id == null && qtyMinField = addIntegerField(pane, "Quantity min: ", di.quantity_min, false, writable, listener);
item.quantity_min == null && qtyMaxField = addIntegerField(pane, "Quantity max: ", di.quantity_max, false, writable, listener);
item.quantity_max == null && chanceField = addChanceField(pane, "Chance: ", di.chance, "100", writable, listener);//addDoubleField(pane, "Chance: ", di.chance, writable, listener);
item.chance == null }
)); pane.revalidate();
} pane.repaint();
} }
public class DroppedItemsListModel implements ListModel<Droplist.DroppedItem> {
public class DroplistFieldUpdater implements FieldUpdateListener {
@Override Droplist source;
public void valueChanged(JComponent source, Object value) {
Droplist droplist = ((Droplist)target); public DroppedItemsListModel(Droplist droplist) {
if (source == idField) { this.source = droplist;
//Events caused by cancel an ID edition. Dismiss. }
if (skipNext) {
skipNext = false; @Override
return; public int getSize() {
} if (source.dropped_items == null) return 0;
if (target.id.equals(value)) return; return source.dropped_items.size();
}
if (idChanging()) {
droplist.id = (String) value; @Override
DroplistEditor.this.name = droplist.getDesc(); public Droplist.DroppedItem getElementAt(int index) {
droplist.childrenChanged(new ArrayList<>()); if (source.dropped_items == null) return null;
ATContentStudio.frame.editorChanged(DroplistEditor.this); return source.dropped_items.get(index);
} else { }
cancelIdEdit(idField);
return; public void addItem(Droplist.DroppedItem item) {
} if (source.dropped_items == null) {
} else if (source == itemCombo) { source.dropped_items = new ArrayList<Droplist.DroppedItem>();
if (selectedItem.item != null) { }
selectedItem.item.removeBacklink(droplist); source.dropped_items.add(item);
} int index = source.dropped_items.indexOf(item);
selectedItem.item = (Item) value; for (ListDataListener l : listeners) {
if (selectedItem.item != null) { l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
selectedItem.item_id = selectedItem.item.id; }
selectedItem.item.addBacklink(droplist); }
} else {
selectedItem.item_id = null; public void removeItem(Droplist.DroppedItem item) {
} int index = source.dropped_items.indexOf(item);
droppedItemsListModel.itemChanged(selectedItem); source.dropped_items.remove(item);
} else if (source == qtyMinField) { if (source.dropped_items.isEmpty()) {
selectedItem.quantity_min = (Integer) value; source.dropped_items = null;
droppedItemsListModel.itemChanged(selectedItem); }
} else if (source == qtyMaxField) { for (ListDataListener l : listeners) {
selectedItem.quantity_max = (Integer) value; l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
droppedItemsListModel.itemChanged(selectedItem); }
} else if (source == chanceField) { }
selectedItem.chance = (String) value;
droppedItemsListModel.itemChanged(selectedItem); public void itemChanged(Droplist.DroppedItem item) {
} int index = source.dropped_items.indexOf(item);
for (ListDataListener l : listeners) {
if (droplist.state != GameDataElement.State.modified) { l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
droplist.state = GameDataElement.State.modified; }
DroplistEditor.this.name = droplist.getDesc(); }
droplist.childrenChanged(new ArrayList<>());
ATContentStudio.frame.editorChanged(DroplistEditor.this); List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
}
updateJsonViewText(droplist.toJsonString()); @Override
} public void addListDataListener(ListDataListener l) {
} listeners.add(l);
} }
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
}
public static class DroppedItemsCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 7987880146189575234L;
@Override
public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel label = ((JLabel)c);
Droplist.DroppedItem di = (Droplist.DroppedItem)value;
if (di.item != null) {
label.setIcon(new ImageIcon(di.item.getIcon()));
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item.getDesc());
} else if (!isNull(di)) {
label.setText(di.chance+(di.chance != null && di.chance.contains("/") ? "" : "%")+" to get "+di.quantity_min+"-"+di.quantity_max+" "+di.item_id);
} else {
label.setText("New, undefined, dropped item.");
}
}
return c;
}
public boolean isNull(Droplist.DroppedItem item) {
return ((item == null) || (
item.item == null &&
item.item_id == null &&
item.quantity_min == null &&
item.quantity_max == null &&
item.chance == null
));
}
}
public class DroplistFieldUpdater implements FieldUpdateListener {
@Override
public void valueChanged(JComponent source, Object value) {
Droplist droplist = ((Droplist)target);
if (source == idField) {
//Events caused by cancel an ID edition. Dismiss.
if (skipNext) {
skipNext = false;
return;
}
if (target.id.equals((String) value)) return;
if (idChanging()) {
droplist.id = (String) value;
DroplistEditor.this.name = droplist.getDesc();
droplist.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(DroplistEditor.this);
} else {
cancelIdEdit(idField);
return;
}
} else if (source == itemCombo) {
if (selectedItem.item != null) {
selectedItem.item.removeBacklink(droplist);
}
selectedItem.item = (Item) value;
if (selectedItem.item != null) {
selectedItem.item_id = selectedItem.item.id;
selectedItem.item.addBacklink(droplist);
} else {
selectedItem.item_id = null;
}
droppedItemsListModel.itemChanged(selectedItem);
} else if (source == qtyMinField) {
selectedItem.quantity_min = (Integer) value;
droppedItemsListModel.itemChanged(selectedItem);
} else if (source == qtyMaxField) {
selectedItem.quantity_max = (Integer) value;
droppedItemsListModel.itemChanged(selectedItem);
} else if (source == chanceField) {
selectedItem.chance = (String) value;
droppedItemsListModel.itemChanged(selectedItem);
}
if (droplist.state != GameDataElement.State.modified) {
droplist.state = GameDataElement.State.modified;
DroplistEditor.this.name = droplist.getDesc();
droplist.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(DroplistEditor.this);
}
updateJsonViewText(droplist.toJsonString());
}
}
}

View File

@@ -1,18 +1,29 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors; package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner; import javax.swing.JSpinner;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.gpl.rpg.atcontentstudio.ATContentStudio; import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
@@ -20,9 +31,9 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest; import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage; import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel; import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener; import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox; import com.gpl.rpg.atcontentstudio.ui.IntegerBasedCheckBox;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import com.jidesoft.swing.JideBoxLayout; import com.jidesoft.swing.JideBoxLayout;
public class QuestEditor extends JSONElementEditor { public class QuestEditor extends JSONElementEditor {
@@ -66,26 +77,94 @@ public class QuestEditor extends JSONElementEditor {
nameField = addTranslatableTextField(pane, "Quest Name: ", quest.name, quest.writable, listener); nameField = addTranslatableTextField(pane, "Quest Name: ", quest.name, quest.writable, listener);
visibleBox = addIntegerBasedCheckBox(pane, "Visible in quest log", quest.visible_in_log, quest.writable, listener); visibleBox = addIntegerBasedCheckBox(pane, "Visible in quest log", quest.visible_in_log, quest.writable, listener);
String title = "Quest stages: "; CollapsiblePanel stagesPane = new CollapsiblePanel("Quest stages: ");
StagesCellRenderer cellRenderer = new StagesCellRenderer(); stagesPane.setLayout(new JideBoxLayout(stagesPane, JideBoxLayout.PAGE_AXIS));
stagesListModel = new StagesListModel(quest); stagesListModel = new StagesListModel(quest);
final boolean moveUpDownEnabled = true; stagesList = new JList<QuestStage>(stagesListModel);
stagesList.setCellRenderer(new StagesCellRenderer());
CollapsiblePanel stagesPane = CommonEditor.createListPanel( stagesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
title, stagesPane.add(new JScrollPane(stagesList), JideBoxLayout.FIX);
cellRenderer, final JPanel stagesEditorPane = new JPanel();
stagesListModel, final JButton createStage = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
quest.writable, final JButton deleteStage = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
moveUpDownEnabled, final JButton moveStageUp = new JButton(new ImageIcon(DefaultIcons.getArrowUpIcon()));
(e)->selectedStage=e, final JButton moveStageDown = new JButton(new ImageIcon(DefaultIcons.getArrowDownIcon()));
()->selectedStage, deleteStage.setEnabled(false);
this::updateStageEditorPane, moveStageUp.setEnabled(false);
listener, moveStageDown.setEnabled(false);
()->new QuestStage(quest)).panel; stagesList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectedStage = (QuestStage) stagesList.getSelectedValue();
if (selectedStage != null) {
deleteStage.setEnabled(true);
moveStageUp.setEnabled(stagesList.getSelectedIndex() > 0);
moveStageDown.setEnabled(stagesList.getSelectedIndex() < (stagesListModel.getSize() - 1));
} else {
deleteStage.setEnabled(false);
moveStageUp.setEnabled(false);
moveStageDown.setEnabled(false);
}
updateStageEditorPane(stagesEditorPane, selectedStage, listener);
}
});
if (quest.writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createStage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
QuestStage stage = new QuestStage(quest);
stagesListModel.addItem(stage);
stagesList.setSelectedValue(stage, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
deleteStage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedStage != null) {
stagesListModel.removeItem(selectedStage);
selectedStage = null;
stagesList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
moveStageUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedStage != null) {
stagesListModel.moveUp(selectedStage);
stagesList.setSelectedValue(selectedStage, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
moveStageDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedStage != null) {
stagesListModel.moveDown(selectedStage);
stagesList.setSelectedValue(selectedStage, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
}
});
listButtonsPane.add(createStage, JideBoxLayout.FIX);
listButtonsPane.add(deleteStage, JideBoxLayout.FIX);
listButtonsPane.add(moveStageUp, JideBoxLayout.FIX);
listButtonsPane.add(moveStageDown, JideBoxLayout.FIX);
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
stagesPane.add(listButtonsPane, JideBoxLayout.FIX);
}
if (quest.stages == null || quest.stages.isEmpty()) { if (quest.stages == null || quest.stages.isEmpty()) {
stagesPane.collapse(); stagesPane.collapse();
} }
stagesEditorPane.setLayout(new JideBoxLayout(stagesEditorPane, JideBoxLayout.PAGE_AXIS));
stagesPane.add(stagesEditorPane, JideBoxLayout.FIX);
pane.add(stagesPane, JideBoxLayout.FIX); pane.add(stagesPane, JideBoxLayout.FIX);
} }
@@ -105,21 +184,88 @@ public class QuestEditor extends JSONElementEditor {
pane.repaint(); pane.repaint();
} }
public static class StagesListModel extends CommonEditor.AtListModel<QuestStage,Quest> { public static class StagesListModel implements ListModel<QuestStage> {
Quest source;
public StagesListModel(Quest quest) { public StagesListModel(Quest quest) {
super(quest); this.source = quest;
}
@Override
public int getSize() {
if (source.stages == null) return 0;
return source.stages.size();
} }
@Override @Override
protected List<QuestStage> getInner() { public QuestStage getElementAt(int index) {
return source.stages; if (source.stages == null) return null;
return source.stages.get(index);
}
public void addItem(QuestStage item) {
if (source.stages == null) {
source.stages = new ArrayList<QuestStage>();
}
source.stages.add(item);
int index = source.stages.indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(QuestStage item) {
int index = source.stages.indexOf(item);
source.stages.remove(item);
if (source.stages.isEmpty()) {
source.stages = null;
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(QuestStage item) {
int index = source.stages.indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
public void moveUp(QuestStage item) {
int index = source.stages.indexOf(item);
QuestStage exchanged = source.stages.get(index - 1);
source.stages.set(index, exchanged);
source.stages.set(index - 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index - 1, index));
}
}
public void moveDown(QuestStage item) {
int index = source.stages.indexOf(item);
QuestStage exchanged = source.stages.get(index + 1);
source.stages.set(index, exchanged);
source.stages.set(index + 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index + 1));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
} }
@Override @Override
protected void setInner(List<QuestStage> value) { public void removeListDataListener(ListDataListener l) {
source.stages = value; listeners.remove(l);
} }
} }

View File

@@ -18,7 +18,6 @@ import javax.swing.JToolTip;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.ToolTipManager; import javax.swing.ToolTipManager;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import prefuse.Display; import prefuse.Display;
import prefuse.Visualization; import prefuse.Visualization;
import prefuse.action.ActionList; import prefuse.action.ActionList;
@@ -322,7 +321,23 @@ public class DialogueGraphView extends Display {
@Override @Override
protected String getText(VisualItem item) { protected String getText(VisualItem item) {
return CommonEditor.wordWrap(super.getText(item), 40); return wordWrap(super.getText(item), 40);
}
public String wordWrap(String in, int length) {
final String newline = "\n";
//:: Trim
while(in.length() > 0 && (in.charAt(0) == '\t' || in.charAt(0) == ' ')) in = in.substring(1);
//:: If Small Enough Already, Return Original
if(in.length() < length) return in;
//:: If Next length Contains Newline, Split There
if(in.substring(0, length).contains(newline)) return in.substring(0, in.indexOf(newline)).trim() + newline + wordWrap(in.substring(in.indexOf("\n") + 1), length);
//:: Otherwise, Split Along Nearest Previous Space/Tab/Dash
int spaceIndex = Math.max(Math.max( in.lastIndexOf(" ", length), in.lastIndexOf("\t", length)), in.lastIndexOf("-", length));
//:: If No Nearest Space, Split At length
if(spaceIndex == -1) spaceIndex = length;
//:: Split
return in.substring(0, spaceIndex).trim() + newline + wordWrap(in.substring(spaceIndex), length);
} }
} }

View File

@@ -62,7 +62,6 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel; import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
@@ -379,7 +378,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addMapchange.addActionListener(new ActionListener() { addMapchange.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newMapchange(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newMapchange(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -392,7 +391,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addSpawn.addActionListener(new ActionListener() { addSpawn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newSpawnArea(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newSpawnArea(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -405,7 +404,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addRest.addActionListener(new ActionListener() { addRest.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newRest(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newRest(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -418,7 +417,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addKey.addActionListener(new ActionListener() { addKey.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newKey(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newKey(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -431,7 +430,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addReplace.addActionListener(new ActionListener() { addReplace.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newReplace(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newReplace(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -444,7 +443,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addScript.addActionListener(new ActionListener() { addScript.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newScript(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newScript(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -457,7 +456,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addContainer.addActionListener(new ActionListener() { addContainer.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newContainer(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newContainer(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -470,7 +469,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addSign.addActionListener(new ActionListener() { addSign.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.addItem(MapObject.newSign(new tiled.core.MapObject(0, 0, 32, 32), map)); groupObjectsListModel.addObject(MapObject.newSign(new tiled.core.MapObject(0, 0, 32, 32), map));
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -483,7 +482,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
deleteObject.addActionListener(new ActionListener() { deleteObject.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
groupObjectsListModel.removeItem(selectedMapObject); groupObjectsListModel.removeObject(selectedMapObject);
map.state = GameDataElement.State.modified; map.state = GameDataElement.State.modified;
map.childrenChanged(new ArrayList<ProjectTreeNode>()); map.childrenChanged(new ArrayList<ProjectTreeNode>());
ATContentStudio.frame.editorChanged(TMXMapEditor.this); ATContentStudio.frame.editorChanged(TMXMapEditor.this);
@@ -588,7 +587,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
addReplacement.addActionListener(new ActionListener() { addReplacement.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
replacementsListModel.addReplacement(null, null); replacementsListModel.addObject(null, null);
} }
}); });
deleteReplacement = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon())); deleteReplacement = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
@@ -597,7 +596,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
deleteReplacement.addActionListener(new ActionListener() { deleteReplacement.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
replacementsListModel.removeItem(selectedReplacement); replacementsListModel.removeObject(selectedReplacement);
} }
}); });
replacementListButtonsPane.add(new JPanel(), JideBoxLayout.VARY); replacementListButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
@@ -1154,22 +1153,61 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} }
} }
public class ReplacementsListModel extends CommonEditor.AtListModel<ReplaceArea.Replacement, ReplaceArea> { public class ReplacementsListModel implements ListModel<ReplaceArea.Replacement> {
public ReplaceArea area;
public ReplacementsListModel(ReplaceArea area) { public ReplacementsListModel(ReplaceArea area) {
super(area); this.area = area;
} }
@Override @Override
protected List<ReplaceArea.Replacement> getInner() { public int getSize() {
return source.replacements; if (area.replacements == null) return 0;
return area.replacements.size();
} }
@Override @Override
protected void setInner(List<ReplaceArea.Replacement> value) { public ReplaceArea.Replacement getElementAt(int index) {
source.replacements = value; if (index < 0 || index > getSize()) return null;
if (area.replacements == null) return null;
return area.replacements.get(index);
} }
public void addReplacement(String source, String target) {
addItem(this.source.createReplacement(source, target)); public void objectChanged(ReplaceArea.Replacement repl) {
int index = area.replacements.indexOf(repl);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
public void addObject(String source, String target) {
ReplaceArea.Replacement repl = area.addReplacement(source, target);
int index = area.replacements.indexOf(repl);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeObject(ReplaceArea.Replacement repl) {
int index = area.replacements.indexOf(repl);
area.removeReplacement(repl);
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
} }
} }
@@ -1248,20 +1286,58 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} }
} }
public class MapObjectsListModel extends CommonEditor.AtListModel<MapObject, MapObjectGroup> { public class MapObjectsListModel implements ListModel<MapObject> {
public MapObjectGroup group;
public MapObjectsListModel(MapObjectGroup group) { public MapObjectsListModel(MapObjectGroup group) {
super(group); this.group = group;
}
@Override
public int getSize() {
return group.mapObjects.size();
} }
@Override @Override
protected List<MapObject> getInner() { public MapObject getElementAt(int index) {
return source.mapObjects; return group.mapObjects.get(index);
}
public void objectChanged(MapObject area) {
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(groupObjectsList, ListDataEvent.CONTENTS_CHANGED, group.mapObjects.indexOf(area), group.mapObjects.indexOf(area)));
}
}
public void addObject(MapObject area) {
group.mapObjects.add(area);
int index = group.mapObjects.indexOf(area);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(groupObjectsList, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeObject(MapObject area) {
int index = group.mapObjects.indexOf(area);
group.mapObjects.remove(area);
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(groupObjectsList, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
} }
@Override @Override
protected void setInner(List<MapObject> value) { public void removeListDataListener(ListDataListener l) {
source.mapObjects = value; listeners.remove(l);
} }
} }
public class GroupObjectsRenderer extends DefaultListCellRenderer { public class GroupObjectsRenderer extends DefaultListCellRenderer {
@@ -1277,20 +1353,36 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} }
} }
public class SpawnGroupNpcListModel extends CommonEditor.AtListModel<NPC, SpawnArea> { public class SpawnGroupNpcListModel implements ListModel<NPC> {
public SpawnArea area;
public SpawnGroupNpcListModel(SpawnArea area) { public SpawnGroupNpcListModel(SpawnArea area) {
super(area); this.area = area;
}
@Override
public int getSize() {
return area.spawnGroup.size();
} }
@Override @Override
protected List<NPC> getInner() { public NPC getElementAt(int index) {
return source.spawnGroup; return area.spawnGroup.get(index);
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<ListDataListener>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
} }
@Override @Override
protected void setInner(List<NPC> value) { public void removeListDataListener(ListDataListener l) {
source.spawnGroup = value; listeners.remove(l);
} }
} }
@@ -1864,7 +1956,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
area.oldSchoolRequirement = false; area.oldSchoolRequirement = false;
} }
} }
groupObjectsListModel.itemChanged(selectedMapObject); groupObjectsListModel.objectChanged(selectedMapObject);
} }
} else if (source == spawngroupField) { } else if (source == spawngroupField) {
if (selectedMapObject instanceof SpawnArea) { if (selectedMapObject instanceof SpawnArea) {
@@ -1877,7 +1969,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
area.spawngroup_id = (String) value; area.spawngroup_id = (String) value;
selectedMapObject.link(); selectedMapObject.link();
npcList.setModel(new SpawnGroupNpcListModel(area)); npcList.setModel(new SpawnGroupNpcListModel(area));
groupObjectsListModel.itemChanged(area); groupObjectsListModel.objectChanged(area);
npcList.revalidate(); npcList.revalidate();
npcList.repaint(); npcList.repaint();
tmxViewer.revalidate(); tmxViewer.revalidate();
@@ -1906,7 +1998,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} else { } else {
area.name = null; area.name = null;
} }
groupObjectsListModel.itemChanged(area); groupObjectsListModel.objectChanged(area);
tmxViewer.revalidate(); tmxViewer.revalidate();
tmxViewer.repaint(); tmxViewer.repaint();
} }
@@ -1935,7 +2027,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} else { } else {
area.name = null; area.name = null;
} }
groupObjectsListModel.itemChanged(area); groupObjectsListModel.objectChanged(area);
tmxViewer.revalidate(); tmxViewer.revalidate();
tmxViewer.repaint(); tmxViewer.repaint();
} else if (selectedMapObject instanceof SignArea) { } else if (selectedMapObject instanceof SignArea) {
@@ -1949,7 +2041,7 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} else { } else {
area.name = null; area.name = null;
} }
groupObjectsListModel.itemChanged(area); groupObjectsListModel.objectChanged(area);
tmxViewer.revalidate(); tmxViewer.revalidate();
tmxViewer.repaint(); tmxViewer.repaint();
} }
@@ -2134,12 +2226,12 @@ public class TMXMapEditor extends Editor implements TMXMap.MapChangedOnDiskListe
} }
} else if (source == sourceLayer) { } else if (source == sourceLayer) {
selectedReplacement.sourceLayer = (String)value; selectedReplacement.sourceLayer = (String)value;
replacementsListModel.itemChanged(selectedReplacement); replacementsListModel.objectChanged(selectedReplacement);
groupObjectsListModel.itemChanged(selectedMapObject); groupObjectsListModel.objectChanged(selectedMapObject);
} else if (source == targetLayer) { } else if (source == targetLayer) {
selectedReplacement.targetLayer = (String)value; selectedReplacement.targetLayer = (String)value;
replacementsListModel.itemChanged(selectedReplacement); replacementsListModel.objectChanged(selectedReplacement);
groupObjectsListModel.itemChanged(selectedMapObject); groupObjectsListModel.objectChanged(selectedMapObject);
} }
if (modified) { if (modified) {
if (map.state != GameDataElement.State.modified) { if (map.state != GameDataElement.State.modified) {

View File

@@ -1,282 +0,0 @@
package com.gpl.rpg.atcontentstudio.ui.tools;
import com.gpl.rpg.atcontentstudio.ATContentStudio;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.gamedata.Common;
import com.gpl.rpg.atcontentstudio.ui.CollapsiblePanel;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
import com.gpl.rpg.atcontentstudio.ui.Editor;
import com.gpl.rpg.atcontentstudio.ui.FieldUpdateListener;
import com.gpl.rpg.atcontentstudio.utils.lambda.CallWithReturn;
import com.gpl.rpg.atcontentstudio.utils.lambda.CallWithSingleArg;
import com.gpl.rpg.atcontentstudio.utils.lambda.CallWithThreeArgs;
import com.jidesoft.swing.JideBoxLayout;
import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public final class CommonEditor {
public static class PanelCreateResult<E>{
public CollapsiblePanel panel;
public JList<E> list;
}
public static <E, S> PanelCreateResult<E> createListPanel(String title,
ListCellRenderer<? super E> cellRenderer,
AtListModel<E, S> listModel,
boolean writable,
boolean moveUpDownEnabled,
CallWithSingleArg<E> selectedValueSetter,
CallWithReturn<E> selectedValueGetter,
CallWithThreeArgs<JPanel, E, FieldUpdateListener> updateRepliesEditorPane,
FieldUpdateListener listener,
CallWithReturn<E> createNew) {
CollapsiblePanel replies = new CollapsiblePanel(title);
replies.setLayout(new JideBoxLayout(replies, JideBoxLayout.PAGE_AXIS));
JList<E> repliesList = new JList<>(listModel);
repliesList.setCellRenderer(cellRenderer);
repliesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
replies.add(new JScrollPane(repliesList), JideBoxLayout.FIX);
final JPanel repliesEditorPane = new JPanel();
final JButton createReply = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteReply = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
final JButton moveReplyUp = new JButton(new ImageIcon(DefaultIcons.getArrowUpIcon()));
final JButton moveReplyDown = new JButton(new ImageIcon(DefaultIcons.getArrowDownIcon()));
deleteReply.setEnabled(false);
moveReplyUp.setEnabled(false);
moveReplyDown.setEnabled(false);
repliesList.addListSelectionListener(e -> {
E selectedReply = repliesList.getSelectedValue();
selectedValueSetter.call(selectedReply);
if (selectedReply != null) {
deleteReply.setEnabled(true);
if (moveUpDownEnabled) {
moveReplyUp.setEnabled(repliesList.getSelectedIndex() > 0);
moveReplyDown.setEnabled(repliesList.getSelectedIndex() < (listModel.getSize() - 1));
}
} else {
deleteReply.setEnabled(false);
if (moveUpDownEnabled) {
moveReplyUp.setEnabled(false);
moveReplyDown.setEnabled(false);
}
}
updateRepliesEditorPane.call(repliesEditorPane, selectedReply, listener);
});
repliesList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
GameDataElement navObj = listModel.getNavigationElement( repliesList.getSelectedValue());
if (navObj != null) {
ATContentStudio.frame.openEditor(navObj);
ATContentStudio.frame.selectInTree(navObj);
}
}
}
});
repliesList.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
GameDataElement navObj = listModel.getNavigationElement( repliesList.getSelectedValue());
ATContentStudio.frame.openEditor(navObj);
ATContentStudio.frame.selectInTree(navObj);
}
}
});
if (writable) {
JPanel listButtonsPane = new JPanel();
listButtonsPane.setLayout(new JideBoxLayout(listButtonsPane, JideBoxLayout.LINE_AXIS, 6));
createReply.addActionListener(e -> {
E created = createNew.call();
listModel.addItem(created);
repliesList.setSelectedValue(created, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
});
deleteReply.addActionListener(e -> {
E selected = selectedValueGetter.call();
if (selected != null) {
listModel.removeItem(selected);
selected = null;
selectedValueSetter.call(selected);
repliesList.clearSelection();
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
if (moveUpDownEnabled) {
moveReplyUp.addActionListener(e -> {
E selected = selectedValueGetter.call();
if (selected != null) {
listModel.moveUp(selected);
repliesList.setSelectedValue(selected, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
moveReplyDown.addActionListener(e -> {
E selected = selectedValueGetter.call();
if (selected != null) {
listModel.moveDown(selected);
repliesList.setSelectedValue(selected, true);
listener.valueChanged(new JLabel(), null); //Item changed, but we took care of it, just do the usual notification and JSON update stuff.
}
});
}
listButtonsPane.add(createReply, JideBoxLayout.FIX);
listButtonsPane.add(deleteReply, JideBoxLayout.FIX);
if (moveUpDownEnabled) {
listButtonsPane.add(moveReplyUp, JideBoxLayout.FIX);
listButtonsPane.add(moveReplyDown, JideBoxLayout.FIX);
}
listButtonsPane.add(new JPanel(), JideBoxLayout.VARY);
replies.add(listButtonsPane, JideBoxLayout.FIX);
}
repliesEditorPane.setLayout(new JideBoxLayout(repliesEditorPane, JideBoxLayout.PAGE_AXIS));
replies.add(repliesEditorPane, JideBoxLayout.FIX);
PanelCreateResult<E> ePanelCreateResult = new PanelCreateResult<>();
ePanelCreateResult.panel =replies;
ePanelCreateResult.list = repliesList;
return ePanelCreateResult;
}
public static class CreateDeathEffectPanelResult {
public CollapsiblePanel panel;
public JSpinner HPMin;
public JSpinner HPMax;
public JSpinner APMin;
public JSpinner APMax;
}
public static CreateDeathEffectPanelResult createDeathEffectPanel(Common.DeathEffect hitEffect, boolean writable, FieldUpdateListener listener, String title){
CreateDeathEffectPanelResult result = new CreateDeathEffectPanelResult();
result.panel = new CollapsiblePanel(title);
result.panel.setLayout(new JideBoxLayout(result.panel, JideBoxLayout.PAGE_AXIS));
result.HPMin = Editor.addIntegerField(result.panel, "HP bonus min: ", hitEffect.hp_boost_min, true, writable, listener);
result.HPMax = Editor.addIntegerField(result.panel, "HP bonus max: ", hitEffect.hp_boost_max, true, writable, listener);
result.APMin = Editor.addIntegerField(result.panel, "AP bonus min: ", hitEffect.ap_boost_min, true, writable, listener);
result.APMax = Editor.addIntegerField(result.panel, "AP bonus max: ", hitEffect.ap_boost_max, true, writable, listener);
return result;
}
public static String wordWrap(String in, int length) {
if (in == null) return null;
final String newline = "\n";
//:: Trim
while (!in.isEmpty() && (in.charAt(0) == '\t' || in.charAt(0) == ' ')) in = in.substring(1);
//:: If Small Enough Already, Return Original
if (in.length() < length) return in;
//:: If Next length Contains Newline, Split There
if (in.substring(0, length).contains(newline))
return in.substring(0, in.indexOf(newline)).trim() + newline + wordWrap(in.substring(in.indexOf("\n") + 1), length);
//:: Otherwise, Split Along Nearest Previous Space/Tab/Dash
int spaceIndex = Math.max(Math.max(in.lastIndexOf(" ", length), in.lastIndexOf("\t", length)), in.lastIndexOf("-", length));
//:: If No Nearest Space, Split At length
if (spaceIndex == -1) spaceIndex = length;
//:: Split
return in.substring(0, spaceIndex).trim() + newline + wordWrap(in.substring(spaceIndex), length);
}
public abstract static class AtListModel<E, S> implements ListModel<E> {
protected S source;
protected abstract List<E> getInner();
protected abstract void setInner(List<E> value);
protected GameDataElement getNavigationElement(E element){
return null;
}
public AtListModel(S source) {
this.source = source;
}
@Override
public int getSize() {
if (getInner() == null) return 0;
return getInner().size();
}
@Override
public E getElementAt(int index) {
if (index < 0 || index >= getSize()) return null;
return getInner().get(index);
}
public void addItem(E item) {
if (getInner() == null) {
setInner(new ArrayList<>());
}
getInner().add(item);
int index = getInner().indexOf(item);
for (ListDataListener l : listeners) {
l.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
}
public void removeItem(E item) {
int index = getInner().indexOf(item);
getInner().remove(item);
if (getInner().isEmpty()) {
setInner(null);
}
for (ListDataListener l : listeners) {
l.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public void itemChanged(E item) {
int index = getInner().indexOf(item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
}
}
public void moveUp(E item) {
int index = getInner().indexOf(item);
E exchanged = getInner().get(index - 1);
getInner().set(index, exchanged);
getInner().set(index - 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index - 1, index));
}
}
public void moveDown(E item) {
int index = getInner().indexOf(item);
E exchanged = getInner().get(index + 1);
getInner().set(index, exchanged);
getInner().set(index + 1, item);
for (ListDataListener l : listeners) {
l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index + 1));
}
}
List<ListDataListener> listeners = new CopyOnWriteArrayList<>();
@Override
public void addListDataListener(ListDataListener l) {
listeners.add(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
}
}
}

View File

@@ -5,7 +5,14 @@ import java.util.List;
import com.gpl.rpg.atcontentstudio.model.GameDataElement; import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource; import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.model.gamedata.*; 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.Item;
import com.gpl.rpg.atcontentstudio.model.gamedata.ItemCategory;
import com.gpl.rpg.atcontentstudio.model.gamedata.NPC;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.Requirement;
import com.gpl.rpg.atcontentstudio.model.maps.ContainerArea; import com.gpl.rpg.atcontentstudio.model.maps.ContainerArea;
import com.gpl.rpg.atcontentstudio.model.maps.KeyArea; import com.gpl.rpg.atcontentstudio.model.maps.KeyArea;
import com.gpl.rpg.atcontentstudio.model.maps.MapChange; import com.gpl.rpg.atcontentstudio.model.maps.MapChange;
@@ -104,18 +111,18 @@ public class GDEVisitor {
visit(element.category, visited, includeSource); visit(element.category, visited, includeSource);
if (element.icon_id != null) visit(element.getProject().getSpritesheet(element.icon_id.split(":")[0]), visited, includeSource); if (element.icon_id != null) visit(element.getProject().getSpritesheet(element.icon_id.split(":")[0]), visited, includeSource);
if (element.equip_effect != null && element.equip_effect.conditions != null) { if (element.equip_effect != null && element.equip_effect.conditions != null) {
for (Common.ConditionEffect condEffect : element.equip_effect.conditions) { for (Item.ConditionEffect condEffect : element.equip_effect.conditions) {
visit(condEffect.condition, visited, includeSource); visit(condEffect.condition, visited, includeSource);
} }
} }
if (element.hit_effect != null) { if (element.hit_effect != null) {
if (element.hit_effect.conditions_source != null) { if (element.hit_effect.conditions_source != null) {
for (Common.ConditionEffect condEffect : element.hit_effect.conditions_source) { for (Item.ConditionEffect condEffect : element.hit_effect.conditions_source) {
visit(condEffect.condition, visited, includeSource); visit(condEffect.condition, visited, includeSource);
} }
} }
if (element.hit_effect.conditions_target != null) { if (element.hit_effect.conditions_target != null) {
for (Common.ConditionEffect condEffect : element.hit_effect.conditions_target) { for (Item.ConditionEffect condEffect : element.hit_effect.conditions_target) {
visit(condEffect.condition, visited, includeSource); visit(condEffect.condition, visited, includeSource);
} }
} }
@@ -137,12 +144,12 @@ public class GDEVisitor {
if (element.icon_id != null) visit(element.getProject().getSpritesheet(element.icon_id.split(":")[0]), visited, includeSource); if (element.icon_id != null) visit(element.getProject().getSpritesheet(element.icon_id.split(":")[0]), visited, includeSource);
if (element.hit_effect != null) { if (element.hit_effect != null) {
if (element.hit_effect.conditions_source != null) { if (element.hit_effect.conditions_source != null) {
for (Common.TimedConditionEffect condEffect : element.hit_effect.conditions_source) { for (NPC.TimedConditionEffect condEffect : element.hit_effect.conditions_source) {
visit(condEffect.condition, visited, includeSource); visit(condEffect.condition, visited, includeSource);
} }
} }
if (element.hit_effect.conditions_target != null) { if (element.hit_effect.conditions_target != null) {
for (Common.TimedConditionEffect condEffect : element.hit_effect.conditions_target) { for (NPC.TimedConditionEffect condEffect : element.hit_effect.conditions_target) {
visit(condEffect.condition, visited, includeSource); visit(condEffect.condition, visited, includeSource);
} }
} }

View File

@@ -27,7 +27,6 @@ import javax.swing.JTextArea;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.plaf.basic.BasicInternalFrameUI;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import prefuse.Display; import prefuse.Display;
import prefuse.Visualization; import prefuse.Visualization;
import prefuse.action.Action; import prefuse.action.Action;
@@ -416,9 +415,25 @@ public class WriterModeEditor extends Editor {
@Override @Override
protected String getText(VisualItem item) { protected String getText(VisualItem item) {
if (!item.getBoolean(IS_REPLY) && super.getText(item) == null) return "[Selector]"; if (!item.getBoolean(IS_REPLY) && super.getText(item) == null) return "[Selector]";
return CommonEditor.wordWrap(super.getText(item), 40); return wordWrap(super.getText(item), 40);
}
public String wordWrap(String in, int length) {
if (in == null) return null;
final String newline = "\n";
//:: Trim
while(in.length() > 0 && (in.charAt(0) == '\t' || in.charAt(0) == ' ')) in = in.substring(1);
//:: If Small Enough Already, Return Original
if(in.length() < length) return in;
//:: If Next length Contains Newline, Split There
if(in.substring(0, length).contains(newline)) return in.substring(0, in.indexOf(newline)).trim() + newline + wordWrap(in.substring(in.indexOf("\n") + 1), length);
//:: Otherwise, Split Along Nearest Previous Space/Tab/Dash
int spaceIndex = Math.max(Math.max( in.lastIndexOf(" ", length), in.lastIndexOf("\t", length)), in.lastIndexOf("-", length));
//:: If No Nearest Space, Split At length
if(spaceIndex == -1) spaceIndex = length;
//:: Split
return in.substring(0, spaceIndex).trim() + newline + wordWrap(in.substring(spaceIndex), length);
} }
} }
class NodeStrokeColorAction extends ColorAction { class NodeStrokeColorAction extends ColorAction {

View File

@@ -1,5 +0,0 @@
package com.gpl.rpg.atcontentstudio.utils.lambda;
public interface CallWithReturn<T> {
T call();
}

View File

@@ -1,7 +0,0 @@
package com.gpl.rpg.atcontentstudio.utils.lambda;
public interface CallWithSingleArg<T> {
void call(T arg);
}

View File

@@ -1,5 +0,0 @@
package com.gpl.rpg.atcontentstudio.utils.lambda;
public interface CallWithThreeArgs<T1, T2, T3> {
void call(T1 arg1, T2 arg2, T3 arg3);
}

View File

@@ -1,6 +0,0 @@
package com.gpl.rpg.atcontentstudio.utils.lambda;
public interface CallWithTwoArgs<T1, T2> {
void call(T1 arg1, T2 arg2);
}