mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Code for reading a deck refactored.
This commit is contained in:
@@ -329,36 +329,40 @@ public class DeckManager {
|
|||||||
* @param d a {@link forge.deck.Deck} object.
|
* @param d a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
private static void addCardList(ListIterator<String> lineIterator, Deck d) {
|
private static void addCardList(ListIterator<String> lineIterator, Deck d) {
|
||||||
String line;
|
|
||||||
|
|
||||||
Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*");
|
|
||||||
|
|
||||||
//readDeck main deck
|
//readDeck main deck
|
||||||
while (lineIterator.hasNext() && !(line = lineIterator.next()).equals("[sideboard]")) {
|
for (String cardName : readCardList(lineIterator)) {
|
||||||
Matcher m = p.matcher(line);
|
d.addMain(cardName);
|
||||||
m.matches();
|
|
||||||
String s = m.group(2);
|
|
||||||
int count = s == null ? 1 : parseInt(s);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
d.addMain(m.group(3));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//readDeck sideboard
|
//readDeck sideboard
|
||||||
/*while (lineIterator.hasNext()) {
|
for (String cardName : readCardList(lineIterator)) {
|
||||||
line = lineIterator.next();
|
d.addSideboard(cardName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Precondition: iterator should point at the first line of cards list
|
||||||
|
private static List<String> readCardList(final ListIterator<String> lineIterator) {
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*");
|
||||||
|
|
||||||
|
while (lineIterator.hasNext()) {
|
||||||
|
String line = lineIterator.next();
|
||||||
|
if (line.startsWith("[")) { break; } // there comes another section
|
||||||
|
|
||||||
Matcher m = p.matcher(line);
|
Matcher m = p.matcher(line);
|
||||||
m.matches();
|
m.matches();
|
||||||
String s = m.group(2);
|
String sCnt = m.group(2);
|
||||||
String cardName = m.group(3);
|
String cardName = m.group(3);
|
||||||
if (StringUtils.isBlank(cardName)) { continue; }
|
if (StringUtils.isBlank(cardName)) { continue; }
|
||||||
|
|
||||||
int count = s == null ? 1 : parseInt(s);
|
int count = sCnt == null ? 1 : parseInt(sCnt);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
d.addSideboard(cardName);
|
result.add(cardName);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user