mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
reverting 18047, making changes from 17875 not ruin quest logics
This commit is contained in:
@@ -20,6 +20,7 @@ package forge.game;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.beust.jcommander.internal.Lists;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
@@ -39,6 +40,9 @@ public class GameFormat {
|
|||||||
protected final List<String> allowedSetCodes;
|
protected final List<String> allowedSetCodes;
|
||||||
protected final List<String> bannedCardNames;
|
protected final List<String> bannedCardNames;
|
||||||
|
|
||||||
|
protected final List<String> allowedSetCodes_ro;
|
||||||
|
protected final List<String> bannedCardNames_ro;
|
||||||
|
|
||||||
protected final transient Predicate<CardPrinted> filterRules;
|
protected final transient Predicate<CardPrinted> filterRules;
|
||||||
protected final transient Predicate<CardPrinted> filterPrinted;
|
protected final transient Predicate<CardPrinted> filterPrinted;
|
||||||
|
|
||||||
@@ -54,8 +58,12 @@ public class GameFormat {
|
|||||||
*/
|
*/
|
||||||
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards) {
|
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards) {
|
||||||
this.name = fName;
|
this.name = fName;
|
||||||
this.allowedSetCodes = Collections.unmodifiableList(sets);
|
this.allowedSetCodes = Lists.newArrayList(sets);
|
||||||
this.bannedCardNames = Collections.unmodifiableList(bannedCards);
|
this.bannedCardNames = Lists.newArrayList(bannedCards);
|
||||||
|
|
||||||
|
this.allowedSetCodes_ro = Collections.unmodifiableList(allowedSetCodes);
|
||||||
|
this.bannedCardNames_ro = Collections.unmodifiableList(bannedCardNames);
|
||||||
|
|
||||||
this.filterRules = this.buildFilterRules();
|
this.filterRules = this.buildFilterRules();
|
||||||
this.filterPrinted = this.buildFilterPritned();
|
this.filterPrinted = this.buildFilterPritned();
|
||||||
}
|
}
|
||||||
@@ -89,7 +97,7 @@ public class GameFormat {
|
|||||||
* @return list of allowed set codes
|
* @return list of allowed set codes
|
||||||
*/
|
*/
|
||||||
public List<String> getAllowedSetCodes() {
|
public List<String> getAllowedSetCodes() {
|
||||||
return this.allowedSetCodes;
|
return this.allowedSetCodes_ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +106,7 @@ public class GameFormat {
|
|||||||
* @return list of banned card names
|
* @return list of banned card names
|
||||||
*/
|
*/
|
||||||
public List<String> getBannedCardNames() {
|
public List<String> getBannedCardNames() {
|
||||||
return this.bannedCardNames;
|
return this.bannedCardNames_ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,15 +21,11 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.CardRulesPredicates;
|
|
||||||
import forge.game.GameFormat;
|
import forge.game.GameFormat;
|
||||||
import forge.item.CardPrinted;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,54 +33,8 @@ import forge.item.CardPrinted;
|
|||||||
* is not immutable. This class is necessary because we may wish to update
|
* is not immutable. This class is necessary because we may wish to update
|
||||||
* its contents in certain circumstances, and it was safer to create a new
|
* its contents in certain circumstances, and it was safer to create a new
|
||||||
* class than to make the preset game formats modifiable.
|
* class than to make the preset game formats modifiable.
|
||||||
*
|
|
||||||
* N.B! This class MUST NOT INHERIT GameFormat.java as long as that class
|
|
||||||
* has its data in immutable lists, otherwise this class WILL NOT WORK!
|
|
||||||
* The whole purpose of this class is to allow modification of the lists,
|
|
||||||
* otherwise the plain GameFormat.java would have sufficed!
|
|
||||||
*/
|
*/
|
||||||
public final class GameFormatQuest {
|
public final class GameFormatQuest extends GameFormat {
|
||||||
|
|
||||||
private final String name;
|
|
||||||
// contains allowed sets, when empty allows all sets
|
|
||||||
private final List<String> allowedSetCodes;
|
|
||||||
private final List<String> bannedCardNames;
|
|
||||||
|
|
||||||
private Predicate<CardPrinted> filterRules;
|
|
||||||
private Predicate<CardPrinted> filterPrinted;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new game format based on an existing format.
|
|
||||||
*
|
|
||||||
* @param toCopy
|
|
||||||
* an existing format
|
|
||||||
*/
|
|
||||||
public GameFormatQuest(final GameFormat toCopy) {
|
|
||||||
this.name = new String(toCopy.getName());
|
|
||||||
|
|
||||||
this.allowedSetCodes = new ArrayList<String>();
|
|
||||||
allowedSetCodes.addAll(toCopy.getAllowedSetCodes());
|
|
||||||
|
|
||||||
this.bannedCardNames = new ArrayList<String>();
|
|
||||||
bannedCardNames.addAll(toCopy.getBannedCardNames());
|
|
||||||
|
|
||||||
this.filterRules = this.buildFilterRules();
|
|
||||||
this.filterPrinted = this.buildFilterPrinted();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates an empty new game format.
|
|
||||||
*
|
|
||||||
* @param newName
|
|
||||||
* String, the name
|
|
||||||
*/
|
|
||||||
public GameFormatQuest(final String newName) {
|
|
||||||
this.name = new String(newName);
|
|
||||||
|
|
||||||
this.allowedSetCodes = new ArrayList<String>();
|
|
||||||
this.bannedCardNames = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new game format based on two lists.
|
* Instantiates a new game format based on two lists.
|
||||||
@@ -97,41 +47,29 @@ public final class GameFormatQuest {
|
|||||||
* List<String>, these will be the banned cards
|
* List<String>, these will be the banned cards
|
||||||
*/
|
*/
|
||||||
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
public GameFormatQuest(final String newName, final List<String> setsToAllow, final List<String> cardsToBan) {
|
||||||
this.name = new String(newName);
|
super(newName, setsToAllow, cardsToBan);
|
||||||
|
|
||||||
this.allowedSetCodes = new ArrayList<String>();
|
|
||||||
allowedSetCodes.addAll(setsToAllow);
|
|
||||||
|
|
||||||
this.bannedCardNames = new ArrayList<String>();
|
|
||||||
bannedCardNames.addAll(cardsToBan);
|
|
||||||
|
|
||||||
this.filterRules = this.buildFilterRules();
|
|
||||||
this.filterPrinted = this.buildFilterPrinted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildFilterPrinted() {
|
/**
|
||||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
* Instantiates a new game format based on an existing format.
|
||||||
if (this.allowedSetCodes.isEmpty()) {
|
*
|
||||||
return banNames;
|
* @param toCopy
|
||||||
}
|
* an existing format
|
||||||
return com.google.common.base.Predicates.and(banNames, CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true));
|
*/
|
||||||
|
public GameFormatQuest(final GameFormat toCopy) {
|
||||||
|
this(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildFilterRules() {
|
|
||||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
|
||||||
if (this.allowedSetCodes.isEmpty()) {
|
|
||||||
return banNames;
|
|
||||||
}
|
|
||||||
return com.google.common.base.Predicates.and(banNames, com.google.common.base.Predicates.compose(CardRulesPredicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Updates the filters based on the current list data.
|
* Updates the filters based on the current list data.
|
||||||
*/
|
*/
|
||||||
public void updateFilters() {
|
public void updateFilters() {
|
||||||
this.filterRules = this.buildFilterRules();
|
// nothing to do here.
|
||||||
this.filterPrinted = this.buildFilterPrinted();
|
// predicates hold references to lists and thus get auto updated.
|
||||||
|
|
||||||
|
// remove this method after reading.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,51 +92,6 @@ public final class GameFormatQuest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param banCard
|
|
||||||
* the card to ban
|
|
||||||
*/
|
|
||||||
public void addBannedCard(final String banCard) {
|
|
||||||
if (!bannedCardNames.contains(banCard)) {
|
|
||||||
bannedCardNames.add(banCard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the name.
|
|
||||||
*
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the filter rules.
|
|
||||||
*
|
|
||||||
* @return the filter rules
|
|
||||||
*/
|
|
||||||
public Predicate<CardPrinted> getFilterRules() {
|
|
||||||
return this.filterRules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the filter printed.
|
|
||||||
*
|
|
||||||
* @return the filter printed
|
|
||||||
*/
|
|
||||||
public Predicate<CardPrinted> getFilterPrinted() {
|
|
||||||
return this.filterPrinted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the set list.
|
|
||||||
*
|
|
||||||
* @return unmodifiable list of allowed set codes
|
|
||||||
*/
|
|
||||||
public List<String> getAllowedSetCodes() {
|
|
||||||
return Collections.unmodifiableList(this.allowedSetCodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of excluded sets.
|
* Get the list of excluded sets.
|
||||||
@@ -235,26 +128,6 @@ public final class GameFormatQuest {
|
|||||||
updateFilters();
|
updateFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the banned cards.
|
|
||||||
*
|
|
||||||
* @return unmodifiable list of banned card names
|
|
||||||
*/
|
|
||||||
public List<String> getBannedCardNames() {
|
|
||||||
return Collections.unmodifiableList(this.bannedCardNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if is sets the legal.
|
|
||||||
*
|
|
||||||
* @param setCode
|
|
||||||
* the set code
|
|
||||||
* @return true, if is sets the legal
|
|
||||||
*/
|
|
||||||
public boolean isSetLegal(final String setCode) {
|
|
||||||
return this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current format contains sets with snow-land (horrible hack...).
|
* Checks if the current format contains sets with snow-land (horrible hack...).
|
||||||
* @return boolean, contains snow-land sets.
|
* @return boolean, contains snow-land sets.
|
||||||
@@ -264,17 +137,6 @@ public final class GameFormatQuest {
|
|||||||
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
return (this.isSetLegal("ICE") || this.isSetLegal("CSP"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.name + " (format)";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Predicates.
|
* The Class Predicates.
|
||||||
*/
|
*/
|
||||||
@@ -303,11 +165,5 @@ public final class GameFormatQuest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Function<GameFormat, String> FN_GET_NAME = new Function<GameFormat, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(GameFormat arg1) {
|
|
||||||
return arg1.getName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user