Code cleanup

This commit is contained in:
drdev
2014-07-31 18:05:08 +00:00
parent d7664e6cfc
commit 2d55e64c23
2 changed files with 29 additions and 16 deletions

View File

@@ -117,8 +117,9 @@ public final class CardDb implements ICardDatabase {
String lastCardName = null; String lastCardName = null;
int artIdx = 1; int artIdx = 1;
for (CardEdition.CardInSet cis : e.getCards()) { for (CardEdition.CardInSet cis : e.getCards()) {
if (cis.name.equals(lastCardName)) if (cis.name.equals(lastCardName)) {
artIdx++; artIdx++;
}
else { else {
artIdx = 1; artIdx = 1;
lastCardName = cis.name; lastCardName = cis.name;
@@ -209,22 +210,25 @@ public final class CardDb implements ICardDatabase {
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);
if (edition != null) if (edition != null) {
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) {
if (pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null) if (pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null) {
candidates.add(pc); candidates.add(pc);
} }
}
if (candidates.isEmpty()) { if (candidates.isEmpty()) {
return null; return null;
} }
result = Aggregates.random(candidates); result = Aggregates.random(candidates);
} else { }
else {
for (PaperCard pc : cards) { for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex()) { if (pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex()) {
result = pc; result = pc;
@@ -266,14 +270,17 @@ public final class CardDb implements ICardDatabase {
for (int i = sz - 1 ; i >= 0 ; i--) { for (int i = sz - 1 ; i >= 0 ; i--) {
PaperCard pc = cards.get(i); PaperCard pc = cards.get(i);
CardEdition ed = editions.get(pc.getEdition()); CardEdition ed = editions.get(pc.getEdition());
if (!fromSet.accept(ed)) if (!fromSet.accept(ed)) {
continue; continue;
}
if ((artIndex <= 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore))) if ((artIndex <= 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore))) {
return pc; return pc;
} }
}
return null; return null;
} else if (fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest || fromSet == null || fromSet == SetPreference.Random) { }
else if (fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest || fromSet == null || fromSet == SetPreference.Random) {
for (int i = 0 ; i < sz ; i++) { for (int i = 0 ; i < sz ; i++) {
PaperCard pc = cards.get(i); PaperCard pc = cards.get(i);
CardEdition ed = editions.get(pc.getEdition()); CardEdition ed = editions.get(pc.getEdition());
@@ -302,9 +309,10 @@ public final class CardDb implements ICardDatabase {
public int getPrintCount(String cardName, String edition) { public int getPrintCount(String cardName, String edition) {
int cnt = 0; int cnt = 0;
for (PaperCard pc : allCardsByName.get(cardName)) { for (PaperCard pc : allCardsByName.get(cardName)) {
if (pc.getEdition().equals(edition)) if (pc.getEdition().equals(edition)) {
cnt++; cnt++;
} }
}
return cnt; return cnt;
} }
@@ -312,9 +320,10 @@ public final class CardDb implements ICardDatabase {
public int getMaxPrintCount(String cardName) { public int getMaxPrintCount(String cardName) {
int max = -1; int max = -1;
for (PaperCard pc : allCardsByName.get(cardName)) { for (PaperCard pc : allCardsByName.get(cardName)) {
if (max < pc.getArtIndex()) if (max < pc.getArtIndex()) {
max = pc.getArtIndex(); max = pc.getArtIndex();
} }
}
return max; return max;
} }
@@ -423,18 +432,21 @@ public final class CardDb implements ICardDatabase {
break; break;
} }
} }
if (cE != CardEdition.UNKNOWN) if (cE != CardEdition.UNKNOWN) {
break; break;
} }
} else { }
}
else {
cE = editions.get(request.edition); cE = editions.get(request.edition);
if (cE != null) if (cE != null) {
for (CardInSet cs : cE.getCards()) { for (CardInSet cs : cE.getCards()) {
if (cs.name.equals(request.cardName)) { if (cs.name.equals(request.cardName)) {
cR = cs.rarity; cR = cs.rarity;
break; break;
} }
} }
}
else { else {
cE = CardEdition.UNKNOWN; cE = CardEdition.UNKNOWN;
} }
@@ -450,7 +462,6 @@ public final class CardDb implements ICardDatabase {
} }
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cE.getCode(), cR, 1); return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cE.getCode(), cR, 1);
} }
private final Editor editor = new Editor(); private final Editor editor = new Editor();
@@ -481,7 +492,8 @@ public final class CardDb implements ICardDatabase {
paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++)); paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++));
} }
} }
} else { }
else {
String lastEdition = null; String lastEdition = null;
int artIdx = 0; int artIdx = 0;
for (Pair<String, CardRarity> tuple : whenItWasPrinted){ for (Pair<String, CardRarity> tuple : whenItWasPrinted){

View File

@@ -847,6 +847,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
cardManager.replaceAll(card, result); cardManager.replaceAll(card, result);
} }
prefs.setPreferredArt(result.getEdition() + "|" + result.getArtIndex()); prefs.setPreferredArt(result.getEdition() + "|" + result.getArtIndex());
CardPreferences.save();
} }
} }
}); });
@@ -1139,14 +1140,14 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
@Override @Override
protected void buildMenu(final FDropDownMenu menu, final PaperCard card) { protected void buildMenu(final FDropDownMenu menu, final PaperCard card) {
addItem(menu, "Add", "to main deck", parentScreen.getMainDeckPage().getIcon(), true, true, new Callback<Integer>() { addItem(menu, "Add", "to Main Deck", parentScreen.getMainDeckPage().getIcon(), true, true, new Callback<Integer>() {
@Override @Override
public void run(Integer result) { //ignore quantity public void run(Integer result) { //ignore quantity
parentScreen.getMainDeckPage().addCard(card); parentScreen.getMainDeckPage().addCard(card);
afterCardPicked(card); afterCardPicked(card);
} }
}); });
addItem(menu, "Add", "to sideboard", parentScreen.getSideboardPage().getIcon(), true, true, new Callback<Integer>() { addItem(menu, "Add", "to Sideboard", parentScreen.getSideboardPage().getIcon(), true, true, new Callback<Integer>() {
@Override @Override
public void run(Integer result) { //ignore quantity public void run(Integer result) { //ignore quantity
parentScreen.getSideboardPage().addCard(card); parentScreen.getSideboardPage().addCard(card);