mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
- Added mana cost color shard count to deck statistics. Currently counts all individual mana symbols in mana costs (hybrid symbols count as one mana symbol of each color, Phyrexian symbols count as their respective color). Uses very basic text-based messages in the statistics UI, improvements are welcome.
This commit is contained in:
@@ -153,6 +153,39 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of color shards in the card's mana cost.
|
||||
*
|
||||
* @return an array of five integers containing the amount of color shards in the card's mana cost in WUBRG order
|
||||
*/
|
||||
public int[] getColorShardCounts() {
|
||||
int[] counts = new int[5]; // in WUBRG order
|
||||
String cost = getSimpleString();
|
||||
|
||||
for (int i = 0; i < cost.length(); i++) {
|
||||
switch (cost.charAt(i)) {
|
||||
case 'W':
|
||||
counts[0]++;
|
||||
break;
|
||||
case 'U':
|
||||
counts[1]++;
|
||||
break;
|
||||
case 'B':
|
||||
counts[2]++;
|
||||
break;
|
||||
case 'R':
|
||||
counts[3]++;
|
||||
break;
|
||||
case 'G':
|
||||
counts[4]++;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generic cost.
|
||||
*
|
||||
|
||||
@@ -72,6 +72,7 @@ public enum CStatistics implements ICDoc {
|
||||
final ItemPool<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
||||
|
||||
int total = deck.countAll();
|
||||
int[] shardCount = calculateShards(deck);
|
||||
|
||||
// Hack-ish: avoid /0 cases, but still populate labels :)
|
||||
if (total == 0) { total = 1; }
|
||||
@@ -100,6 +101,12 @@ public enum CStatistics implements ICDoc {
|
||||
setLabelValue(VStatistics.SINGLETON_INSTANCE.getLblCMC5(), deck, StatTypes.CMC_5.predicate, total);
|
||||
setLabelValue(VStatistics.SINGLETON_INSTANCE.getLblCMC6(), deck, StatTypes.CMC_6.predicate, total);
|
||||
|
||||
VStatistics.SINGLETON_INSTANCE.getLblTSCWhite().setText("WHITE MANA SYMBOLS IN MANA COST: " + shardCount[0]);
|
||||
VStatistics.SINGLETON_INSTANCE.getLblTSCBlue().setText("BLUE MANA SYMBOLS IN MANA COST: " + shardCount[1]);
|
||||
VStatistics.SINGLETON_INSTANCE.getLblTSCBlack().setText("BLACK MANA SYMBOLS IN MANA COST: " + shardCount[2]);
|
||||
VStatistics.SINGLETON_INSTANCE.getLblTSCRed().setText("RED MANA SYMBOLS IN MANA COST: " + shardCount[3]);
|
||||
VStatistics.SINGLETON_INSTANCE.getLblTSCGreen().setText("GREEN MANA SYMBOLS IN MANA COST: " + shardCount[4]);
|
||||
|
||||
int tmc = 0;
|
||||
for (final Entry<PaperCard, Integer> e : deck) {
|
||||
tmc += e.getKey().getRules().getManaCost().getCMC() * e.getValue();
|
||||
@@ -121,4 +128,15 @@ public enum CStatistics implements ICDoc {
|
||||
public static int calculatePercentage(final int x0, final int y0) {
|
||||
return (int) Math.round((double) (x0 * 100) / (double) y0);
|
||||
}
|
||||
|
||||
public static int[] calculateShards(ItemPool<PaperCard> deck) {
|
||||
int[] counts = new int[5]; // in WUBRG order
|
||||
for (PaperCard c : deck.toFlatList()) {
|
||||
int[] cShards = c.getRules().getManaCost().getColorShardCounts();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
counts[i] += cShards[i];
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,28 @@ public enum VStatistics implements IVDoc<CStatistics> {
|
||||
|
||||
// Global stats
|
||||
private FLabel lblTotal = new FLabel.Builder()
|
||||
.text("Total cards: 0").tooltip("TOTAL CARDS")
|
||||
.text("TOTAL CARDS: 0").tooltip("Total cards")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTMC = new FLabel.Builder()
|
||||
.text("Total mana cost: 0").tooltip("TOTAL MANA COST")
|
||||
.text("TOTAL MANA COST: 0").tooltip("Total mana cost")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblAMC = new FLabel.Builder()
|
||||
.text("Average mana cost: 0.00").tooltip("AVERAGE MANA COST")
|
||||
.text("AVERAGE MANA COST: 0.00").tooltip("Average mana cost")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTSCWhite = new FLabel.Builder()
|
||||
.text("WHITE MANA SYMBOLS IN MANA COST: 0").tooltip("White mana symbol count")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTSCBlue = new FLabel.Builder()
|
||||
.text("BLUE MANA SYMBOLS IN MANA COST: 0").tooltip("Blue mana symbol count")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTSCBlack = new FLabel.Builder()
|
||||
.text("BLACK MANA SYMBOLS IN MANA COST: 0").tooltip("Black mana symbol count")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTSCRed = new FLabel.Builder()
|
||||
.text("RED MANA SYMBOLS IN MANA COST: 0").tooltip("Red mana symbol count")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
private FLabel lblTSCGreen = new FLabel.Builder()
|
||||
.text("GREEN MANA SYMBOLS IN MANA COST: 0").tooltip("Green mana symbol count")
|
||||
.fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD).build();
|
||||
|
||||
// Total and color count labels
|
||||
@@ -139,6 +154,12 @@ public enum VStatistics implements IVDoc<CStatistics> {
|
||||
pnlStats.add(lblColorless, constraints);
|
||||
pnlStats.add(lblSorcery, constraints);
|
||||
pnlStats.add(lblCMC6, constraints);
|
||||
|
||||
pnlStats.add(lblTSCWhite, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0");
|
||||
pnlStats.add(lblTSCBlue, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0");
|
||||
pnlStats.add(lblTSCBlack, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0");
|
||||
pnlStats.add(lblTSCRed, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0");
|
||||
pnlStats.add(lblTSCGreen, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0");
|
||||
}
|
||||
|
||||
//========== Overridden methods
|
||||
@@ -245,10 +266,21 @@ public enum VStatistics implements IVDoc<CStatistics> {
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblAMC() { return lblAMC; }
|
||||
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblTSCWhite() { return lblTSCWhite; }
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblTSCBlue() { return lblTSCBlue; }
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblTSCBlack() { return lblTSCBlack; }
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblTSCRed() { return lblTSCRed; }
|
||||
/** @return {@link forge.toolbox.FLabel} */
|
||||
public FLabel getLblTSCGreen() { return lblTSCGreen; }
|
||||
|
||||
//========== Other methods
|
||||
|
||||
private FLabel buildLabel(SkinImage icon, boolean zebra) {
|
||||
final FLabel lbl = new FLabel.Builder().text("0")
|
||||
final FLabel lbl = new FLabel.Builder().text("0 (0%)")
|
||||
.icon(icon).iconScaleAuto(false)
|
||||
.fontSize(11).build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user