mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
small rework of MageBook card stats, removed 500 number limit
This commit is contained in:
parent
69a9b663c9
commit
cfef00f90b
1 changed files with 23 additions and 28 deletions
|
@ -40,8 +40,12 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.Locale;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
import static org.mage.plugins.card.images.DownloadPicturesService.getTokenCardUrls;
|
import static org.mage.plugins.card.images.DownloadPicturesService.getTokenCardUrls;
|
||||||
|
@ -515,39 +519,30 @@ public class MageBook extends JComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cards stats
|
// cards stats
|
||||||
int startNumber = 9999;
|
List<Integer> haveNumbers = set
|
||||||
int endNumber = 0;
|
.getSetCardInfo()
|
||||||
|
.stream()
|
||||||
|
.map(ExpansionSet.SetCardInfo::getCardNumberAsInt)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<ExpansionSet.SetCardInfo> cards = set.getSetCardInfo();
|
int startNumber = haveNumbers
|
||||||
|
.stream()
|
||||||
// first run for numbers list
|
.min(Integer::compareTo)
|
||||||
LinkedList<Integer> haveNumbers = new LinkedList<>();
|
.orElse(9999);
|
||||||
for (ExpansionSet.SetCardInfo card : cards) {
|
int endNumber = haveNumbers
|
||||||
int cardNumber = card.getCardNumberAsInt();
|
.stream()
|
||||||
|
.max(Integer::compareTo)
|
||||||
// skip xmage special numbers for cards (TODO: replace full art cards numbers from 180+20 to 180b, 180c and vice versa like scryfall)
|
.orElse(0);
|
||||||
if (cardNumber > 500) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
startNumber = min(startNumber, cardNumber);
|
|
||||||
endNumber = Math.max(endNumber, cardNumber);
|
|
||||||
haveNumbers.add(cardNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
// second run for empty numbers
|
// second run for empty numbers
|
||||||
int countHave = haveNumbers.size();
|
int countHave = haveNumbers.size();
|
||||||
int countNotHave = 0;
|
int countNotHave = IntStream
|
||||||
if (!cards.isEmpty()) {
|
.range(startNumber, endNumber + 1)
|
||||||
for (int i = startNumber; i <= endNumber; i++) {
|
.map(x -> haveNumbers.contains(x) ? 0 : 1)
|
||||||
if (!haveNumbers.contains(i)) {
|
.sum();
|
||||||
countNotHave++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// result
|
// result
|
||||||
setInfo.setText(String.format("Have %d cards of %d", countHave, countHave + countNotHave));
|
setInfo.setText(String.format("%d cards of %d are available", countHave, countHave + countNotHave));
|
||||||
if (countNotHave > 0) {
|
if (countNotHave > 0) {
|
||||||
setInfo.setForeground(new Color(150, 0, 0));
|
setInfo.setForeground(new Color(150, 0, 0));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue