Merge branch 'master' into 'master'

New Net Deck Category: Deck Standard Archive

See merge request core-developers/forge!3940
This commit is contained in:
Michael Kamensky
2021-02-20 08:15:16 +00:00
13 changed files with 2560 additions and 7 deletions

View File

@@ -43,6 +43,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
private DeckType selectedDeckType;
private ItemManagerContainer lstDecksContainer;
private NetDeckCategory netDeckCategory;
private NetDeckArchiveStandard NetDeckArchiveStandard;
private boolean refreshingDeckType;
private boolean isForCommander;
@@ -262,6 +263,13 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
updateDecks(DeckProxy.getNetDecks(netDeckCategory), ItemManagerConfig.NET_DECKS);
}
private void updateNetArchiveDecks() {
if (NetDeckArchiveStandard != null) {
decksComboBox.setText(NetDeckArchiveStandard.getDeckType());
}
updateDecks(DeckProxy.getNetArchiveDecks(NetDeckArchiveStandard), ItemManagerConfig.NET_DECKS);
}
public Deck getDeck() {
final DeckProxy proxy = lstDecks.getSelectedItem();
if (proxy == null) {
@@ -318,7 +326,33 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
@Override
public void deckTypeSelected(final DecksComboBoxEvent ev) {
if ((ev.getDeckType() == DeckType.NET_DECK || ev.getDeckType() == DeckType.NET_COMMANDER_DECK) && !refreshingDeckType) {
if (ev.getDeckType() == DeckType.NET_ARCHIVE_STANDARD_DECK&& !refreshingDeckType) {
if(lstDecks.getGameType() != GameType.Constructed)
return;
FThreads.invokeInBackgroundThread(new Runnable() { //needed for loading net decks
@Override
public void run() {
final NetDeckArchiveStandard category = NetDeckArchiveStandard.selectAndLoad(lstDecks.getGameType());
FThreads.invokeInEdtLater(new Runnable() {
@Override
public void run() {
if (category == null) {
decksComboBox.setDeckType(selectedDeckType); //restore old selection if user cancels
if (selectedDeckType == DeckType.NET_ARCHIVE_STANDARD_DECK && NetDeckArchiveStandard != null) {
decksComboBox.setText(NetDeckArchiveStandard.getDeckType());
}
return;
}
NetDeckArchiveStandard = category;
refreshDecksList(ev.getDeckType(), true, ev);
}
});
}
});
return;
} else if ((ev.getDeckType() == DeckType.NET_DECK || ev.getDeckType() == DeckType.NET_COMMANDER_DECK) && !refreshingDeckType) {
FThreads.invokeInBackgroundThread(new Runnable() { //needed for loading net decks
@Override
public void run() {
@@ -436,6 +470,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
case NET_COMMANDER_DECK:
updateNetDecks();
break;
case NET_ARCHIVE_STANDARD_DECK:
updateNetArchiveDecks();
break;
default:
break; //other deck types not currently supported here
}
@@ -453,7 +490,10 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
private String getState() {
final StringBuilder state = new StringBuilder();
if (decksComboBox.getDeckType() == null || decksComboBox.getDeckType() == DeckType.NET_DECK) {
if (decksComboBox.getDeckType() == DeckType.NET_ARCHIVE_STANDARD_DECK) {
if (NetDeckArchiveStandard == null) { return ""; }
state.append(NetDeckArchiveStandard.PREFIX).append(NetDeckArchiveStandard.getName());
} else if (decksComboBox.getDeckType() == null || decksComboBox.getDeckType() == DeckType.NET_DECK) {
//handle special case of net decks
if (netDeckCategory == null) { return ""; }
state.append(NetDeckCategory.PREFIX).append(netDeckCategory.getName());
@@ -506,6 +546,9 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
if (deckType.startsWith(NetDeckCategory.PREFIX)) {
netDeckCategory = NetDeckCategory.selectAndLoad(lstDecks.getGameType(), deckType.substring(NetDeckCategory.PREFIX.length()));
return DeckType.NET_DECK;
} else if (deckType.startsWith(NetDeckArchiveStandard.PREFIX)) {
NetDeckArchiveStandard = NetDeckArchiveStandard.selectAndLoad(lstDecks.getGameType(), deckType.substring(NetDeckArchiveStandard.PREFIX.length()));
return DeckType.NET_ARCHIVE_STANDARD_DECK;
}
return DeckType.valueOf(deckType);
}

View File

@@ -584,6 +584,7 @@ lblRandomThemeDecks=Decks - zufälliges Thema
lblRandomDecks=zufälliges Deck
lblNetDecks=Decks aus dem Netz
lblNetCommanderDecks=Commanderdecks aus dem Netz
lblNetArchiveStandardDecks=Net Archive Standard Decks
#VSubmenuTutorial
lblTutorial=Tutorial
lblTutorialMode=Tutorial Mode

View File

@@ -584,6 +584,7 @@ lblRandomThemeDecks=Random Theme Decks
lblRandomDecks=Random Decks
lblNetDecks=Net Decks
lblNetCommanderDecks=Net Commander Decks
lblNetArchiveStandardDecks=Net Archive Standard Decks
#VSubmenuTutorial
lblTutorial=Tutorial
lblTutorialMode=Tutorial Mode

View File

@@ -584,6 +584,7 @@ lblRandomThemeDecks=Mazos Aleatorios Temáticos
lblRandomDecks=Mazos Aleatorios
lblNetDecks=Mazos en Línea
lblNetCommanderDecks=Mazos Commander en línea
lblNetArchiveStandardDecks=Net Archive Standard Decks
#VSubmenuTutorial
lblTutorial=Tutorial
lblTutorialMode=Tutorial Mode

View File

@@ -584,6 +584,7 @@ lblRandomThemeDecks=Mazzi tematici casuali
lblRandomDecks=Mazzi casuali
lblNetDecks=Net Decks
lblNetCommanderDecks=Mazzi Net Commander
lblNetArchiveDecks=Net Archive Standard Decks
#VSubmenuTutorial
lblTutorial=Tutorial
lblTutorialMode=Tutorial Mode

View File

@@ -584,6 +584,7 @@ lblRandomThemeDecks=ランダムテーマデッキ
lblRandomDecks=ランダムデッキ
lblNetDecks=ネットデッキ
lblNetCommanderDecks=ネット統率者デッキ
lblNetArchiveStandardDecks=Net Archive Decks
#VSubmenuTutorial
lblTutorial=チュートリアル
lblTutorialMode=チュートリアルモード

View File

@@ -35,7 +35,6 @@ lblQuestDeckEditor=冒险套牌编辑器
lblQuestTournamentDeckEditor=冒险比赛套牌编辑器
lblSpellShop=卡牌商店
lblLeaveShop=离开商店
lblLeaveDraft=离开轮抓
lblBazaar=珍宝集市
lblConcedeGame=这场游戏认输
txerrFailedtodeletelayoutfile=删除布局文件失败。
@@ -584,6 +583,7 @@ lblRandomThemeDecks=随机主题套牌
lblRandomDecks=随机套牌
lblNetDecks=网络套牌
lblNetCommanderDecks=网络指挥官套牌
lblNetArchiveStandardDecks=Net Archive Standard Decks
#VSubmenuTutorial
lblTutorial=教程
lblTutorialMode=教程模式
@@ -1232,7 +1232,6 @@ lblSelectNCardsToDiscardUnlessDiscarduType=选择要丢弃的%d张牌除非
lblCleanupPhase=清除步骤
lblSelectCardsToDiscardHandDownMaximum=选择要丢弃的{0}张牌,以使你的手牌数量减少到{1}张。
lblChooseMinCardToDiscard=选择%d张牌弃掉
lblDiscarded=弃牌
lblChooseDamageOrderFor=选择{0}造成伤害的顺序
lblDamagedFirst=先造成伤害
lblChooseBlockerAfterWhichToPlaceAttackert=选择{0}后造成伤害的阻挡者; cancel to place it first

File diff suppressed because it is too large Load Diff

View File

@@ -624,6 +624,14 @@ public class DeckProxy implements InventoryItem {
return decks;
}
public static List<DeckProxy> getNetArchiveDecks(final NetDeckArchiveStandard 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

@@ -30,7 +30,8 @@ public enum DeckType {
THEME_DECK("lblRandomThemeDecks"),
RANDOM_DECK("lblRandomDecks"),
NET_DECK("lblNetDecks"),
NET_COMMANDER_DECK("lblNetCommanderDecks");
NET_COMMANDER_DECK("lblNetCommanderDecks"),
NET_ARCHIVE_STANDARD_DECK("lblNetArchiveStandardDecks");
public static DeckType[] ConstructedOptions;
public static DeckType[] CommanderOptions;
@@ -51,7 +52,8 @@ public enum DeckType {
DeckType.MODERN_COLOR_DECK,
DeckType.THEME_DECK,
DeckType.RANDOM_DECK,
DeckType.NET_DECK
DeckType.NET_DECK,
DeckType.NET_ARCHIVE_STANDARD_DECK
};
} else {
ConstructedOptions = new DeckType[]{
@@ -63,7 +65,8 @@ public enum DeckType {
DeckType.MODERN_COLOR_DECK,
DeckType.THEME_DECK,
DeckType.RANDOM_DECK,
DeckType.NET_DECK
DeckType.NET_DECK,
DeckType.NET_ARCHIVE_STANDARD_DECK
};
}
}

View File

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

View File

@@ -50,6 +50,7 @@ public final class ForgeConstants {
public static final String NET_DECKS_BRAWL_LIST_FILE = LISTS_DIR + "net-decks-brawl.txt";
public static final String BORDERLESS_CARD_LIST_FILE = LISTS_DIR + "borderlessCardList.txt";
public static final String SKINS_LIST_FILE = LISTS_DIR + "skinsList.txt";
public static final String NET_ARCHIVE_STANDARD_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-standard.txt";
public static final String CHANGES_FILE = ASSETS_DIR + "README.txt";
@@ -234,6 +235,7 @@ public final class ForgeConstants {
public static final String COMMANDER_PRECON_DIR = QUEST_DIR + "commanderprecons" + PATH_SEPARATOR;
public static final String DECK_OATHBREAKER_DIR = DECK_BASE_DIR + "oathbreaker" + PATH_SEPARATOR;
public static final String DECK_NET_DIR = DECK_BASE_DIR + "net" + PATH_SEPARATOR;
public static final String DECK_NET_ARCHIVE_DIR = DECK_BASE_DIR + "archive" + PATH_SEPARATOR;
public static final String QUEST_SAVE_DIR = USER_QUEST_DIR + "saves" + PATH_SEPARATOR;
public static final String CONQUEST_SAVE_DIR = USER_CONQUEST_DIR + "saves" + PATH_SEPARATOR;
public static final String DECK_TINY_LEADERS_DIR= DECK_BASE_DIR + "tiny_leaders" + PATH_SEPARATOR;

View File

@@ -293,6 +293,12 @@
<artifactId>wagon-ftp</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.sipgate</groupId>
<artifactId>mp3-wav</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
</plugin>