Some housekeeping

This commit is contained in:
Krazy
2017-06-07 19:38:18 +00:00
parent 3e72db117f
commit 7633eab1cc
3 changed files with 89 additions and 90 deletions

View File

@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -39,14 +39,14 @@ import java.util.Map.Entry;
public final class CardDb implements ICardDatabase, IDeckGenPool {
public final static String foilSuffix = "+";
public final static char NameSetSeparator = '|';
// need this to obtain cardReference by name+set+artindex
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 = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
private final Map<String, CardRules> rulesByName;
private final Map<String, ICardFace> facesByName = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
private static Map<String, String> artPrefs = new HashMap<String, String>();
private final Map<String, String> alternateName = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
private final Map<String, Integer> artIds = new HashMap<String, Integer>();
@@ -60,32 +60,32 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
Earliest(false),
EarliestCoreExp(true),
Random(false);
final boolean filterSets;
private SetPreference(boolean filterIrregularSets) {
filterSets = filterIrregularSets;
}
public boolean accept(CardEdition ed) {
if (ed == null) return false;
return !filterSets || ed.getType() == Type.CORE || ed.getType() == Type.EXPANSION || ed.getType() == Type.REPRINT;
return !filterSets || ed.getType() == Type.CORE || ed.getType() == Type.EXPANSION || ed.getType() == Type.REPRINT;
}
}
// NO GETTERS/SETTERS HERE!
public static class CardRequest {
public String cardName;
public String edition;
public int artIndex;
public boolean isFoil;
private CardRequest(String name, String edition, int artIndex, boolean isFoil) {
cardName = name;
this.edition = edition;
this.artIndex = artIndex;
this.isFoil = isFoil;
}
public static CardRequest fromString(String name) {
boolean isFoil = name.endsWith(foilSuffix);
if (isFoil) {
@@ -107,7 +107,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
cardName = cardName.substring(0, cardName.length() - foilSuffix.length());
isFoil = true;
}
int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos]) : 0;
String setName = setPos > 0 ? nameParts[setPos] : null;
if ("???".equals(setName)) {
@@ -124,7 +124,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
// create faces list from rules
for (final CardRules rule : rules.values() ) {
final ICardFace main = rule.getMainPart();
final ICardFace main = rule.getMainPart();
facesByName.put(main.getName(), main);
if (main.getAltName() != null) {
alternateName.put(main.getAltName(), main.getName());
@@ -138,7 +138,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
}
}
private void addSetCard(CardEdition e, CardInSet cis, CardRules cr) {
int artIdx = 1;
String key = e.getCode() + "/" + cis.name;
@@ -171,7 +171,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
Date today = new Date();
for (CardEdition e : editions.getOrderedEditions()) {
boolean isCoreExpSet = e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION || e.getType() == CardEdition.Type.REPRINT;
boolean isCoreExpSet = e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION || e.getType() == CardEdition.Type.REPRINT;
if (logMissingPerEdition && isCoreExpSet) {
System.out.print(e.getName() + " (" + e.getCards().length + " cards)");
}
@@ -203,7 +203,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
missingCards.clear();
artIds.clear();
}
if (logMissingSummary) {
System.out.printf("Totally %d cards not implemented: %s\n", allMissingCards.size(), StringUtils.join(allMissingCards, " | "));
}
@@ -309,7 +309,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
return tryGetCard(request);
}
public int getCardCollectorNumber(String cardName, String reqEdition) {
cardName = getName(cardName);
CardEdition edition = editions.get(reqEdition);
@@ -499,7 +499,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
Collection<PaperCard> cards = getAllCards(cardName);
if (null == cards) {
return 0;
}
}
for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(setName)) {
@@ -539,7 +539,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
return cardName;
}
@Override
public List<PaperCard> getAllCards(String cardName) {
return allCardsByName.get(getName(cardName));
@@ -582,7 +582,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
return false;
}
}
public StringBuilder appendCardToStringBuilder(PaperCard card, StringBuilder sb) {
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
sb.append(card.getName());
@@ -601,51 +601,49 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
return sb;
}
public PaperCard createUnsuportedCard(String cardName) {
public PaperCard createUnsupportedCard(String cardName) {
CardRequest request = CardRequest.fromString(cardName);
CardEdition cE = CardEdition.UNKNOWN;
CardRarity cR = CardRarity.Unknown;
CardEdition cardEdition = CardEdition.UNKNOWN;
CardRarity cardRarity = CardRarity.Unknown;
// May iterate over editions and find out if there is any card named 'cardName' but not implemented with Forge script.
if (StringUtils.isBlank(request.edition)) {
for (CardEdition e : editions) {
for (CardInSet cs : e.getCards()) {
if (cs.name.equals(request.cardName)) {
cE = e;
cR = cs.rarity;
for (CardEdition edition : editions) {
for (CardInSet cardInSet : edition.getCards()) {
if (cardInSet.name.equals(request.cardName)) {
cardEdition = edition;
cardRarity = cardInSet.rarity;
break;
}
}
if (cE != CardEdition.UNKNOWN) {
if (cardEdition != CardEdition.UNKNOWN) {
break;
}
}
}
else {
cE = editions.get(request.edition);
if (cE != null) {
for (CardInSet cs : cE.getCards()) {
if (cs.name.equals(request.cardName)) {
cR = cs.rarity;
} else {
cardEdition = editions.get(request.edition);
if (cardEdition != null) {
for (CardInSet cardInSet : cardEdition.getCards()) {
if (cardInSet.name.equals(request.cardName)) {
cardRarity = cardInSet.rarity;
break;
}
}
}
else {
cE = CardEdition.UNKNOWN;
cardEdition = CardEdition.UNKNOWN;
}
}
// Write to log that attempt,
if (cR == CardRarity.Unknown) {
if (cardRarity == CardRarity.Unknown) {
System.err.println(String.format("An unknown card found when loading Forge decks: \"%s\" Forge does not know of such a card's existence. Have you mistyped the card name?", cardName));
} else {
System.err.println(String.format("An unsupported card was requested: \"%s\" from \"%s\" set. We're sorry, but you cannot use this card yet.", request.cardName, cardEdition.getName()));
}
else {
System.err.println(String.format("An unsupported card was requested: \"%s\" from \"%s\" set. We're sorry, but you cannot use this card yet.", request.cardName, cE.getName()));
}
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cE.getCode(), cR, 1);
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cardEdition.getCode(), cardRarity, 1);
}
private final Editor editor = new Editor();
@@ -663,7 +661,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
result = rulesByName.put(cardName, rules);
// 1. generate all paper cards from edition data we have (either explicit, or found in res/editions, or add to unknown edition)
List<PaperCard> paperCards = new ArrayList<PaperCard>();
if (null == whenItWasPrinted || whenItWasPrinted.isEmpty()) {

View File

@@ -6,17 +6,26 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.deck;
import com.google.common.collect.Lists;
import forge.StaticData;
import forge.card.CardDb;
import forge.item.PaperCard;
import forge.util.ItemPool;
import forge.util.ItemPoolSorter;
import forge.util.MyRandom;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -24,17 +33,6 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import forge.StaticData;
import forge.card.CardDb;
import forge.item.PaperCard;
import forge.util.ItemPool;
import forge.util.ItemPoolSorter;
import forge.util.MyRandom;
public class CardPool extends ItemPool<PaperCard> {
private static final long serialVersionUID = -5379091255613968393L;
@@ -47,7 +45,7 @@ public class CardPool extends ItemPool<PaperCard> {
this();
this.addAll(cards);
}
public void add(final String cardName, final int amount) {
if (cardName.contains("|")) {
// an encoded cardName with set and possibly art index was passed, split it and pass in full
@@ -62,7 +60,7 @@ public class CardPool extends ItemPool<PaperCard> {
} else {
this.add(cardName, null, -1, amount);
}
}
}
public void add(final String cardName, final String setCode) {
this.add(cardName, setCode, -1, 1);
@@ -74,50 +72,51 @@ public class CardPool extends ItemPool<PaperCard> {
// NOTE: ART indices are "1" -based
public void add(String cardName, String setCode, final int artIndex, final int amount) {
PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex);
final boolean isCommonCard = cp != null;
PaperCard paperCard = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex);
final boolean isCommonCard = paperCard != null;
if (!isCommonCard) {
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
if (cp == null) {
paperCard = StaticData.instance().getVariantCards().getCard(cardName, setCode);
if (paperCard == null) {
StaticData.instance().attemptToLoadCard(cardName, setCode);
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
paperCard = StaticData.instance().getVariantCards().getCard(cardName, setCode);
}
}
int artCount = 1;
if (cp != null ) {
setCode = cp.getEdition();
cardName = cp.getName();
if (paperCard != null) {
setCode = paperCard.getEdition();
cardName = paperCard.getName();
artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
}
else {
cp = StaticData.instance().getCommonCards().createUnsuportedCard(cardName);
} else {
paperCard = StaticData.instance().getCommonCards().createUnsupportedCard(cardName);
}
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length()-1)) && cardName.charAt(cardName.length()-2) == CardDb.NameSetSeparator;
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length() - 1)) && cardName.charAt(cardName.length() - 2) == CardDb.NameSetSeparator;
if (artIndexExplicitlySet || artCount <= 1) {
// either a specific art index is specified, or there is only one art, so just add the card
this.add(cp, amount);
this.add(paperCard, amount);
} else {
// random art index specified, make sure we get different groups of cards with different art
int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount);
for (int i = 1; i <= artGroups.length; i++) {
int cnt = artGroups[i-1];
if (cnt <= 0)
int cnt = artGroups[i - 1];
if (cnt <= 0) {
continue;
PaperCard cp_random = isCommonCard
? StaticData.instance().getCommonCards().getCard(cardName, setCode, i)
: StaticData.instance().getVariantCards().getCard(cardName, setCode, i);
this.add(cp_random, cnt);
}
PaperCard randomCard = StaticData.instance().getCommonCards().getCard(cardName, setCode, i);
this.add(randomCard, cnt);
}
}
}
/**
* Add all from a List of CardPrinted.
*
*
* @param list
* CardPrinteds to add
*/
@@ -194,25 +193,25 @@ public class CardPool extends ItemPool<PaperCard> {
}
return pool;
}
public String toCardList(String separator) {
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(this);
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
final CardDb commonDb = StaticData.instance().getCommonCards();
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (final Entry<PaperCard, Integer> e : main2sort) {
if(!isFirst)
sb.append(separator);
else
isFirst = false;
CardDb db = !e.getKey().getRules().isVariant() ? commonDb : StaticData.instance().getVariantCards();
sb.append(e.getValue()).append(" ");
db.appendCardToStringBuilder(e.getKey(), sb);
}
return sb.toString();
}

View File

@@ -143,6 +143,8 @@ public class DialogChooseColors {
left.setOpaque(false);
left.add(new FLabel.Builder().text("Distribution").fontSize(18).build(), "gaptop 10");
left.add(new FTextPane("Hover over each item for a more detailed description."), "gaptop 20");
final JXButtonPanel poolTypePanel = new JXButtonPanel();
final String radioConstraints = "h 25px!, gaptop 5";
poolTypePanel.add(radBalanced, radioConstraints);
@@ -201,9 +203,9 @@ public class DialogChooseColors {
cbxArtifacts.setVisible(!radSurpriseMe.isSelected() && !radBoosters.isSelected());
numberOfBoostersField.setVisible(radBoosters.isSelected());
radBalanced.setToolTipText("A balanced distribution will provide a roughly equal number of cards in each selected color.");
radRandom.setToolTipText("A random distribution will be almost entirely randomly selected. This ignores any color selections.");
radSurpriseMe.setToolTipText("This is the same as a balanced distribution, except the colors picked will be random and you will not be told what they are.");
radBalanced.setToolTipText("A \"Balanced\" distribution will provide a roughly equal number of cards in each selected color.");
radRandom.setToolTipText("A \"True Random\" distribution will be almost entirely randomly selected. This ignores any color selections.");
radSurpriseMe.setToolTipText("This is the same as a \"Balanced\" distribution, except the colors picked will be random and you will not be told what they are.");
radBoosters.setToolTipText("This ignores all color settings and instead generates a card pool out of a specified number of booster packs.");
cbxArtifacts.setToolTipText("When selected, artifacts will be included in your pool regardless of color selections. This mimics the old card pool behavior.");