Adding support for set V1 in the deckbuilding importer. Adding support for V1 and errata in the deck sharing screen. Improved deck import flexibility and accent removal

This commit is contained in:
Christian 'ketura' McCarty
2022-12-07 21:22:08 -06:00
parent f0c35775a1
commit f0bba302e2
6 changed files with 57 additions and 36 deletions

View File

@@ -401,10 +401,31 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
private String generateCardTooltip(LotroCardBlueprint bp, String bpid) throws CardNotFoundException {
String[] parts = bpid.split("_");
String cardnum = parts[1].replace("*", "").replace("T", "");
String tlhhID = "LOTR" + String.format("%02d", Integer.parseInt(parts[0])) + String.format("%03d", Integer.parseInt(cardnum));
int setnum = Integer.parseInt(parts[0]);
String set = String.format("%02d", setnum);
String subset = "S";
int version = 0;
if(setnum >= 50 && setnum <= 69) {
setnum -= 50;
set = String.format("%02d", setnum);
subset = "E";
version = 1;
}
else if(setnum >= 70 && setnum <= 89) {
setnum -= 70;
set = String.format("%02d", setnum);
subset = "E";
version = 1;
}
else if(setnum >= 100 && setnum <= 149) {
setnum -= 100;
set = "V" + setnum;
}
int cardnum = Integer.parseInt(parts[1].replace("*", "").replace("T", ""));
String id = "LOTR-EN" + set + subset + String.format("%03d", cardnum) + "." + String.format("%01d", version);
String result = "<span class=\"tooltip\">" + GameUtils.getFullName(bp)
+ "<span><img class=\"ttimage\" src=\"https://i.lotrtcgpc.net/decipher/" + tlhhID + ".jpg\" ></span></span>";
+ "<span><img class=\"ttimage\" src=\"https://wiki.lotrtcgpc.net/images/" + id + "_card.jpg\" ></span></span>";
return result;
}

View File

@@ -298,7 +298,7 @@
101_12: {
title: Three Rings for the Elven Kings
title: Three Rings for the Elven-kings
unique: true
culture: elven
twilight: 1

View File

@@ -112,7 +112,7 @@
}
101_15: {
title: Gwaihir
subtitle: Lord of All Eagles
subtitle: Lord of Eagles
unique: true
culture: gandalf
twilight: 4

View File

@@ -246,7 +246,7 @@
}
101_56: {
title: We're Coming Too
title: We're Coming, Too!
culture: shire
twilight: 2
type: event

View File

@@ -4,12 +4,13 @@ import com.gempukku.lotro.common.*;
import com.gempukku.lotro.logic.GameUtils;
import java.util.*;
import java.util.regex.Pattern;
public class ImportCards {
//For a deck to be legal in a Pre-shadows format, it must contain one of these sites
private final Set<String> fellowshipSiteCheck = new HashSet<>(Arrays.asList("council courtyard",
"ford of bruinen", "frodo's bedroom", "rivendell terrace", "rivendell valley", "rivendell waterfall",
"house of elrond"));
"house of elrond", "rivendell gateway"));
private final Set<String> towersSiteCheck = new HashSet<>(Arrays.asList("derndingle", "eastfold",
"fangorn forest", "plains of rohan camp", "rohirrim village", "uruk camp", "wold of rohan"));
private final Set<String> kingSiteCheck = new HashSet<>(Arrays.asList("king's tent", "rohirrim camp", "west road"));
@@ -22,7 +23,7 @@ public class ImportCards {
for (CardCount cardCount : decklist) {
for (Map.Entry<String, LotroCardBlueprint> cardBlueprint : cardLibrary.getBaseCards().entrySet()) {
String id = cardBlueprint.getKey();
if (isFromOfficialSet(id)) {
if (isFromSupportedSet(id)) {
LotroCardBlueprint blueprint = cardBlueprint.getValue();
if (isNotSiteOrSiteFromBlock(blueprint, sitesBlock)) {
if (exactNameMatch(blueprint, cardCount.getName())) {
@@ -60,14 +61,17 @@ public class ImportCards {
&& SortAndFilterCards.replaceSpecialCharacters(GameUtils.getFullName(blueprint).toLowerCase()).equals(title);
}
private boolean isFromOfficialSet(String id) {
private boolean isFromSupportedSet(String id) {
try {
return Integer.parseInt(id.split("_")[0]) < 20;
int set = Integer.parseInt(id.split("_")[0]);
return set < 20 || (set > 99 && set < 149);
} catch (NumberFormatException exp) {
return false;
}
}
private Pattern cardLinePattern = Pattern.compile("^(x?\\s*\\d+\\s*x?)?\\s*(.*)\\s*(x?\\d+x?)?\\s*$");
private List<CardCount> getDecklist(String rawDecklist) {
int quantity;
String cardLine;
@@ -79,17 +83,22 @@ public class ImportCards {
line = line.toLowerCase();
try {
if (Character.isDigit(line.charAt(0))) {
quantity = Character.getNumericValue(line.charAt(0));
cardLine = line.substring(line.indexOf(" "));
} else if (Character.isDigit(line.charAt(line.length() - 1))) {
quantity = Character.getNumericValue(line.charAt(line.length() - 1));
cardLine = line.substring(0, line.indexOf(" ", line.length() - 3));
} else {
quantity = 1;
cardLine = line;
var matches = cardLinePattern.matcher(line);
if(matches.matches()) {
if(!matches.group(1).isBlank()) {
quantity = Integer.parseInt(matches.group(1).replaceAll("\\D+", ""));
}
else if(!matches.group(3).isBlank()) {
quantity = Integer.parseInt(matches.group(3).replaceAll("\\D+", ""));
}
else {
quantity = 1;
}
cardLine = matches.group(2).trim();
result.add(new CardCount(SortAndFilterCards.replaceSpecialCharacters(cardLine).trim(), quantity));
}
} catch (Exception exp) {
// Ignore the card
}

View File

@@ -6,6 +6,7 @@ import com.gempukku.lotro.game.packs.SetDefinition;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.util.MultipleComparator;
import java.text.Normalizer;
import java.util.*;
public class SortAndFilterCards {
@@ -281,22 +282,12 @@ public class SortAndFilterCards {
}
public static String replaceSpecialCharacters(String text) {
return text
.replace('á', 'a')
.replace('â', 'a')
.replace('ä', 'a')
.replace('é', 'e')
.replace('ê', 'e')
.replace('ë', 'e')
.replace('í', 'i')
.replace('ï', 'i')
.replace('ó', 'o')
.replace('ú', 'u')
.replace('û', 'u')
.replace('', '\'')
.replace('', '\'')
.replace('”', '"')
.replace('“', '"');
return Normalizer.normalize(text, Normalizer.Form.NFD)
.replaceAll("", "'")
.replaceAll("", "'")
.replaceAll("", "\"")
.replaceAll("", "\"")
.replaceAll("\\p{M}", "");
}
private <T extends Enum> Set<T> getEnumFilter(T[] enumValues, Class<T> enumType, String prefix, Set<T> defaultResult, String[] filterParams) {