- Reverting r29415-29422 for now because the UTF-8 characters prove to be problematic for the player unless they are transparent enough when searching for cards and typing card names (including the deck editor).

- Before having to revert these changes I managed to get the game to recognize both accented and unaccented card names in decks and for the purposes of card picture file names. However, I was not successful in implementing the similar level of transparency in the deck editor and in the card search box (e.g. "Add Card To Hand" - that type of thing).
- To continue working on this project, feel free to revert this commit locally and update the functionality to be more transparent and intuitive for the end user.
This commit is contained in:
Agetian
2015-05-17 16:44:30 +00:00
parent 9f15e72a4f
commit 46f17edad0
69 changed files with 160 additions and 226 deletions

View File

@@ -1,18 +1,16 @@
package forge.limited;
import com.esotericsoftware.minlog.Log;
import forge.properties.ForgeConstants;
import forge.util.FileUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.esotericsoftware.minlog.Log;
import forge.properties.ForgeConstants;
import forge.util.FileUtil;
/**
* ReadDraftRankings class.
*
*/
public class ReadDraftRankings {
@@ -32,23 +30,19 @@ public class ReadDraftRankings {
this.draftRankings = this.readFile(FileUtil.readFile(ForgeConstants.DRAFT_RANKINGS_FILE));
} // setup()
private static String getRankingCardName(final String name) {
return StringUtils.replaceChars(name.trim(), "-áàâéèêúùûíìîóòô", " aaaeeeuuuiiiooo").replaceAll("[^A-Za-z ]", "");
}
/**
* <p>
* readFile.
* </p>
*
*
* @param file
* a {@link java.io.File} object.
* @return a {@link java.util.Map} object.
*/
private Map<String, Map<String, Integer>> readFile(final List<String> lines) {
private Map<String, Map<String, Integer>> readFile(List<String> lines) {
final Map<String, Map<String, Integer>> map = new HashMap<String, Map<String, Integer>>();
for (final String line : lines) {
for (String line : lines) {
// stop reading if end of file or blank line is read
if (line == null || line.length() == 0) {
break;
@@ -59,7 +53,7 @@ public class ReadDraftRankings {
}
final String[] s = line.split("\\|");
final String rankStr = s[0].trim().substring(1);
final String name = getRankingCardName(s[1]);
final String name = s[1].trim().replaceAll("-", " ").replaceAll("[^A-Za-z ]", "");
// final String rarity = s[2].trim();
final String edition = s[3].trim();
@@ -74,7 +68,7 @@ public class ReadDraftRankings {
} else {
setSizes.put(edition, rank);
}
} catch (final NumberFormatException nfe) {
} catch (NumberFormatException nfe) {
Log.warn("NumberFormatException: " + nfe.getMessage());
}
}
@@ -84,24 +78,26 @@ public class ReadDraftRankings {
/**
* Get the relative ranking for the given card name in the given edition.
*
*
* @param cardName
* the card name
* @param edition
* the card's edition
* @return ranking
*/
public Double getRanking(final String cardName, final String edition) {
public Double getRanking(String cardName, String edition) {
Double rank = null;
if (draftRankings.containsKey(edition)) {
final String safeName = getRankingCardName(cardName);
String safeName = cardName.replaceAll("-", " ").replaceAll("[^A-Za-z ]", "");
// If a card has no ranking, don't try to look it up --BBU
if (draftRankings.get(edition).get(safeName) == null) {
// System.out.println("WARNING! " + safeName + " NOT found in " + edition);
return null;
}
return Double.valueOf(draftRankings.get(edition).get(safeName).doubleValue() / setSizes.get(edition).doubleValue());
rank = (double) draftRankings.get(edition).get(safeName) / (double) setSizes.get(edition);
}
return null;
return rank;
}
}