mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Net Deck Archive Block (Desktop & Android)
This commit is contained in:
@@ -663,6 +663,14 @@ public class DeckProxy implements InventoryItem {
|
||||
return decks;
|
||||
}
|
||||
|
||||
public static List<DeckProxy> getNetArchiveBlockecks(final NetDeckArchiveBlock category) {
|
||||
final List<DeckProxy> decks = new ArrayList<>();
|
||||
if (category != null) {
|
||||
addDecksRecursivelly("Constructed", GameType.Constructed, decks, "", category, null);
|
||||
}
|
||||
return decks;
|
||||
}
|
||||
|
||||
public static CardEdition getDefaultLandSet(Deck deck) {
|
||||
List<CardEdition> availableEditions = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ public enum DeckType {
|
||||
NET_ARCHIVE_PIONEER_DECK("lblNetArchivePioneerDecks"),
|
||||
NET_ARCHIVE_MODERN_DECK("lblNetArchiveModernDecks"),
|
||||
NET_ARCHIVE_LEGACY_DECK("lblNetArchiveLegacyDecks"),
|
||||
NET_ARCHIVE_VINTAGE_DECK("lblNetArchiveVintageDecks");
|
||||
NET_ARCHIVE_VINTAGE_DECK("lblNetArchiveVintageDecks"),
|
||||
NET_ARCHIVE_BLOCK_DECK("lblNetArchiveBlockDecks");
|
||||
|
||||
public static DeckType[] ConstructedOptions;
|
||||
public static DeckType[] CommanderOptions;
|
||||
@@ -61,7 +62,8 @@ public enum DeckType {
|
||||
DeckType.NET_ARCHIVE_PIONEER_DECK,
|
||||
DeckType.NET_ARCHIVE_MODERN_DECK,
|
||||
DeckType.NET_ARCHIVE_LEGACY_DECK,
|
||||
DeckType.NET_ARCHIVE_VINTAGE_DECK
|
||||
DeckType.NET_ARCHIVE_VINTAGE_DECK,
|
||||
DeckType.NET_ARCHIVE_BLOCK_DECK
|
||||
};
|
||||
} else {
|
||||
ConstructedOptions = new DeckType[]{
|
||||
@@ -79,7 +81,6 @@ public enum DeckType {
|
||||
DeckType.NET_ARCHIVE_MODERN_DECK,
|
||||
DeckType.NET_ARCHIVE_LEGACY_DECK,
|
||||
DeckType.NET_ARCHIVE_VINTAGE_DECK
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
122
forge-gui/src/main/java/forge/deck/NetDeckArchiveBlock.java
Normal file
122
forge-gui/src/main/java/forge/deck/NetDeckArchiveBlock.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package forge.deck;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
import forge.deck.io.DeckStorage;
|
||||
import forge.download.GuiDownloadZipService;
|
||||
import forge.game.GameType;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.WaitCallback;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
public class NetDeckArchiveBlock extends StorageBase<Deck> {
|
||||
public static final String PREFIX = "NET_ARCHIVE_BLOCK_DECK";
|
||||
private static Map<String, NetDeckArchiveBlock> constructed, commander, brawl;
|
||||
|
||||
private static Map<String, NetDeckArchiveBlock> loadCategories(String filename) {
|
||||
Map<String, NetDeckArchiveBlock> categories = new TreeMap<>();
|
||||
if (FileUtil.doesFileExist(filename)) {
|
||||
List<String> lines = FileUtil.readFile(filename);
|
||||
for (String line : lines) {
|
||||
int idx = line.indexOf('|');
|
||||
if (idx != -1) {
|
||||
String name = line.substring(0, idx).trim();
|
||||
String url = line.substring(idx + 1).trim();
|
||||
categories.put(name, new NetDeckArchiveBlock(name, url));
|
||||
}
|
||||
}
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
|
||||
public static NetDeckArchiveBlock selectAndLoad(GameType gameType) {
|
||||
return selectAndLoad(gameType, null);
|
||||
}
|
||||
public static NetDeckArchiveBlock selectAndLoad(GameType gameType, String name) {
|
||||
Map<String, NetDeckArchiveBlock> categories;
|
||||
switch (gameType) {
|
||||
case Constructed:
|
||||
case Gauntlet:
|
||||
if (constructed == null) {
|
||||
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_BLOCK_DECKS_LIST_FILE);
|
||||
}
|
||||
categories = constructed;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
NetDeckArchiveBlock category = categories.get(name);
|
||||
if (category != null && category.map.isEmpty()) {
|
||||
//if name passed in, try to load decks from current cached files
|
||||
File downloadDir = new File(category.getFullPath());
|
||||
if (downloadDir.exists()) {
|
||||
for (File file : downloadDir.listFiles(DeckStorage.DCK_FILE_FILTER)) {
|
||||
Deck deck = DeckSerializer.fromFile(file);
|
||||
if (deck != null) {
|
||||
category.map.put(deck.getName(), deck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return category;
|
||||
}
|
||||
|
||||
final NetDeckArchiveBlock c = SGuiChoose.oneOrNone("Select a Net Deck Archive Block category", categories.values());
|
||||
if (c == null) { return null; }
|
||||
|
||||
if (c.map.isEmpty()) { //only download decks once per session
|
||||
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
|
||||
@Override
|
||||
public void run() {
|
||||
String downloadLoc = c.getFullPath();
|
||||
GuiBase.getInterface().download(new GuiDownloadZipService(c.getName(), "decks", c.getUrl(), downloadLoc, downloadLoc, null) {
|
||||
@Override
|
||||
protected void copyInputStream(InputStream in, String outPath) throws IOException {
|
||||
super.copyInputStream(in, outPath);
|
||||
|
||||
Deck deck = DeckSerializer.fromFile(new File(outPath));
|
||||
if (deck != null) {
|
||||
c.map.put(deck.getName(), deck);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
};
|
||||
if (!callback.invokeAndWait()) { return null; } //wait for download to finish
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private final String url;
|
||||
|
||||
private NetDeckArchiveBlock(String name0, String url0) {
|
||||
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, new HashMap<>());
|
||||
url = url0;
|
||||
}
|
||||
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getDeckType() {
|
||||
return "Net Archive Block Decks - " + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,8 @@ public enum ItemManagerConfig {
|
||||
null, null, 3, 0),
|
||||
NET_ARCHIVE_VINTAGE_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,
|
||||
null, null, 3, 0),
|
||||
NET_ARCHIVE_BLOCK_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,
|
||||
null, null, 3, 0),
|
||||
SIDEBOARD(SColumnUtil.getDeckEditorDefaultColumns(), false, false, true,
|
||||
GroupDef.DEFAULT, ColumnDef.CMC, 3, 0);
|
||||
|
||||
|
||||
@@ -54,8 +54,9 @@ public final class ForgeConstants {
|
||||
public static final String NET_ARCHIVE_STANDARD_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-standard.txt";
|
||||
public static final String NET_ARCHIVE_PIONEER_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-pioneer.txt";
|
||||
public static final String NET_ARCHIVE_MODERN_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-modern.txt";
|
||||
public static final String NET_ARCHIVE_LEGACY_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-legacy.txt";
|
||||
public static final String NET_ARCHIVE_LEGACY_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-legacy.txt";
|
||||
public static final String NET_ARCHIVE_VINTAGE_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-vintage.txt";
|
||||
public static final String NET_ARCHIVE_BLOCK_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-block.txt";
|
||||
|
||||
|
||||
public static final String CHANGES_FILE = ASSETS_DIR + "README.txt";
|
||||
|
||||
Reference in New Issue
Block a user