mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
QuestEventChallenge are keyed by id in their storage.
The storage reader will print a warnings in console when you are trying to load a second object with same id.
This commit is contained in:
@@ -109,20 +109,12 @@ public class DeckgenUtil {
|
||||
return Singletons.getModel().getDecks().getConstructed().get(selection[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a quest deck.
|
||||
*
|
||||
* @param selection {java.lang.String}
|
||||
* @return {@link forge.deck.Deck}
|
||||
*/
|
||||
public static Deck buildQuestDeck(final String[] selection) {
|
||||
return getQuestEvent(selection[0]).getEventDeck();
|
||||
}
|
||||
|
||||
public static QuestEvent getQuestEvent(final String name) {
|
||||
QuestController qCtrl = Singletons.getModel().getQuest();
|
||||
QuestEventChallenge challenge = qCtrl.getChallenges().get(name);
|
||||
if( null != challenge ) return challenge;
|
||||
for(QuestEventChallenge challenge : qCtrl.getChallenges()) {
|
||||
if( challenge.getTitle().equals(name) )
|
||||
return challenge;
|
||||
}
|
||||
|
||||
QuestEventDuel duel = Iterables.find(qCtrl.getDuelsManager().getAllDuels(), new Predicate<QuestEventDuel>() {
|
||||
@Override public boolean apply(QuestEventDuel in) { return in.getName().equals(name); }
|
||||
|
||||
@@ -133,11 +133,9 @@ public enum CSubmenuChallenges implements ICDoc {
|
||||
|
||||
view.getPnlChallenges().removeAll();
|
||||
qCtrl.regenerateChallenges();
|
||||
final List<String> ids = qCtrl.getAchievements().getCurrentChallenges();
|
||||
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
||||
for(final QuestEventChallenge qc : qCtrl.getChallenges()) {
|
||||
if(ids.contains(qc.getId()))
|
||||
challenges.add(qc);
|
||||
for(String id : qCtrl.getAchievements().getCurrentChallenges()) {
|
||||
challenges.add(qCtrl.getChallenges().get(id));
|
||||
}
|
||||
|
||||
JXButtonPanel grpPanel = new JXButtonPanel();
|
||||
|
||||
@@ -50,10 +50,6 @@ public abstract class QuestEvent implements IHasIcon {
|
||||
public static final Function<QuestEvent, String> FN_GET_NAME = new Function<QuestEvent, String>() {
|
||||
@Override public final String apply(QuestEvent qe) { return qe.name; }
|
||||
};
|
||||
public static final Function<QuestEvent, String> FN_GET_TITLE = new Function<QuestEvent, String>() {
|
||||
@Override public final String apply(QuestEvent qe) { return qe.title; }
|
||||
};
|
||||
|
||||
|
||||
public final String getTitle() {
|
||||
return this.title;
|
||||
|
||||
@@ -20,6 +20,8 @@ package forge.quest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* QuestQuest class.
|
||||
@@ -30,6 +32,10 @@ import java.util.List;
|
||||
*
|
||||
*/
|
||||
public class QuestEventChallenge extends QuestEvent {
|
||||
public static final Function<QuestEventChallenge, String> FN_GET_ID = new Function<QuestEventChallenge, String>() {
|
||||
@Override public final String apply(QuestEventChallenge qe) { return qe.id; }
|
||||
};
|
||||
|
||||
// ID (default -1, should be explicitly set at later time.)
|
||||
/** The id. */
|
||||
private String id = "-1";
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Map;
|
||||
import forge.ImageCache;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.quest.QuestEvent;
|
||||
import forge.quest.QuestEventChallenge;
|
||||
import forge.quest.QuestEventDifficulty;
|
||||
import forge.util.FileSection;
|
||||
@@ -19,7 +18,7 @@ import forge.util.storage.StorageReaderFolder;
|
||||
|
||||
public class QuestChallengeReader extends StorageReaderFolder<QuestEventChallenge> {
|
||||
public QuestChallengeReader(File deckDir0) {
|
||||
super(deckDir0, QuestEvent.FN_GET_TITLE);
|
||||
super(deckDir0, QuestEventChallenge.FN_GET_ID);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,11 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
|
||||
}
|
||||
|
||||
idx++;
|
||||
result.put(this.keySelector.apply(item), item);
|
||||
String newKey = keySelector.apply(item);
|
||||
if( result.containsKey(newKey))
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
result.put(newKey, item);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -90,7 +90,11 @@ public abstract class StorageReaderFileSections<T> implements IItemReader<T> {
|
||||
if ( !accumulator.isEmpty() ) {
|
||||
T item = readItem(header, accumulator, idx);
|
||||
if( item != null ) {
|
||||
result.put(this.keySelector.apply(item), item);
|
||||
String newKey = keySelector.apply(item);
|
||||
if( result.containsKey(newKey))
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
result.put(newKey, item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -104,7 +104,11 @@ public abstract class StorageReaderFolder<T> implements IItemReader<T> {
|
||||
JOptionPane.showMessageDialog(null, msg);
|
||||
continue;
|
||||
}
|
||||
result.put(keySelector.apply(newDeck), newDeck);
|
||||
String newKey = keySelector.apply(newDeck);
|
||||
if( result.containsKey(newKey))
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
result.put(newKey, newDeck);
|
||||
} catch (final OldDeckFileFormatException ex) {
|
||||
if (!hasWarnedOfOldFormat) {
|
||||
JOptionPane
|
||||
|
||||
Reference in New Issue
Block a user