mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
First CardDb optimisation - reusing same strategy for lazyLoading
There was a FIXME/TODO comment I just have found out relating to putCard implementation being inefficient. I've re-used the new-methods implemented for lazyCardLoading to improve existing implementation. Also, now all the PaperCard constructors won't miss collectorNumber and ArtistNames as gathered from CardInSet in CardEdition - YAY
This commit is contained in:
@@ -1006,29 +1006,33 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
// 1. generate all paper cards from edition data we have (either explicit, or found in res/editions, or add to unknown edition)
|
// 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<>();
|
List<PaperCard> paperCards = new ArrayList<>();
|
||||||
if (null == whenItWasPrinted || whenItWasPrinted.isEmpty()) {
|
if (null == whenItWasPrinted || whenItWasPrinted.isEmpty()) {
|
||||||
// TODO Not performant Each time we "putCard" we loop through ALL CARDS IN ALL editions
|
// @friarsol: Not performant Each time we "putCard" we loop through ALL CARDS IN ALL editions
|
||||||
|
// @leriomaggio: DONE! re-using here the same strategy implemented for lazy-loading!
|
||||||
for (CardEdition e : editions.getOrderedEditions()) {
|
for (CardEdition e : editions.getOrderedEditions()) {
|
||||||
int artIdx = IPaperCard.DEFAULT_ART_INDEX;
|
int artIdx = IPaperCard.DEFAULT_ART_INDEX;
|
||||||
for (CardInSet cis : e.getAllCardsInSet()) {
|
for (CardInSet cis : e.getCardInSet(cardName))
|
||||||
if (!cis.name.equals(cardName)) {
|
paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++, false,
|
||||||
continue;
|
cis.collectorNumber, cis.artistName));
|
||||||
}
|
|
||||||
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) {
|
||||||
if (!tuple.getKey().equals(lastEdition)) {
|
if (!tuple.getKey().equals(lastEdition)) {
|
||||||
artIdx = IPaperCard.DEFAULT_ART_INDEX;
|
artIdx = IPaperCard.DEFAULT_ART_INDEX; // reset artIndex
|
||||||
lastEdition = tuple.getKey();
|
lastEdition = tuple.getKey();
|
||||||
}
|
}
|
||||||
CardEdition ed = editions.get(lastEdition);
|
CardEdition ed = editions.get(lastEdition);
|
||||||
if (null == ed) {
|
if (ed == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
paperCards.add(new PaperCard(rules, lastEdition, tuple.getValue(), artIdx++));
|
List<CardInSet> cardsInSet = ed.getCardInSet(cardName);
|
||||||
|
if (cardsInSet.isEmpty())
|
||||||
|
continue;
|
||||||
|
int cardInSetIndex = Math.max(artIdx-1, 0); // make sure doesn't go below zero
|
||||||
|
CardInSet cds = cardsInSet.get(cardInSetIndex); // use ArtIndex to get the right Coll. Number
|
||||||
|
paperCards.add(new PaperCard(rules, lastEdition, tuple.getValue(), artIdx++, false,
|
||||||
|
cds.collectorNumber, cds.artistName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (paperCards.isEmpty()) {
|
if (paperCards.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user