Altering json handling of numeric keywords; "keyword X" and "keyword+X" are now both valid

This commit is contained in:
Christian 'ketura' McCarty
2024-04-15 01:53:52 -05:00
parent b891385e26
commit d5a3691cb2

View File

@@ -5,9 +5,12 @@ import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
import com.gempukku.lotro.cards.build.FieldProcessor;
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
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.Map;
import java.util.regex.Pattern;
public class KeywordFieldProcessor implements FieldProcessor {
@Override
@@ -16,15 +19,23 @@ public class KeywordFieldProcessor implements FieldProcessor {
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<>();
for (String keywordString : keywords) {
final String[] keywordSplit = keywordString.split("\\+");
Keyword keyword = FieldUtils.getEnum(Keyword.class, keywordSplit[0], key);
int value = 1;
if (keywordSplit.length == 2)
value = Integer.parseInt(keywordSplit[1]);
result.put(keyword, value);
for (String keywordStr : keywords) {
var match = numericKeywordPattern.matcher(keywordStr);
if(match.matches()) {
Keyword keyword = FieldUtils.getEnum(Keyword.class, match.group(1), key);
int value = Integer.parseInt(match.group(3));
result.put(keyword, value);
}
else {
Keyword keyword = FieldUtils.getEnum(Keyword.class, keywordStr, key);
result.put(keyword, 1);
}
}
return result;
}