mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
[Mobile] Auto optimize card art when importing
This commit is contained in:
@@ -266,7 +266,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
}
|
}
|
||||||
deferredSections = null; // set to null, just in case!
|
deferredSections = null; // set to null, just in case!
|
||||||
if (includeCardsFromUnspecifiedSet && smartCardArtSelection)
|
if (includeCardsFromUnspecifiedSet && smartCardArtSelection)
|
||||||
optimiseCardArtSelectionInDeckSections(cardsWithNoEdition);
|
optimiseCardArtSelectionInDeckSections(cardsWithNoEdition, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateDeferredSections() {
|
private void validateDeferredSections() {
|
||||||
@@ -351,7 +351,15 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return String.format("%d %s", amount, originalRequestCandidate);
|
return String.format("%d %s", amount, originalRequestCandidate);
|
||||||
return String.format("%d %s", amount, poolCardRequest);
|
return String.format("%d %s", amount, poolCardRequest);
|
||||||
}
|
}
|
||||||
|
public void optimizeMainCardArt() {
|
||||||
|
Map<DeckSection, ArrayList<String>> cardsWithNoEdition = new EnumMap<>(DeckSection.class);
|
||||||
|
List<String> mainCards = new ArrayList<>();
|
||||||
|
for (Entry<PaperCard, Integer> e: getMain())
|
||||||
|
mainCards.add(e.getKey().getName());
|
||||||
|
cardsWithNoEdition.put(DeckSection.Main, getAllCardNamesWithNoSpecifiedEdition(mainCards));
|
||||||
|
optimiseCardArtSelectionInDeckSections(cardsWithNoEdition, false);
|
||||||
|
|
||||||
|
}
|
||||||
private ArrayList<String> getAllCardNamesWithNoSpecifiedEdition(List<String> cardsInSection) {
|
private ArrayList<String> getAllCardNamesWithNoSpecifiedEdition(List<String> cardsInSection) {
|
||||||
ArrayList<String> cardNamesWithNoEdition = new ArrayList<>();
|
ArrayList<String> cardNamesWithNoEdition = new ArrayList<>();
|
||||||
List<Pair<String, Integer>> cardRequests = CardPool.processCardList(cardsInSection);
|
List<Pair<String, Integer>> cardRequests = CardPool.processCardList(cardsInSection);
|
||||||
@@ -364,7 +372,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return cardNamesWithNoEdition;
|
return cardNamesWithNoEdition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void optimiseCardArtSelectionInDeckSections(Map<DeckSection, ArrayList<String>> cardsWithNoEdition) {
|
private void optimiseCardArtSelectionInDeckSections(Map<DeckSection, ArrayList<String>> cardsWithNoEdition, boolean multiArtPrint) {
|
||||||
StaticData data = StaticData.instance();
|
StaticData data = StaticData.instance();
|
||||||
// Get current Card Art Preference Settings
|
// Get current Card Art Preference Settings
|
||||||
boolean isCardArtPreferenceLatestArt = data.cardArtPreferenceIsLatest();
|
boolean isCardArtPreferenceLatestArt = data.cardArtPreferenceIsLatest();
|
||||||
@@ -397,13 +405,13 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
int totalToAddToPool = cp.getValue();
|
int totalToAddToPool = cp.getValue();
|
||||||
// A. Skip cards not requiring any update, because they add the edition specified!
|
// A. Skip cards not requiring any update, because they add the edition specified!
|
||||||
if (!cardNamesWithNoEditionInSection.contains(card.getName())) {
|
if (!cardNamesWithNoEditionInSection.contains(card.getName())) {
|
||||||
addCardToPool(newPool, card, totalToAddToPool, card.isFoil());
|
addCardToPool(newPool, card, totalToAddToPool, card.isFoil(), multiArtPrint);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// B. Determine if current card requires update
|
// B. Determine if current card requires update
|
||||||
boolean cardArtNeedsOptimisation = this.isCardArtUpdateRequired(card, releaseDatePivotEdition);
|
boolean cardArtNeedsOptimisation = this.isCardArtUpdateRequired(card, releaseDatePivotEdition);
|
||||||
if (!cardArtNeedsOptimisation) {
|
if (!cardArtNeedsOptimisation) {
|
||||||
addCardToPool(newPool, card, totalToAddToPool, card.isFoil());
|
addCardToPool(newPool, card, totalToAddToPool, card.isFoil(), multiArtPrint);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PaperCard alternativeCardPrint = data.getAlternativeCardPrint(card, releaseDatePivotEdition,
|
PaperCard alternativeCardPrint = data.getAlternativeCardPrint(card, releaseDatePivotEdition,
|
||||||
@@ -412,20 +420,22 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
isExpansionTheMajorityInThePool,
|
isExpansionTheMajorityInThePool,
|
||||||
isPoolModernFramed);
|
isPoolModernFramed);
|
||||||
if (alternativeCardPrint == null) // no alternative found, add original card in Pool
|
if (alternativeCardPrint == null) // no alternative found, add original card in Pool
|
||||||
addCardToPool(newPool, card, totalToAddToPool, card.isFoil());
|
addCardToPool(newPool, card, totalToAddToPool, card.isFoil(), multiArtPrint);
|
||||||
else
|
else
|
||||||
addCardToPool(newPool, alternativeCardPrint, totalToAddToPool, card.isFoil());
|
addCardToPool(newPool, alternativeCardPrint, totalToAddToPool, card.isFoil(), multiArtPrint);
|
||||||
}
|
}
|
||||||
parts.put(deckSection, newPool);
|
parts.put(deckSection, newPool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCardToPool(CardPool pool, PaperCard card, int totalToAdd, boolean isFoil) {
|
private void addCardToPool(CardPool pool, PaperCard card, int totalToAdd, boolean isFoil, boolean multiArtPrint) {
|
||||||
StaticData data = StaticData.instance();
|
StaticData data = StaticData.instance();
|
||||||
if (card.getArtIndex() != IPaperCard.NO_ART_INDEX && card.getArtIndex() != IPaperCard.DEFAULT_ART_INDEX)
|
if (card.getArtIndex() != IPaperCard.NO_ART_INDEX && card.getArtIndex() != IPaperCard.DEFAULT_ART_INDEX)
|
||||||
pool.add(isFoil ? card.getFoiled() : card, totalToAdd); // art index requested, keep that way!
|
pool.add(isFoil ? card.getFoiled() : card, totalToAdd); // art index requested, keep that way!
|
||||||
else {
|
else {
|
||||||
int artCount = data.getCardArtCount(card);
|
int artCount = 1;
|
||||||
|
if (multiArtPrint)
|
||||||
|
artCount = data.getCardArtCount(card);
|
||||||
if (artCount > 1)
|
if (artCount > 1)
|
||||||
addAlternativeCardPrintInPoolWithMultipleArt(card, pool, totalToAdd, artCount);
|
addAlternativeCardPrintInPoolWithMultipleArt(card, pool, totalToAdd, artCount);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ public class FDeckImportDialog extends FDialog {
|
|||||||
FThreads.invokeInEdtLater(new Runnable() {
|
FThreads.invokeInEdtLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
deck.optimizeMainCardArt();
|
||||||
hide();
|
hide();
|
||||||
callback.run(deck);
|
callback.run(deck);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user