mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Support displaying scripts in Workshop again
This commit is contained in:
@@ -2,8 +2,8 @@ package forge;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardScriptInfo;
|
||||
|
||||
public interface ICardStorageReader{
|
||||
List<CardRules> loadCards();
|
||||
List<CardScriptInfo> loadCards();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -8,6 +9,7 @@ import java.util.TreeMap;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardScriptInfo;
|
||||
import forge.card.PrintSheet;
|
||||
import forge.item.FatPack;
|
||||
import forge.item.SealedProduct;
|
||||
@@ -29,26 +31,31 @@ public class StaticData {
|
||||
private final IStorage<SealedProduct.Template> tournaments;
|
||||
private final IStorage<FatPack.Template> fatPacks;
|
||||
private final IStorage<PrintSheet> printSheets;
|
||||
private final HashMap<CardRules, CardScriptInfo> scriptLookup;
|
||||
|
||||
private static StaticData lastInstance = null;
|
||||
|
||||
public StaticData(ICardStorageReader reader, String editionFolder, String blockDataFolder) {
|
||||
this.scriptLookup = new HashMap<CardRules, CardScriptInfo>();
|
||||
this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder)));
|
||||
lastInstance = this;
|
||||
|
||||
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
List<CardRules> rules = reader.loadCards();
|
||||
for (CardRules card : rules) {
|
||||
List<CardScriptInfo> cards = reader.loadCards();
|
||||
for (CardScriptInfo card : cards) {
|
||||
if (null == card) continue;
|
||||
|
||||
final String cardName = card.getName();
|
||||
if ( card.isVariant() ) {
|
||||
variantsCards.put(cardName, card);
|
||||
final CardRules rules = card.getRules();
|
||||
scriptLookup.put(rules, card);
|
||||
|
||||
final String cardName = rules.getName();
|
||||
if (rules.isVariant()) {
|
||||
variantsCards.put(cardName, rules);
|
||||
}
|
||||
else {
|
||||
regularCards.put(cardName, card);
|
||||
regularCards.put(cardName, rules);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +69,7 @@ public class StaticData {
|
||||
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
|
||||
}
|
||||
|
||||
public final static StaticData instance() {
|
||||
public final static StaticData instance() {
|
||||
return lastInstance;
|
||||
}
|
||||
|
||||
@@ -100,4 +107,8 @@ public class StaticData {
|
||||
public CardDb getVariantCards() {
|
||||
return variantCards;
|
||||
}
|
||||
|
||||
public CardScriptInfo getScriptInfo(CardRules rules) {
|
||||
return scriptLookup.get(rules);
|
||||
}
|
||||
}
|
||||
|
||||
52
forge-core/src/main/java/forge/card/CardScriptInfo.java
Normal file
52
forge-core/src/main/java/forge/card/CardScriptInfo.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Info pertaining to a card script file
|
||||
*
|
||||
*/
|
||||
public final class CardScriptInfo {
|
||||
private String text;
|
||||
private File file;
|
||||
private CardRules rules;
|
||||
|
||||
public CardScriptInfo(String text0, File file0, CardRules rules0) {
|
||||
this.text = text0;
|
||||
this.file = file0;
|
||||
this.rules = rules0;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
public boolean canEdit() {
|
||||
return this.file != null;
|
||||
}
|
||||
|
||||
public CardRules getRules() {
|
||||
return this.rules;
|
||||
}
|
||||
}
|
||||
@@ -112,11 +112,7 @@ public final class FileUtil {
|
||||
} // writeAllDecks()
|
||||
|
||||
public static String readFileToString(String filename) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (String line : readFile(filename)) {
|
||||
s.append(line).append('\n');
|
||||
}
|
||||
return s.toString();
|
||||
return TextUtil.join(readFile(filename), "\n");
|
||||
}
|
||||
|
||||
public static List<String> readFile(final String filename) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TextUtil {
|
||||
return mapAsString.toString();
|
||||
}
|
||||
|
||||
public static String[] split(CharSequence input, char delimiter) {
|
||||
public static String[] split(CharSequence input, char delimiter) {
|
||||
return splitWithParenthesis(input, delimiter, Integer.MAX_VALUE, '\0', '\0', true);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TextUtil {
|
||||
|
||||
/**
|
||||
* Split string separated by a single char delimiter, can take parenthesis in account
|
||||
* It's faster than String.split, and allows parenthesis
|
||||
* It's faster than String.split, and allows parenthesis
|
||||
*/
|
||||
public static String[] splitWithParenthesis(CharSequence input, char delimiter, int maxEntries, char openPar, char closePar, boolean skipEmpty) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
@@ -98,7 +98,18 @@ public class TextUtil {
|
||||
String[] toReturn = result.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
return trimParenthesis ? StringUtils.stripAll(toReturn, String.valueOf(openPar)) : toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static String join(Iterable<String> strs, String delim) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str : strs) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(delim);
|
||||
}
|
||||
sb.append(str);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an enum value to a printable label but upcasing the first letter
|
||||
* and lcasing all subsequent letters
|
||||
|
||||
Reference in New Issue
Block a user