Altering json handling of numeric keywords; "keyword X" and "keyword+X" are now both valid
This commit is contained in:
@@ -5,9 +5,12 @@ import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
|||||||
import com.gempukku.lotro.cards.build.FieldProcessor;
|
import com.gempukku.lotro.cards.build.FieldProcessor;
|
||||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||||
import com.gempukku.lotro.common.Keyword;
|
import com.gempukku.lotro.common.Keyword;
|
||||||
|
import com.gempukku.lotro.common.Names;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class KeywordFieldProcessor implements FieldProcessor {
|
public class KeywordFieldProcessor implements FieldProcessor {
|
||||||
@Override
|
@Override
|
||||||
@@ -16,15 +19,23 @@ public class KeywordFieldProcessor implements FieldProcessor {
|
|||||||
blueprint.setKeywords(convertKeywords(keywords, key));
|
blueprint.setKeywords(convertKeywords(keywords, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Keyword, Integer> convertKeywords(String[] keywords, String key) throws InvalidCardDefinitionException {
|
private static final Pattern numericKeywordPattern = Pattern.compile("([a-zA-Z-_ ]+?)([ +]*)(\\d+)");
|
||||||
|
|
||||||
|
private static Map<Keyword, Integer> convertKeywords(String[] keywords, String key) throws InvalidCardDefinitionException {
|
||||||
Map<Keyword, Integer> result = new HashMap<>();
|
Map<Keyword, Integer> result = new HashMap<>();
|
||||||
for (String keywordString : keywords) {
|
for (String keywordStr : keywords) {
|
||||||
final String[] keywordSplit = keywordString.split("\\+");
|
var match = numericKeywordPattern.matcher(keywordStr);
|
||||||
Keyword keyword = FieldUtils.getEnum(Keyword.class, keywordSplit[0], key);
|
|
||||||
int value = 1;
|
if(match.matches()) {
|
||||||
if (keywordSplit.length == 2)
|
Keyword keyword = FieldUtils.getEnum(Keyword.class, match.group(1), key);
|
||||||
value = Integer.parseInt(keywordSplit[1]);
|
int value = Integer.parseInt(match.group(3));
|
||||||
result.put(keyword, value);
|
|
||||||
|
result.put(keyword, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Keyword keyword = FieldUtils.getEnum(Keyword.class, keywordStr, key);
|
||||||
|
result.put(keyword, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user