From cf006d1c16119e559434acbab1cd422e1188df1f Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Wed, 28 Jul 2021 16:07:38 +0100 Subject: [PATCH] Updated and Aligned implementation for DeckController whenever a pick for limited catalog is required. Most of this commit is for code formatting and cleaning. Major changes include the use fo getAlternativeCardPrint from Static Data (using the same policy that was used before) and the use of the `getTheLatestOfAllEditionsForCardsIn` method :D --- .../controllers/DeckController.java | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/DeckController.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/DeckController.java index 7ef2bc6e79e..b97418ddeea 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/DeckController.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/DeckController.java @@ -19,6 +19,7 @@ package forge.screens.deckeditor.controllers; import com.google.common.base.Supplier; import forge.StaticData; +import forge.card.CardEdition; import forge.deck.*; import forge.item.PaperCard; import forge.screens.deckeditor.menus.DeckFileMenu; @@ -110,11 +111,13 @@ public class DeckController { } private Deck pickFromCatalog(Deck deck, CardPool catalog) { - Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(catalog); + // Getting Latest among the earliest editions in catalog! + CardEdition referenceEdition = StaticData.instance().getEditions().getTheLatestOfAllTheOriginalEditionsOfCardsIn(catalog); + Date referenceReleaseDate = referenceEdition.getDate(); Deck result = new Deck(); for (DeckSection section: EnumSet.allOf(DeckSection.class)) { if (view.isSectionImportable(section)) { - CardPool cards = pickSectionFromCatalog(catalog, deck.getOrCreate(section), dateWithAllCards); + CardPool cards = pickSectionFromCatalog(catalog, deck.getOrCreate(section), referenceReleaseDate); result.putSection(section, cards); } } @@ -122,43 +125,35 @@ public class DeckController { return result; } - private CardPool pickSectionFromCatalog(CardPool catalog, CardPool sourceSection, Date dateWithAllCards) { - HashMap countByName = groupByName(sourceSection); - HashMap basicLandsByName = getBasicLandsByName(sourceSection); + private CardPool pickSectionFromCatalog(CardPool catalog, CardPool sourceSection, Date referenceReleaseDate) { + Map countByName = groupByName(sourceSection); + Map basicLandsByName = getBasicLandsByName(sourceSection); CardPool targetSection = new CardPool(); pickFromCatalog(countByName, catalog, targetSection); - importBasicLands(countByName, basicLandsByName, dateWithAllCards, targetSection); + importBasicLands(countByName, basicLandsByName, referenceReleaseDate, targetSection); return targetSection; } - private HashMap groupByName(CardPool section) { - HashMap result = new HashMap<>(); - + private Map groupByName(CardPool section) { + Map result = new HashMap<>(); for (Map.Entry entry : section) { PaperCard importedCard = entry.getKey(); - Integer previousCount = result.getOrDefault(importedCard.getName(), 0); int countToAdd = entry.getValue(); - result.put(importedCard.getName(), countToAdd + previousCount); } - return result; } - private void pickFromCatalog(HashMap countByName, CardPool catalog, CardPool targetSection) { + private void pickFromCatalog(Map countByName, CardPool catalog, CardPool targetSection) { CardPool catalogClone = new CardPool(catalog); // clone to iterate modified collection for (Map.Entry entry : catalogClone) { - PaperCard availableCard = entry.getKey(); - if (availableCard.getRules().getType().isBasicLand()) { - // basic lands are added regardless of catalog cards + if (availableCard.getRules().getType().isBasicLand()) // basic lands are added regardless of catalog cards continue; - } - Integer availableCount = entry.getValue(); int toAddByName = countByName.getOrDefault(availableCard.getName(), 0); int toAdd = Math.min(availableCount, toAddByName); @@ -171,19 +166,17 @@ public class DeckController { } } - private void importBasicLands(HashMap countByName, HashMap basicLandsByName, Date dateWithAllCards, CardPool targetSection) { + private void importBasicLands(Map countByName, Map basicLandsByName, + Date referenceReleaseDate, CardPool targetSection) { for (String cardName : countByName.keySet()) { - PaperCard card = basicLandsByName.getOrDefault(cardName, null); - - if (card == null) { + if (card == null) continue; - } - int countToAdd = countByName.get(cardName); - - card = StaticData.instance().getAlternativeCardPrint(card, dateWithAllCards); - targetSection.add(card.getName(), card.getEdition(), countToAdd); + card = StaticData.instance().getAlternativeCardPrint(card, referenceReleaseDate, + true, true); + if (card != null) + targetSection.add(card.getName(), card.getEdition(), countToAdd); } }