mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Support respecting saved card preferred art on future sessions
This commit is contained in:
@@ -22,10 +22,12 @@ import com.google.common.collect.Iterables;
|
|||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
|
|
||||||
import forge.card.CardEdition.CardInSet;
|
import forge.card.CardEdition.CardInSet;
|
||||||
import forge.card.CardEdition.Type;
|
import forge.card.CardEdition.Type;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.*;
|
import forge.util.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
@@ -40,10 +42,10 @@ public final class CardDb implements ICardDatabase {
|
|||||||
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
|
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
|
||||||
private final Map<String, PaperCard> uniqueCardsByName = new TreeMap<String, PaperCard>(String.CASE_INSENSITIVE_ORDER);
|
private final Map<String, PaperCard> uniqueCardsByName = new TreeMap<String, PaperCard>(String.CASE_INSENSITIVE_ORDER);
|
||||||
private final Map<String, CardRules> rulesByName;
|
private final Map<String, CardRules> rulesByName;
|
||||||
|
private static Map<String, String> artPrefs = new HashMap<String, String>();
|
||||||
|
|
||||||
private final List<PaperCard> allCards = new ArrayList<PaperCard>();
|
private final List<PaperCard> allCards = new ArrayList<PaperCard>();
|
||||||
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
|
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
|
||||||
private final Collection<PaperCard> roUniqueCards = Collections.unmodifiableCollection(uniqueCardsByName.values());
|
|
||||||
private final CardEdition.Collection editions;
|
private final CardEdition.Collection editions;
|
||||||
|
|
||||||
public enum SetPreference {
|
public enum SetPreference {
|
||||||
@@ -174,8 +176,23 @@ public final class CardDb implements ICardDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean setPreferredArt(String cardName, String preferredArt) {
|
||||||
|
CardRequest request = CardRequest.fromString(cardName + NameSetSeparator + preferredArt);
|
||||||
|
PaperCard pc = tryGetCard(request);
|
||||||
|
if (pc != null) {
|
||||||
|
artPrefs.put(cardName, preferredArt);
|
||||||
|
uniqueCardsByName.put(cardName, pc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaperCard getCard(final String cardName) {
|
public PaperCard getCard(String cardName) {
|
||||||
|
String preferredArt = artPrefs.get(cardName);
|
||||||
|
if (preferredArt != null) { //account for preferred art if needed
|
||||||
|
cardName += NameSetSeparator + preferredArt;
|
||||||
|
}
|
||||||
CardRequest request = CardRequest.fromString(cardName);
|
CardRequest request = CardRequest.fromString(cardName);
|
||||||
return tryGetCard(request);
|
return tryGetCard(request);
|
||||||
}
|
}
|
||||||
@@ -206,7 +223,7 @@ public final class CardDb implements ICardDatabase {
|
|||||||
if (null == cards) { return null; }
|
if (null == cards) { return null; }
|
||||||
|
|
||||||
PaperCard result = null;
|
PaperCard result = null;
|
||||||
|
|
||||||
String reqEdition = request.edition;
|
String reqEdition = request.edition;
|
||||||
if (reqEdition != null && !editions.contains(reqEdition)) {
|
if (reqEdition != null && !editions.contains(reqEdition)) {
|
||||||
CardEdition edition = editions.get(reqEdition);
|
CardEdition edition = editions.get(reqEdition);
|
||||||
@@ -214,7 +231,7 @@ public final class CardDb implements ICardDatabase {
|
|||||||
reqEdition = edition.getCode();
|
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) {
|
||||||
@@ -237,20 +254,20 @@ public final class CardDb implements ICardDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == null) { return null; }
|
if (result == null) { return null; }
|
||||||
|
|
||||||
return request.isFoil ? getFoiled(result) : result;
|
return request.isFoil ? getFoiled(result) : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaperCard getCardFromEdition(final String cardName, SetPreference fromSet) {
|
public PaperCard getCardFromEdition(final String cardName, SetPreference fromSet) {
|
||||||
return getCardFromEdition(cardName, null, fromSet);
|
return getCardFromEdition(cardName, null, fromSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet) {
|
public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet) {
|
||||||
return getCardFromEdition(cardName, printedBefore, fromSet, -1);
|
return getCardFromEdition(cardName, printedBefore, fromSet, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet, int artIndex) {
|
public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet, int artIndex) {
|
||||||
final CardRequest cr = CardRequest.fromString(cardName);
|
final CardRequest cr = CardRequest.fromString(cardName);
|
||||||
@@ -345,10 +362,10 @@ public final class CardDb implements ICardDatabase {
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a list of all cards from their respective latest editions
|
// returns a list of all cards from their respective latest (or preferred) editions
|
||||||
@Override
|
@Override
|
||||||
public Collection<PaperCard> getUniqueCards() {
|
public Collection<PaperCard> getUniqueCards() {
|
||||||
return roUniqueCards;
|
return uniqueCardsByName.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import forge.assets.FSkin;
|
|||||||
import forge.assets.FSkinFont;
|
import forge.assets.FSkinFont;
|
||||||
import forge.assets.FSkinImage;
|
import forge.assets.FSkinImage;
|
||||||
import forge.assets.FTextureRegionImage;
|
import forge.assets.FTextureRegionImage;
|
||||||
|
import forge.card.CardDb;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.CardPreferences;
|
import forge.card.CardPreferences;
|
||||||
import forge.card.CardRulesPredicates;
|
import forge.card.CardRulesPredicates;
|
||||||
@@ -746,7 +747,13 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
cardManager.setPool(cardpool);
|
cardManager.setPool(cardpool);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cardManager.setPool(ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true);
|
if (cardManager.getConfig().getUniqueCardsOnly()) {
|
||||||
|
cardManager.setWantUnique(false); //prevent needing to perform logic to calculate uniqueness since we're passing a unique collection
|
||||||
|
cardManager.setPool(ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class), true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cardManager.setPool(ItemPool.createFrom(FModel.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -846,7 +853,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
if (result != card) {
|
if (result != card) {
|
||||||
cardManager.replaceAll(card, result);
|
cardManager.replaceAll(card, result);
|
||||||
}
|
}
|
||||||
prefs.setPreferredArt(result.getEdition() + "|" + result.getArtIndex());
|
prefs.setPreferredArt(result.getEdition() + CardDb.NameSetSeparator + result.getArtIndex());
|
||||||
CardPreferences.save();
|
CardPreferences.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package forge.card;
|
package forge.card;
|
||||||
|
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
|
import forge.model.FModel;
|
||||||
import forge.properties.ForgeConstants;
|
import forge.properties.ForgeConstants;
|
||||||
import forge.util.XmlUtil;
|
import forge.util.XmlUtil;
|
||||||
|
|
||||||
@@ -24,11 +25,11 @@ public class CardPreferences {
|
|||||||
private static Map<String, CardPreferences> allPrefs = new HashMap<String, CardPreferences>();
|
private static Map<String, CardPreferences> allPrefs = new HashMap<String, CardPreferences>();
|
||||||
|
|
||||||
public static CardPreferences getPrefs(IPaperCard card) {
|
public static CardPreferences getPrefs(IPaperCard card) {
|
||||||
String key = card.getName(); //TODO: Consider include art/set in key
|
String cardName = card.getName();
|
||||||
CardPreferences prefs = allPrefs.get(key);
|
CardPreferences prefs = allPrefs.get(cardName);
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
prefs = new CardPreferences();
|
prefs = new CardPreferences(cardName);
|
||||||
allPrefs.put(key, prefs);
|
allPrefs.put(cardName, prefs);
|
||||||
}
|
}
|
||||||
return prefs;
|
return prefs;
|
||||||
}
|
}
|
||||||
@@ -41,14 +42,11 @@ public class CardPreferences {
|
|||||||
final Document document = builder.parse(ForgeConstants.CARD_PREFS_FILE);
|
final Document document = builder.parse(ForgeConstants.CARD_PREFS_FILE);
|
||||||
final NodeList cards = document.getElementsByTagName("card");
|
final NodeList cards = document.getElementsByTagName("card");
|
||||||
for (int i = 0; i < cards.getLength(); i++) {
|
for (int i = 0; i < cards.getLength(); i++) {
|
||||||
final CardPreferences prefs = new CardPreferences();
|
|
||||||
final Element el = (Element)cards.item(i);
|
final Element el = (Element)cards.item(i);
|
||||||
allPrefs.put(el.getAttribute("name"), prefs);
|
final CardPreferences prefs = new CardPreferences(el.getAttribute("name"));
|
||||||
prefs.starCount = Integer.parseInt(el.getAttribute("stars"));
|
allPrefs.put(prefs.cardName, prefs);
|
||||||
prefs.preferredArt = el.getAttribute("art");
|
prefs.setStarCount(getIntAttribute(el, "stars"));
|
||||||
if (prefs.preferredArt.length() == 0) {
|
prefs.setPreferredArt(getStringAttribute(el, "art"));
|
||||||
prefs.preferredArt = null; //don't store empty string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
catch (FileNotFoundException e) {
|
||||||
@@ -62,6 +60,25 @@ public class CardPreferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getIntAttribute(Element el, String name) {
|
||||||
|
String value = el.getAttribute(name);
|
||||||
|
if (value.length() > 0) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getStringAttribute(Element el, String name) {
|
||||||
|
String value = el.getAttribute(name);
|
||||||
|
if (value.length() > 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
try {
|
try {
|
||||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
@@ -91,10 +108,12 @@ public class CardPreferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final String cardName;
|
||||||
private int starCount;
|
private int starCount;
|
||||||
private String preferredArt;
|
private String preferredArt;
|
||||||
|
|
||||||
private CardPreferences() {
|
private CardPreferences(String cardName0) {
|
||||||
|
cardName = cardName0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStarCount() {
|
public int getStarCount() {
|
||||||
@@ -110,6 +129,14 @@ public class CardPreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferredArt(String preferredArt0) {
|
public void setPreferredArt(String preferredArt0) {
|
||||||
preferredArt = preferredArt0;
|
if (preferredArt0 == null) {
|
||||||
|
preferredArt = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (preferredArt0.equals(preferredArt)) { return; }
|
||||||
|
|
||||||
|
if (FModel.getMagicDb().getCommonCards().setPreferredArt(cardName, preferredArt0)) {
|
||||||
|
preferredArt = preferredArt0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user