mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Merge branch 'token_phase_two' into 'master'
Add more support for migrating Editions to TokenScripts See merge request core-developers/forge!885
This commit is contained in:
@@ -123,12 +123,19 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
private boolean smallSetOverride = false;
|
||||
private String boosterMustContain = "";
|
||||
private final CardInSet[] cards;
|
||||
private final String[] tokenNormalized;
|
||||
|
||||
private int boosterArts = 1;
|
||||
private SealedProduct.Template boosterTpl = null;
|
||||
|
||||
private CardEdition(CardInSet[] cards) {
|
||||
this.cards = cards;
|
||||
tokenNormalized = null;
|
||||
}
|
||||
|
||||
private CardEdition(CardInSet[] cards, String[] tokens) {
|
||||
this.cards = cards;
|
||||
this.tokenNormalized = tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,6 +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<>();
|
||||
List<CardEdition.CardInSet> processedCards = new ArrayList<>();
|
||||
if (contents.containsKey("cards")) {
|
||||
for(String line : contents.get("cards")) {
|
||||
@@ -277,7 +285,19 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
}
|
||||
}
|
||||
|
||||
CardEdition res = new CardEdition(processedCards.toArray(new CardInSet[processedCards.size()]));
|
||||
if (contents.containsKey("tokens")) {
|
||||
for(String line : contents.get("tokens")) {
|
||||
if (StringUtils.isBlank(line))
|
||||
continue;
|
||||
|
||||
tokenNormalized.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
CardEdition res = new CardEdition(
|
||||
processedCards.toArray(new CardInSet[processedCards.size()]),
|
||||
tokenNormalized.toArray(new String[tokenNormalized.size()])
|
||||
);
|
||||
|
||||
FileSection section = FileSection.parse(contents.get("metadata"), "=");
|
||||
res.name = section.get("name");
|
||||
|
||||
@@ -39,13 +39,19 @@ public class TokenDb implements ITokenDatabase {
|
||||
|
||||
@Override
|
||||
public PaperToken getToken(String tokenName, String edition) {
|
||||
try {
|
||||
PaperToken pt = new PaperToken(rulesByName.get(tokenName), editions.get(edition));
|
||||
// TODO Cache the token after it's referenced
|
||||
return pt;
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
String fullName = String.format("%s_%s", tokenName, edition.toLowerCase());
|
||||
|
||||
if (!tokensByName.containsKey(fullName)) {
|
||||
try {
|
||||
PaperToken pt = new PaperToken(rulesByName.get(tokenName), editions.get(edition));
|
||||
tokensByName.put(fullName, pt);
|
||||
return pt;
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return tokensByName.get(fullName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user