- Read the foil chance in booster value from edition files as a US locale double.

This commit is contained in:
Agetian
2014-02-10 08:32:49 +00:00
parent 30fda0e7a8
commit a72655fc79
2 changed files with 38 additions and 1 deletions

View File

@@ -286,7 +286,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
res.foilType = FoilType.NOT_SUPPORTED;
break;
}
res.foilChanceInBooster = section.getInt("FoilChanceInBooster", 2143) / 10000.0F;
res.foilChanceInBooster = section.getDouble("FoilChanceInBooster", 21.43F) / 100.0F;
System.out.println("chance = " + res.foilChanceInBooster);
res.foilAlwaysInCommonSlot = section.getBoolean("FoilAlwaysInCommonSlot", false);

View File

@@ -17,10 +17,15 @@
*/
package forge.util;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
/**
@@ -113,6 +118,38 @@ public class FileSection {
return lines.containsKey(keyName);
}
/**
* Gets the double.
*
* @param fieldName the field name
* @return the int
*/
public double getDouble(final String fieldName) {
return this.getDouble(fieldName, 0.0F);
}
/**
* Gets the double.
*
* @param fieldName the field name
* @param defaultValue the default value
* @return the int
*/
public double getDouble(final String fieldName, final double defaultValue) {
try {
if (this.get(fieldName) == null) {
return defaultValue;
}
NumberFormat format = NumberFormat.getInstance(Locale.US);
Number number = format.parse(this.get(fieldName));
return number.doubleValue();
} catch (final NumberFormatException | ParseException ex) {
return defaultValue;
}
}
/**
* Gets the int.
*