* GUI: double faced cards improves:

* fixed images download for alternative prints (#9826, #9701);
 * fixed wrong pair of main and second side arts for alternative prints;
This commit is contained in:
Oleg Agafonov 2023-03-11 17:35:18 +04:00
parent 18a3ec5247
commit 4e9ffdfaf9
12 changed files with 59 additions and 32 deletions

View file

@ -326,12 +326,13 @@ public class TestCardRenderDialog extends MageDialog {
//*/
// test variant double faced cards (main and second sides must be same pair)
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "65")); // Jacob Hauken, Inspector
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "320")); // Jacob Hauken, Inspector
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "332")); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "65", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "320", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "332", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
// Jacob Hauken, Inspector -> Hauken's Insight
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "65"));
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "320"));
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "332"));
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "65", 1, 1, 0, false, false, null));
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "320", 1, 1, 0, false, false, null));
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "332", 1, 1, 0, false, false, null));
//*/
/*//test card icons

View file

@ -456,7 +456,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
throw new IllegalStateException("Second side card can't have empty name.");
}
CardInfo secondSideCard = CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode());
CardInfo secondSideCard = CardRepository.instance.findCardWithPreferredSetAndNumber(card.getSecondSideName(), card.getSetCode(), card.getCardNumber());
if (secondSideCard == null) {
throw new IllegalStateException("Can''t find second side card in database: " + card.getSecondSideName());
}
@ -490,7 +490,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
throw new IllegalStateException("MeldsToCardName can't be empty in " + card.getName());
}
CardInfo meldsToCard = CardRepository.instance.findCardWPreferredSet(card.getMeldsToCardName(), card.getSetCode());
CardInfo meldsToCard = CardRepository.instance.findCardWithPreferredSetAndNumber(card.getMeldsToCardName(), card.getSetCode(), card.getCardNumber());
if (meldsToCard == null) {
throw new IllegalStateException("Can''t find meldsToCard in database: " + card.getMeldsToCardName());
}

View file

@ -358,7 +358,7 @@ public final class Battlebond extends ExpansionSet {
//Check if the pack already contains a partner pair
if (partnerAllowed) {
//Added card always replaces an uncommon card
Card card = CardRepository.instance.findCardWPreferredSet(partnerName, sourceCard.getExpansionSetCode()).getCard();
Card card = CardRepository.instance.findCardWithPreferredSetAndNumber(partnerName, sourceCard.getExpansionSetCode(), null).getCard();
if (i < max) {
booster.add(card);
} else {

View file

@ -3482,7 +3482,7 @@ public class MysteryBooster extends ExpansionSet {
private void populateSlot(int slotNumber, List<String> cardNames) {
final List<CardInfo> cardInfoList = this.possibleCardsPerBoosterSlot.get(slotNumber);
for (String name : cardNames) {
final CardInfo cardWithGivenName = CardRepository.instance.findCardWPreferredSet(name, this.code);
final CardInfo cardWithGivenName = CardRepository.instance.findCardWithPreferredSetAndNumber(name, this.code, null);
cardInfoList.add(cardWithGivenName);
}
}

View file

@ -180,7 +180,7 @@ public class CardRepositoryTest {
* so search result must return main side first
*/
@Test
public void test_SearchSetWithSecondSides() {
public void test_SearchSecondSides_FindCard() {
// XLN - Ixalan - Arguel's Blood Fast -> Temple of Aclazotz - 90
Assert.assertEquals("Arguel's Blood Fast", CardRepository.instance.findCard("XLN", "90").getName());
Assert.assertEquals("Arguel's Blood Fast", CardRepository.instance.findCard("XLN", "90", true).getName());
@ -191,4 +191,18 @@ public class CardRepositoryTest {
Assert.assertEquals("Jacob Hauken, Inspector", CardRepository.instance.findCard("VOW", "320", true).getName());
Assert.assertEquals("Jacob Hauken, Inspector", CardRepository.instance.findCard("VOW", "320", false).getName());
}
@Test
public void test_SearchSecondSides_FindCardWithPreferredSetAndNumber() {
// VOW - Innistrad: Crimson Vow - Jacob Hauken, Inspector -> Hauken's Insight - 65
// VOW - Innistrad: Crimson Vow - Jacob Hauken, Inspector -> Hauken's Insight - 320
// VOW - Innistrad: Crimson Vow - Jacob Hauken, Inspector -> Hauken's Insight - 332
Assert.assertEquals("65", CardRepository.instance.findCardWithPreferredSetAndNumber("Jacob Hauken, Inspector", "VOW", "65").getCardNumber());
Assert.assertEquals("320", CardRepository.instance.findCardWithPreferredSetAndNumber("Jacob Hauken, Inspector", "VOW", "320").getCardNumber());
Assert.assertEquals("332", CardRepository.instance.findCardWithPreferredSetAndNumber("Jacob Hauken, Inspector", "VOW", "332").getCardNumber());
Assert.assertEquals("65", CardRepository.instance.findCardWithPreferredSetAndNumber("Hauken's Insight", "VOW", "65").getCardNumber());
Assert.assertEquals("320", CardRepository.instance.findCardWithPreferredSetAndNumber("Hauken's Insight", "VOW", "320").getCardNumber());
Assert.assertEquals("332", CardRepository.instance.findCardWithPreferredSetAndNumber("Hauken's Insight", "VOW", "332").getCardNumber());
}
}

View file

@ -1968,7 +1968,7 @@ public class VerifyCardDataTest {
// same find code as original cube
CardInfo cardInfo;
if (!cardId.getExtension().isEmpty()) {
cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension());
cardInfo = CardRepository.instance.findCardWithPreferredSetAndNumber(cardId.getName(), cardId.getExtension(), null);
} else {
cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName());
}

View file

@ -643,7 +643,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
// must be non strict search in any sets, not one set
// example: if set contains only one card side
// method used in cards database creating, so can't use repository here
ExpansionSet.SetCardInfo info = Sets.findCardByClass(cardClazz, expansionSetCode);
ExpansionSet.SetCardInfo info = Sets.findCardByClass(cardClazz, expansionSetCode, cardNumber);
if (info == null) {
return null;
}

View file

@ -199,15 +199,23 @@ public class Sets extends HashMap<String, ExpansionSet> {
return null;
}
public static ExpansionSet.SetCardInfo findCardByClass(Class<?> clazz, String preferredSetCode) {
public static ExpansionSet.SetCardInfo findCardByClass(Class<?> clazz, String preferredSetCode, String preferredCardNumber) {
ExpansionSet.SetCardInfo info = null;
if (instance.containsKey(preferredSetCode)) {
info = instance.get(preferredSetCode).findCardInfoByClass(clazz).stream().findFirst().orElse(null);
info = instance.get(preferredSetCode).findCardInfoByClass(clazz)
.stream()
.filter(card -> preferredCardNumber == null || card.getCardNumber().equals(preferredCardNumber))
.findFirst()
.orElse(null);
}
if (info == null) {
for (Map.Entry<String, ExpansionSet> entry : instance.entrySet()) {
info = entry.getValue().findCardInfoByClass(clazz).stream().findFirst().orElse(null);
info = entry.getValue().findCardInfoByClass(clazz)
.stream()
.filter(card -> preferredCardNumber == null || card.getCardNumber().equals(preferredCardNumber))
.findFirst()
.orElse(null);
if (info != null) {
break;
}

View file

@ -65,7 +65,7 @@ public class MockCard extends CardImpl {
this.nightCard = card.isNightCard();
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode()));
this.secondSideCard = new MockCard(CardRepository.instance.findCardWithPreferredSetAndNumber(card.getSecondSideName(), card.getSetCode(), card.getCardNumber()));
}
if (card.isAdventureCard()) {

View file

@ -40,7 +40,7 @@ public class MockSplitCard extends SplitCard {
this.nightCard = card.isNightCard();
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode()));
this.secondSideCard = new MockCard(CardRepository.instance.findCardWithPreferredSetAndNumber(card.getSecondSideName(), card.getSetCode(), card.getCardNumber()));
}
this.flipCardName = card.getFlipCardName();
@ -49,13 +49,13 @@ public class MockSplitCard extends SplitCard {
this.addAbility(textAbilityFromString(ruleText));
}
CardInfo leftHalf = CardRepository.instance.findCardWPreferredSet(getLeftHalfName(card), card.getSetCode(), true);
CardInfo leftHalf = CardRepository.instance.findCardWithPreferredSetAndNumber(getLeftHalfName(card), card.getSetCode(), card.getCardNumber(), true);
if (leftHalf != null) {
this.leftHalfCard = new MockSplitCardHalf(leftHalf);
((SplitCardHalf) this.leftHalfCard).setParentCard(this);
}
CardInfo rightHalf = CardRepository.instance.findCardWPreferredSet(getRightHalfName(card), card.getSetCode(), true);
CardInfo rightHalf = CardRepository.instance.findCardWithPreferredSetAndNumber(getRightHalfName(card), card.getSetCode(), card.getCardNumber(), true);
if (rightHalf != null) {
this.rightHalfCard = new MockSplitCardHalf(rightHalf);
((SplitCardHalf) this.rightHalfCard).setParentCard(this);

View file

@ -394,32 +394,36 @@ public enum CardRepository {
/**
* Function to find a card by name from a specific set.
* Used for building cubes, packs, and for ensuring that dual faces and split cards have sides/halves from the same set.
* Used for building cubes, packs, and for ensuring that dual faces and split cards have sides/halves from
* the same set and variant art.
*
* @param name name of the card, or side of the card, to find
* @param expansion the set name from which to find the card
* @param cardNumber the card number for variant arts in one set
* @param returnSplitCardHalf whether to return a half of a split card or the corresponding full card.
* Want this `false` when user is searching by either names in a split card so that
* the full card can be found by either name.
* @return
*/
public CardInfo findCardWPreferredSet(String name, String expansion, boolean returnSplitCardHalf) {
public CardInfo findCardWithPreferredSetAndNumber(String name, String expansion, String cardNumber, boolean returnSplitCardHalf) {
List<CardInfo> cards;
cards = findCards(name, 0, returnSplitCardHalf);
CardInfo bestCard = cards.stream()
.filter(card -> expansion == null || expansion.equalsIgnoreCase(card.getSetCode()))
.filter(card -> cardNumber == null || cardNumber.equals(card.getCardNumber()))
.findFirst()
.orElse(null);
if (!cards.isEmpty()) {
for (CardInfo cardinfo : cards) {
if (cardinfo.getSetCode() != null && expansion != null && expansion.equalsIgnoreCase(cardinfo.getSetCode())) {
return cardinfo;
}
}
if (bestCard != null) {
return bestCard;
} else {
return findPreferredCoreExpansionCard(name);
}
return findPreferredCoreExpansionCard(name);
}
public CardInfo findCardWPreferredSet(String name, String expansion) {
return findCardWPreferredSet(name, expansion, false);
public CardInfo findCardWithPreferredSetAndNumber(String name, String expansion, String cardNumber) {
return findCardWithPreferredSetAndNumber(name, expansion, cardNumber, false);
}
public List<CardInfo> findCards(String name) {

View file

@ -84,7 +84,7 @@ public abstract class DraftCube {
if (!cardId.getName().isEmpty()) {
CardInfo cardInfo = null;
if (!cardId.getExtension().isEmpty()) {
cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension());
cardInfo = CardRepository.instance.findCardWithPreferredSetAndNumber(cardId.getName(), cardId.getExtension(), null);
} else {
cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName());
}