Merge branch 'customCards_Folder' into 'master'

Support loading Custom Cards & Editions from User Folder

See merge request core-developers/forge!4222
This commit is contained in:
Anthony Calosa
2021-03-20 07:28:26 +00:00
6 changed files with 75 additions and 8 deletions

View File

@@ -232,6 +232,9 @@ public final class ForgeConstants {
public static final String USER_PUZZLE_DIR = USER_DIR + "puzzle" + PATH_SEPARATOR;
public static final String LOG_FILE = USER_DIR + "forge.log";
public static final String ACHIEVEMENTS_DIR = USER_DIR + "achievements" + PATH_SEPARATOR;
public static final String USER_CUSTOM_DIR = USER_DIR + "custom" + PATH_SEPARATOR;
public static final String USER_CUSTOM_EDITIONS_DIR = USER_CUSTOM_DIR + "editions" + PATH_SEPARATOR;
public static final String USER_CUSTOM_CARDS_DIR = USER_CUSTOM_DIR + "cards" + PATH_SEPARATOR;
public static final String DECK_DRAFT_DIR = DECK_BASE_DIR + "draft" + PATH_SEPARATOR;
public static final String DECK_WINSTON_DIR = DECK_BASE_DIR + "winston" + PATH_SEPARATOR;
public static final String DECK_SEALED_DIR = DECK_BASE_DIR + "sealed" + PATH_SEPARATOR;

View File

@@ -176,7 +176,14 @@ public final class FModel {
FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY));
final CardStorageReader tokenReader = new CardStorageReader(ForgeConstants.TOKEN_DATA_DIR, progressBarBridge,
FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY));
magicDb = new StaticData(reader, tokenReader, ForgeConstants.EDITIONS_DIR, ForgeConstants.BLOCK_DATA_DIR, FModel.getPreferences().getPrefBoolean(FPref.UI_LOAD_UNKNOWN_CARDS), FModel.getPreferences().getPrefBoolean(FPref.UI_LOAD_NONLEGAL_CARDS));
CardStorageReader customReader;
try {
customReader = new CardStorageReader(ForgeConstants.USER_CUSTOM_CARDS_DIR, progressBarBridge,
FModel.getPreferences().getPrefBoolean(FPref.LOAD_CARD_SCRIPTS_LAZILY));
} catch (Exception e) {
customReader = null;
}
magicDb = new StaticData(reader, tokenReader, customReader, ForgeConstants.EDITIONS_DIR, ForgeConstants.USER_CUSTOM_EDITIONS_DIR,ForgeConstants.BLOCK_DATA_DIR, FModel.getPreferences().getPrefBoolean(FPref.UI_LOAD_UNKNOWN_CARDS), FModel.getPreferences().getPrefBoolean(FPref.UI_LOAD_NONLEGAL_CARDS));
CardTranslation.preloadTranslation(preferences.getPref(FPref.UI_LANGUAGE), ForgeConstants.LANG_DIR);
//create profile dirs if they don't already exist

View File

@@ -2580,12 +2580,18 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final CardDb carddb = FModel.getMagicDb().getCommonCards();
final List<ICardFace> faces = Lists.newArrayList(carddb.getAllFaces());
final CardDb customDb = FModel.getMagicDb().getCustomCards();
final List<ICardFace> customFaces = Lists.newArrayList(customDb.getAllFaces());
List<CardFaceView> choices = new ArrayList<>();
CardFaceView cardFaceView;
for (ICardFace cardFace : faces) {
cardFaceView = new CardFaceView(CardTranslation.getTranslatedName(cardFace.getName()), cardFace.getName());
choices.add(cardFaceView);
}
for (ICardFace cardFace : customFaces) {
cardFaceView = new CardFaceView(CardTranslation.getTranslatedName(cardFace.getName()), cardFace.getName());
choices.add(cardFaceView);
}
Collections.sort(choices);
// use standard forge's list selection dialog
@@ -2594,10 +2600,13 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return;
}
final PaperCard c = carddb.getUniqueByName(f.getOracleName());
PaperCard c = carddb.getUniqueByName(f.getOracleName());
if (c == null)
c = customDb.getUniqueByName(f.getOracleName());
final Card forgeCard = Card.fromPaperCard(c, p);
forgeCard.setTimestamp(getGame().getNextTimestamp());
PaperCard finalC = c;
getGame().getAction().invoke(new Runnable() {
@Override
public void run() {
@@ -2629,7 +2638,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
return;
}
} else {
if (c.getRules().getType().isLand()) {
if (finalC.getRules().getType().isLand()) {
// this is needed to ensure land abilities fire
getGame().getAction().moveToHand(forgeCard, null);
getGame().getAction().moveToPlay(forgeCard, null);