use of mage.cards.Sets in project mage by magefree.
the class MageBook method updateCardStats.
private void updateCardStats(String setCode, boolean isCardsShow) {
// sets do not have total cards number, it's a workaround
ExpansionSet set = Sets.findSet(setCode);
if (set != null) {
setCaption.setText(set.getCode() + " - " + set.getName());
} else {
setCaption.setText("ERROR");
setInfo.setText("ERROR");
return;
}
if (!isCardsShow) {
// tokens or emblems, stats not need
setInfo.setText("");
return;
}
// cards stats
List<Integer> haveNumbers = set.getSetCardInfo().stream().map(ExpansionSet.SetCardInfo::getCardNumberAsInt).collect(Collectors.toList());
int startNumber = haveNumbers.stream().min(Integer::compareTo).orElse(9999);
int endNumber = haveNumbers.stream().max(Integer::compareTo).orElse(0);
// second run for empty numbers
int countHave = haveNumbers.size();
int countNotHave = IntStream.range(startNumber, endNumber + 1).map(x -> haveNumbers.contains(x) ? 0 : 1).sum();
// result
setInfo.setText(String.format("%d cards of %d are available", countHave, countHave + countNotHave));
if (countNotHave > 0) {
setInfo.setForeground(new Color(150, 0, 0));
} else {
setInfo.setForeground(jLayeredPane.getForeground());
}
}
Aggregations