Fixes to JSON parsing of resource files.

This commit is contained in:
Oskar Wiksten
2013-01-21 00:20:03 +01:00
parent 9ff01745d0
commit 8e75512cfa
6 changed files with 25 additions and 17 deletions

View File

@@ -24,8 +24,8 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
int requiresItemQuantity = 0;
int itemRequirementType = Reply.ITEM_REQUIREMENT_TYPE_INVENTORY_REMOVE;
if (requires != null) {
requiresProgress = requires.optString(JsonFieldNames.ReplyRequires.progress);
JSONObject requiresItem = o.optJSONObject(JsonFieldNames.ReplyRequires.item);
requiresProgress = requires.optString(JsonFieldNames.ReplyRequires.progress, null);
JSONObject requiresItem = requires.optJSONObject(JsonFieldNames.ReplyRequires.item);
if (requiresItem != null) {
requiresItemTypeID = requiresItem.getString(JsonFieldNames.ReplyRequiresItem.itemID);
requiresItemQuantity = requiresItem.getInt(JsonFieldNames.ReplyRequiresItem.quantity);
@@ -33,8 +33,8 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
}
}
return new Reply(
o.optString(JsonFieldNames.Reply.text)
,o.optString(JsonFieldNames.Reply.nextPhraseID)
o.optString(JsonFieldNames.Reply.text, "")
,o.getString(JsonFieldNames.Reply.nextPhraseID)
,QuestProgress.parseQuestProgress(requiresProgress)
,requiresItemTypeID
,requiresItemQuantity
@@ -49,7 +49,7 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
return new Reward(
o.getInt(JsonFieldNames.PhraseReward.rewardType)
,o.getString(JsonFieldNames.PhraseReward.rewardID)
,o.getInt(JsonFieldNames.PhraseReward.value)
,o.optInt(JsonFieldNames.PhraseReward.value, 0)
);
}
};
@@ -68,7 +68,7 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
if (_rewards.length == 0) _rewards = null;
return new Pair<String, Phrase>(id, new Phrase(
o.optString(JsonFieldNames.Phrase.message)
o.optString(JsonFieldNames.Phrase.message, null)
, _replies
, _rewards
));

View File

@@ -50,12 +50,12 @@ public final class MonsterTypeParser extends JsonCollectionParserFor<MonsterType
, o.getString(JsonFieldNames.Monster.name)
, o.getString(JsonFieldNames.Monster.spawnGroup)
, exp
, droplists.getDropList(o.optString(JsonFieldNames.Monster.droplistID))
, o.optString(JsonFieldNames.Monster.phraseID)
, droplists.getDropList(o.optString(JsonFieldNames.Monster.droplistID, null))
, o.optString(JsonFieldNames.Monster.phraseID, null)
, o.optInt(JsonFieldNames.Monster.unique, 0) > 0
, o.optString(JsonFieldNames.Monster.faction)
, o.optString(JsonFieldNames.Monster.faction, null)
, o.optInt(JsonFieldNames.Monster.monsterClass, MonsterType.MONSTERCLASS_HUMANOID)
, ResourceParserUtils.parseSize(o.optString(JsonFieldNames.Monster.size), size1x1) //TODO: This could be loaded from the tileset size instead.
, ResourceParserUtils.parseSize(o.optString(JsonFieldNames.Monster.size, null), size1x1) //TODO: This could be loaded from the tileset size instead.
, ResourceParserUtils.parseImageID(tileLoader, o.getString(JsonFieldNames.Monster.iconID))
, maxAP
, maxHP

View File

@@ -21,7 +21,7 @@ public final class QuestParser extends JsonCollectionParserFor<Quest> {
protected QuestLogEntry parseObject(JSONObject o) throws JSONException {
return new QuestLogEntry(
o.getInt(JsonFieldNames.QuestLogEntry.progress)
,o.getString(JsonFieldNames.QuestLogEntry.logText)
,o.optString(JsonFieldNames.QuestLogEntry.logText, null)
,o.optInt(JsonFieldNames.QuestLogEntry.rewardExperience, 0)
,o.optInt(JsonFieldNames.QuestLogEntry.finishesQuest, 0) > 0
);

View File

@@ -75,8 +75,8 @@ public final class ResourceParserUtils {
public static StatsModifierTraits parseStatsModifierTraits(JSONObject o) throws JSONException {
if (o == null) return null;
ConstRange boostCurrentHP = parseConstRange(o.getJSONObject(JsonFieldNames.StatsModifierTraits.increaseCurrentHP));
ConstRange boostCurrentAP = parseConstRange(o.getJSONObject(JsonFieldNames.StatsModifierTraits.increaseCurrentAP));
ConstRange boostCurrentHP = parseConstRange(o.optJSONObject(JsonFieldNames.StatsModifierTraits.increaseCurrentHP));
ConstRange boostCurrentAP = parseConstRange(o.optJSONObject(JsonFieldNames.StatsModifierTraits.increaseCurrentAP));
if (boostCurrentHP == null && boostCurrentAP == null) {
if (AndorsTrailApplication.DEVELOPMENT_VALIDATEDATA) {
L.log("OPTIMIZE: Tried to parseStatsModifierTraits , where hasEffect=" + o.toString() + ", but all data was empty.");

View File

@@ -6,6 +6,8 @@ import com.gpl.rpg.AndorsTrail.util.Pair;
import org.json.JSONArray;
import org.json.JSONException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -19,7 +21,16 @@ public abstract class JsonCollectionParserFor<T> extends JsonParserFor<Pair<Stri
try {
parseRows(new JSONArray(input), objects);
} catch (JSONException e) {
L.log("ERROR loading resource data: " + e.toString());
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
L.log("ERROR loading resource data: " + e.toString());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
sw.flush();
L.log(sw.toString());
L.log("Failing data: " + input);
}
}
for (Pair<String, T> o : objects) {

View File

@@ -1,8 +1,5 @@
package com.gpl.rpg.AndorsTrail.resource.parsers.json;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnEquip;
public final class JsonFieldNames {
public static final class ActorCondition {
public static final String conditionTypeID = "id";