Net Deck Archive Vintage (Desktop implementation)

This commit is contained in:
Churrufli
2021-03-02 09:24:10 +01:00
parent 043e767c79
commit f02a3c8786
12 changed files with 1544 additions and 9 deletions

View File

@@ -655,6 +655,14 @@ public class DeckProxy implements InventoryItem {
return decks;
}
public static List<DeckProxy> getNetArchiveVintageDecks(final NetDeckArchiveVintage 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<>();

View File

@@ -34,7 +34,8 @@ public enum DeckType {
NET_ARCHIVE_STANDARD_DECK("lblNetArchiveStandardDecks"),
NET_ARCHIVE_PIONEER_DECK("lblNetArchivePioneerDecks"),
NET_ARCHIVE_MODERN_DECK("lblNetArchiveModernDecks"),
NET_ARCHIVE_LEGACY_DECK("lblNetArchiveLegacyDecks");
NET_ARCHIVE_LEGACY_DECK("lblNetArchiveLegacyDecks"),
NET_ARCHIVE_VINTAGE_DECK("lblNetArchiveVintageDecks");
public static DeckType[] ConstructedOptions;
public static DeckType[] CommanderOptions;
@@ -59,8 +60,8 @@ public enum DeckType {
DeckType.NET_ARCHIVE_STANDARD_DECK,
DeckType.NET_ARCHIVE_PIONEER_DECK,
DeckType.NET_ARCHIVE_MODERN_DECK,
DeckType.NET_ARCHIVE_LEGACY_DECK
DeckType.NET_ARCHIVE_LEGACY_DECK,
DeckType.NET_ARCHIVE_VINTAGE_DECK
};
} else {
ConstructedOptions = new DeckType[]{
@@ -74,8 +75,11 @@ public enum DeckType {
DeckType.RANDOM_DECK,
DeckType.NET_DECK,
DeckType.NET_ARCHIVE_STANDARD_DECK,
DeckType.NET_ARCHIVE_PIONEER_DECK,
DeckType.NET_ARCHIVE_MODERN_DECK,
DeckType.NET_ARCHIVE_PIONEER_DECK
DeckType.NET_ARCHIVE_LEGACY_DECK,
DeckType.NET_ARCHIVE_VINTAGE_DECK
};
}
}

View 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 NetDeckArchiveVintage extends StorageBase<Deck> {
public static final String PREFIX = "NET_ARCHIVE_VINTAGE_DECK";
private static Map<String, NetDeckArchiveVintage> constructed, commander, brawl;
private static Map<String, NetDeckArchiveVintage> loadCategories(String filename) {
Map<String, NetDeckArchiveVintage> 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 NetDeckArchiveVintage(name, url));
}
}
}
return categories;
}
public static NetDeckArchiveVintage selectAndLoad(GameType gameType) {
return selectAndLoad(gameType, null);
}
public static NetDeckArchiveVintage selectAndLoad(GameType gameType, String name) {
Map<String, NetDeckArchiveVintage> categories;
switch (gameType) {
case Constructed:
case Gauntlet:
if (constructed == null) {
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_VINTAGE_DECKS_LIST_FILE);
}
categories = constructed;
break;
default:
return null;
}
if (name != null) {
NetDeckArchiveVintage 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 NetDeckArchiveVintage c = SGuiChoose.oneOrNone("Select a Net Deck Archive Vintage 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 NetDeckArchiveVintage(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 Vintage Decks - " + name;
}
@Override
public String toString() {
return name;
}
}

View File

@@ -54,6 +54,8 @@ public final class ForgeConstants {
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_VINTAGE_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-vintage.txt";
public static final String CHANGES_FILE = ASSETS_DIR + "README.txt";
public static final String CHANGES_FILE_NO_RELEASE = ASSETS_DIR + "CHANGES.txt";