fix deck loading problem (wrong editions were shown)

This commit is contained in:
Maxmtg
2014-01-25 21:30:56 +00:00
parent dbf77d8548
commit dfebb08e1e
5 changed files with 26 additions and 15 deletions

View File

@@ -97,7 +97,7 @@ public final class CardDb implements ICardDatabase {
isFoil = true; isFoil = true;
} }
int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos]) : -1; int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos])-1 : -1;
String setName = setPos > 0 ? nameParts[setPos] : null; String setName = setPos > 0 ? nameParts[setPos] : null;
if( "???".equals(setName) ) if( "???".equals(setName) )
setName = null; setName = null;
@@ -173,6 +173,7 @@ public final class CardDb implements ICardDatabase {
@Override @Override
public PaperCard getCard(final String cardName, String setName) { public PaperCard getCard(final String cardName, String setName) {
CardRequest request = CardRequest.fromString(cardName); CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
request.edition = setName; request.edition = setName;
return tryGetCard(request); return tryGetCard(request);
} }
@@ -180,7 +181,9 @@ public final class CardDb implements ICardDatabase {
@Override @Override
public PaperCard getCard(final String cardName, String setName, int artIndex) { public PaperCard getCard(final String cardName, String setName, int artIndex) {
CardRequest request = CardRequest.fromString(cardName); CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
request.edition = setName; request.edition = setName;
if(artIndex >= 0)
request.artIndex = artIndex; request.artIndex = artIndex;
return tryGetCard(request); return tryGetCard(request);
} }
@@ -191,10 +194,17 @@ public final class CardDb implements ICardDatabase {
PaperCard result = null; PaperCard result = null;
String reqEdition = request.edition;
if(reqEdition != null && !editions.contains(reqEdition)) {
CardEdition edition = editions.get(reqEdition);
if( edition != null )
reqEdition = edition.getCode();
}
if ( request.artIndex < 0 ) { // this stands for 'random art' if ( request.artIndex < 0 ) { // this stands for 'random art'
List<PaperCard> candidates = new ArrayList<PaperCard>(9); // 9 cards with same name per set is a maximum of what has been printed (Arnchenemy) List<PaperCard> candidates = new ArrayList<PaperCard>(9); // 9 cards with same name per set is a maximum of what has been printed (Arnchenemy)
for( PaperCard pc : cards ) { for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(request.edition) || request.edition == null ) if( pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null )
candidates.add(pc); candidates.add(pc);
} }
@@ -203,7 +213,7 @@ public final class CardDb implements ICardDatabase {
result = Aggregates.random(candidates); result = Aggregates.random(candidates);
} else { } else {
for( PaperCard pc : cards ) { for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(request.edition) && request.artIndex == pc.getArtIndex() ) { if( pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex() ) {
result = pc; result = pc;
break; break;
} }

View File

@@ -347,6 +347,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
} }
public Iterable<CardEdition> getOrderedEditions() { public Iterable<CardEdition> getOrderedEditions() {
List<CardEdition> res = Lists.newArrayList(this); List<CardEdition> res = Lists.newArrayList(this);
Collections.sort(res); Collections.sort(res);

View File

@@ -55,12 +55,12 @@ public class CardPool extends ItemPool<PaperCard> {
this.add(cardName, setCode, -1, amount); this.add(cardName, setCode, -1, amount);
} }
// NOTE: ART indices are "1" -based
public void add(final String cardName, final String setCode, final int artIndex, final int amount) { public void add(final String cardName, final String setCode, final int artIndex, final int amount) {
boolean isCommonCard = true;
PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex); PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex);
if ( cp == null ) { boolean isCommonCard = cp != null;
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode, artIndex); if ( !isCommonCard ) {
isCommonCard = false; cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
} }
int artCount = isCommonCard int artCount = isCommonCard
@@ -73,7 +73,7 @@ public class CardPool extends ItemPool<PaperCard> {
} else { } else {
// random art index specified, make sure we get different groups of cards with different art // random art index specified, make sure we get different groups of cards with different art
int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount); int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount);
for (int i = 0; i < artGroups.length; i++) { for (int i = 1; i <= artGroups.length; i++) {
PaperCard cp_random = isCommonCard ? StaticData.instance().getCommonCards().getCard(cardName, setCode, i) : StaticData.instance().getVariantCards().getCard(cardName, setCode, i); PaperCard cp_random = isCommonCard ? StaticData.instance().getCommonCards().getCard(cardName, setCode, i) : StaticData.instance().getVariantCards().getCard(cardName, setCode, i);
this.add(cp_random, artGroups[i]); this.add(cp_random, artGroups[i]);
} }

View File

@@ -162,11 +162,11 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(landName, landSet); final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(landName, landSet);
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) { if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
for (int i = 0; i < numArt; i++) { for (int i = 1; i <= numArt; i++) {
deck.get(DeckSection.Sideboard).add(landName, landSet, i, numArt > 1 ? landsCount : 30); deck.get(DeckSection.Sideboard).add(landName, landSet, i, numArt > 1 ? landsCount : 30);
} }
} else { } else {
deck.get(DeckSection.Sideboard).add(landName, landSet, numArt > 1 ? MyRandom.getRandom().nextInt(numArt) : 0, 30); deck.get(DeckSection.Sideboard).add(landName, landSet, 30);
} }
} }

View File

@@ -178,11 +178,11 @@ public enum CSubmenuSealed implements ICDoc {
final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(element, sd.getLandSetCode()); final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(element, sd.getLandSetCode());
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) { if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
for (int i = 0; i < numArt; i++) { for (int i = 1; i <= numArt; i++) {
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), i, numArt > 1 ? landsCount : 30); deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), i, numArt > 1 ? landsCount : 30);
} }
} else { } else {
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), numArt > 1 ? MyRandom.getRandom().nextInt(numArt) : 0, 30); deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), 30);
} }
} }