Compare commits

...

31 Commits

Author SHA1 Message Date
OMGeeky
775aba3a3f refactor: improve bounds checking in getElementAt method in CommonEditor 2025-06-18 13:53:49 +02:00
OMGeeky
bec4ddb71c refactor: update object handling in ReplaceArea and TMXMapEditor for consistency 2025-06-18 13:53:31 +02:00
OMGeeky
58603d32a1 add todo 2025-06-16 12:38:12 +02:00
OMGeeky
829bb336b8 cleanup 2025-06-16 12:38:00 +02:00
OMGeeky
57cf71da17 refactor: simplify panel creation for rewards and conditions in DialogueEditor & NPCEditor 2025-06-16 12:33:35 +02:00
OMGeeky
84dbca6ce1 refactor: encapsulate death effect panel creation in CommonEditor 2025-06-16 12:12:25 +02:00
OMGeeky
d6d742feac cleanup 2025-06-16 11:46:54 +02:00
OMGeeky
b775be08fc refactor: update createListPanel to return a result object containing both panel and list 2025-06-16 11:46:22 +02:00
OMGeeky
63d6397da5 refactor: streamline list panel creation in DroplistEditor & ItemEditor 2025-06-16 11:16:12 +02:00
OMGeeky
ee6907efdd refactor: streamline requirements panel creation in DialogueEditor 2025-06-16 10:50:32 +02:00
OMGeeky
02210d7581 refactor: clean up formatting and remove unnecessary line breaks in editor classes 2025-06-16 10:45:01 +02:00
OMGeeky
8a7ad08aa7 refactor: add navigation handling for replies in CommonEditor and DialogueEditor 2025-06-16 10:44:44 +02:00
OMGeeky
0081c325bb refactor: simplify stages panel creation in QuestEditor 2025-06-16 10:25:50 +02:00
OMGeeky
e10bcfe20f refactor: remove isCollapsed parameter and handle collapsing logic in DialogueEditor 2025-06-16 10:17:30 +02:00
OMGeeky
9deac7047f formatting 2025-06-16 10:11:41 +02:00
OMGeeky
0befc5563b refactor: change more ListModel implementations to AtListModel 2025-06-16 10:11:06 +02:00
OMGeeky
f747c40520 refactor: change StagesListModel to AtListModel 2025-06-16 09:57:17 +02:00
OMGeeky
92be506c11 refactor: add option to enable up down buttons or not 2025-06-16 09:56:40 +02:00
OMGeeky
64ea5377bf refactor: extract common ListModel implementation to AtListModel
and use that for moving elements up and down
2025-06-16 09:46:14 +02:00
OMGeeky
719be70744 refactor: extract replies panel creation to CommonEditor 2025-06-16 09:28:21 +02:00
OMGeeky
8f846c6098 add lambda call interfaces for single and multiple arguments 2025-06-16 09:27:19 +02:00
OMGeeky
975d13f36f extract wordWrap function to common class 2025-06-16 08:31:22 +02:00
OMGeeky
0a1fef4198 refactor: simplify link method by extracting parsing/linking logic 2025-06-16 08:23:43 +02:00
OMGeeky
5809d33bb4 refactor: remove unnecessary blank lines in multiple classes 2025-06-16 08:23:31 +02:00
OMGeeky
d8797fa826 add .output.txt to .gitignore 2025-06-16 07:49:46 +02:00
OMGeeky
70055be6d2 improve usings 2025-05-03 20:16:57 +02:00
OMGeeky
286d95d83d improve imports 2025-05-03 20:14:45 +02:00
OMGeeky
04b704daf0 more de-duplication 2025-05-03 20:10:36 +02:00
OMGeeky
3f1f988808 fix missed null check 2025-05-03 20:07:28 +02:00
OMGeeky
e232c33339 more de-duplication 2025-05-03 20:07:28 +02:00
OMGeeky
4239beb825 de-dupe code 2025-05-03 20:07:28 +02:00
27 changed files with 7091 additions and 8357 deletions

1
.gitignore vendored
View File

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

View File

@@ -1,193 +1,219 @@
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
public abstract class GameDataElement implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 2028934451226743389L;
public static enum State {
init, // We know the object exists, and have its key/ID.
parsed, // We know the object's properties, but related objects are referenced by ID only.
linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least.
created, // This is an object we are creating
modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON.
saved // Whether altered or created, this item has been saved since last modification.
}
public State state = State.init;
//Available from state init.
public ProjectTreeNode parent;
public boolean writable = false;
public BookmarkEntry bookmark = null;
//List of objects whose transition to "linked" state made them point to this instance.
private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>();
public String id = null;
@Override
public Enumeration<ProjectTreeNode> children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public TreeNode getChildAt(int arg0) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public int getIndex(TreeNode arg0) {
return 0;
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public abstract String getDesc();
public static String getStaticDesc() {
return "GameDataElements";
}
public abstract void parse();
public abstract void link();
@Override
public Project getProject() {
return parent == null ? null : parent.getProject();
}
public Image getIcon() {
return null;
}
@Override
public Image getClosedIcon() {return null;}
@Override
public Image getOpenIcon() {return null;}
@Override
public Image getLeafIcon() {
return getIcon();
}
public abstract GameDataElement clone();
public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
@Override
public GameSource.Type getDataType() {
if (parent == null) {
System.out.println("blerf.");
}
return parent.getDataType();
}
public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>();
public void addBacklinkListener(BacklinksListener l) {
backlinkListeners.add(l);
}
public void removeBacklinkListener(BacklinksListener l) {
backlinkListeners.remove(l);
}
public void addBacklink(GameDataElement gde) {
if (!backlinks.containsKey(gde)) {
backlinks.put(gde, 1);
for (BacklinksListener l : backlinkListeners) {
l.backlinkAdded(gde);
}
} else {
backlinks.put(gde, backlinks.get(gde) + 1);
}
}
public void removeBacklink(GameDataElement gde) {
if (backlinks.get(gde) == null) return;
backlinks.put(gde, backlinks.get(gde) - 1);
if (backlinks.get(gde) == 0) {
backlinks.remove(gde);
for (BacklinksListener l : backlinkListeners) {
l.backlinkRemoved(gde);
}
}
}
public Set<GameDataElement> getBacklinks() {
return backlinks.keySet();
}
public static interface BacklinksListener {
public void backlinkAdded(GameDataElement gde);
public void backlinkRemoved(GameDataElement gde);
}
@Override
public boolean isEmpty() {
return false;
}
public boolean needsSaving() {
return this.state == State.modified || this.state == State.created;
}
public abstract String getProjectFilename();
public abstract void save();
public abstract List<SaveEvent> attemptSave();
}
package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
public abstract class GameDataElement implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 2028934451226743389L;
public static enum State {
init, // We know the object exists, and have its key/ID.
parsed, // We know the object's properties, but related objects are referenced by ID only.
linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least.
created, // This is an object we are creating
modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON.
saved // Whether altered or created, this item has been saved since last modification.
}
public State state = State.init;
//Available from state init.
public ProjectTreeNode parent;
public boolean writable = false;
public BookmarkEntry bookmark = null;
//List of objects whose transition to "linked" state made them point to this instance.
private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>();
public String id = null;
@Override
public Enumeration<ProjectTreeNode> children() {
return null;
}
@Override
public boolean getAllowsChildren() {
return false;
}
@Override
public TreeNode getChildAt(int arg0) {
return null;
}
@Override
public int getChildCount() {
return 0;
}
@Override
public int getIndex(TreeNode arg0) {
return 0;
}
@Override
public TreeNode getParent() {
return parent;
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenAdded(path);
}
@Override
public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenChanged(path);
}
@Override
public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this);
parent.childrenRemoved(path);
}
@Override
public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>());
}
@Override
public abstract String getDesc();
public static String getStaticDesc() {
return "GameDataElements";
}
public abstract void parse();
public abstract void link();
@Override
public Project getProject() {
return parent == null ? null : parent.getProject();
}
public Image getIcon() {
return null;
}
@Override
public Image getClosedIcon() {return null;}
@Override
public Image getOpenIcon() {return null;}
@Override
public Image getLeafIcon() {
return getIcon();
}
public abstract GameDataElement clone();
public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
@Override
public GameSource.Type getDataType() {
if (parent == null) {
System.out.println("blerf.");
}
return parent.getDataType();
}
public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>();
public void addBacklinkListener(BacklinksListener l) {
backlinkListeners.add(l);
}
public void removeBacklinkListener(BacklinksListener l) {
backlinkListeners.remove(l);
}
public void addBacklink(GameDataElement gde) {
if (!backlinks.containsKey(gde)) {
backlinks.put(gde, 1);
for (BacklinksListener l : backlinkListeners) {
l.backlinkAdded(gde);
}
} else {
backlinks.put(gde, backlinks.get(gde) + 1);
}
}
public void removeBacklink(GameDataElement gde) {
if (backlinks.get(gde) == null) return;
backlinks.put(gde, backlinks.get(gde) - 1);
if (backlinks.get(gde) == 0) {
backlinks.remove(gde);
for (BacklinksListener l : backlinkListeners) {
l.backlinkRemoved(gde);
}
}
}
public Set<GameDataElement> getBacklinks() {
return backlinks.keySet();
}
public static interface BacklinksListener {
public void backlinkAdded(GameDataElement gde);
public void backlinkRemoved(GameDataElement gde);
}
@Override
public boolean isEmpty() {
return false;
}
public boolean needsSaving() {
return this.state == State.modified || this.state == State.created;
}
public abstract String getProjectFilename();
public abstract void save();
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,381 +1,374 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ActorCondition extends JSONElement {
private static final long serialVersionUID = -3969824899972048507L;
public static final Integer MAGNITUDE_CLEAR = -99;
public static final Integer DURATION_FOREVER = 999;;
public static final Integer DURATION_NONE = 0;
// Available from init state
//public String id; inherited.
public String icon_id;
public String display_name;
public String description;
// Available from parsed state
public ACCategory category = null;
public Integer positive = null;
public Integer stacking = null;
public RoundEffect round_effect = null;
public RoundEffect full_round_effect = null;
public AbilityEffect constant_ability_effect = null;
public enum ACCategory {
spiritual,
mental,
physical,
blood
}
public static enum VisualEffectID {
redSplash
,blueSwirl
,greenSplash
,miss
}
public static class RoundEffect implements Cloneable {
// Available from parsed state
public VisualEffectID visual_effect = null;
public Integer hp_boost_min = null;
public Integer hp_boost_max = null;
public Integer ap_boost_min = null;
public Integer ap_boost_max = null;
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
public static class AbilityEffect implements Cloneable {
// Available from parsed state
public Integer max_hp_boost = null;
public Integer max_ap_boost = null;
public Integer increase_move_cost = null;
public Integer increase_use_cost = null;
public Integer increase_reequip_cost = null;
public Integer increase_attack_cost = null;
public Integer increase_attack_chance = null;
public Integer increase_damage_min = null;
public Integer increase_damage_max = null;
public Integer increase_critical_skill = null;
public Integer increase_block_chance = null;
public Integer increase_damage_resistance = null;
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+display_name+" ("+id+")";
}
@SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<ActorCondition> category) {
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List actorConditions = (List) parser.parse(reader);
for (Object obj : actorConditions) {
Map aCondJson = (Map)obj;
ActorCondition aCond = fromJson(aCondJson);
aCond.jsonFile = jsonFile;
aCond.parent = category;
if (aCond.getDataType() == GameSource.Type.created || aCond.getDataType() == GameSource.Type.altered) {
aCond.writable = true;
}
category.add(aCond);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public static ActorCondition fromJson(String jsonString) throws ParseException {
Map aCondJson = (Map) new JSONParser().parse(jsonString);
ActorCondition aCond = fromJson(aCondJson);
aCond.parse(aCondJson);
return aCond;
}
@SuppressWarnings("rawtypes")
public static ActorCondition fromJson(Map aCondJson) {
ActorCondition aCond = new ActorCondition();
aCond.icon_id = (String) aCondJson.get("iconID");
aCond.id = (String) aCondJson.get("id");
aCond.display_name = (String) aCondJson.get("name");
return aCond;
}
@SuppressWarnings("rawtypes")
@Override
public void parse(Map aCondJson) {
if (aCondJson.get("description") != null) this.description = (String) aCondJson.get("description");
if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category"));
this.positive = JSONElement.getInteger((Number) aCondJson.get("isPositive"));
Map abilityEffect = (Map) aCondJson.get("abilityEffect");
if (abilityEffect != null) {
this.constant_ability_effect = new AbilityEffect();
this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance"));
if (abilityEffect.get("increaseAttackDamage") != null) {
this.constant_ability_effect.increase_damage_min = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("min")));
this.constant_ability_effect.increase_damage_max = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("max")));
}
this.constant_ability_effect.max_hp_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxHP"));
this.constant_ability_effect.max_ap_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxAP"));
this.constant_ability_effect.increase_move_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseMoveCost"));
this.constant_ability_effect.increase_use_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseUseItemCost"));
this.constant_ability_effect.increase_reequip_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseReequipCost"));
this.constant_ability_effect.increase_attack_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackCost"));
this.constant_ability_effect.increase_critical_skill = JSONElement.getInteger((Number) abilityEffect.get("increaseCriticalSkill"));
this.constant_ability_effect.increase_block_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseBlockChance"));
this.constant_ability_effect.increase_damage_resistance = JSONElement.getInteger((Number) abilityEffect.get("increaseDamageResistance"));
}
this.stacking = JSONElement.getInteger((Number) aCondJson.get("isStacking"));
Map roundEffect = (Map) aCondJson.get("roundEffect");
if (roundEffect != null) {
this.round_effect = new RoundEffect();
if (roundEffect.get("increaseCurrentHP") != null) {
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max")));
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min")));
}
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_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) roundEffect.get("visualEffectID");
this.round_effect.visual_effect = null;
if (vfx != null) {
try {
this.round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
}
}
Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect");
if (fullRoundEffect != null) {
this.full_round_effect = new RoundEffect();
if (fullRoundEffect.get("increaseCurrentHP") != null) {
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max")));
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min")));
}
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_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) fullRoundEffect.get("visualEffectID");
this.full_round_effect.visual_effect = null;
if (vfx != null) {
try {
this.full_round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
return;
}
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
if (getProject().getSpritesheet(spritesheetId) == null) {
System.out.println("Actor Condition");
System.out.println(this.id);
System.out.println("failed to load spritesheet:");
System.out.println(spritesheetId);
System.out.println("while creating backlink for icon_id:");
System.out.println(this.icon_id);
}
getProject().getSpritesheet(spritesheetId).addBacklink(this);
}
this.state = State.linked;
}
public static String getStaticDesc() {
return "Actor Conditions";
}
@Override
public Image getIcon() {
return getProject().getIcon(icon_id);
}
public Image getImage() {
return getProject().getImage(icon_id);
}
@Override
public JSONElement clone() {
ActorCondition clone = new ActorCondition();
clone.jsonFile = this.jsonFile;
clone.state = this.state;
clone.id = this.id;
clone.display_name = this.display_name;
clone.description = this.description;
clone.icon_id = this.icon_id;
clone.category = this.category;
clone.positive = this.positive;
clone.stacking = this.stacking;
if (this.round_effect != null) {
clone.round_effect = (RoundEffect) this.round_effect.clone();
}
if (this.constant_ability_effect != null) {
clone.constant_ability_effect = (AbilityEffect) constant_ability_effect.clone();
}
if (this.full_round_effect != null) {
clone.full_round_effect = (RoundEffect) this.full_round_effect.clone();
}
return clone;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map jsonAC = new LinkedHashMap();
jsonAC.put("id", this.id);
if (this.icon_id != null) jsonAC.put("iconID", this.icon_id);
if (this.display_name != null) jsonAC.put("name", this.display_name);
if (this.description != null) jsonAC.put("description", this.description);
if (this.category != null) jsonAC.put("category", this.category.toString());
if (this.positive != null && this.positive == 1) jsonAC.put("isPositive", this.positive);
if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking);
if (this.round_effect != null) {
Map jsonRound = new LinkedHashMap();
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) {
Map jsonHP = new LinkedHashMap();
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max);
else jsonHP.put("max", 0);
jsonRound.put("increaseCurrentHP", jsonHP);
}
if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) {
Map jsonAP = new LinkedHashMap();
if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max);
else jsonAP.put("max", 0);
jsonRound.put("increaseCurrentAP", jsonAP);
}
jsonAC.put("roundEffect", jsonRound);
}
if (this.full_round_effect != null) {
Map jsonFullRound = new LinkedHashMap();
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) {
Map jsonHP = new LinkedHashMap();
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max);
else jsonHP.put("max", 0);
jsonFullRound.put("increaseCurrentHP", jsonHP);
}
if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) {
Map jsonAP = new LinkedHashMap();
if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max);
else jsonAP.put("max", 0);
jsonFullRound.put("increaseCurrentAP", jsonAP);
}
jsonAC.put("fullRoundEffect", jsonFullRound);
}
if (this.constant_ability_effect != null) {
Map jsonAbility = new LinkedHashMap();
if (this.constant_ability_effect.increase_attack_chance != null) jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance);
if (this.constant_ability_effect.increase_damage_min != null || this.constant_ability_effect.increase_damage_max != null) {
Map jsonAD = new LinkedHashMap();
if (this.constant_ability_effect.increase_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
else jsonAD.put("min", 0);
if (this.constant_ability_effect.increase_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
else jsonAD.put("max", 0);
jsonAbility.put("increaseAttackDamage", jsonAD);
}
if (this.constant_ability_effect.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
if (this.constant_ability_effect.max_ap_boost != null) jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
if (this.constant_ability_effect.increase_move_cost != null) jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost);
if (this.constant_ability_effect.increase_use_cost != null) jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_use_cost);
if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("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);
if (this.constant_ability_effect.increase_block_chance != null) jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
jsonAC.put("abilityEffect", jsonAbility);
}
return jsonAC;
}
@Override
public String getProjectFilename() {
return "actorconditions_"+getProject().name+".json";
}
}
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
public class ActorCondition extends JSONElement {
private static final long serialVersionUID = -3969824899972048507L;
public static final Integer MAGNITUDE_CLEAR = -99;
public static final Integer DURATION_FOREVER = 999;;
public static final Integer DURATION_NONE = 0;
// Available from init state
//public String id; inherited.
public String icon_id;
public String display_name;
public String description;
// Available from parsed state
public ACCategory category = null;
public Integer positive = null;
public Integer stacking = null;
public RoundEffect round_effect = null;
public RoundEffect full_round_effect = null;
public AbilityEffect constant_ability_effect = null;
public enum ACCategory {
spiritual,
mental,
physical,
blood
}
public static enum VisualEffectID {
redSplash
,blueSwirl
,greenSplash
,miss
}
public static class RoundEffect implements Cloneable {
// Available from parsed state
public VisualEffectID visual_effect = null;
public Integer hp_boost_min = null;
public Integer hp_boost_max = null;
public Integer ap_boost_min = null;
public Integer ap_boost_max = null;
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
public static class AbilityEffect implements Cloneable {
// Available from parsed state
public Integer max_hp_boost = null;
public Integer max_ap_boost = null;
public Integer increase_move_cost = null;
public Integer increase_use_cost = null;
public Integer increase_reequip_cost = null;
public Integer increase_attack_cost = null;
public Integer increase_attack_chance = null;
public Integer increase_damage_min = null;
public Integer increase_damage_max = null;
public Integer increase_critical_skill = null;
public Integer increase_block_chance = null;
public Integer increase_damage_resistance = null;
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+display_name+" ("+id+")";
}
@SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<ActorCondition> category) {
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List actorConditions = (List) parser.parse(reader);
for (Object obj : actorConditions) {
Map aCondJson = (Map)obj;
ActorCondition aCond = fromJson(aCondJson);
aCond.jsonFile = jsonFile;
aCond.parent = category;
if (aCond.getDataType() == GameSource.Type.created || aCond.getDataType() == GameSource.Type.altered) {
aCond.writable = true;
}
category.add(aCond);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public static ActorCondition fromJson(String jsonString) throws ParseException {
Map aCondJson = (Map) new JSONParser().parse(jsonString);
ActorCondition aCond = fromJson(aCondJson);
aCond.parse(aCondJson);
return aCond;
}
@SuppressWarnings("rawtypes")
public static ActorCondition fromJson(Map aCondJson) {
ActorCondition aCond = new ActorCondition();
aCond.icon_id = (String) aCondJson.get("iconID");
aCond.id = (String) aCondJson.get("id");
aCond.display_name = (String) aCondJson.get("name");
return aCond;
}
@SuppressWarnings("rawtypes")
@Override
public void parse(Map aCondJson) {
if (aCondJson.get("description") != null) this.description = (String) aCondJson.get("description");
if (aCondJson.get("category") != null) this.category = ACCategory.valueOf((String) aCondJson.get("category"));
this.positive = JSONElement.getInteger((Number) aCondJson.get("isPositive"));
Map abilityEffect = (Map) aCondJson.get("abilityEffect");
if (abilityEffect != null) {
this.constant_ability_effect = new AbilityEffect();
this.constant_ability_effect.increase_attack_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackChance"));
if (abilityEffect.get("increaseAttackDamage") != null) {
this.constant_ability_effect.increase_damage_min = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("min")));
this.constant_ability_effect.increase_damage_max = JSONElement.getInteger((Number) (((Map)abilityEffect.get("increaseAttackDamage")).get("max")));
}
this.constant_ability_effect.max_hp_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxHP"));
this.constant_ability_effect.max_ap_boost = JSONElement.getInteger((Number) abilityEffect.get("increaseMaxAP"));
this.constant_ability_effect.increase_move_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseMoveCost"));
this.constant_ability_effect.increase_use_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseUseItemCost"));
this.constant_ability_effect.increase_reequip_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseReequipCost"));
this.constant_ability_effect.increase_attack_cost = JSONElement.getInteger((Number) abilityEffect.get("increaseAttackCost"));
this.constant_ability_effect.increase_critical_skill = JSONElement.getInteger((Number) abilityEffect.get("increaseCriticalSkill"));
this.constant_ability_effect.increase_block_chance = JSONElement.getInteger((Number) abilityEffect.get("increaseBlockChance"));
this.constant_ability_effect.increase_damage_resistance = JSONElement.getInteger((Number) abilityEffect.get("increaseDamageResistance"));
}
this.stacking = JSONElement.getInteger((Number) aCondJson.get("isStacking"));
Map roundEffect = (Map) aCondJson.get("roundEffect");
if (roundEffect != null) {
this.round_effect = new RoundEffect();
if (roundEffect.get("increaseCurrentHP") != null) {
this.round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("max")));
this.round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentHP")).get("min")));
}
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_min = JSONElement.getInteger((Number) (((Map)roundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) roundEffect.get("visualEffectID");
this.round_effect.visual_effect = null;
if (vfx != null) {
try {
this.round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
}
}
Map fullRoundEffect = (Map) aCondJson.get("fullRoundEffect");
if (fullRoundEffect != null) {
this.full_round_effect = new RoundEffect();
if (fullRoundEffect.get("increaseCurrentHP") != null) {
this.full_round_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("max")));
this.full_round_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentHP")).get("min")));
}
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_min = JSONElement.getInteger((Number) (((Map)fullRoundEffect.get("increaseCurrentAP")).get("min")));
}
String vfx = (String) fullRoundEffect.get("visualEffectID");
this.full_round_effect.visual_effect = null;
if (vfx != null) {
try {
this.full_round_effect.visual_effect = VisualEffectID.valueOf(vfx);
} catch(IllegalArgumentException e) {}
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
if (this.icon_id != null) {
String spritesheetId = this.icon_id.split(":")[0];
if (getProject().getSpritesheet(spritesheetId) == null) {
System.out.println("Actor Condition");
System.out.println(this.id);
System.out.println("failed to load spritesheet:");
System.out.println(spritesheetId);
System.out.println("while creating backlink for icon_id:");
System.out.println(this.icon_id);
}
getProject().getSpritesheet(spritesheetId).addBacklink(this);
}
this.state = State.linked;
}
public static String getStaticDesc() {
return "Actor Conditions";
}
@Override
public Image getIcon() {
return getProject().getIcon(icon_id);
}
public Image getImage() {
return getProject().getImage(icon_id);
}
@Override
public JSONElement clone() {
ActorCondition clone = new ActorCondition();
clone.jsonFile = this.jsonFile;
clone.state = this.state;
clone.id = this.id;
clone.display_name = this.display_name;
clone.description = this.description;
clone.icon_id = this.icon_id;
clone.category = this.category;
clone.positive = this.positive;
clone.stacking = this.stacking;
if (this.round_effect != null) {
clone.round_effect = (RoundEffect) this.round_effect.clone();
}
if (this.constant_ability_effect != null) {
clone.constant_ability_effect = (AbilityEffect) constant_ability_effect.clone();
}
if (this.full_round_effect != null) {
clone.full_round_effect = (RoundEffect) this.full_round_effect.clone();
}
return clone;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map jsonAC = new LinkedHashMap();
jsonAC.put("id", this.id);
if (this.icon_id != null) jsonAC.put("iconID", this.icon_id);
if (this.display_name != null) jsonAC.put("name", this.display_name);
if (this.description != null) jsonAC.put("description", this.description);
if (this.category != null) jsonAC.put("category", this.category.toString());
if (this.positive != null && this.positive == 1) jsonAC.put("isPositive", this.positive);
if (this.stacking != null && this.stacking == 1) jsonAC.put("isStacking", this.stacking);
if (this.round_effect != null) {
Map jsonRound = new LinkedHashMap();
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) {
Map jsonHP = new LinkedHashMap();
if (this.round_effect.hp_boost_min != null) jsonHP.put("min", this.round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.round_effect.hp_boost_max != null) jsonHP.put("max", this.round_effect.hp_boost_max);
else jsonHP.put("max", 0);
jsonRound.put("increaseCurrentHP", jsonHP);
}
if (this.round_effect.ap_boost_min != null || this.round_effect.ap_boost_max != null) {
Map jsonAP = new LinkedHashMap();
if (this.round_effect.ap_boost_min != null) jsonAP.put("min", this.round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.round_effect.ap_boost_max != null) jsonAP.put("max", this.round_effect.ap_boost_max);
else jsonAP.put("max", 0);
jsonRound.put("increaseCurrentAP", jsonAP);
}
jsonAC.put("roundEffect", jsonRound);
}
if (this.full_round_effect != null) {
Map jsonFullRound = new LinkedHashMap();
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) {
Map jsonHP = new LinkedHashMap();
if (this.full_round_effect.hp_boost_min != null) jsonHP.put("min", this.full_round_effect.hp_boost_min);
else jsonHP.put("min", 0);
if (this.full_round_effect.hp_boost_max != null) jsonHP.put("max", this.full_round_effect.hp_boost_max);
else jsonHP.put("max", 0);
jsonFullRound.put("increaseCurrentHP", jsonHP);
}
if (this.full_round_effect.ap_boost_min != null || this.full_round_effect.ap_boost_max != null) {
Map jsonAP = new LinkedHashMap();
if (this.full_round_effect.ap_boost_min != null) jsonAP.put("min", this.full_round_effect.ap_boost_min);
else jsonAP.put("min", 0);
if (this.full_round_effect.ap_boost_max != null) jsonAP.put("max", this.full_round_effect.ap_boost_max);
else jsonAP.put("max", 0);
jsonFullRound.put("increaseCurrentAP", jsonAP);
}
jsonAC.put("fullRoundEffect", jsonFullRound);
}
if (this.constant_ability_effect != null) {
Map jsonAbility = new LinkedHashMap();
if (this.constant_ability_effect.increase_attack_chance != null) jsonAbility.put("increaseAttackChance", this.constant_ability_effect.increase_attack_chance);
if (this.constant_ability_effect.increase_damage_min != null || this.constant_ability_effect.increase_damage_max != null) {
Map jsonAD = new LinkedHashMap();
if (this.constant_ability_effect.increase_damage_min != null) jsonAD.put("min", this.constant_ability_effect.increase_damage_min);
else jsonAD.put("min", 0);
if (this.constant_ability_effect.increase_damage_max != null) jsonAD.put("max", this.constant_ability_effect.increase_damage_max);
else jsonAD.put("max", 0);
jsonAbility.put("increaseAttackDamage", jsonAD);
}
if (this.constant_ability_effect.max_hp_boost != null) jsonAbility.put("increaseMaxHP", this.constant_ability_effect.max_hp_boost);
if (this.constant_ability_effect.max_ap_boost != null) jsonAbility.put("increaseMaxAP", this.constant_ability_effect.max_ap_boost);
if (this.constant_ability_effect.increase_move_cost != null) jsonAbility.put("increaseMoveCost", this.constant_ability_effect.increase_move_cost);
if (this.constant_ability_effect.increase_use_cost != null) jsonAbility.put("increaseUseItemCost", this.constant_ability_effect.increase_use_cost);
if (this.constant_ability_effect.increase_reequip_cost != null) jsonAbility.put("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);
if (this.constant_ability_effect.increase_block_chance != null) jsonAbility.put("increaseBlockChance", this.constant_ability_effect.increase_block_chance);
if (this.constant_ability_effect.increase_damage_resistance != null) jsonAbility.put("increaseDamageResistance", this.constant_ability_effect.increase_damage_resistance);
jsonAC.put("abilityEffect", jsonAbility);
}
return jsonAC;
}
@Override
public String getProjectFilename() {
return "actorconditions_"+getProject().name+".json";
}
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,180 +1,179 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
public abstract class JSONElement extends GameDataElement {
private static final long serialVersionUID = -8015398814080503982L;
//Available from state init.
public File jsonFile;
@SuppressWarnings("rawtypes")
public void parse() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List gameDataElements = (List) parser.parse(reader);
for (Object obj : gameDataElements) {
Map jsonObj = (Map)obj;
String id = (String) jsonObj.get("id");
try {
if (id != null && id.equals(this.id )) {
this.parse(jsonObj);
this.state = State.parsed;
break;
}
}
catch(Exception e){
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());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.println(id);
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public abstract void parse(@SuppressWarnings("rawtypes") Map jsonObj);
@SuppressWarnings("rawtypes")
public abstract Map toJson();
public String toJsonString() {
StringWriter writer = new JsonPrettyWriter();
try {
JSONObject.writeJSONString(this.toJson(), writer);
} catch (IOException e) {
//Impossible with a StringWriter
}
return writer.toString();
}
@Override
public GameDataSet getDataSet() {
if (parent == null) {
System.out.println("blerf.");
}
return parent.getDataSet();
}
public void save() {
if (this.getParent() instanceof GameDataCategory<?> && writable) {
((GameDataCategory<?>)this.getParent()).save(this.jsonFile);
}
}
/**
* Returns null if save occurred (no notable events).
*/
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName());
if (events == null || events.isEmpty()) {
return null;
}
if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) {
save();
return null;
}
return events;
}
public static Integer getInteger(Number n) {
return n == null ? null : n.intValue();
}
public static Double getDouble(Number n) {
return n == null ? null : n.doubleValue();
}
public static Double parseChance(String s) {
if (s.equals("100")) return 100d;
else if (s.equals("70")) return 70d;
else if (s.equals("30")) return 30d;
else if (s.equals("25")) return 25d;
else if (s.equals("20")) return 20d;
else if (s.equals("10")) return 10d;
else if (s.equals("5")) return 5d;
else if (s.equals("1")) return 1d;
else if (s.equals("1/1000")) return 0.1;
else if (s.equals("1/10000")) return 0.01;
else if (s.indexOf('/') >= 0) {
int c = s.indexOf('/');
double a = 1;
try {
a = Integer.parseInt(s.substring(0, c));
} catch (NumberFormatException nfe) {}
double b = 100;
try {
b = Integer.parseInt(s.substring(c+1));
} catch (NumberFormatException nfe) {}
return a/b;
}
else {
double a = 10;
try {
a = Double.parseDouble(s);
} catch (NumberFormatException nfe) {}
return a;
}
}
public static String printJsonChance(Double chance) {
if (chance.equals(100d)) return "100";
else if (chance.equals(70d)) return "70";
else if (chance.equals(30d)) return "30";
else if (chance.equals(25d)) return "25";
else if (chance.equals(20d)) return "20";
else if (chance.equals(10d)) return "10";
else if (chance.equals(5d)) return "5";
else if (chance.equals(1d)) return "1";
else if (chance.equals(0.1d)) return "1/1000";
else if (chance.equals(0.01d)) return "1/10000";
else {
if (chance.intValue() == chance) return Integer.toString(chance.intValue());
//TODO Better handling of fractions. Chance description need a complete overhaul in AT.
//This part does not output the input content of parseDouble(String s) in the case of fractions.
return chance.toString();
}
}
}
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.io.JsonPrettyWriter;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.SaveEvent;
public abstract class JSONElement extends GameDataElement {
private static final long serialVersionUID = -8015398814080503982L;
//Available from state init.
public File jsonFile;
@SuppressWarnings("rawtypes")
public void parse() {
if (shouldSkipParseOrLink()) {
return;
}
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List gameDataElements = (List) parser.parse(reader);
for (Object obj : gameDataElements) {
Map jsonObj = (Map)obj;
String id = (String) jsonObj.get("id");
try {
if (id != null && id.equals(this.id )) {
this.parse(jsonObj);
this.state = State.parsed;
break;
}
}
catch(Exception e){
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());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.println(id);
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public abstract void parse(@SuppressWarnings("rawtypes") Map jsonObj);
@SuppressWarnings("rawtypes")
public abstract Map toJson();
public String toJsonString() {
StringWriter writer = new JsonPrettyWriter();
try {
JSONObject.writeJSONString(this.toJson(), writer);
} catch (IOException e) {
//Impossible with a StringWriter
}
return writer.toString();
}
@Override
public GameDataSet getDataSet() {
if (parent == null) {
System.out.println("blerf.");
}
return parent.getDataSet();
}
public void save() {
if (this.getParent() instanceof GameDataCategory<?> && writable) {
((GameDataCategory<?>)this.getParent()).save(this.jsonFile);
}
}
/**
* Returns null if save occurred (no notable events).
*/
public List<SaveEvent> attemptSave() {
List<SaveEvent> events = ((GameDataCategory<?>)this.getParent()).attemptSave(true, this.jsonFile.getName());
if (events == null || events.isEmpty()) {
return null;
}
if (events.size() == 1 && events.get(0).type == SaveEvent.Type.alsoSave && events.get(0).target == this) {
save();
return null;
}
return events;
}
public static Integer getInteger(Number n) {
return n == null ? null : n.intValue();
}
public static Double getDouble(Number n) {
return n == null ? null : n.doubleValue();
}
public static Double parseChance(String s) {
if (s.equals("100")) return 100d;
else if (s.equals("70")) return 70d;
else if (s.equals("30")) return 30d;
else if (s.equals("25")) return 25d;
else if (s.equals("20")) return 20d;
else if (s.equals("10")) return 10d;
else if (s.equals("5")) return 5d;
else if (s.equals("1")) return 1d;
else if (s.equals("1/1000")) return 0.1;
else if (s.equals("1/10000")) return 0.01;
else if (s.indexOf('/') >= 0) {
int c = s.indexOf('/');
double a = 1;
try {
a = Integer.parseInt(s.substring(0, c));
} catch (NumberFormatException nfe) {}
double b = 100;
try {
b = Integer.parseInt(s.substring(c+1));
} catch (NumberFormatException nfe) {}
return a/b;
}
else {
double a = 10;
try {
a = Double.parseDouble(s);
} catch (NumberFormatException nfe) {}
return a;
}
}
public static String printJsonChance(Double chance) {
if (chance.equals(100d)) return "100";
else if (chance.equals(70d)) return "70";
else if (chance.equals(30d)) return "30";
else if (chance.equals(25d)) return "25";
else if (chance.equals(20d)) return "20";
else if (chance.equals(10d)) return "10";
else if (chance.equals(5d)) return "5";
else if (chance.equals(1d)) return "1";
else if (chance.equals(0.1d)) return "1/1000";
else if (chance.equals(0.01d)) return "1/10000";
else {
if (chance.intValue() == chance) return Integer.toString(chance.intValue());
//TODO Better handling of fractions. Chance description need a complete overhaul in AT.
//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,198 +1,191 @@
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Quest extends JSONElement {
private static final long serialVersionUID = 2004839647483250099L;
//Available from init state
//public String id = null; inherited.
public String name = null;
//Available in parsed state
public Integer visible_in_log = null;
public List<QuestStage> stages = null;
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
return "Quests";
}
@SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Quest> category) {
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List quests = (List) parser.parse(reader);
for (Object obj : quests) {
Map questJson = (Map)obj;
Quest quest = fromJson(questJson);
quest.jsonFile = jsonFile;
quest.parent = category;
if (quest.getDataType() == GameSource.Type.created || quest.getDataType() == GameSource.Type.altered) {
quest.writable = true;
}
category.add(quest);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public static Quest fromJson(String jsonString) throws ParseException {
Map questJson = (Map) new JSONParser().parse(jsonString);
Quest quest = fromJson(questJson);
quest.parse(questJson);
return quest;
}
@SuppressWarnings("rawtypes")
public static Quest fromJson(Map questJson) {
Quest quest = new Quest();
quest.id = (String) questJson.get("id");
quest.name = (String) questJson.get("name");
//Quests have to be parsed to have their stages initialized.
quest.parse(questJson);
return quest;
}
@SuppressWarnings("rawtypes")
@Override
public void parse(Map questJson) {
this.visible_in_log = JSONElement.getInteger((Number) questJson.get("showInLog"));
List questStagesJson = (List) questJson.get("stages");
this.stages = new ArrayList<QuestStage>();
if (questStagesJson != null && !questStagesJson.isEmpty()) {
for (Object questStageJsonObj : questStagesJson) {
Map questStageJson = (Map)questStageJsonObj;
QuestStage questStage = new QuestStage(this);
questStage.parse(questStageJson);
this.stages.add(questStage);
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
return;
}
for (QuestStage stage : stages) {
stage.link();
}
//Nothing to link to :D
this.state = State.linked;
}
@Override
public Image getIcon() {
return DefaultIcons.getQuestIcon();
}
public Image getImage() {
return DefaultIcons.getQuestImage();
}
@Override
public GameDataElement clone() {
Quest clone = new Quest();
clone.jsonFile = this.jsonFile;
clone.state = this.state;
clone.id = this.id;
clone.name = this.name;
clone.visible_in_log = this.visible_in_log;
if (this.stages != null) {
clone.stages = new ArrayList<QuestStage>();
for (QuestStage stage : this.stages){
clone.stages.add((QuestStage) stage.clone(clone));
}
}
return clone;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map questJson = new LinkedHashMap();
questJson.put("id", this.id);
if (this.name != null) questJson.put("name", this.name);
if (this.visible_in_log != null) questJson.put("showInLog", this.visible_in_log);
if (this.stages != null) {
List stagesJson = new ArrayList();
questJson.put("stages", stagesJson);
for (QuestStage stage : this.stages) {
stagesJson.add(stage.toJson());
}
}
return questJson;
}
@Override
public String getProjectFilename() {
return "questlist_"+getProject().name+".json";
}
public QuestStage getStage(Integer stageId) {
for (QuestStage stage : stages) {
if (stage.progress.equals(stageId)) {
return stage;
}
}
return null;
}
}
package com.gpl.rpg.atcontentstudio.model.gamedata;
import java.awt.Image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.gpl.rpg.atcontentstudio.Notification;
import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.model.GameSource;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class Quest extends JSONElement {
private static final long serialVersionUID = 2004839647483250099L;
//Available from init state
//public String id = null; inherited.
public String name = null;
//Available in parsed state
public Integer visible_in_log = null;
public List<QuestStage> stages = null;
@Override
public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")";
}
public static String getStaticDesc() {
return "Quests";
}
@SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Quest> category) {
JSONParser parser = new JSONParser();
FileReader reader = null;
try {
reader = new FileReader(jsonFile);
List quests = (List) parser.parse(reader);
for (Object obj : quests) {
Map questJson = (Map)obj;
Quest quest = fromJson(questJson);
quest.jsonFile = jsonFile;
quest.parent = category;
if (quest.getDataType() == GameSource.Type.created || quest.getDataType() == GameSource.Type.altered) {
quest.writable = true;
}
category.add(quest);
}
} catch (FileNotFoundException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} catch (ParseException e) {
Notification.addError("Error while parsing JSON file "+jsonFile.getAbsolutePath()+": "+e.getMessage());
e.printStackTrace();
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("rawtypes")
public static Quest fromJson(String jsonString) throws ParseException {
Map questJson = (Map) new JSONParser().parse(jsonString);
Quest quest = fromJson(questJson);
quest.parse(questJson);
return quest;
}
@SuppressWarnings("rawtypes")
public static Quest fromJson(Map questJson) {
Quest quest = new Quest();
quest.id = (String) questJson.get("id");
quest.name = (String) questJson.get("name");
//Quests have to be parsed to have their stages initialized.
quest.parse(questJson);
return quest;
}
@SuppressWarnings("rawtypes")
@Override
public void parse(Map questJson) {
this.visible_in_log = JSONElement.getInteger((Number) questJson.get("showInLog"));
List questStagesJson = (List) questJson.get("stages");
this.stages = new ArrayList<QuestStage>();
if (questStagesJson != null && !questStagesJson.isEmpty()) {
for (Object questStageJsonObj : questStagesJson) {
Map questStageJson = (Map)questStageJsonObj;
QuestStage questStage = new QuestStage(this);
questStage.parse(questStageJson);
this.stages.add(questStage);
}
}
this.state = State.parsed;
}
@Override
public void link() {
if (shouldSkipParseOrLink()) {
return;
}
ensureParseIfNeeded();
for (QuestStage stage : stages) {
stage.link();
}
//Nothing to link to :D
this.state = State.linked;
}
@Override
public Image getIcon() {
return DefaultIcons.getQuestIcon();
}
public Image getImage() {
return DefaultIcons.getQuestImage();
}
@Override
public GameDataElement clone() {
Quest clone = new Quest();
clone.jsonFile = this.jsonFile;
clone.state = this.state;
clone.id = this.id;
clone.name = this.name;
clone.visible_in_log = this.visible_in_log;
if (this.stages != null) {
clone.stages = new ArrayList<QuestStage>();
for (QuestStage stage : this.stages){
clone.stages.add((QuestStage) stage.clone(clone));
}
}
return clone;
}
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
//Nothing to link to.
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Map toJson() {
Map questJson = new LinkedHashMap();
questJson.put("id", this.id);
if (this.name != null) questJson.put("name", this.name);
if (this.visible_in_log != null) questJson.put("showInLog", this.visible_in_log);
if (this.stages != null) {
List stagesJson = new ArrayList();
questJson.put("stages", stagesJson);
for (QuestStage stage : this.stages) {
stagesJson.add(stage.toJson());
}
}
return questJson;
}
@Override
public String getProjectFilename() {
return "questlist_"+getProject().name+".json";
}
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;
public class QuestStage extends JSONElement {
private static final long serialVersionUID = 8313645819951513431L;
public Integer progress = null;
public String log_text = null;
public Integer exp_reward = null;
public Integer finishes_quest = null;
public QuestStage(Quest parent){
this.parent = parent;
}
public QuestStage clone(Quest cloneParent) {
QuestStage clone = new QuestStage(cloneParent);
clone.progress = progress != null ? new Integer(progress) : null;
@@ -59,18 +59,11 @@ public class QuestStage extends JSONElement {
@Override
public void link() {
if (this.state == State.created || this.state == State.modified || this.state == State.saved) {
//This type of state is unrelated to parsing/linking.
if (shouldSkipParseOrLink()) {
return;
}
if (this.state == State.init) {
//Not parsed yet.
this.parse();
} else if (this.state == State.linked) {
//Already linked.
return;
}
ensureParseIfNeeded();
//Nothing to link to :D
this.state = State.linked;
}
@@ -89,15 +82,15 @@ public class QuestStage extends JSONElement {
public GameDataElement clone() {
return null;
}
@Override
public Image getIcon() {
return DefaultIcons.getQuestIcon();
}
public Image getImage() {
return DefaultIcons.getQuestImage();
}
}
}

View File

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

View File

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

View File

@@ -1,29 +1,18 @@
package com.gpl.rpg.atcontentstudio.ui.gamedataeditors;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
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.model.GameDataElement;
@@ -31,9 +20,9 @@ import com.gpl.rpg.atcontentstudio.model.ProjectTreeNode;
import com.gpl.rpg.atcontentstudio.model.gamedata.Quest;
import com.gpl.rpg.atcontentstudio.model.gamedata.QuestStage;
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.IntegerBasedCheckBox;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import com.jidesoft.swing.JideBoxLayout;
public class QuestEditor extends JSONElementEditor {
@@ -77,94 +66,26 @@ public class QuestEditor extends JSONElementEditor {
nameField = addTranslatableTextField(pane, "Quest Name: ", quest.name, quest.writable, listener);
visibleBox = addIntegerBasedCheckBox(pane, "Visible in quest log", quest.visible_in_log, quest.writable, listener);
CollapsiblePanel stagesPane = new CollapsiblePanel("Quest stages: ");
stagesPane.setLayout(new JideBoxLayout(stagesPane, JideBoxLayout.PAGE_AXIS));
String title = "Quest stages: ";
StagesCellRenderer cellRenderer = new StagesCellRenderer();
stagesListModel = new StagesListModel(quest);
stagesList = new JList<QuestStage>(stagesListModel);
stagesList.setCellRenderer(new StagesCellRenderer());
stagesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
stagesPane.add(new JScrollPane(stagesList), JideBoxLayout.FIX);
final JPanel stagesEditorPane = new JPanel();
final JButton createStage = new JButton(new ImageIcon(DefaultIcons.getCreateIcon()));
final JButton deleteStage = new JButton(new ImageIcon(DefaultIcons.getNullifyIcon()));
final JButton moveStageUp = new JButton(new ImageIcon(DefaultIcons.getArrowUpIcon()));
final JButton moveStageDown = new JButton(new ImageIcon(DefaultIcons.getArrowDownIcon()));
deleteStage.setEnabled(false);
moveStageUp.setEnabled(false);
moveStageDown.setEnabled(false);
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);
}
final boolean moveUpDownEnabled = true;
CollapsiblePanel stagesPane = CommonEditor.createListPanel(
title,
cellRenderer,
stagesListModel,
quest.writable,
moveUpDownEnabled,
(e)->selectedStage=e,
()->selectedStage,
this::updateStageEditorPane,
listener,
()->new QuestStage(quest)).panel;
if (quest.stages == null || quest.stages.isEmpty()) {
stagesPane.collapse();
}
stagesEditorPane.setLayout(new JideBoxLayout(stagesEditorPane, JideBoxLayout.PAGE_AXIS));
stagesPane.add(stagesEditorPane, JideBoxLayout.FIX);
pane.add(stagesPane, JideBoxLayout.FIX);
}
@@ -184,88 +105,21 @@ public class QuestEditor extends JSONElementEditor {
pane.repaint();
}
public static class StagesListModel implements ListModel<QuestStage> {
Quest source;
public static class StagesListModel extends CommonEditor.AtListModel<QuestStage,Quest> {
public StagesListModel(Quest quest) {
this.source = quest;
}
@Override
public int getSize() {
if (source.stages == null) return 0;
return source.stages.size();
super(quest);
}
@Override
public QuestStage getElementAt(int index) {
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);
protected List<QuestStage> getInner() {
return source.stages;
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.remove(l);
protected void setInner(List<QuestStage> value) {
source.stages = value;
}
}

View File

@@ -18,6 +18,7 @@ import javax.swing.JToolTip;
import javax.swing.SwingConstants;
import javax.swing.ToolTipManager;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.ActionList;
@@ -321,23 +322,7 @@ public class DialogueGraphView extends Display {
@Override
protected String getText(VisualItem item) {
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);
return CommonEditor.wordWrap(super.getText(item), 40);
}
}

View File

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

View File

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

View File

@@ -27,6 +27,7 @@ import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import com.gpl.rpg.atcontentstudio.ui.tools.CommonEditor;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.Action;
@@ -415,25 +416,9 @@ public class WriterModeEditor extends Editor {
@Override
protected String getText(VisualItem item) {
if (!item.getBoolean(IS_REPLY) && super.getText(item) == null) return "[Selector]";
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);
return CommonEditor.wordWrap(super.getText(item), 40);
}
}
class NodeStrokeColorAction extends ColorAction {

View File

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

View File

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

View File

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

View File

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