mirror of
https://github.com/OMGeeky/ATCS.git
synced 2025-12-26 23:57:25 +01:00
extract some toJson stuff to reduce duplication
This commit is contained in:
@@ -4,11 +4,13 @@ import com.gpl.rpg.atcontentstudio.model.GameDataElement;
|
||||
import com.gpl.rpg.atcontentstudio.model.Project;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Common {
|
||||
|
||||
//region link common stuff
|
||||
public static void linkConditions(List<? extends ActorConditionEffect> conditions, Project proj, GameDataElement backlink) {
|
||||
if (conditions != null) {
|
||||
for (ActorConditionEffect ce : conditions) {
|
||||
@@ -36,6 +38,106 @@ public final class Common {
|
||||
proj.getSpritesheet(spritesheetId).addBacklink(backlink);
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region write common stuff
|
||||
|
||||
public static void writeHitReceivedEffectToMap(Map parent, HitReceivedEffect effect) {
|
||||
if(effect != null){
|
||||
writeHitEffectToMap(parent, effect);
|
||||
writeBasicEffectObjectToMap(effect.target, parent, "increaseAttackerCurrentHP", "increaseAttackerCurrentAP");
|
||||
}
|
||||
}
|
||||
public static void writeHitReceivedEffectToMap(Map parent, HitReceivedEffect effect, String key) {
|
||||
if (effect != null) {
|
||||
Map effectJson = new LinkedHashMap();
|
||||
parent.put(key, effectJson);
|
||||
writeHitReceivedEffectToMap(effectJson, effect);
|
||||
}
|
||||
}
|
||||
public static void writeHitEffectToMap(Map parent, HitEffect effect) {
|
||||
if(effect != null){
|
||||
writeDeathEffectToMap(parent, effect);
|
||||
writeTimedActorConditionEffectObjectToMap(effect.conditions_target, parent, "conditionsTarget");
|
||||
}
|
||||
}
|
||||
public static void writeHitEffectToMap(Map parent, HitEffect effect, String key) {
|
||||
if (effect != null) {
|
||||
Map effectJson = new LinkedHashMap();
|
||||
parent.put(key, effectJson);
|
||||
writeHitEffectToMap(effectJson, effect);
|
||||
}
|
||||
}
|
||||
public static void writeDeathEffectToMap(Map parent, DeathEffect effect) {
|
||||
writeBasicEffectObjectToMap(effect, parent, "increaseCurrentHP", "increaseCurrentAP");
|
||||
writeTimedActorConditionEffectObjectToMap(effect.conditions_source, parent, "conditionsSource");
|
||||
}
|
||||
public static void writeDeathEffectToMap(Map parent, DeathEffect effect, String key) {
|
||||
if (effect != null) {
|
||||
Map effectJson = new LinkedHashMap();
|
||||
parent.put(key, effectJson);
|
||||
writeDeathEffectToMap(effectJson, effect);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBasicEffectObjectToMap(BasicEffect effect, Map parent, String keyHP, String keyAP) {
|
||||
if (effect.hp_boost_min != null || effect.hp_boost_max != null) {
|
||||
Map hpJson = new LinkedHashMap();
|
||||
parent.put(keyHP, hpJson);
|
||||
if (effect.hp_boost_min != null)
|
||||
hpJson.put("min", effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (effect.hp_boost_max != null)
|
||||
hpJson.put("max", effect.hp_boost_max);
|
||||
else hpJson.put("max", 0);
|
||||
}
|
||||
|
||||
if (effect.ap_boost_min != null || effect.ap_boost_max != null) {
|
||||
Map apJson = new LinkedHashMap();
|
||||
parent.put(keyAP, apJson);
|
||||
if (effect.ap_boost_min != null)
|
||||
apJson.put("min", effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (effect.ap_boost_max != null)
|
||||
apJson.put("max", effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTimedActorConditionEffectObjectToMap(List<TimedActorConditionEffect> list, Map parent, String key) {
|
||||
if (list != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
parent.put(key, conditionsSourceJson);
|
||||
for (TimedActorConditionEffect condition : list) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
writeTimedConditionEffectToMap(condition, conditionJson);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void writeConditionEffectToMap(ActorConditionEffect condition, Map parent) {
|
||||
if (condition.condition != null) {
|
||||
parent.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
parent.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) {
|
||||
parent.put("magnitude", condition.magnitude);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeTimedConditionEffectToMap(TimedActorConditionEffect condition, Map parent) {
|
||||
writeConditionEffectToMap(condition, parent);
|
||||
if (condition.duration != null) {
|
||||
parent.put("duration", condition.duration);
|
||||
}
|
||||
if (condition.chance != null) {
|
||||
parent.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
public static class TimedActorConditionEffect extends ActorConditionEffect {
|
||||
//Available from parsed state
|
||||
public Integer duration = null;
|
||||
|
||||
@@ -408,12 +408,7 @@ public class Item extends JSONElement {
|
||||
for (ActorConditionEffect condition : this.equip_effect.conditions) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
writeConditionEffectToMap(condition, conditionJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,15 +437,7 @@ public class Item extends JSONElement {
|
||||
for (TimedActorConditionEffect condition : this.hit_effect.conditions_source) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null)
|
||||
conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
writeTimedConditionEffectToMap(condition, conditionJson);
|
||||
}
|
||||
}
|
||||
if (this.hit_effect.conditions_target != null) {
|
||||
@@ -459,140 +446,32 @@ public class Item extends JSONElement {
|
||||
for (TimedActorConditionEffect condition : this.hit_effect.conditions_target) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsTargetJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null)
|
||||
conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
writeTimedConditionEffectToMap(condition, conditionJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.hit_received_effect != null) {
|
||||
Map hitReceivedEffectJson = new LinkedHashMap();
|
||||
itemJson.put("hitReceivedEffect", hitReceivedEffectJson);
|
||||
if (this.hit_received_effect.hp_boost_min != null || this.hit_received_effect.hp_boost_max != null) {
|
||||
Map hpJson = new LinkedHashMap();
|
||||
hitReceivedEffectJson.put("increaseCurrentHP", hpJson);
|
||||
if (this.hit_received_effect.hp_boost_min != null)
|
||||
hpJson.put("min", this.hit_received_effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.hit_received_effect.hp_boost_max != null)
|
||||
hpJson.put("max", this.hit_received_effect.hp_boost_max);
|
||||
else hpJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_received_effect.ap_boost_min != null || this.hit_received_effect.ap_boost_max != null) {
|
||||
Map apJson = new LinkedHashMap();
|
||||
hitReceivedEffectJson.put("increaseCurrentAP", apJson);
|
||||
if (this.hit_received_effect.ap_boost_min != null)
|
||||
apJson.put("min", this.hit_received_effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.hit_received_effect.ap_boost_max != null)
|
||||
apJson.put("max", this.hit_received_effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_received_effect.target.hp_boost_min != null || this.hit_received_effect.target.hp_boost_max != null) {
|
||||
Map hpJson = new LinkedHashMap();
|
||||
hitReceivedEffectJson.put("increaseAttackerCurrentHP", hpJson);
|
||||
if (this.hit_received_effect.target.hp_boost_min != null)
|
||||
hpJson.put("min", this.hit_received_effect.target.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.hit_received_effect.target.hp_boost_max != null)
|
||||
hpJson.put("max", this.hit_received_effect.target.hp_boost_max);
|
||||
else hpJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_received_effect.target.ap_boost_min != null || this.hit_received_effect.target.ap_boost_max != null) {
|
||||
Map apJson = new LinkedHashMap();
|
||||
hitReceivedEffectJson.put("increaseAttackerCurrentAP", apJson);
|
||||
if (this.hit_received_effect.target.ap_boost_min != null)
|
||||
apJson.put("min", this.hit_received_effect.target.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.hit_received_effect.target.ap_boost_max != null)
|
||||
apJson.put("max", this.hit_received_effect.target.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.hit_received_effect.conditions_source != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
hitReceivedEffectJson.put("conditionsSource", conditionsSourceJson);
|
||||
for (TimedActorConditionEffect condition : this.hit_received_effect.conditions_source) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null)
|
||||
conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
if (this.hit_received_effect.conditions_target != null) {
|
||||
List conditionsTargetJson = new ArrayList();
|
||||
hitReceivedEffectJson.put("conditionsTarget", conditionsTargetJson);
|
||||
for (TimedActorConditionEffect condition : this.hit_received_effect.conditions_target) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsTargetJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null)
|
||||
conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
writeHitReceivedEffectToMap(itemJson, this.hit_received_effect, "hitReceivedEffect");
|
||||
String key;
|
||||
if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.equip) {
|
||||
key = "killEffect";
|
||||
} else if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.use) {
|
||||
key = "useEffect";
|
||||
} else {
|
||||
try {
|
||||
throw new IllegalArgumentException("Could not create JSON-Map for Item: Failed to determine if the items should be used or equipped.");
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
key = null;
|
||||
}
|
||||
if (this.kill_effect != null) {
|
||||
Map killEffectJson = new LinkedHashMap();
|
||||
if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.equip) {
|
||||
itemJson.put("killEffect", killEffectJson);
|
||||
} else if (this.category != null && this.category.action_type != null && this.category.action_type == ItemCategory.ActionType.use) {
|
||||
itemJson.put("useEffect", killEffectJson);
|
||||
}
|
||||
if (this.kill_effect.hp_boost_min != null || this.kill_effect.hp_boost_max != null) {
|
||||
Map hpJson = new LinkedHashMap();
|
||||
killEffectJson.put("increaseCurrentHP", hpJson);
|
||||
if (this.kill_effect.hp_boost_min != null) hpJson.put("min", this.kill_effect.hp_boost_min);
|
||||
else hpJson.put("min", 0);
|
||||
if (this.kill_effect.hp_boost_max != null) hpJson.put("max", this.kill_effect.hp_boost_max);
|
||||
else hpJson.put("min", 0);
|
||||
}
|
||||
if (this.kill_effect.ap_boost_min != null || this.kill_effect.ap_boost_max != null) {
|
||||
Map apJson = new LinkedHashMap();
|
||||
killEffectJson.put("increaseCurrentAP", apJson);
|
||||
if (this.kill_effect.ap_boost_min != null) apJson.put("min", this.kill_effect.ap_boost_min);
|
||||
else apJson.put("min", 0);
|
||||
if (this.kill_effect.ap_boost_max != null) apJson.put("max", this.kill_effect.ap_boost_max);
|
||||
else apJson.put("max", 0);
|
||||
}
|
||||
if (this.kill_effect.conditions_source != null) {
|
||||
List conditionsSourceJson = new ArrayList();
|
||||
killEffectJson.put("conditionsSource", conditionsSourceJson);
|
||||
for (TimedActorConditionEffect condition : this.kill_effect.conditions_source) {
|
||||
Map conditionJson = new LinkedHashMap();
|
||||
conditionsSourceJson.add(conditionJson);
|
||||
if (condition.condition != null) {
|
||||
conditionJson.put("condition", condition.condition.id);
|
||||
} else if (condition.condition_id != null) {
|
||||
conditionJson.put("condition", condition.condition_id);
|
||||
}
|
||||
if (condition.magnitude != null) conditionJson.put("magnitude", condition.magnitude);
|
||||
if (condition.duration != null) conditionJson.put("duration", condition.duration);
|
||||
if (condition.chance != null)
|
||||
conditionJson.put("chance", JSONElement.printJsonChance(condition.chance));
|
||||
}
|
||||
}
|
||||
if (key != null) {
|
||||
writeDeathEffectToMap(itemJson, this.kill_effect, key);
|
||||
}
|
||||
|
||||
return itemJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProjectFilename() {
|
||||
return "itemlist_" + getProject().name + ".json";
|
||||
|
||||
Reference in New Issue
Block a user