Add better validation for Planar Conquest readers

This commit is contained in:
drdev
2016-02-06 19:30:00 +00:00
parent 63d1d42df6
commit a6818c1e17
7 changed files with 106 additions and 72 deletions

View File

@@ -238,7 +238,7 @@ public final class CardBlock implements Comparable<CardBlock> {
*/
@Override
protected CardBlock read(String line, int i) {
final String[] sParts = TextUtil.splitWithParenthesis(line.trim(), ',', 3);
final String[] sParts = TextUtil.splitWithParenthesis(line, ',', 3);
String name = sParts[0];
String[] numbers = sParts[1].trim().split("/");

View File

@@ -103,11 +103,19 @@ public class ConquestEvent {
String avatar = null;
String description = null;
String[] pieces = line.trim().split("\\|");
String key, value;
String[] pieces = line.split("\\|");
for (String piece : pieces) {
String[] kv = piece.split(":", 2);
String key = kv[0].trim().toLowerCase();
String value = kv[1].trim();
int idx = piece.indexOf(':');
if (idx != -1) {
key = piece.substring(0, idx).trim().toLowerCase();
value = piece.substring(idx + 1).trim();
}
else {
alertInvalidLine(line, "Invalid event definition.");
key = piece.trim().toLowerCase();
value = "";
}
switch(key) {
case "name":
name = value;
@@ -133,6 +141,9 @@ public class ConquestEvent {
case "desc":
description = value;
break;
default:
alertInvalidLine(line, "Invalid event definition.");
break;
}
}
if (deck == null) {

View File

@@ -243,11 +243,19 @@ public class ConquestPlane {
String description = null;
boolean unreachable = false;
String[] pieces = line.trim().split("\\|");
String key, value;
String[] pieces = line.split("\\|");
for (String piece : pieces) {
String[] kv = piece.split(":", 2);
String key = kv[0].trim().toLowerCase();
String value = kv[1].trim();
int idx = piece.indexOf(':');
if (idx != -1) {
key = piece.substring(0, idx).trim().toLowerCase();
value = piece.substring(idx + 1).trim();
}
else {
alertInvalidLine(line, "Invalid plane definition.");
key = piece.trim().toLowerCase();
value = "";
}
switch(key) {
case "name":
name = value;
@@ -266,6 +274,9 @@ public class ConquestPlane {
case "desc":
description = value;
break;
default:
alertInvalidLine(line, "Invalid plane definition.");
break;
}
}
return new ConquestPlane(name, description, regionSize, unreachable);

View File

@@ -90,11 +90,19 @@ public class ConquestRegion {
ColorSet colorSet = ColorSet.ALL_COLORS;
Predicate<PaperCard> pred = Predicates.alwaysTrue();
String[] pieces = line.trim().split("\\|");
String key, value;
String[] pieces = line.split("\\|");
for (String piece : pieces) {
String[] kv = piece.split(":", 2);
String key = kv[0].trim().toLowerCase();
String value = kv[1].trim();
int idx = piece.indexOf(':');
if (idx != -1) {
key = piece.substring(0, idx).trim().toLowerCase();
value = piece.substring(idx + 1).trim();
}
else {
alertInvalidLine(line, "Invalid plane definition.");
key = piece.trim().toLowerCase();
value = "";
}
switch(key) {
case "name":
name = value;
@@ -129,6 +137,9 @@ public class ConquestRegion {
}
};
break;
default:
alertInvalidLine(line, "Invalid region definition.");
break;
}
}
return new ConquestRegion(plane, name, artCardName, colorSet, pred);

View File

@@ -18,7 +18,6 @@
package forge.quest;
import com.google.common.base.Function;
import forge.deck.Deck;
import forge.game.GameFormat;
import forge.item.PaperCard;
@@ -131,28 +130,41 @@ public class QuestWorld implements Comparable<QuestWorld>{
final List<String> sets = new ArrayList<String>();
final List<String> bannedCards = new ArrayList<String>(); // if both empty, no format
// This is what you need to use here =>
// FileSection.parse(line, ":", "|");
final String[] sParts = line.trim().split("\\|");
for (final String sPart : sParts) {
final String[] kv = sPart.split(":", 2);
final String key = kv[0].toLowerCase();
if ("name".equals(key)) {
useName = kv[1];
} else if ("dir".equals(key)) {
useDir = kv[1];
} else if ("sets".equals(key)) {
sets.addAll(Arrays.asList(kv[1].split(", ")));
} else if ("banned".equals(key)) {
bannedCards.addAll(Arrays.asList(kv[1].split("; ")));
String key, value;
String[] pieces = line.split("\\|");
for (String piece : pieces) {
int idx = piece.indexOf(':');
if (idx != -1) {
key = piece.substring(0, idx).trim().toLowerCase();
value = piece.substring(idx + 1).trim();
}
else {
alertInvalidLine(line, "Invalid plane definition.");
key = piece.trim().toLowerCase();
value = "";
}
switch(key) {
case "name":
useName = value;
break;
case "dir":
useDir = value;
break;
case "sets":
sets.addAll(Arrays.asList(value.split(", ")));
break;
case "banned":
bannedCards.addAll(Arrays.asList(value.split("; ")));
break;
default:
alertInvalidLine(line, "Invalid quest world definition.");
break;
}
}
if (useName == null) {
throw new RuntimeException("A Quest World must have a name! Check worlds.txt file");
alertInvalidLine(line, "Quest world must have a name.");
return null;
}
if (!sets.isEmpty() || !bannedCards.isEmpty()) {