mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
refactored getSetCodes to be used from ExpansionReposiitory
This commit is contained in:
parent
e2152c59a2
commit
0166975e83
5 changed files with 52 additions and 72 deletions
|
@ -4,10 +4,12 @@ import mage.constants.CardType;
|
|||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.Mana;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
|
@ -28,8 +30,6 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.ExpansionSet;
|
||||
|
||||
/**
|
||||
* Generates random card pool and builds a deck.
|
||||
*
|
||||
|
@ -140,7 +140,7 @@ public class DeckGenerator {
|
|||
List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
|
||||
if (setsToUse.isEmpty()) {
|
||||
// use all
|
||||
setsToUse = CardRepository.instance.getSetCodes();
|
||||
setsToUse = ExpansionRepository.instance.getSetCodes();
|
||||
}
|
||||
|
||||
if (selectedColors.contains("X")) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import mage.cards.CardImpl;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.components.HoverButton;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
|
@ -301,7 +302,7 @@ public class MageBook extends JComponent {
|
|||
this.setsToDisplay = ConstructedFormats.getSetsByFormat(format);
|
||||
if (this.setsToDisplay.isEmpty()) {
|
||||
// display all
|
||||
this.setsToDisplay = CardRepository.instance.getSetCodes();
|
||||
this.setsToDisplay = ExpansionRepository.instance.getSetCodes();
|
||||
}
|
||||
addSetTabs();
|
||||
tabs.get(0).execute();
|
||||
|
|
|
@ -5,9 +5,8 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
|
||||
/**
|
||||
* Utility class for constructed formats (expansions and other editions).
|
||||
|
@ -16,35 +15,36 @@ import mage.cards.repository.CardRepository;
|
|||
*/
|
||||
public class ConstructedFormats {
|
||||
|
||||
private static final String[] constructedFormats = {"- All Sets", "- Standard", "- Extended", "- Modern",
|
||||
"Modern Masters",
|
||||
"* Return to Ravnica Block", "Dragon's Maze", "Gatecrash","Return to Ravnica",
|
||||
"Magic 2013", "Planechase 2012",
|
||||
"* Innistrad Block", "Avacyn Restored", "Dark Ascension", "Innistrad",
|
||||
"Magic 2012", "Commander",
|
||||
"* Scars of Mirrodin Block", "New Phyrexia", "Mirrodin Besieged", "Scars of Mirrodin", "Magic 2011",
|
||||
"* Zendikar Block", "Rise of the Eldrazi", "Worldwake", "Zendikar",
|
||||
"Magic 2010", "Planechase",
|
||||
"* Shards of Alara Block", "Alara Reborn", "Conflux", "Shards of Alara",
|
||||
"* Shadowmoor Block", "Shadowmoor", "Eventide",
|
||||
"* Lorwyn Block", "Lorwyn", "Morningtide",
|
||||
"* Time Spiral Block", "Future Sight", "Planar Chaos", "Time Spiral", "Tenth Edition",
|
||||
"* Ravnica Block", "Dissension", "Guildpact", "Ravnica: City of Guilds",
|
||||
"* Kamigawa Block", "Saviors of Kamigawa", "Betrayers of Kamigawa", "Champions of Kamigawa","Ninth Edition",
|
||||
"* Mirrodin Block", "Fifth Dawn", "Darksteel", "Mirrodin",
|
||||
"* Onslaught Block", "Scourge", "Legions", "Onslaught","Eighth Edition",
|
||||
"* Odyssey Block", "Judgment", "Torment", "Odyssey",
|
||||
"* Invasion Block", "Apocalypse", "Planeshift", "Invasion","Seventh Edition",
|
||||
"* Masquerade Block", "Prophecy", "Nemesis", "Mercadian Masques",
|
||||
"* Urza Block", "Urza's Destiny", "Urza's Legacy", "Urza's Saga", "Sixth Edition",
|
||||
"* Tempest Block", "Exodus", "Stronghold", "Tempest",
|
||||
"* Mirage Block", "Weatherlight", "Visions", "Mirage", "Fifth Edition",
|
||||
"* Ice Age Block", "Coldsnap", "Alliances", "Ice Age", "Fourth Edition",
|
||||
"Homelands","Fallen Empires","The Dark","Legends","Antiquities", "Arabian Nights",
|
||||
"Revised Edition", "Unlimited Edition", "Limited Edition Beta", "Limited Edition Alpha",
|
||||
"Guru",
|
||||
"Duel Decks: Elspeth vs. Tezzeret"
|
||||
};
|
||||
private static final String[] constructedFormats = {
|
||||
"- All Sets", "- Standard", "- Extended", "- Modern",
|
||||
"Modern Masters",
|
||||
"* Return to Ravnica Block", "Dragon's Maze", "Gatecrash", "Return to Ravnica",
|
||||
"Magic 2013", "Planechase 2012",
|
||||
"* Innistrad Block", "Avacyn Restored", "Dark Ascension", "Innistrad",
|
||||
"Magic 2012", "Commander",
|
||||
"* Scars of Mirrodin Block", "New Phyrexia", "Mirrodin Besieged", "Scars of Mirrodin", "Magic 2011",
|
||||
"* Zendikar Block", "Rise of the Eldrazi", "Worldwake", "Zendikar",
|
||||
"Magic 2010", "Planechase",
|
||||
"* Shards of Alara Block", "Alara Reborn", "Conflux", "Shards of Alara",
|
||||
"* Shadowmoor Block", "Shadowmoor", "Eventide",
|
||||
"* Lorwyn Block", "Lorwyn", "Morningtide",
|
||||
"* Time Spiral Block", "Future Sight", "Planar Chaos", "Time Spiral", "Tenth Edition",
|
||||
"* Ravnica Block", "Dissension", "Guildpact", "Ravnica: City of Guilds",
|
||||
"* Kamigawa Block", "Saviors of Kamigawa", "Betrayers of Kamigawa", "Champions of Kamigawa", "Ninth Edition",
|
||||
"* Mirrodin Block", "Fifth Dawn", "Darksteel", "Mirrodin",
|
||||
"* Onslaught Block", "Scourge", "Legions", "Onslaught", "Eighth Edition",
|
||||
"* Odyssey Block", "Judgment", "Torment", "Odyssey",
|
||||
"* Invasion Block", "Apocalypse", "Planeshift", "Invasion", "Seventh Edition",
|
||||
"* Masquerade Block", "Prophecy", "Nemesis", "Mercadian Masques",
|
||||
"* Urza Block", "Urza's Destiny", "Urza's Legacy", "Urza's Saga", "Sixth Edition",
|
||||
"* Tempest Block", "Exodus", "Stronghold", "Tempest",
|
||||
"* Mirage Block", "Weatherlight", "Visions", "Mirage", "Fifth Edition",
|
||||
"* Ice Age Block", "Coldsnap", "Alliances", "Ice Age", "Fourth Edition",
|
||||
"Homelands", "Fallen Empires", "The Dark", "Legends", "Antiquities", "Arabian Nights",
|
||||
"Revised Edition", "Unlimited Edition", "Limited Edition Beta", "Limited Edition Alpha",
|
||||
"Guru",
|
||||
"Duel Decks: Elspeth vs. Tezzeret"
|
||||
};
|
||||
|
||||
private ConstructedFormats() {
|
||||
}
|
||||
|
@ -379,9 +379,7 @@ public class ConstructedFormats {
|
|||
}
|
||||
|
||||
private static void buildLists() {
|
||||
for (String setCode : CardRepository.instance.getSetCodes()) {
|
||||
ExpansionSet set = Sets.findSet(setCode);
|
||||
|
||||
for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
|
||||
if (set.getReleaseDate().after(standardDate)) {
|
||||
standard.add(set.getCode());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mage.card.arcane;
|
||||
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.BufferedImageBuilder;
|
||||
|
@ -49,7 +50,7 @@ public class ManaSymbols {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
List<String> setCodes = CardRepository.instance.getSetCodes();
|
||||
List<String> setCodes = ExpansionRepository.instance.getSetCodes();
|
||||
for (String set : setCodes) {
|
||||
File file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET + set + "-C.jpg");
|
||||
try {
|
||||
|
@ -106,7 +107,7 @@ public class ManaSymbols {
|
|||
}
|
||||
|
||||
File file;
|
||||
for (String set : CardRepository.instance.getSetCodes()) {
|
||||
for (String set : ExpansionRepository.instance.getSetCodes()) {
|
||||
file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET_SMALL);
|
||||
if (!file.exists()) {
|
||||
break;
|
||||
|
|
|
@ -32,7 +32,6 @@ import com.j256.ormlite.dao.DaoManager;
|
|||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import java.io.File;
|
||||
|
@ -54,7 +53,8 @@ public enum CardRepository {
|
|||
instance;
|
||||
|
||||
private static final String JDBC_URL = "jdbc:sqlite:db/cards.db";
|
||||
private static final long DB_VERSION = 7;
|
||||
private static final String VERSION_ENTITY_NAME = "card";
|
||||
private static final long CARD_DB_VERSION = 7;
|
||||
|
||||
private Random random = new Random();
|
||||
private Dao<CardInfo, Object> cardDao;
|
||||
|
@ -67,16 +67,10 @@ public enum CardRepository {
|
|||
}
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
|
||||
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
|
||||
List<DatabaseVersion> dbVersions = dbVersionDao.queryForAll();
|
||||
if (dbVersions.isEmpty() || dbVersions.get(0).getVersion() != DB_VERSION) {
|
||||
boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, CARD_DB_VERSION);
|
||||
|
||||
if (obsolete) {
|
||||
TableUtils.dropTable(connectionSource, CardInfo.class, true);
|
||||
if (dbVersions.isEmpty()) {
|
||||
DatabaseVersion dbVersion = new DatabaseVersion();
|
||||
dbVersion.setVersion(DB_VERSION);
|
||||
dbVersionDao.create(dbVersion);
|
||||
}
|
||||
}
|
||||
|
||||
TableUtils.createTableIfNotExists(connectionSource, CardInfo.class);
|
||||
|
@ -123,20 +117,6 @@ public enum CardRepository {
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<String> getSetCodes() {
|
||||
List<String> setCodes = new ArrayList<String>();
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
|
||||
qb.distinct().selectColumns("setCode");
|
||||
List<CardInfo> results = cardDao.query(qb.prepare());
|
||||
for (CardInfo card : results) {
|
||||
setCodes.add(card.getSetCode());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return setCodes;
|
||||
}
|
||||
|
||||
public Set<String> getNames() {
|
||||
Set<String> names = new TreeSet<String>();
|
||||
try {
|
||||
|
@ -183,14 +163,16 @@ public enum CardRepository {
|
|||
try {
|
||||
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
|
||||
qb.distinct().selectColumns("name");
|
||||
Where where = qb.where();
|
||||
where.and(where.not().like("types", '%' + CardType.CREATURE.name() +'%'),where.not().like("types", '%' + CardType.LAND.name() + '%'));
|
||||
qb.where()
|
||||
.not().like("types", '%' + CardType.CREATURE.name() + '%')
|
||||
.and()
|
||||
.not().like("types", '%' + CardType.LAND.name() + '%');
|
||||
List<CardInfo> results = cardDao.query(qb.prepare());
|
||||
for (CardInfo card : results) {
|
||||
int result = card.getName().indexOf(" // ");
|
||||
if (result > 0) {
|
||||
names.add(card.getName().substring(0, result));
|
||||
names.add(card.getName().substring(result+4));
|
||||
names.add(card.getName().substring(result + 4));
|
||||
} else {
|
||||
names.add(card.getName());
|
||||
}
|
||||
|
@ -265,9 +247,7 @@ public enum CardRepository {
|
|||
|
||||
public List<CardInfo> getAllCards() {
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
|
||||
return cardDao.query(queryBuilder.prepare());
|
||||
return cardDao.queryForAll();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<CardInfo>();
|
||||
|
|
Loading…
Reference in a new issue