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]);
|
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) {
|
public static QuestEvent getQuestEvent(final String name) {
|
||||||
QuestController qCtrl = Singletons.getModel().getQuest();
|
QuestController qCtrl = Singletons.getModel().getQuest();
|
||||||
QuestEventChallenge challenge = qCtrl.getChallenges().get(name);
|
for(QuestEventChallenge challenge : qCtrl.getChallenges()) {
|
||||||
if( null != challenge ) return challenge;
|
if( challenge.getTitle().equals(name) )
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
|
||||||
QuestEventDuel duel = Iterables.find(qCtrl.getDuelsManager().getAllDuels(), new Predicate<QuestEventDuel>() {
|
QuestEventDuel duel = Iterables.find(qCtrl.getDuelsManager().getAllDuels(), new Predicate<QuestEventDuel>() {
|
||||||
@Override public boolean apply(QuestEventDuel in) { return in.getName().equals(name); }
|
@Override public boolean apply(QuestEventDuel in) { return in.getName().equals(name); }
|
||||||
|
|||||||
@@ -133,11 +133,9 @@ public enum CSubmenuChallenges implements ICDoc {
|
|||||||
|
|
||||||
view.getPnlChallenges().removeAll();
|
view.getPnlChallenges().removeAll();
|
||||||
qCtrl.regenerateChallenges();
|
qCtrl.regenerateChallenges();
|
||||||
final List<String> ids = qCtrl.getAchievements().getCurrentChallenges();
|
|
||||||
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
||||||
for(final QuestEventChallenge qc : qCtrl.getChallenges()) {
|
for(String id : qCtrl.getAchievements().getCurrentChallenges()) {
|
||||||
if(ids.contains(qc.getId()))
|
challenges.add(qCtrl.getChallenges().get(id));
|
||||||
challenges.add(qc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JXButtonPanel grpPanel = new JXButtonPanel();
|
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>() {
|
public static final Function<QuestEvent, String> FN_GET_NAME = new Function<QuestEvent, String>() {
|
||||||
@Override public final String apply(QuestEvent qe) { return qe.name; }
|
@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() {
|
public final String getTitle() {
|
||||||
return this.title;
|
return this.title;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ package forge.quest;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* QuestQuest class.
|
* QuestQuest class.
|
||||||
@@ -30,6 +32,10 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class QuestEventChallenge extends QuestEvent {
|
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.)
|
// ID (default -1, should be explicitly set at later time.)
|
||||||
/** The id. */
|
/** The id. */
|
||||||
private String id = "-1";
|
private String id = "-1";
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.util.Map;
|
|||||||
import forge.ImageCache;
|
import forge.ImageCache;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.io.DeckSerializer;
|
import forge.deck.io.DeckSerializer;
|
||||||
import forge.quest.QuestEvent;
|
|
||||||
import forge.quest.QuestEventChallenge;
|
import forge.quest.QuestEventChallenge;
|
||||||
import forge.quest.QuestEventDifficulty;
|
import forge.quest.QuestEventDifficulty;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
@@ -19,7 +18,7 @@ import forge.util.storage.StorageReaderFolder;
|
|||||||
|
|
||||||
public class QuestChallengeReader extends StorageReaderFolder<QuestEventChallenge> {
|
public class QuestChallengeReader extends StorageReaderFolder<QuestEventChallenge> {
|
||||||
public QuestChallengeReader(File deckDir0) {
|
public QuestChallengeReader(File deckDir0) {
|
||||||
super(deckDir0, QuestEvent.FN_GET_TITLE);
|
super(deckDir0, QuestEventChallenge.FN_GET_ID);
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,11 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx++;
|
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;
|
return result;
|
||||||
|
|||||||
@@ -90,7 +90,11 @@ public abstract class StorageReaderFileSections<T> implements IItemReader<T> {
|
|||||||
if ( !accumulator.isEmpty() ) {
|
if ( !accumulator.isEmpty() ) {
|
||||||
T item = readItem(header, accumulator, idx);
|
T item = readItem(header, accumulator, idx);
|
||||||
if( item != null ) {
|
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;
|
return result;
|
||||||
|
|||||||
@@ -104,7 +104,11 @@ public abstract class StorageReaderFolder<T> implements IItemReader<T> {
|
|||||||
JOptionPane.showMessageDialog(null, msg);
|
JOptionPane.showMessageDialog(null, msg);
|
||||||
continue;
|
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) {
|
} catch (final OldDeckFileFormatException ex) {
|
||||||
if (!hasWarnedOfOldFormat) {
|
if (!hasWarnedOfOldFormat) {
|
||||||
JOptionPane
|
JOptionPane
|
||||||
|
|||||||
Reference in New Issue
Block a user