mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Merge branch 'token-multiple-art' into 'master'
Allow multiple art for tokens based on edition files See merge request core-developers/forge!1473
This commit is contained in:
@@ -21,7 +21,6 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.StaticData;
|
||||
import forge.card.CardDb.SetPreference;
|
||||
import forge.deck.CardPool;
|
||||
@@ -31,7 +30,6 @@ import forge.util.*;
|
||||
import forge.util.storage.StorageBase;
|
||||
import forge.util.storage.StorageReaderBase;
|
||||
import forge.util.storage.StorageReaderFolder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -123,7 +121,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
private boolean smallSetOverride = false;
|
||||
private String boosterMustContain = "";
|
||||
private final CardInSet[] cards;
|
||||
private final String[] tokenNormalized;
|
||||
private final Map<String, Integer> tokenNormalized;
|
||||
|
||||
private int boosterArts = 1;
|
||||
private SealedProduct.Template boosterTpl = null;
|
||||
@@ -133,7 +131,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
tokenNormalized = null;
|
||||
}
|
||||
|
||||
private CardEdition(CardInSet[] cards, String[] tokens) {
|
||||
private CardEdition(CardInSet[] cards, Map<String, Integer> tokens) {
|
||||
this.cards = cards;
|
||||
this.tokenNormalized = tokens;
|
||||
}
|
||||
@@ -191,6 +189,8 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
public String getBoosterMustContain() { return boosterMustContain; }
|
||||
public CardInSet[] getCards() { return cards; }
|
||||
|
||||
public Map<String, Integer> getTokens() { return tokenNormalized; };
|
||||
|
||||
public static final Function<CardEdition, String> FN_GET_CODE = new Function<CardEdition, String>() {
|
||||
@Override
|
||||
public String apply(final CardEdition arg1) {
|
||||
@@ -261,7 +261,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
protected CardEdition read(File file) {
|
||||
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(file));
|
||||
|
||||
List<String> tokenNormalized = new ArrayList<>();
|
||||
Map<String, Integer> tokenNormalized = new HashMap<>();
|
||||
List<CardEdition.CardInSet> processedCards = new ArrayList<>();
|
||||
if (contents.containsKey("cards")) {
|
||||
for(String line : contents.get("cards")) {
|
||||
@@ -290,13 +290,17 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
if (StringUtils.isBlank(line))
|
||||
continue;
|
||||
|
||||
tokenNormalized.add(line);
|
||||
if (!tokenNormalized.containsKey(line)) {
|
||||
tokenNormalized.put(line, 1);
|
||||
} else {
|
||||
tokenNormalized.put(line, tokenNormalized.get(line) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CardEdition res = new CardEdition(
|
||||
processedCards.toArray(new CardInSet[processedCards.size()]),
|
||||
tokenNormalized.toArray(new String[tokenNormalized.size()])
|
||||
tokenNormalized
|
||||
);
|
||||
|
||||
FileSection section = FileSection.parse(contents.get("metadata"), "=");
|
||||
|
||||
@@ -5,6 +5,7 @@ import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.ColorSet;
|
||||
import forge.util.MyRandom;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -13,8 +14,9 @@ import java.util.Locale;
|
||||
public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
private String name;
|
||||
private CardEdition edition;
|
||||
private String imageFileName;
|
||||
private ArrayList<String> imageFileName = new ArrayList<>();
|
||||
private CardRules card;
|
||||
private int artIndex = 0;
|
||||
|
||||
// takes a string of the form "<colors> <power> <toughness> <name>" such as: "B 0 0 Germ"
|
||||
public static String makeTokenFileName(String in) {
|
||||
@@ -108,12 +110,23 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
this.name = c.getName();
|
||||
this.edition = edition0;
|
||||
|
||||
if (edition.getTokens().containsKey(imageFileName)) {
|
||||
this.artIndex = edition.getTokens().get(imageFileName);
|
||||
}
|
||||
|
||||
if (imageFileName == null) {
|
||||
// This shouldn't really happen. We can just use the normalized name again for the base image name
|
||||
this.imageFileName = makeTokenFileName(c, edition0);
|
||||
this.imageFileName.add(makeTokenFileName(c, edition0));
|
||||
} else {
|
||||
String formatEdition = null == edition || CardEdition.UNKNOWN == edition ? "" : "_" + edition.getCode().toLowerCase();
|
||||
this.imageFileName = String.format("%s%s", imageFileName, formatEdition);
|
||||
int arts = Math.max(this.artIndex, 1);
|
||||
for(int idx = 0; idx < arts; idx++) {
|
||||
if (idx == 0) {
|
||||
this.imageFileName.add(String.format("%s%s", imageFileName, formatEdition));
|
||||
} else {
|
||||
this.imageFileName.add(String.format("%s%d%s", imageFileName, idx, formatEdition));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,14 +134,14 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
@Override public String toString() { return name; }
|
||||
@Override public String getEdition() { return edition != null ? edition.getCode() : "???"; }
|
||||
@Override public int getArtIndex() { return 0; } // This might change however
|
||||
@Override public int getArtIndex() { return artIndex; }
|
||||
@Override public boolean isFoil() { return false; }
|
||||
@Override public CardRules getRules() { return card; }
|
||||
|
||||
@Override public CardRarity getRarity() { return CardRarity.None; }
|
||||
|
||||
// Unfortunately this is a property of token, cannot move it outside of class
|
||||
public String getImageFilename() { return imageFileName; }
|
||||
public String getImageFilename() { return imageFileName.get(0); }
|
||||
|
||||
@Override public String getItemType() { return "Token"; }
|
||||
|
||||
@@ -136,6 +149,7 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
@Override
|
||||
public String getImageKey(boolean altState) {
|
||||
return ImageKeys.TOKEN_PREFIX + imageFileName.replace(" ", "_");
|
||||
int idx = MyRandom.getRandom().nextInt() % artIndex;
|
||||
return ImageKeys.TOKEN_PREFIX + imageFileName.get(idx).replace(" ", "_");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,11 @@ import forge.game.keyword.KeywordInterface;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.item.PaperToken;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class TokenInfo {
|
||||
final String name;
|
||||
final String imageName;
|
||||
@@ -129,8 +128,6 @@ public class TokenInfo {
|
||||
c.setName(name);
|
||||
c.setImageKey(ImageKeys.getTokenKey(imageName));
|
||||
|
||||
// TODO - most tokens mana cost is 0, this needs to be fixed
|
||||
// c.setManaCost(manaCost);
|
||||
c.setColor(color.isEmpty() ? manaCost : color);
|
||||
c.setToken(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user