Merge remote-tracking branch 'upstream/master' into collector-number-in-card-list-and-card-db-refactoring

This commit is contained in:
leriomaggio
2021-07-25 08:09:09 +01:00
116 changed files with 263 additions and 254 deletions

View File

@@ -138,7 +138,7 @@ public class CardStorageReader {
final CardRules.Reader rulesReader = new CardRules.Reader();
final List<CardRules> result = new ArrayList<>();
for(int i = from; i < to; i++) {
for (int i = from; i < to; i++) {
final ZipEntry ze = files.get(i);
// if (ze.getName().endsWith(CardStorageReader.CARD_FILE_DOT_EXTENSION)) // already filtered!
result.add(this.loadCard(rulesReader, ze));
@@ -315,11 +315,11 @@ public class CardStorageReader {
final List<Future<List<CardRules>>> parts = executor.invokeAll(tasks);
executor.shutdown();
cdl.await();
for(final Future<List<CardRules>> pp : parts) {
for (final Future<List<CardRules>> pp : parts) {
result.addAll(pp.get());
}
} else {
for(final Callable<List<CardRules>> c : tasks) {
for (final Callable<List<CardRules>> c : tasks) {
result.addAll(c.call());
}
}

View File

@@ -240,7 +240,6 @@ public class StaticData {
private void tryToLoadCard(String requestInfo){
CardDb.CardRequest r = CardRequest.fromString(requestInfo);
String cardName = r.cardName;
String setCode = r.edition;
CardRules rules = cardReader.attemptToLoadCard(cardName, setCode);
CardRules customRules = null;
if (customCardReader != null) {
@@ -258,14 +257,6 @@ public class StaticData {
}
}
// TODO Remove these in favor of them being associated to the Edition
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public IStorage<FatPack.Template> getFatPacks() {
if (fatPacks == null)
fatPacks = new StorageBase<>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
return fatPacks;
}
/** @return {@link forge.util.storage.IStorage}<{@link forge.item.SealedProduct.Template}> */
public final IStorage<SealedProduct.Template> getTournamentPacks() {
if (tournaments == null)

View File

@@ -84,6 +84,16 @@ public final class CardEdition implements Comparable<CardEdition> {
}
}
public String getFatPackDefault() {
switch (this) {
case CORE:
case EXPANSION:
return "10";
default:
return "0";
}
}
public String toString(){
String[] names = TextUtil.splitWithParenthesis(this.name().toLowerCase(), '_');
for (int i = 0; i < names.length; i++)
@@ -128,7 +138,8 @@ public final class CardEdition implements Comparable<CardEdition> {
BUY_A_BOX("buy a box"),
PROMO("promo"),
BUNDLE("bundle"),
BOX_TOPPER("box topper");
BOX_TOPPER("box topper"),
DUNGEONS("dungeons");
private final String name;
@@ -198,11 +209,11 @@ public final class CardEdition implements Comparable<CardEdition> {
try {
collNr = Integer.parseInt(onlyNumeric);
} catch (NumberFormatException exon) {
collNr = 0; // this is the case of ONLY-letters collector numbers
collNr = 0; // this is the case of ONLY-letters collector numbers
}
if ((collNr > 0) && (sortableCollNr.startsWith(onlyNumeric))) // e.g. 12a, 37+, 2018f,
sortableCollNr = String.format("%05d", collNr) + nonNumeric;
else // e.g. WS6, S1
else // e.g. WS6, S1
sortableCollNr = nonNumeric + String.format("%05d", collNr);
}
return sortableCollNr;
@@ -242,6 +253,8 @@ public final class CardEdition implements Comparable<CardEdition> {
// SealedProduct
private String prerelease = null;
private int boosterBoxCount = 36;
private int fatPackCount = 10;
private String fatPackExtraSlots = "";
// Booster/draft info
private boolean smallSetOverride = false;
@@ -332,6 +345,8 @@ public final class CardEdition implements Comparable<CardEdition> {
public String getPrerelease() { return prerelease; }
public int getBoosterBoxCount() { return boosterBoxCount; }
public int getFatPackCount() { return fatPackCount; }
public String getFatPackExtraSlots() { return fatPackExtraSlots; }
public FoilType getFoilType() { return foilType; }
public double getFoilChanceInBooster() { return foilChanceInBooster; }
@@ -441,11 +456,11 @@ public final class CardEdition implements Comparable<CardEdition> {
Map<String, Integer> cardToIndex = new HashMap<>();
List<PrintSheet> sheets = Lists.newArrayList();
for(String sectionName : cardMap.keySet()) {
for (String sectionName : cardMap.keySet()) {
PrintSheet sheet = new PrintSheet(String.format("%s %s", this.getCode(), sectionName));
List<CardInSet> cards = cardMap.get(sectionName);
for(CardInSet card : cards) {
for (CardInSet card : cards) {
int index = 1;
if (cardToIndex.containsKey(card.name)) {
index = cardToIndex.get(card.name);
@@ -460,7 +475,7 @@ public final class CardEdition implements Comparable<CardEdition> {
sheets.add(sheet);
}
for(String sheetName : customPrintSheetsToParse.keySet()) {
for (String sheetName : customPrintSheetsToParse.keySet()) {
List<String> sheetToParse = customPrintSheetsToParse.get(sheetName);
CardPool sheetPool = CardPool.fromCardList(sheetToParse);
PrintSheet sheet = new PrintSheet(String.format("%s %s", this.getCode(), sheetName), sheetPool);
@@ -543,7 +558,7 @@ public final class CardEdition implements Comparable<CardEdition> {
// parse tokens section
if (contents.containsKey("tokens")) {
for(String line : contents.get("tokens")) {
for (String line : contents.get("tokens")) {
if (StringUtils.isBlank(line))
continue;
@@ -571,11 +586,11 @@ public final class CardEdition implements Comparable<CardEdition> {
res.mciCode = res.code2.toLowerCase();
}
res.scryfallCode = section.get("ScryfallCode");
if (res.scryfallCode == null){
if (res.scryfallCode == null) {
res.scryfallCode = res.code;
}
res.cardsLanguage = section.get("CardLang");
if (res.cardsLanguage == null){
if (res.cardsLanguage == null) {
res.cardsLanguage = "en";
}
@@ -601,7 +616,7 @@ public final class CardEdition implements Comparable<CardEdition> {
res.borderColor = BorderColor.valueOf(section.get("border", "Black").toUpperCase(Locale.ENGLISH));
Type enumType = Type.UNKNOWN;
if (this.isCustomEditions){
enumType = Type.CUSTOM_SET; // Forcing ThirdParty Edition Type to avoid inconsistencies
enumType = Type.CUSTOM_SET; // Forcing ThirdParty Edition Type to avoid inconsistencies
} else {
String type = section.get("type");
if (null != type && !type.isEmpty()) {
@@ -617,8 +632,10 @@ public final class CardEdition implements Comparable<CardEdition> {
res.type = enumType;
res.prerelease = section.get("Prerelease", null);
res.boosterBoxCount = Integer.parseInt(section.get("BoosterBox", enumType.getBoosterBoxDefault()));
res.fatPackCount = Integer.parseInt(section.get("FatPack", enumType.getFatPackDefault()));
res.fatPackExtraSlots = section.get("FatPackExtraSlots", "");
switch(section.get("foil", "newstyle").toLowerCase()) {
switch (section.get("foil", "newstyle").toLowerCase()) {
case "notsupported":
res.foilType = FoilType.NOT_SUPPORTED;
break;
@@ -751,7 +768,7 @@ public final class CardEdition implements Comparable<CardEdition> {
@Override
public Map<String, SealedProduct.Template> readAll() {
Map<String, SealedProduct.Template> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for(CardEdition ce : Collection.this) {
for (CardEdition ce : Collection.this) {
List<String> boosterTypes = Lists.newArrayList(ce.getAvailableBoosterTypes());
for (String type : boosterTypes) {
String setAffix = type.equals("Draft") ? "" : type;
@@ -805,14 +822,14 @@ public final class CardEdition implements Comparable<CardEdition> {
strictness = CardArtPreference.ORIGINAL_ART_ALL_EDITIONS; // card is not found in core and expansions only (probably something CMD or C13)
cp = StaticData.instance().getCommonCards().getCardFromEditions(k.getKey().getName(), strictness);
}
if ( cp == null )
if (cp == null)
cp = k.getKey(); // it's unlikely, this code will ever run
minEditions.add(cp.getEdition());
}
for(CardEdition ed : getOrderedEditions()) {
if(minEditions.contains(ed.getCode()))
for (CardEdition ed : getOrderedEditions()) {
if (minEditions.contains(ed.getCode()))
return ed;
}
return UNKNOWN;
@@ -854,7 +871,7 @@ public final class CardEdition implements Comparable<CardEdition> {
private static class CanMakeFatPack implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return StaticData.instance().getFatPacks().contains(subject.getCode());
return subject.getFatPackCount() > 0;
}
}

View File

@@ -513,14 +513,14 @@ public final class CardRules implements ICardCharacteristics {
case 'S':
if ("S".equals(key)) {
this.faces[this.curFace].addStaticAbility(value);
} else if ( "SVar".equals(key) ) {
if ( null == value ) throw new IllegalArgumentException("SVar has no variable name");
} else if ("SVar".equals(key)) {
if (null == value) throw new IllegalArgumentException("SVar has no variable name");
colonPos = value.indexOf(':');
String variable = colonPos > 0 ? value.substring(0, colonPos) : value;
value = colonPos > 0 ? value.substring(1+colonPos) : null;
if ( "Picture".equals(variable) ) {
if ("Picture".equals(variable)) {
this.pictureUrl[this.curFace] = value;
} else
this.faces[curFace].addSVar(variable, value);

View File

@@ -451,8 +451,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
if (calculatedType == null) {
if (subtypes.isEmpty()) {
calculatedType = StringUtils.join(getTypesBeforeDash(), ' ');
}
else {
} else {
calculatedType = StringUtils.join(getTypesBeforeDash(), ' ') + " - " + StringUtils.join(subtypes, " ");
}
}

View File

@@ -84,7 +84,7 @@ public final class MagicColor {
}
public static String toShortString(final byte color) {
switch (color){
switch (color) {
case WHITE: return "W";
case BLUE: return "U";
case BLACK: return "B";
@@ -95,7 +95,7 @@ public final class MagicColor {
}
public static String toLongString(final byte color) {
switch (color){
switch (color) {
case WHITE: return Constant.WHITE;
case BLUE: return Constant.BLUE;
case BLACK: return Constant.BLACK;

View File

@@ -29,8 +29,8 @@ public class PrintSheet {
public static final IStorage<PrintSheet> initializePrintSheets(File sheetsFile, CardEdition.Collection editions) {
IStorage<PrintSheet> sheets = new StorageExtendable<>("Special print runs", new PrintSheet.Reader(sheetsFile));
for(CardEdition edition : editions) {
for(PrintSheet ps : edition.getPrintSheetsBySection()) {
for (CardEdition edition : editions) {
for (PrintSheet ps : edition.getPrintSheetsBySection()) {
sheets.add(ps.name, ps);
}
}
@@ -64,7 +64,7 @@ public class PrintSheet {
}
public void addAll(Iterable<PaperCard> cards, int weight) {
for(PaperCard card : cards)
for (PaperCard card : cards)
cardsWithWeights.add(card, weight);
}
@@ -78,15 +78,15 @@ public class PrintSheet {
private PaperCard fetchRoulette(int start, int roulette, Collection<PaperCard> toSkip) {
int sum = start;
boolean isSecondRun = start > 0;
for(Entry<PaperCard, Integer> cc : cardsWithWeights ) {
for (Entry<PaperCard, Integer> cc : cardsWithWeights ) {
sum += cc.getValue();
if( sum > roulette ) {
if( toSkip != null && toSkip.contains(cc.getKey()))
if (sum > roulette) {
if (toSkip != null && toSkip.contains(cc.getKey()))
continue;
return cc.getKey();
}
}
if( isSecondRun )
if (isSecondRun)
throw new IllegalStateException("Print sheet does not have enough unique cards");
return fetchRoulette(sum + 1, roulette, toSkip); // start over from beginning, in case last cards were to skip
@@ -94,8 +94,8 @@ public class PrintSheet {
public List<PaperCard> all() {
List<PaperCard> result = new ArrayList<>();
for(Entry<PaperCard, Integer> kv : cardsWithWeights) {
for(int i = 0; i < kv.getValue(); i++) {
for (Entry<PaperCard, Integer> kv : cardsWithWeights) {
for (int i = 0; i < kv.getValue(); i++) {
result.add(kv.getKey());
}
}
@@ -106,26 +106,26 @@ public class PrintSheet {
List<PaperCard> result = new ArrayList<>();
int totalWeight = cardsWithWeights.countAll();
if( totalWeight == 0) {
if (totalWeight == 0) {
System.err.println("No cards were found on sheet " + name);
return result;
}
// If they ask for 40 unique basic lands (to make a fatpack) out of 20 distinct possible, add the whole print run N times.
int uniqueCards = cardsWithWeights.countDistinct();
while ( number >= uniqueCards ) {
for(Entry<PaperCard, Integer> kv : cardsWithWeights) {
while (number >= uniqueCards) {
for (Entry<PaperCard, Integer> kv : cardsWithWeights) {
result.add(kv.getKey());
}
number -= uniqueCards;
}
List<PaperCard> uniques = wantUnique ? new ArrayList<>() : null;
for(int iC = 0; iC < number; iC++) {
for (int iC = 0; iC < number; iC++) {
int index = MyRandom.getRandom().nextInt(totalWeight);
PaperCard toAdd = fetchRoulette(0, index, wantUnique ? uniques : null);
result.add(toAdd);
if( wantUnique )
if (wantUnique)
uniques.add(toAdd);
}
return result;

View File

@@ -257,7 +257,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
// I used to store planes and schemes under sideboard header, so this will assign them to a correct section
IPaperCard sample = pool.get(0);
if (sample != null && ( sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon()))
if (sample != null && (sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon()))
sec = DeckSection.Planes;
if (sample != null && sample.getRules().getType().isScheme())
sec = DeckSection.Schemes;
@@ -331,7 +331,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
}
}
// == 3. Last step, update the pool!
// Get Reference release date as two days AFTER the actual release date
// Get Reference release date as two days AFTER the actual release date
// of the reference date so that in case, the reference date will be counted in too!
Calendar cal = Calendar.getInstance();
cal.setTime(referenceEdition.getDate());
@@ -339,7 +339,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
Date releaseDateReferenceEdition = cal.getTime();
CardPool newPool = new CardPool();
for(Entry<PaperCard, Integer> cp : pool) {
for (Entry<PaperCard, Integer> cp : pool) {
PaperCard card = cp.getKey();
int count = cp.getValue();
if (!cardNamesWithNoEditionInSection.contains(card.getName()))

View File

@@ -18,10 +18,8 @@
package forge.item;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
@@ -30,16 +28,17 @@ import forge.ImageKeys;
import forge.StaticData;
import forge.card.CardEdition;
import forge.item.generation.BoosterGenerator;
import forge.util.TextUtil;
import forge.util.storage.StorageReaderFile;
public class FatPack extends BoxedProduct {
public static final Function<CardEdition, FatPack> FN_FROM_SET = new Function<CardEdition, FatPack>() {
@Override
public FatPack apply(final CardEdition arg1) {
FatPack.Template d = StaticData.instance().getFatPacks().get(arg1.getCode());
public FatPack apply(final CardEdition edition) {
int boosters = edition.getFatPackCount();
if (boosters <= 0) { return null; }
FatPack.Template d = new Template(edition);
if (d == null) { return null; }
return new FatPack(arg1.getName(), d, d.cntBoosters);
return new FatPack(edition.getName(), d, d.cntBoosters);
}
};
@@ -68,17 +67,6 @@ public class FatPack extends BoxedProduct {
return BoosterGenerator.getBoosterPack(fpData);
}
/*@Override
protected List<PaperCard> generate() {
List<PaperCard> result = new ArrayList<PaperCard>();
for (int i = 0; i < fpData.getCntBoosters(); i++) {
result.addAll(super.generate());
}
// Add any extra cards that may come in the fatpack after Boosters
result.addAll(BoosterGenerator.getBoosterPack(fpData));
return result;
}*/
@Override
public final Object clone() {
return new FatPack(name, fpData, fpData.cntBoosters);
@@ -92,38 +80,12 @@ public class FatPack extends BoxedProduct {
public static class Template extends SealedProduct.Template {
private final int cntBoosters;
public int getCntBoosters() { return cntBoosters; }
private Template(String edition, int boosters, Iterable<Pair<String, Integer>> itrSlots)
{
super(edition, itrSlots);
cntBoosters = boosters;
}
private Template(CardEdition edition) {
super(edition.getCode(), edition.getFatPackExtraSlots());
public static final class Reader extends StorageReaderFile<Template> {
public Reader(String pathname) {
super(pathname, FN_GET_NAME);
}
@Override
protected Template read(String line, int i) {
String[] headAndData = TextUtil.split(line, ':', 2);
final String edition = headAndData[0];
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
int nBoosters = 6;
List<Pair<String, Integer>> slots = new ArrayList<>();
for(String slotDesc : data) {
String[] kv = TextUtil.split(slotDesc, ' ', 2);
if (kv[1].startsWith("Booster"))
nBoosters = Integer.parseInt(kv[0]);
else
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
}
return new FatPack.Template(edition, nBoosters, slots);
}
cntBoosters = edition.getFatPackCount();
}
@Override

View File

@@ -60,7 +60,7 @@ public abstract class SealedProduct implements InventoryItemFromSet {
public SealedProduct(String name0, Template boosterData) {
if (null == name0) { throw new IllegalArgumentException("name0 must not be null"); }
if (null == boosterData) {
throw new IllegalArgumentException("boosterData must not be null");
throw new IllegalArgumentException("boosterData for " + name0 + " must not be null");
}
contents = boosterData;
name = name0;