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 { private String generateCardTooltip(LotroCardBlueprint bp, String bpid) throws CardNotFoundException {
String[] parts = bpid.split("_"); String[] parts = bpid.split("_");
String cardnum = parts[1].replace("*", "").replace("T", ""); int setnum = Integer.parseInt(parts[0]);
String tlhhID = "LOTR" + String.format("%02d", Integer.parseInt(parts[0])) + String.format("%03d", Integer.parseInt(cardnum)); 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) 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; return result;
} }

View File

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

View File

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

View File

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

View File

@@ -4,12 +4,13 @@ import com.gempukku.lotro.common.*;
import com.gempukku.lotro.logic.GameUtils; import com.gempukku.lotro.logic.GameUtils;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
public class ImportCards { public class ImportCards {
//For a deck to be legal in a Pre-shadows format, it must contain one of these sites //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", private final Set<String> fellowshipSiteCheck = new HashSet<>(Arrays.asList("council courtyard",
"ford of bruinen", "frodo's bedroom", "rivendell terrace", "rivendell valley", "rivendell waterfall", "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", private final Set<String> towersSiteCheck = new HashSet<>(Arrays.asList("derndingle", "eastfold",
"fangorn forest", "plains of rohan camp", "rohirrim village", "uruk camp", "wold of rohan")); "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")); 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 (CardCount cardCount : decklist) {
for (Map.Entry<String, LotroCardBlueprint> cardBlueprint : cardLibrary.getBaseCards().entrySet()) { for (Map.Entry<String, LotroCardBlueprint> cardBlueprint : cardLibrary.getBaseCards().entrySet()) {
String id = cardBlueprint.getKey(); String id = cardBlueprint.getKey();
if (isFromOfficialSet(id)) { if (isFromSupportedSet(id)) {
LotroCardBlueprint blueprint = cardBlueprint.getValue(); LotroCardBlueprint blueprint = cardBlueprint.getValue();
if (isNotSiteOrSiteFromBlock(blueprint, sitesBlock)) { if (isNotSiteOrSiteFromBlock(blueprint, sitesBlock)) {
if (exactNameMatch(blueprint, cardCount.getName())) { if (exactNameMatch(blueprint, cardCount.getName())) {
@@ -60,14 +61,17 @@ public class ImportCards {
&& SortAndFilterCards.replaceSpecialCharacters(GameUtils.getFullName(blueprint).toLowerCase()).equals(title); && SortAndFilterCards.replaceSpecialCharacters(GameUtils.getFullName(blueprint).toLowerCase()).equals(title);
} }
private boolean isFromOfficialSet(String id) { private boolean isFromSupportedSet(String id) {
try { 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) { } catch (NumberFormatException exp) {
return false; return false;
} }
} }
private Pattern cardLinePattern = Pattern.compile("^(x?\\s*\\d+\\s*x?)?\\s*(.*)\\s*(x?\\d+x?)?\\s*$");
private List<CardCount> getDecklist(String rawDecklist) { private List<CardCount> getDecklist(String rawDecklist) {
int quantity; int quantity;
String cardLine; String cardLine;
@@ -79,17 +83,22 @@ public class ImportCards {
line = line.toLowerCase(); line = line.toLowerCase();
try { try {
if (Character.isDigit(line.charAt(0))) { var matches = cardLinePattern.matcher(line);
quantity = Character.getNumericValue(line.charAt(0));
cardLine = line.substring(line.indexOf(" ")); if(matches.matches()) {
} else if (Character.isDigit(line.charAt(line.length() - 1))) { if(!matches.group(1).isBlank()) {
quantity = Character.getNumericValue(line.charAt(line.length() - 1)); quantity = Integer.parseInt(matches.group(1).replaceAll("\\D+", ""));
cardLine = line.substring(0, line.indexOf(" ", line.length() - 3)); }
} else { else if(!matches.group(3).isBlank()) {
quantity = 1; quantity = Integer.parseInt(matches.group(3).replaceAll("\\D+", ""));
cardLine = line; }
else {
quantity = 1;
}
cardLine = matches.group(2).trim();
result.add(new CardCount(SortAndFilterCards.replaceSpecialCharacters(cardLine).trim(), quantity));
} }
result.add(new CardCount(SortAndFilterCards.replaceSpecialCharacters(cardLine).trim(), quantity));
} catch (Exception exp) { } catch (Exception exp) {
// Ignore the card // 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.lotro.logic.GameUtils;
import com.gempukku.util.MultipleComparator; import com.gempukku.util.MultipleComparator;
import java.text.Normalizer;
import java.util.*; import java.util.*;
public class SortAndFilterCards { public class SortAndFilterCards {
@@ -281,22 +282,12 @@ public class SortAndFilterCards {
} }
public static String replaceSpecialCharacters(String text) { public static String replaceSpecialCharacters(String text) {
return text return Normalizer.normalize(text, Normalizer.Form.NFD)
.replace('á', 'a') .replaceAll("", "'")
.replace('â', 'a') .replaceAll("", "'")
.replace('ä', 'a') .replaceAll("", "\"")
.replace('é', 'e') .replaceAll("", "\"")
.replace('ê', 'e') .replaceAll("\\p{M}", "");
.replace('ë', 'e')
.replace('í', 'i')
.replace('ï', 'i')
.replace('ó', 'o')
.replace('ú', 'u')
.replace('û', 'u')
.replace('', '\'')
.replace('', '\'')
.replace('”', '"')
.replace('“', '"');
} }
private <T extends Enum> Set<T> getEnumFilter(T[] enumValues, Class<T> enumType, String prefix, Set<T> defaultResult, String[] filterParams) { private <T extends Enum> Set<T> getEnumFilter(T[] enumValues, Class<T> enumType, String prefix, Set<T> defaultResult, String[] filterParams) {