Revert to CollectorNumber in PaperCard as String to handle cases of mulitple art (e.g. 21a).

This commit is contained in:
leriomaggio
2021-05-23 16:52:12 +01:00
parent a0c126f39e
commit c03da7eb74
4 changed files with 14 additions and 21 deletions

View File

@@ -19,7 +19,7 @@ import forge.util.PredicateString;
public interface IPaperCard extends InventoryItem, Serializable { public interface IPaperCard extends InventoryItem, Serializable {
int NO_COLLECTOR_NUMBER = 0; String NO_COLLECTOR_NUMBER = "N.A."; // Placeholder for No-Collection number available
int DEFAULT_ART_INDEX = 1; int DEFAULT_ART_INDEX = 1;
/** /**
@@ -229,7 +229,7 @@ public interface IPaperCard extends InventoryItem, Serializable {
String getName(); String getName();
String getEdition(); String getEdition();
int getCollectorNumber(); String getCollectorNumber();
int getArtIndex(); int getArtIndex();
boolean isFoil(); boolean isFoil();
boolean isToken(); boolean isToken();

View File

@@ -42,7 +42,6 @@ import forge.util.TextUtil;
*/ */
public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet, IPaperCard, Serializable { public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet, IPaperCard, Serializable {
private static final long serialVersionUID = 2942081982620691205L; private static final long serialVersionUID = 2942081982620691205L;
private static final int UNSET_COLLECTOR_NUMBER = -1;
// Reference to rules // Reference to rules
private transient CardRules rules; private transient CardRules rules;
@@ -54,7 +53,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
By default the attribute is marked as "unset" so that it could be retrieved and set. By default the attribute is marked as "unset" so that it could be retrieved and set.
(see getCollectorNumber()) (see getCollectorNumber())
*/ */
private int collectorNumber = UNSET_COLLECTOR_NUMBER; private String collectorNumber = null;
private final int artIndex; private final int artIndex;
private final boolean foil; private final boolean foil;
private Boolean hasImage; private Boolean hasImage;
@@ -75,7 +74,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
} }
@Override @Override
public int getCollectorNumber() { public String getCollectorNumber() {
/* The collectorNumber attribute is managed in a property-like fashion. /* The collectorNumber attribute is managed in a property-like fashion.
By default it is marked as "unset" (-1), which integrates with all constructors By default it is marked as "unset" (-1), which integrates with all constructors
invocations not including this as an extra parameter. In this way, the new invocations not including this as an extra parameter. In this way, the new
@@ -84,7 +83,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
If "unset", the corresponding collectorNumber will be retrieved If "unset", the corresponding collectorNumber will be retrieved
from the corresponding CardEdition (see retrieveCollectorNumber) from the corresponding CardEdition (see retrieveCollectorNumber)
* */ * */
if (collectorNumber == UNSET_COLLECTOR_NUMBER){ if (collectorNumber == null){
collectorNumber = this.retrieveCollectorNumber(); collectorNumber = this.retrieveCollectorNumber();
} }
return collectorNumber; return collectorNumber;
@@ -193,13 +192,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0,
final int artIndex0, final boolean foil0, final String collectorNumber0){ final int artIndex0, final boolean foil0, final String collectorNumber0){
this(rules0, edition0, rarity0, artIndex0, foil0); this(rules0, edition0, rarity0, artIndex0, foil0);
int collNr = NO_COLLECTOR_NUMBER; collectorNumber = collectorNumber0;
try {
collNr = Integer.parseInt(collectorNumber0);
} catch (NumberFormatException ex) {}
finally {
collectorNumber = collNr;
}
} }
// Want this class to be a key for HashTable // Want this class to be a key for HashTable
@@ -222,7 +215,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
if (!edition.equals(other.edition)) { if (!edition.equals(other.edition)) {
return false; return false;
} }
if (getCollectorNumber() != other.getCollectorNumber()) if (!getCollectorNumber().equals(other.getCollectorNumber()))
return false; return false;
return (other.foil == foil) && (other.artIndex == artIndex); return (other.foil == foil) && (other.artIndex == artIndex);
} }
@@ -235,7 +228,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
@Override @Override
public int hashCode() { public int hashCode() {
final int code = (name.hashCode() * 11) + (edition.hashCode() * 59) + final int code = (name.hashCode() * 11) + (edition.hashCode() * 59) +
(artIndex * 2) + (getCollectorNumber() * 383); (artIndex * 2) + (getCollectorNumber().hashCode() * 383);
if (foil) { if (foil) {
return code + 1; return code + 1;
} }
@@ -260,7 +253,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
int setDiff = edition.compareTo(o.getEdition()); int setDiff = edition.compareTo(o.getEdition());
if ( 0 != setDiff ) if ( 0 != setDiff )
return setDiff; return setDiff;
final int collNrCmp = Integer.compare(getCollectorNumber(), o.getCollectorNumber()); final int collNrCmp = getCollectorNumber().compareTo(o.getCollectorNumber());
if (0 != collNrCmp) { if (0 != collNrCmp) {
return collNrCmp; return collNrCmp;
} }
@@ -282,7 +275,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
rarity = pc.getRarity(); rarity = pc.getRarity();
} }
private int retrieveCollectorNumber() { private String retrieveCollectorNumber() {
CardEdition.Collection editions = StaticData.instance().getEditions(); CardEdition.Collection editions = StaticData.instance().getEditions();
CardEdition edition = editions.get(this.edition); CardEdition edition = editions.get(this.edition);
int artIndexCount = 0; int artIndexCount = 0;
@@ -299,7 +292,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
// CardEdition stores collectorNumber as a String, which is null if there isn't any. // CardEdition stores collectorNumber as a String, which is null if there isn't any.
// In this case, the NO_COLLECTOR_NUMBER value (i.e. 0) is returned. // In this case, the NO_COLLECTOR_NUMBER value (i.e. 0) is returned.
return ((collectorNumberInEdition != null) && (collectorNumberInEdition.length() > 0)) ? return ((collectorNumberInEdition != null) && (collectorNumberInEdition.length() > 0)) ?
Integer.parseInt(collectorNumberInEdition) : NO_COLLECTOR_NUMBER; collectorNumberInEdition : NO_COLLECTOR_NUMBER;
} }
@Override @Override

View File

@@ -134,7 +134,7 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
@Override public String getEdition() { return edition != null ? edition.getCode() : "???"; } @Override public String getEdition() { return edition != null ? edition.getCode() : "???"; }
@Override @Override
public int getCollectorNumber() { public String getCollectorNumber() {
return IPaperCard.NO_COLLECTOR_NUMBER; return IPaperCard.NO_COLLECTOR_NUMBER;
} }

View File

@@ -96,7 +96,7 @@ public enum ColumnDef {
public Object apply(final Entry<? extends InventoryItem, Integer> from) { public Object apply(final Entry<? extends InventoryItem, Integer> from) {
InventoryItem item = from.getKey(); InventoryItem item = from.getKey();
return item instanceof PaperCard ? return item instanceof PaperCard ?
String.format("%03d", ((PaperCard) item).getCollectorNumber()) : ""; ((PaperCard) item).getCollectorNumber() : IPaperCard.NO_COLLECTOR_NUMBER;
} }
}), }),
/**The type column.*/ /**The type column.*/
@@ -581,7 +581,7 @@ public enum ColumnDef {
@return A sortable numeric string based on the item's attributes.*/ @return A sortable numeric string based on the item's attributes.*/
private static String toCollectorPrefix(final InventoryItem i) { private static String toCollectorPrefix(final InventoryItem i) {
//make sure it's a card. if not, pointless to proceed. //make sure it's a card. if not, pointless to proceed.
return (i instanceof PaperCard ? String.format("%03d", ((PaperCard) i).getCollectorNumber()) : "") + toSortableName(i.getName()); return (i instanceof PaperCard ? ((PaperCard) i).getCollectorNumber() : IPaperCard.NO_COLLECTOR_NUMBER) + toSortableName(i.getName());
} }
/**Returns 1 for land, otherwise 0 and continues sorting. /**Returns 1 for land, otherwise 0 and continues sorting.