Fix so FatPacks load

Fix references to non-existant quest icon files
This commit is contained in:
drdev
2014-04-10 02:43:51 +00:00
parent 53c090def2
commit 221be3d93d
4 changed files with 109 additions and 85 deletions

View File

@@ -56,7 +56,7 @@ public class StaticData {
this.boosters = new StorageBase<SealedProduct.Template>("Boosters", editions.getBoosterGenerator());
this.specialBoosters = new StorageBase<SealedProduct.Template>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
this.tournaments = new StorageBase<SealedProduct.Template>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader("res/blockdata/fatpacks.txt"));
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader(blockDataFolder + "fatpacks.txt"));
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
}

View File

@@ -79,8 +79,9 @@ public final class CardDb implements ICardDatabase {
public static CardRequest fromString(String name) {
boolean isFoil = name.endsWith(foilSuffix);
if( isFoil )
if (isFoil) {
name = name.substring(0, name.length() - foilSuffix.length());
}
String[] nameParts = TextUtil.split(name, NameSetSeparator);
@@ -88,15 +89,16 @@ public final class CardDb implements ICardDatabase {
int artPos = nameParts.length >= 2 && StringUtils.isNumeric(nameParts[1]) ? 1 : nameParts.length >= 3 && StringUtils.isNumeric(nameParts[2]) ? 2 : -1;
String cardName = nameParts[0];
if( cardName.endsWith(foilSuffix)) {
if (cardName.endsWith(foilSuffix)) {
cardName = cardName.substring(0, cardName.length() - foilSuffix.length());
isFoil = true;
}
int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos]) : 0;
String setName = setPos > 0 ? nameParts[setPos] : null;
if( "???".equals(setName) )
if ("???".equals(setName)) {
setName = null;
}
return new CardRequest(cardName, setName, artIndex, isFoil);
}
@@ -107,45 +109,49 @@ public final class CardDb implements ICardDatabase {
this.editions = editions0;
Set<String> allMissingCards = new LinkedHashSet<String>();
List<String> missingCards = new ArrayList<String>();
for(CardEdition e : editions.getOrderedEditions()) {
for (CardEdition e : editions.getOrderedEditions()) {
boolean isCoreExpSet = e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION || e.getType() == CardEdition.Type.REPRINT;
if(logMissingPerEdition && isCoreExpSet)
if (logMissingPerEdition && isCoreExpSet) {
System.out.print(e.getName() + " (" + e.getCards().length + " cards)");
}
String lastCardName = null;
int artIdx = 1;
for(CardEdition.CardInSet cis : e.getCards()) {
if ( cis.name.equals(lastCardName) )
for (CardEdition.CardInSet cis : e.getCards()) {
if (cis.name.equals(lastCardName))
artIdx++;
else {
artIdx = 1;
lastCardName = cis.name;
}
CardRules cr = rulesByName.get(lastCardName);
if( cr != null )
if (cr != null) {
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx));
else
missingCards.add(cis.name);
}
if(isCoreExpSet && logMissingPerEdition) {
if(missingCards.isEmpty())
System.out.println(" ... 100% ");
}
else {
int missing = (e.getCards().length - missingCards.size()) * 10000 / e.getCards().length;
System.out.printf(" ... %.2f%% (%s missing: %s )%n", missing * 0.01f, Lang.nounWithAmount(missingCards.size(), "card"), StringUtils.join(missingCards, " | ") );
missingCards.add(cis.name);
}
}
if( isCoreExpSet && logMissingSummary )
if (isCoreExpSet && logMissingPerEdition) {
if (missingCards.isEmpty()) {
System.out.println(" ... 100% ");
}
else {
int missing = (e.getCards().length - missingCards.size()) * 10000 / e.getCards().length;
System.out.printf(" ... %.2f%% (%s missing: %s)%n", missing * 0.01f, Lang.nounWithAmount(missingCards.size(), "card"), StringUtils.join(missingCards, " | "));
}
}
if (isCoreExpSet && logMissingSummary) {
allMissingCards.addAll(missingCards);
}
missingCards.clear();
}
if( logMissingSummary ) {
if (logMissingSummary) {
System.out.printf("Totally %d cards not implemented: %s\n", allMissingCards.size(), StringUtils.join(allMissingCards, " | "));
}
for(CardRules cr : rulesByName.values()) {
if( !allCardsByName.containsKey(cr.getName()) )
{
for (CardRules cr : rulesByName.values()) {
if (!allCardsByName.containsKey(cr.getName())) {
System.err.println("The card " + cr.getName() + " was not assigned to any set. Adding it to UNKNOWN set... to fix see res/cardeditions/ folder. ");
addCard(new PaperCard(cr, CardEdition.UNKNOWN.getCode(), CardRarity.Special, 1));
}
@@ -161,7 +167,7 @@ public final class CardDb implements ICardDatabase {
private void reIndex() {
uniqueCardsByName.clear();
allCards.clear();
for(Entry<String, Collection<PaperCard>> kv : allCardsByName.asMap().entrySet()) {
for (Entry<String, Collection<PaperCard>> kv : allCardsByName.asMap().entrySet()) {
uniqueCardsByName.put(kv.getKey(), Iterables.getFirst(kv.getValue(), null));
allCards.addAll(kv.getValue());
}
@@ -176,53 +182,57 @@ public final class CardDb implements ICardDatabase {
@Override
public PaperCard getCard(final String cardName, String setName) {
CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
if (setName != null) {
request.edition = setName;
}
return tryGetCard(request);
}
@Override
public PaperCard getCard(final String cardName, String setName, int artIndex) {
CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
if (setName != null) {
request.edition = setName;
if(artIndex > 0)
}
if (artIndex > 0) {
request.artIndex = artIndex;
}
return tryGetCard(request);
}
private PaperCard tryGetCard(CardRequest request) {
Collection<PaperCard> cards = allCardsByName.get(request.cardName);
if ( null == cards ) return null;
if (null == cards) { return null; }
PaperCard result = null;
String reqEdition = request.edition;
if(reqEdition != null && !editions.contains(reqEdition)) {
if (reqEdition != null && !editions.contains(reqEdition)) {
CardEdition edition = editions.get(reqEdition);
if( edition != null )
if (edition != null)
reqEdition = edition.getCode();
}
if ( request.artIndex <= 0 ) { // this stands for 'random art'
if (request.artIndex <= 0) { // this stands for 'random art'
List<PaperCard> candidates = new ArrayList<PaperCard>(9); // 9 cards with same name per set is a maximum of what has been printed (Arnchenemy)
for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null )
for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null)
candidates.add(pc);
}
if (candidates.isEmpty())
if (candidates.isEmpty()) {
return null;
}
result = Aggregates.random(candidates);
} else {
for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex() ) {
for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex()) {
result = pc;
break;
}
}
}
if ( result == null ) return null;
if (result == null) { return null; }
return request.isFoil ? getFoiled(result) : result;
}
@@ -242,37 +252,39 @@ public final class CardDb implements ICardDatabase {
final CardRequest cr = CardRequest.fromString(cardName);
List<PaperCard> cards = this.allCardsByName.get(cr.cardName);
if ( StringUtils.isNotBlank(cr.edition) ) {
if (StringUtils.isNotBlank(cr.edition)) {
cards = Lists.newArrayList(Iterables.filter(cards, new Predicate<PaperCard>() {
@Override public boolean apply(PaperCard input) { return input.getEdition().equalsIgnoreCase(cr.edition); }
}));
}
if(artIndex == -1 && cr.artIndex > 0) {
if (artIndex == -1 && cr.artIndex > 0) {
artIndex = cr.artIndex;
}
int sz = cards.size();
if( fromSet == SetPreference.Earliest || fromSet == SetPreference.EarliestCoreExp) {
for(int i = sz - 1 ; i >= 0 ; i--) {
if (fromSet == SetPreference.Earliest || fromSet == SetPreference.EarliestCoreExp) {
for (int i = sz - 1 ; i >= 0 ; i--) {
PaperCard pc = cards.get(i);
CardEdition ed = editions.get(pc.getEdition());
if(!fromSet.accept(ed))
if (!fromSet.accept(ed))
continue;
if((artIndex <= 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore)))
if ((artIndex <= 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore)))
return pc;
}
return null;
} else if( fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest || fromSet == null || fromSet == SetPreference.Random ) {
for(int i = 0 ; i < sz ; i++) {
} else if (fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest || fromSet == null || fromSet == SetPreference.Random) {
for (int i = 0 ; i < sz ; i++) {
PaperCard pc = cards.get(i);
CardEdition ed = editions.get(pc.getEdition());
if(fromSet != null && !fromSet.accept(ed))
if (fromSet != null && !fromSet.accept(ed)) {
continue;
}
if((artIndex < 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore))) {
if( fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest )
if ((artIndex < 0 || pc.getArtIndex() == artIndex) && (printedBefore == null || ed.getDate().before(printedBefore))) {
if (fromSet == SetPreference.LatestCoreExp || fromSet == SetPreference.Latest) {
return pc;
}
return cards.get(i + MyRandom.getRandom().nextInt(sz-i));
}
}
@@ -289,8 +301,8 @@ public final class CardDb implements ICardDatabase {
@Override
public int getPrintCount(String cardName, String edition) {
int cnt = 0;
for( PaperCard pc : allCardsByName.get(cardName) ) {
if( pc.getEdition().equals(edition) )
for (PaperCard pc : allCardsByName.get(cardName)) {
if (pc.getEdition().equals(edition))
cnt++;
}
return cnt;
@@ -299,8 +311,8 @@ public final class CardDb implements ICardDatabase {
@Override
public int getMaxPrintCount(String cardName) {
int max = -1;
for( PaperCard pc : allCardsByName.get(cardName) ) {
if ( max < pc.getArtIndex() )
for (PaperCard pc : allCardsByName.get(cardName)) {
if (max < pc.getArtIndex())
max = pc.getArtIndex();
}
return max;
@@ -311,12 +323,12 @@ public final class CardDb implements ICardDatabase {
int cnt = 0;
Collection<PaperCard> cards = allCardsByName.get(cardName);
if ( null == cards ) {
if (null == cards) {
return 0;
}
for ( PaperCard pc : cards ) {
if ( pc.getEdition().equalsIgnoreCase(setName) ) {
for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(setName)) {
cnt++;
}
}
@@ -360,9 +372,11 @@ public final class CardDb implements ICardDatabase {
@Override
public boolean apply(final PaperCard subject) {
Collection<PaperCard> cc = allCardsByName.get(subject.getName());
for(PaperCard c : cc)
if (sets.contains(c.getEdition()))
for (PaperCard c : cc) {
if (sets.contains(c.getEdition())) {
return true;
}
}
return false;
}
}
@@ -370,7 +384,7 @@ public final class CardDb implements ICardDatabase {
public StringBuilder appendCardToStringBuilder(PaperCard card, StringBuilder sb) {
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
sb.append(card.getName());
if(card.isFoil()) {
if (card.isFoil()) {
sb.append(CardDb.foilSuffix);
}
@@ -395,10 +409,10 @@ public final class CardDb implements ICardDatabase {
CardRarity cR = CardRarity.Unknown;
// May iterate over editions and find out if there is any card named 'cardName' but not implemented with Forge script.
if( StringUtils.isBlank(request.edition) ) {
for(CardEdition e : editions) {
for(CardInSet cs : e.getCards() ) {
if( cs.name.equals(request.cardName)) {
if (StringUtils.isBlank(request.edition)) {
for (CardEdition e : editions) {
for (CardInSet cs : e.getCards()) {
if (cs.name.equals(request.cardName)) {
cE = e;
cR = cs.rarity;
break;
@@ -409,23 +423,26 @@ public final class CardDb implements ICardDatabase {
}
} else {
cE = editions.get(request.edition);
if ( cE != null )
for(CardInSet cs : cE.getCards() ) {
if( cs.name.equals(request.cardName)) {
if (cE != null)
for (CardInSet cs : cE.getCards()) {
if (cs.name.equals(request.cardName)) {
cR = cs.rarity;
break;
}
}
else
else {
cE = CardEdition.UNKNOWN;
}
}
// Write to log that attempt,
if (cR == CardRarity.Unknown )
if (cR == CardRarity.Unknown) {
System.err.println(String.format("An unknown card found when loading Forge decks: \"%s\" Forge does not know of such a card's existence. Have you mistyped the card name?", cardName));
else
}
else {
System.err.println(String.format("An unsupported card was requested: \"%s\" from \"%s\" set. We're sorry, but you cannot use this card yet.", request.cardName, cE.getName()));
}
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cE.getCode(), cR, 1);
@@ -450,38 +467,41 @@ public final class CardDb implements ICardDatabase {
// 1. generate all paper cards from edition data we have (either explicit, or found in res/editions, or add to unknown edition)
List<PaperCard> paperCards = new ArrayList<PaperCard>();
if (null == whenItWasPrinted || whenItWasPrinted.isEmpty()) {
for(CardEdition e : editions.getOrderedEditions()) {
for (CardEdition e : editions.getOrderedEditions()) {
int artIdx = 1;
for(CardInSet cis : e.getCards()) {
if( !cis.name.equals(cardName) )
for (CardInSet cis : e.getCards()) {
if (!cis.name.equals(cardName)) {
continue;
}
paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++));
}
}
} else {
String lastEdition = null;
int artIdx = 0;
for(Pair<String, CardRarity> tuple : whenItWasPrinted){
if(!tuple.getKey().equals(lastEdition)) {
for (Pair<String, CardRarity> tuple : whenItWasPrinted){
if (!tuple.getKey().equals(lastEdition)) {
artIdx = 1;
lastEdition = tuple.getKey();
}
CardEdition ed = editions.get(lastEdition);
if(null == ed)
if (null == ed) {
continue;
}
paperCards.add(new PaperCard(rules, lastEdition, tuple.getValue(), artIdx++));
}
}
if(paperCards.isEmpty())
if (paperCards.isEmpty()) {
paperCards.add(new PaperCard(rules, CardEdition.UNKNOWN.getCode(), CardRarity.Special, 1));
}
// 2. add them to db
for (PaperCard paperCard : paperCards)
for (PaperCard paperCard : paperCards) {
addCard(paperCard);
}
// 3. reindex can be temporary disabled and run after the whole batch of rules is added to db.
if(immediateReindex)
if (immediateReindex) {
reIndex();
}
return result;
}
public void removeCard(String name) {
@@ -491,11 +511,14 @@ public final class CardDb implements ICardDatabase {
Iterator<PaperCard> it = allCards.iterator();
while(it.hasNext()) {
PaperCard pc = it.next();
if( pc.getName().equalsIgnoreCase(name))
if (pc.getName().equalsIgnoreCase(name)) {
it.remove();
}
}
}
public void rebuildIndex() { reIndex(); }
public void rebuildIndex() {
reIndex();
}
public boolean isImmediateReindex() {
return immediateReindex;

View File

@@ -1,5 +1,6 @@
package forge.screens.home.quest;
import forge.assets.FSkinProp;
import forge.model.FModel;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
@@ -59,7 +60,7 @@ public class QuestPreferencesHandler extends SkinnedPanel {
pnlRewards.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlRewards.add(new FLabel.Builder().text("Rewards")
.icon(new FSkin.UnskinnedIcon("res/images/icons/CoinIcon.png")).build(),
.icon(FSkin.getImage(FSkinProp.ICO_QUEST_COIN)).build(),
"w 100%!, h 30px!, span 2 1");
pnlRewards.add(lblErrRewards, "w 100%!, h 30px!, span 2 1");
@@ -100,7 +101,7 @@ public class QuestPreferencesHandler extends SkinnedPanel {
pnlDifficulty.setOpaque(false);
pnlDifficulty.setLayout(new MigLayout("insets 0, gap 0, wrap 5"));
pnlDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments").icon(new FSkin.UnskinnedIcon("res/images/icons/NotesIcon.png")).build(), "w 100%!, h 30px!, span 5 1");
pnlDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments").icon(FSkin.getImage(FSkinProp.ICO_QUEST_NOTES)).build(), "w 100%!, h 30px!, span 5 1");
pnlDifficulty.add(lblErrDifficulty, "w 100%!, h 30px!, span 5 1");
constraints1 = "w 60px!, h 26px!";
@@ -183,7 +184,7 @@ public class QuestPreferencesHandler extends SkinnedPanel {
pnlBooster.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlBooster.add(new FLabel.Builder().text("Booster Pack Ratios")
.icon(new FSkin.UnskinnedIcon("res/images/icons/BookIcon.png")).build(),
.icon(FSkin.getImage(FSkinProp.ICO_QUEST_BOOK)).build(),
"w 100%!, h 30px!, span 2 1");
pnlBooster.add(lblErrBooster, "w 100%!, h 30px!, span 2 1");
@@ -203,7 +204,7 @@ public class QuestPreferencesHandler extends SkinnedPanel {
pnlShop.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
pnlShop.add(new FLabel.Builder().text("Shop Preferences")
.icon(new FSkin.UnskinnedIcon("res/images/icons/CoinIcon.png")).build(), "w 100%!, h 30px!, span 2 1");
.icon(FSkin.getImage(FSkinProp.ICO_QUEST_COIN)).build(), "w 100%!, h 30px!, span 2 1");
pnlShop.add(lblErrShop, "w 100%!, h 30px!, span 2 1");
constraints1 = "w 60px, h 26px!";

View File

@@ -27,7 +27,7 @@ public class CardDatabaseHelper {
private static void initialize() {
final CardStorageReader reader = new CardStorageReader(ForgeConstants.CARD_DATA_DIR, null, null);
staticData = new StaticData(reader, "res/editions", "res/blockdata");
staticData = new StaticData(reader, ForgeConstants.EDITIONS_DIR, ForgeConstants.BLOCK_DATA_DIR);
}
private static boolean hasBeenInitialized() {