mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Huge update to forge's structure:
everything from the default package moved to package forge. the default package contains classes Deck and QuestData_State to keep compatibility with old files that store serialized objects of these classes if you find other classes that are stored in the res directory through serialization, create a class for it in the default package or tell me. about QuestData_State: i'm getting a NullPointerException when trying to create/resume quest. Maybe the quest files on SVN are simply out of date. otherwise, that seems hard. easy fix would of course be to replace null by a new Map
This commit is contained in:
110
src/Deck.java
110
src/Deck.java
@@ -1,76 +1,44 @@
|
||||
import java.util.*;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Deck implements java.io.Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -2188987217361601903L;
|
||||
|
||||
//gameType is from Constant.GameType, like Constant.GameType.Regular
|
||||
private String deckType;
|
||||
/**
|
||||
* Deck.java
|
||||
*
|
||||
* Created on 26.10.2009
|
||||
*/
|
||||
|
||||
private boolean isRegular;
|
||||
private boolean isSealed;
|
||||
private boolean isDraft;
|
||||
|
||||
private ArrayList<String> main = new ArrayList<String>();
|
||||
private ArrayList<String> sideboard = new ArrayList<String>();
|
||||
|
||||
//very important, do NOT change this
|
||||
private String name = "";
|
||||
|
||||
//gameType is from Constant.GameType, like Constant.GameType.Regular
|
||||
public Deck(String gameType)
|
||||
{
|
||||
deckType = gameType;
|
||||
setDeckType(gameType);
|
||||
}
|
||||
public String getDeckType() {return deckType;}
|
||||
|
||||
//can only call this method ONCE
|
||||
private final void setDeckType(String deckType)
|
||||
{
|
||||
if(isRegular || isSealed || isDraft)
|
||||
throw new RuntimeException("Deck : setDeckType() error, deck type has already been set");
|
||||
|
||||
if(deckType.equals(Constant.GameType.Constructed))
|
||||
isRegular = true;
|
||||
else if(deckType.equals(Constant.GameType.Sealed))
|
||||
isSealed = true;
|
||||
else if(deckType.equals(Constant.GameType.Draft))
|
||||
isDraft = true;
|
||||
else
|
||||
throw new RuntimeException("Deck : setDeckType() error, invalid deck type - " +deckType);
|
||||
}
|
||||
|
||||
public void setName(String s) {name = s;}
|
||||
public String getName() {return name;}//may return null
|
||||
|
||||
public void addMain(String cardName) {main.add(cardName);}
|
||||
public int countMain() {return main.size();}
|
||||
public String getMain(int index) {return main.get(index).toString();}
|
||||
public String removeMain(int index) {return main.remove(index).toString();}
|
||||
|
||||
public void addSideboard(String cardName) {sideboard.add(cardName);}
|
||||
public int countSideboard() {return sideboard.size();}
|
||||
public String getSideboard(int index) {return sideboard.get(index).toString();}
|
||||
public String removeSideboard(int index) {return sideboard.remove(index).toString();}
|
||||
|
||||
public boolean isDraft() {return isDraft;}
|
||||
public boolean isSealed() {return isSealed;}
|
||||
public boolean isRegular() {return isRegular;}
|
||||
|
||||
public int hashcode() {return getName().hashCode();}
|
||||
public String toString() {return getName();}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DeckSort implements Comparator<Object>
|
||||
{
|
||||
public int compare(Object a, Object b)
|
||||
{
|
||||
String a1 = ((Deck)a).getName();
|
||||
String b1 = ((Deck)b).getName();
|
||||
|
||||
return a1.compareTo(b1);
|
||||
}
|
||||
/**
|
||||
* The class Deck. This class is only here for compatibility with forge versions 10/17 and older. When it is read
|
||||
* from the file stream, the object is replaced with an object of type {@link Deck} using {@link #readResolve()}.
|
||||
*
|
||||
* @author Clemens Koza
|
||||
*/
|
||||
public class Deck implements Serializable {
|
||||
private static final long serialVersionUID = -2188987217361601903L;
|
||||
|
||||
private String deckType;
|
||||
|
||||
private boolean isRegular;
|
||||
private boolean isSealed;
|
||||
private boolean isDraft;
|
||||
|
||||
private ArrayList<String> main = new ArrayList<String>();
|
||||
private ArrayList<String> sideboard = new ArrayList<String>();
|
||||
|
||||
//very important, do NOT change this
|
||||
private String name = "";
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
System.out.println("resolving obsolete Deck");
|
||||
forge.Deck d = new forge.Deck(deckType);
|
||||
d.setName(name);
|
||||
for(String s:main)
|
||||
d.addMain(s);
|
||||
for(String s:sideboard)
|
||||
d.addSideboard(s);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user