Added options to disable card based deck generation and to ensure it fails gracefully if .dat data and/or decks folder is missing

This commit is contained in:
austinio7116
2018-02-26 23:54:27 +00:00
committed by maustin
parent 9cb1f2787c
commit aaf27f2d60
11 changed files with 87 additions and 34 deletions

View File

@@ -27,28 +27,38 @@ public final class CardRelationMatrixGenerator {
public static HashMap<String,HashMap<String,List<Map.Entry<PaperCard,Integer>>>> cardPools = new HashMap<>();
public static void initialize(){
HashMap<String,List<Map.Entry<PaperCard,Integer>>> standardMap = CardThemedMatrixIO.loadMatrix(FModel.getFormats().getStandard().getName());
HashMap<String,List<Map.Entry<PaperCard,Integer>>> modernMap = CardThemedMatrixIO.loadMatrix(FModel.getFormats().getModern().getName());
HashMap<String,List<Map.Entry<PaperCard,Integer>>> commanderMap = CardThemedMatrixIO.loadMatrix(DeckFormat.Commander.toString());
if(standardMap==null || modernMap==null || commanderMap==null){
reInitialize();
return;
/** Try to load matrix .dat files, otherwise check for deck folders and build .dat, otherwise return false **/
public static boolean initialize(){
String format=FModel.getFormats().getStandard().getName();
HashMap<String,List<Map.Entry<PaperCard,Integer>>> standardMap = CardThemedMatrixIO.loadMatrix(format);
if(standardMap==null&&CardThemedMatrixIO.getMatrixFolder(format).exists()){
standardMap=initializeFormat(FModel.getFormats().getStandard());
CardThemedMatrixIO.saveMatrix(format,standardMap);
}else if(standardMap==null && !CardThemedMatrixIO.getMatrixFolder(format).exists()){
return false;
}
cardPools.put(FModel.getFormats().getStandard().getName(),standardMap);
cardPools.put(FModel.getFormats().getModern().getName(),modernMap);
cardPools.put(DeckFormat.Commander.toString(),commanderMap);
}
cardPools.put(format,standardMap);
public static void reInitialize(){
cardPools.put(FModel.getFormats().getStandard().getName(),initializeFormat(FModel.getFormats().getStandard()));
cardPools.put(FModel.getFormats().getModern().getName(),initializeFormat(FModel.getFormats().getModern()));
cardPools.put(DeckFormat.Commander.toString(),initializeCommanderFormat());
for(String format:cardPools.keySet()){
HashMap<String,List<Map.Entry<PaperCard,Integer>>> map = cardPools.get(format);
CardThemedMatrixIO.saveMatrix(format,map);
format=FModel.getFormats().getModern().getName();
HashMap<String,List<Map.Entry<PaperCard,Integer>>> modernMap = CardThemedMatrixIO.loadMatrix(format);
if(modernMap==null&&CardThemedMatrixIO.getMatrixFolder(format).exists()){
modernMap=initializeFormat(FModel.getFormats().getModern());
CardThemedMatrixIO.saveMatrix(format,modernMap);
}else if (standardMap==null && !CardThemedMatrixIO.getMatrixFolder(format).exists()){
return false;
}
cardPools.put(format,modernMap);
format=DeckFormat.Commander.toString();
HashMap<String,List<Map.Entry<PaperCard,Integer>>> commanderMap = CardThemedMatrixIO.loadMatrix(format);
if(commanderMap==null&&CardThemedMatrixIO.getMatrixFolder(format).exists()){
commanderMap=initializeCommanderFormat();
CardThemedMatrixIO.saveMatrix(format,commanderMap);
}else if(standardMap==null && !CardThemedMatrixIO.getMatrixFolder(format).exists()){
return false;
}
cardPools.put(format,commanderMap);
return true;
}
public static HashMap<String,List<Map.Entry<PaperCard,Integer>>> initializeFormat(GameFormat format){

View File

@@ -30,7 +30,7 @@ public enum DeckType {
public static DeckType[] CommanderOptions;
static {
if (!FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.LOAD_CARD_SCRIPTS_LAZILY)) {
if (FModel.isdeckGenMatrixLoaded()) {
ConstructedOptions = new DeckType[]{
DeckType.CUSTOM_DECK,
DeckType.PRECONSTRUCTED_DECK,
@@ -59,7 +59,7 @@ public enum DeckType {
}
}
static {
if (!FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.LOAD_CARD_SCRIPTS_LAZILY)) {
if (FModel.isdeckGenMatrixLoaded()) {
CommanderOptions = new DeckType[]{
DeckType.COMMANDER_DECK,
DeckType.RANDOM_COMMANDER_DECK,

View File

@@ -61,6 +61,10 @@ public class CardThemedMatrixIO {
return new File(ForgeConstants.DECK_GEN_DIR, name + SUFFIX_DATA);
}
public static File getMatrixFolder(final String name) {
return new File(ForgeConstants.DECK_GEN_DIR, name);
}
public static File getMatrixFile(final GameFormat gf) {
return getMatrixFile(gf.getName());
}

View File

@@ -27,6 +27,8 @@ import forge.ai.AiProfileUtil;
import forge.card.CardPreferences;
import forge.card.CardType;
import forge.deck.CardRelationMatrixGenerator;
import forge.deck.DeckFormat;
import forge.deck.io.CardThemedMatrixIO;
import forge.deck.io.DeckPreferences;
import forge.game.GameFormat;
import forge.game.GameType;
@@ -216,11 +218,18 @@ public final class FModel {
AiProfileUtil.loadAllProfiles(ForgeConstants.AI_PROFILE_DIR);
//generate Deck Gen matrix
if(!FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY)) {
CardRelationMatrixGenerator.initialize();
if(!FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY)
&&FModel.getPreferences().getPrefBoolean(FPref.DECKGEN_CARDBASED)) {
deckGenMatrixLoaded=CardRelationMatrixGenerator.initialize();
}
}
private static boolean deckGenMatrixLoaded=false;
public static boolean isdeckGenMatrixLoaded(){
return deckGenMatrixLoaded;
}
public static QuestController getQuest() {
return quest;
}

View File

@@ -156,6 +156,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
DECKGEN_SINGLETONS ("false"),
DECKGEN_ARTIFACTS ("false"),
DECKGEN_NOSMALL ("false"),
DECKGEN_CARDBASED ("true"),
PHASE_AI_UPKEEP ("false"),
PHASE_AI_DRAW ("false"),