refactor: remove unnecessary blank lines in multiple classes

This commit is contained in:
OMGeeky
2025-06-16 08:23:31 +02:00
parent d8797fa826
commit 5809d33bb4
10 changed files with 2599 additions and 2599 deletions

View File

@@ -1,193 +1,193 @@
package com.gpl.rpg.atcontentstudio.model; package com.gpl.rpg.atcontentstudio.model;
import java.awt.Image; import java.awt.Image;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry; import com.gpl.rpg.atcontentstudio.model.bookmarks.BookmarkEntry;
public abstract class GameDataElement implements ProjectTreeNode, Serializable { public abstract class GameDataElement implements ProjectTreeNode, Serializable {
private static final long serialVersionUID = 2028934451226743389L; private static final long serialVersionUID = 2028934451226743389L;
public static enum State { public static enum State {
init, // We know the object exists, and have its key/ID. init, // We know the object exists, and have its key/ID.
parsed, // We know the object's properties, but related objects are referenced by ID only. parsed, // We know the object's properties, but related objects are referenced by ID only.
linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least. linked, // We know the object fully, and all links to related objects point to objects in the parsed state at least.
created, // This is an object we are creating created, // This is an object we are creating
modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON. modified, // Whether altered or created, this item has been modified since creation from scratch or from JSON.
saved // Whether altered or created, this item has been saved since last modification. saved // Whether altered or created, this item has been saved since last modification.
} }
public State state = State.init; public State state = State.init;
//Available from state init. //Available from state init.
public ProjectTreeNode parent; public ProjectTreeNode parent;
public boolean writable = false; public boolean writable = false;
public BookmarkEntry bookmark = null; public BookmarkEntry bookmark = null;
//List of objects whose transition to "linked" state made them point to this instance. //List of objects whose transition to "linked" state made them point to this instance.
private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>(); private Map<GameDataElement, Integer> backlinks = new ConcurrentHashMap<GameDataElement, Integer>();
public String id = null; public String id = null;
@Override @Override
public Enumeration<ProjectTreeNode> children() { public Enumeration<ProjectTreeNode> children() {
return null; return null;
} }
@Override @Override
public boolean getAllowsChildren() { public boolean getAllowsChildren() {
return false; return false;
} }
@Override @Override
public TreeNode getChildAt(int arg0) { public TreeNode getChildAt(int arg0) {
return null; return null;
} }
@Override @Override
public int getChildCount() { public int getChildCount() {
return 0; return 0;
} }
@Override @Override
public int getIndex(TreeNode arg0) { public int getIndex(TreeNode arg0) {
return 0; return 0;
} }
@Override @Override
public TreeNode getParent() { public TreeNode getParent() {
return parent; return parent;
} }
@Override @Override
public boolean isLeaf() { public boolean isLeaf() {
return true; return true;
} }
@Override @Override
public void childrenAdded(List<ProjectTreeNode> path) { public void childrenAdded(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenAdded(path); parent.childrenAdded(path);
} }
@Override @Override
public void childrenChanged(List<ProjectTreeNode> path) { public void childrenChanged(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenChanged(path); parent.childrenChanged(path);
} }
@Override @Override
public void childrenRemoved(List<ProjectTreeNode> path) { public void childrenRemoved(List<ProjectTreeNode> path) {
path.add(0,this); path.add(0,this);
parent.childrenRemoved(path); parent.childrenRemoved(path);
} }
@Override @Override
public void notifyCreated() { public void notifyCreated() {
childrenAdded(new ArrayList<ProjectTreeNode>()); childrenAdded(new ArrayList<ProjectTreeNode>());
} }
@Override @Override
public abstract String getDesc(); public abstract String getDesc();
public static String getStaticDesc() { public static String getStaticDesc() {
return "GameDataElements"; return "GameDataElements";
} }
public abstract void parse(); public abstract void parse();
public abstract void link(); public abstract void link();
@Override @Override
public Project getProject() { public Project getProject() {
return parent == null ? null : parent.getProject(); return parent == null ? null : parent.getProject();
} }
public Image getIcon() { public Image getIcon() {
return null; return null;
} }
@Override @Override
public Image getClosedIcon() {return null;} public Image getClosedIcon() {return null;}
@Override @Override
public Image getOpenIcon() {return null;} public Image getOpenIcon() {return null;}
@Override @Override
public Image getLeafIcon() { public Image getLeafIcon() {
return getIcon(); return getIcon();
} }
public abstract GameDataElement clone(); public abstract GameDataElement clone();
public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne); public abstract void elementChanged(GameDataElement oldOne, GameDataElement newOne);
@Override @Override
public GameSource.Type getDataType() { public GameSource.Type getDataType() {
if (parent == null) { if (parent == null) {
System.out.println("blerf."); System.out.println("blerf.");
} }
return parent.getDataType(); return parent.getDataType();
} }
public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>(); public List<BacklinksListener> backlinkListeners = new ArrayList<GameDataElement.BacklinksListener>();
public void addBacklinkListener(BacklinksListener l) { public void addBacklinkListener(BacklinksListener l) {
backlinkListeners.add(l); backlinkListeners.add(l);
} }
public void removeBacklinkListener(BacklinksListener l) { public void removeBacklinkListener(BacklinksListener l) {
backlinkListeners.remove(l); backlinkListeners.remove(l);
} }
public void addBacklink(GameDataElement gde) { public void addBacklink(GameDataElement gde) {
if (!backlinks.containsKey(gde)) { if (!backlinks.containsKey(gde)) {
backlinks.put(gde, 1); backlinks.put(gde, 1);
for (BacklinksListener l : backlinkListeners) { for (BacklinksListener l : backlinkListeners) {
l.backlinkAdded(gde); l.backlinkAdded(gde);
} }
} else { } else {
backlinks.put(gde, backlinks.get(gde) + 1); backlinks.put(gde, backlinks.get(gde) + 1);
} }
} }
public void removeBacklink(GameDataElement gde) { public void removeBacklink(GameDataElement gde) {
if (backlinks.get(gde) == null) return; if (backlinks.get(gde) == null) return;
backlinks.put(gde, backlinks.get(gde) - 1); backlinks.put(gde, backlinks.get(gde) - 1);
if (backlinks.get(gde) == 0) { if (backlinks.get(gde) == 0) {
backlinks.remove(gde); backlinks.remove(gde);
for (BacklinksListener l : backlinkListeners) { for (BacklinksListener l : backlinkListeners) {
l.backlinkRemoved(gde); l.backlinkRemoved(gde);
} }
} }
} }
public Set<GameDataElement> getBacklinks() { public Set<GameDataElement> getBacklinks() {
return backlinks.keySet(); return backlinks.keySet();
} }
public static interface BacklinksListener { public static interface BacklinksListener {
public void backlinkAdded(GameDataElement gde); public void backlinkAdded(GameDataElement gde);
public void backlinkRemoved(GameDataElement gde); public void backlinkRemoved(GameDataElement gde);
} }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return false; return false;
} }
public boolean needsSaving() { public boolean needsSaving() {
return this.state == State.modified || this.state == State.created; return this.state == State.modified || this.state == State.created;
} }
public abstract String getProjectFilename(); public abstract String getProjectFilename();
public abstract void save(); public abstract void save();
public abstract List<SaveEvent> attemptSave(); public abstract List<SaveEvent> attemptSave();
} }

View File

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

View File

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

View File

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

View File

@@ -29,7 +29,7 @@ public class Item extends JSONElement {
public String name = null; public String name = null;
public DisplayType display_type = null; public DisplayType display_type = null;
public String icon_id = null; public String icon_id = null;
//Available from parsed state //Available from parsed state
public Integer has_manual_price = null; public Integer has_manual_price = null;
public Integer base_market_cost = null; public Integer base_market_cost = null;
@@ -39,11 +39,11 @@ public class Item extends JSONElement {
public HitReceivedEffect hit_received_effect = null; public HitReceivedEffect hit_received_effect = null;
public DeathEffect kill_effect = null; public DeathEffect kill_effect = null;
public EquipEffect equip_effect = null; public EquipEffect equip_effect = null;
//Available from linked state //Available from linked state
public ItemCategory category = null; public ItemCategory category = null;
public static class EquipEffect { public static class EquipEffect {
//Available from parsed state //Available from parsed state
public Integer damage_boost_min = null; public Integer damage_boost_min = null;
@@ -63,7 +63,7 @@ public class Item extends JSONElement {
public Integer damage_modifier = null; public Integer damage_modifier = null;
} }
public static enum DisplayType { public static enum DisplayType {
ordinary, ordinary,
quest, quest,
@@ -71,7 +71,7 @@ public class Item extends JSONElement {
legendary, legendary,
rare rare
} }
@Override @Override
public String getDesc() { public String getDesc() {
return (needsSaving() ? "*" : "")+name+" ("+id+")"; return (needsSaving() ? "*" : "")+name+" ("+id+")";
@@ -80,7 +80,7 @@ public class Item extends JSONElement {
public static String getStaticDesc() { public static String getStaticDesc() {
return "Items"; return "Items";
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void fromJson(File jsonFile, GameDataCategory<Item> category) { public static void fromJson(File jsonFile, GameDataCategory<Item> category) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
@@ -116,7 +116,7 @@ public class Item extends JSONElement {
} }
} }
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Item fromJson(String jsonString) throws ParseException { public static Item fromJson(String jsonString) throws ParseException {
Map itemJson = (Map) new JSONParser().parse(jsonString); Map itemJson = (Map) new JSONParser().parse(jsonString);
@@ -124,7 +124,7 @@ public class Item extends JSONElement {
item.parse(itemJson); item.parse(itemJson);
return item; return item;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static Item fromJson(Map itemJson) { public static Item fromJson(Map itemJson) {
Item item = new Item(); Item item = new Item();
@@ -134,7 +134,7 @@ public class Item extends JSONElement {
if (itemJson.get("displaytype") != null) item.display_type = DisplayType.valueOf((String) itemJson.get("displaytype")); if (itemJson.get("displaytype") != null) item.display_type = DisplayType.valueOf((String) itemJson.get("displaytype"));
return item; return item;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void parse(Map itemJson) { public void parse(Map itemJson) {
@@ -145,7 +145,7 @@ public class Item extends JSONElement {
// this.category_id = (String) itemJson.get("category"); // this.category_id = (String) itemJson.get("category");
if (itemJson.get("category") != null) this.category_id = (String) itemJson.get("category").toString(); if (itemJson.get("category") != null) this.category_id = (String) itemJson.get("category").toString();
this.description = (String) itemJson.get("description"); this.description = (String) itemJson.get("description");
Map equipEffect = (Map) itemJson.get("equipEffect"); Map equipEffect = (Map) itemJson.get("equipEffect");
if (equipEffect != null) { if (equipEffect != null) {
this.equip_effect = new EquipEffect(); this.equip_effect = new EquipEffect();
@@ -167,7 +167,7 @@ public class Item extends JSONElement {
// this.equip_effect.critical_multiplier = JSONElement.getDouble((Number) equipEffect.get("setCriticalMultiplier")); // this.equip_effect.critical_multiplier = JSONElement.getDouble((Number) equipEffect.get("setCriticalMultiplier"));
if (equipEffect.get("setCriticalMultiplier") != null) this.equip_effect.critical_multiplier = JSONElement.getDouble(Double.parseDouble(equipEffect.get("setCriticalMultiplier").toString())); if (equipEffect.get("setCriticalMultiplier") != null) this.equip_effect.critical_multiplier = JSONElement.getDouble(Double.parseDouble(equipEffect.get("setCriticalMultiplier").toString()));
this.equip_effect.damage_modifier = JSONElement.getInteger((Number) equipEffect.get("setNonWeaponDamageModifier")); this.equip_effect.damage_modifier = JSONElement.getInteger((Number) equipEffect.get("setNonWeaponDamageModifier"));
List conditionsJson = (List) equipEffect.get("addedConditions"); List conditionsJson = (List) equipEffect.get("addedConditions");
if (conditionsJson != null && !conditionsJson.isEmpty()) { if (conditionsJson != null && !conditionsJson.isEmpty()) {
this.equip_effect.conditions = new ArrayList<>(); this.equip_effect.conditions = new ArrayList<>();
@@ -180,18 +180,18 @@ public class Item extends JSONElement {
} }
} }
} }
Map hitEffect = (Map) itemJson.get("hitEffect"); Map hitEffect = (Map) itemJson.get("hitEffect");
if (hitEffect != null) { if (hitEffect != null) {
this.hit_effect = parseHitEffect(hitEffect); this.hit_effect = parseHitEffect(hitEffect);
} }
Map hitReceivedEffect = (Map) itemJson.get("hitReceivedEffect"); Map hitReceivedEffect = (Map) itemJson.get("hitReceivedEffect");
if (hitReceivedEffect != null) { if (hitReceivedEffect != null) {
this.hit_received_effect = parseHitReceivedEffect(hitReceivedEffect); this.hit_received_effect = parseHitReceivedEffect(hitReceivedEffect);
} }
Map killEffect = (Map) itemJson.get("killEffect"); Map killEffect = (Map) itemJson.get("killEffect");
if (killEffect == null) { if (killEffect == null) {
killEffect = (Map) itemJson.get("useEffect"); killEffect = (Map) itemJson.get("useEffect");
@@ -253,11 +253,11 @@ public class Item extends JSONElement {
public Image getIcon() { public Image getIcon() {
return getProject().getIcon(icon_id); return getProject().getIcon(icon_id);
} }
public Image getImage() { public Image getImage() {
return getProject().getImage(icon_id); return getProject().getImage(icon_id);
} }
@Override @Override
public GameDataElement clone() { public GameDataElement clone() {
Item clone = new Item(); Item clone = new Item();
@@ -319,7 +319,7 @@ public class Item extends JSONElement {
} }
return clone; return clone;
} }
@Override @Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) { public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (this.category == oldOne) { if (this.category == oldOne) {
@@ -366,7 +366,7 @@ public class Item extends JSONElement {
} }
} }
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@Override @Override
public Map toJson() { public Map toJson() {
@@ -375,7 +375,7 @@ public class Item extends JSONElement {
if (this.icon_id != null) itemJson.put("iconID", this.icon_id); if (this.icon_id != null) itemJson.put("iconID", this.icon_id);
if (this.name != null) itemJson.put("name", this.name); if (this.name != null) itemJson.put("name", this.name);
if(this.display_type != null) itemJson.put("displaytype", this.display_type.toString()); if(this.display_type != null) itemJson.put("displaytype", this.display_type.toString());
if (this.has_manual_price != null) itemJson.put("hasManualPrice", this.has_manual_price); if (this.has_manual_price != null) itemJson.put("hasManualPrice", this.has_manual_price);
if (this.base_market_cost != null) itemJson.put("baseMarketCost", this.base_market_cost); if (this.base_market_cost != null) itemJson.put("baseMarketCost", this.base_market_cost);
if (this.category != null) { if (this.category != null) {
@@ -603,19 +603,19 @@ public class Item extends JSONElement {
} }
return Math.max(1, price); return Math.max(1, price);
} }
public int zeroForNull(Integer val) { public int zeroForNull(Integer val) {
return val == null ? 0 : val; return val == null ? 0 : val;
} }
public double zeroForNull(Double val) { public double zeroForNull(Double val) {
return val == null ? 0 : val; return val == null ? 0 : val;
} }
public boolean isWeapon() { public boolean isWeapon() {
return category != null && category.action_type != null && category.action_type == ItemCategory.ActionType.equip && category.slot != null && category.slot == ItemCategory.InventorySlot.weapon; return category != null && category.action_type != null && category.action_type == ItemCategory.ActionType.equip && category.slot != null && category.slot == ItemCategory.InventorySlot.weapon;
} }
public int calculateUseCost() { public int calculateUseCost() {
final float averageHPBoost = (zeroForNull(kill_effect.hp_boost_min) + zeroForNull(kill_effect.hp_boost_max)) / 2.0f; final float averageHPBoost = (zeroForNull(kill_effect.hp_boost_min) + zeroForNull(kill_effect.hp_boost_max)) / 2.0f;
if (averageHPBoost == 0) return 0; if (averageHPBoost == 0) return 0;
@@ -648,7 +648,7 @@ public class Item extends JSONElement {
+ costMaxHP + costMaxAP + costMaxHP + costMaxAP
+ costMovement + costUseItem + costReequip; + costMovement + costUseItem + costReequip;
} }
public int calculateHitCost() { public int calculateHitCost() {
final float averageHPBoost = (zeroForNull(hit_effect.hp_boost_min) + zeroForNull(hit_effect.hp_boost_max)) / 2.0f; final float averageHPBoost = (zeroForNull(hit_effect.hp_boost_min) + zeroForNull(hit_effect.hp_boost_max)) / 2.0f;

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -8,18 +8,18 @@ import com.gpl.rpg.atcontentstudio.model.GameDataElement;
import com.gpl.rpg.atcontentstudio.ui.DefaultIcons; import com.gpl.rpg.atcontentstudio.ui.DefaultIcons;
public class QuestStage extends JSONElement { public class QuestStage extends JSONElement {
private static final long serialVersionUID = 8313645819951513431L; private static final long serialVersionUID = 8313645819951513431L;
public Integer progress = null; public Integer progress = null;
public String log_text = null; public String log_text = null;
public Integer exp_reward = null; public Integer exp_reward = null;
public Integer finishes_quest = null; public Integer finishes_quest = null;
public QuestStage(Quest parent){ public QuestStage(Quest parent){
this.parent = parent; this.parent = parent;
} }
public QuestStage clone(Quest cloneParent) { public QuestStage clone(Quest cloneParent) {
QuestStage clone = new QuestStage(cloneParent); QuestStage clone = new QuestStage(cloneParent);
clone.progress = progress != null ? new Integer(progress) : null; clone.progress = progress != null ? new Integer(progress) : null;
@@ -89,15 +89,15 @@ public class QuestStage extends JSONElement {
public GameDataElement clone() { public GameDataElement clone() {
return null; return null;
} }
@Override @Override
public Image getIcon() { public Image getIcon() {
return DefaultIcons.getQuestIcon(); return DefaultIcons.getQuestIcon();
} }
public Image getImage() { public Image getImage() {
return DefaultIcons.getQuestImage(); return DefaultIcons.getQuestImage();
} }
} }